From a5c0ab54cc6e35955b7e662a29023aaa6e2b59e0 Mon Sep 17 00:00:00 2001 From: YeMingfei666 <1619116647@qq.com> Date: Wed, 16 Oct 2024 14:14:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E5=85=AC=E5=85=B1=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=9D=E5=AD=98=E5=91=98=E5=B7=A5=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=BF=9D=E5=AD=98=E5=95=86=E6=88=B7=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commons/style/common.scss | 4 ++++ commons/utils/format.js | 5 +++-- commons/utils/safe-bottom.js | 26 ++++++++++++++++++++++++++ commons/utils/storageManage.js | 12 +++++++----- 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 commons/utils/safe-bottom.js diff --git a/commons/style/common.scss b/commons/style/common.scss index 1c5f255..5afbff7 100644 --- a/commons/style/common.scss +++ b/commons/style/common.scss @@ -392,4 +392,8 @@ text { // } .line-th{ text-decoration: line-through; +} +//覆盖u-view-plus 颜色 +.u-primary-light { + color: $my-main-color; } \ No newline at end of file diff --git a/commons/utils/format.js b/commons/utils/format.js index f8f915f..f3d5d0a 100644 --- a/commons/utils/format.js +++ b/commons/utils/format.js @@ -7,9 +7,10 @@ * @param {Boolean} returnIsArea - 是否返回值符合范围区间,默认为false。 * @returns {number} - 返回格式化后的价格,如果超出范围则返回最小值或最大值。 */ -export const formatPrice = (price,min=-Infinity, max = 100000000,returnIsArea=false ) => { +export const formatPrice = (price,min=-Infinity, max = 100000000,returnIsArea=false,isRerturnNullString=false) => { + if(price === undefined || price === null||price===''){ - return 0 + return isRerturnNullString?'':0 } // 将价格转换为浮点数并保留两位小数 const newval = parseFloat((Math.floor(price * 100) / 100).toFixed(2)) diff --git a/commons/utils/safe-bottom.js b/commons/utils/safe-bottom.js new file mode 100644 index 0000000..c8ed07d --- /dev/null +++ b/commons/utils/safe-bottom.js @@ -0,0 +1,26 @@ +import { + getCurrentInstance, +} from 'vue'; +export function getElRect(elClass, dataVal) { + const instance = getCurrentInstance(); + return new Promise((resolve, reject) => { + const query = uni.createSelectorQuery().in(instance.proxy); + query.select('.' + elClass).fields({ + size: true + }, res => { + // 如果节点尚未生成,res值为null,循环调用执行 + if (!res) { + setTimeout(() => { + getElRect(elClass); + }, 10); + return; + } + resolve(res); + }).exec(); + }) +} + +export async function getSafeBottomHeight(className, height = 16) { + const bottomEle = await getElRect(className) + return bottomEle.height + height +} \ No newline at end of file diff --git a/commons/utils/storageManage.js b/commons/utils/storageManage.js index bade3e4..690d214 100644 --- a/commons/utils/storageManage.js +++ b/commons/utils/storageManage.js @@ -18,24 +18,26 @@ const appCache = { const model = { setLogin(res){ + const user=res.user.user uni.setStorageSync('logoutHandle',false) uni.setStorageSync('shopId', res.shopId) uni.setStorageSync('shopName',res.shopName) uni.setStorageSync('logo',res.logo) uni.setStorageSync('loginType',res.loginType) - uni.setStorageSync('shopUserId',res.user.user.id) + uni.setStorageSync('shopUserId',user.id) + if(res.loginType=='staff'){ + uni.setStorageSync('merchantName',user.createBy||user.updateBy) + } }, // 退出清空所有的缓存数据。 (不包含 环境相关) cleanByLogout: () => { - // 1. 清空app级别缓存。 Object.keys(appCache).forEach(k => appCache[k] = null) - + const merchantName=uni.getStorageSync('merchantName') let envName = model.env() // 获取到当前的环境变量 uni.clearStorageSync() // 清除所有的缓存信息 + uni.setStorageSync('merchantName',merchantName) model.env(envName) // 重置env - - }, // 获取和放置token