From 2b15dc578c6e8f225732ab1f14c9786fdd213eaf Mon Sep 17 00:00:00 2001 From: czm <2192718639@qq.com> Date: Sun, 31 Jul 2022 16:20:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf(=E5=85=BC=E5=AE=B9=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E9=93=BE=E6=8E=A5=E5=B8=A6http=E6=83=85=E5=86=B5):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/fotmat.js | 196 ++++++++++++++++++++------------------ src/pages/order/index.tsx | 16 +++- 2 files changed, 115 insertions(+), 97 deletions(-) diff --git a/src/common/fotmat.js b/src/common/fotmat.js index 5e72052..7a1acf0 100644 --- a/src/common/fotmat.js +++ b/src/common/fotmat.js @@ -1,29 +1,28 @@ -import { IMG_CND_Prefix } from "./constant"; +import { IMG_CND_Prefix } from './constant' /** * 移除井号 - * @param {String} val code 编码 - * @returns + * @param {String} val code 编码 + * @returns */ -export const formatRemoveHashTag = (val = "") => { - // console.log('移除标签',val,val.endsWith("#")); - return val.endsWith("#") ? val.replace("#", "") : val; -}; - +export const formatRemoveHashTag = (val = '') => { + // console.log('移除标签',val,val.endsWith("#")); + return val.endsWith('#') ? val.replace('#', '') : val +} /** * 格式化编码+名称显示方式 * @param {String} code 编码 * @param {String} name 名称 * @param {*} mode 模式 both:code + 名称 name: 仅显示名称 - * @returns + * @returns */ -export const formatHashTag = (code = "", name = "", mode = "both") => { - if (mode == 'both') { - return `${formatRemoveHashTag(code)}# ${name}` - } else if (mode == 'name') { - return `${name}` - } +export const formatHashTag = (code = '', name = '', mode = 'both') => { + if (mode == 'both') { + return `${formatRemoveHashTag(code)}# ${name}` + } else if (mode == 'name') { + return `${name}` + } } const Digit = 10 * 10 @@ -35,141 +34,150 @@ export const weightDigit = 1000 /** * 除以 - * @param {*} val - * @param {*} digit - * @param {*} priceStatus //是否显示千位分割 - * @returns + * @param {*} val + * @param {*} digit + * @param {*} priceStatus //是否显示千位分割 + * @returns */ export const formatPriceDiv = (val, digit = Digit, priceStatus = false) => { - let res = strip(Number(val / digit)) || 0 - return priceStatus?numberWithCommas({number: res}):res + let res = strip(Number(val / digit)) || 0 + return priceStatus ? numberWithCommas({ number: res }) : res } /** * 乘以 - * @param {*} val - * @param {*} digit - * @returns + * @param {*} val + * @param {*} digit + * @returns */ export const formatPriceMul = (val, digit = Digit) => { - return strip(Number(val * digit)) || 0 + return strip(Number(val * digit)) || 0 } /** * 格式化重量单位 (乘以) - * @param {Number} val - * @returns + * @param {Number} val + * @returns */ export const formatWeightMul = (val, digit = weightDigit) => { - return strip(Number(val * digit)) || 0 + return strip(Number(val * digit)) || 0 } /** * 格式化重量单位 (除以) - * @param {*} val + * @param {*} val */ export const formatWeightDiv = (val, digit = weightDigit) => { - return strip(Number(val / digit)) || 0 + return strip(Number(val / digit)) || 0 } -export const formatDateTime = (val, fmt = "YYYY-MM-DD HH:mm:ss") => { - if (val) { - let time = new Date(val) - let Y = time.getFullYear() - let M = time.getMonth() + 1 - let d = time.getDate() - let h = time.getHours() - let m = time.getMinutes() - let s = time.getSeconds() +export const formatDateTime = (val, fmt = 'YYYY-MM-DD HH:mm:ss') => { + if (val) { + let time = new Date(val) + let Y = time.getFullYear() + let M = time.getMonth() + 1 + let d = time.getDate() + let h = time.getHours() + let m = time.getMinutes() + let s = time.getSeconds() - fmt = fmt.replace('YYYY', Y).replace('MM', M.toString().padStart(2, '0')).replace('DD', d.toString().padStart(2, '0')).replace('HH', h.toString().padStart(2, '0')).replace('mm', m.toString().padStart(2, '0')).replace('ss', s.toString().padStart(2, '0')) - - return fmt - } else { - return val - } + fmt = fmt + .replace('YYYY', Y) + .replace('MM', M.toString().padStart(2, '0')) + .replace('DD', d.toString().padStart(2, '0')) + .replace('HH', h.toString().padStart(2, '0')) + .replace('mm', m.toString().padStart(2, '0')) + .replace('ss', s.toString().padStart(2, '0')) + return fmt + } else { + return val + } } /** * 精度 - * @param {*} num - * @param {*} precision - * @returns + * @param {*} num + * @param {*} precision + * @returns */ export const strip = (num, precision = 12) => { - return +parseFloat(num.toPrecision(precision)); + return +parseFloat(num.toPrecision(precision)) } /** * 转换金额单位 * @param {*} num 金额 / 数值 * @param {*} digit 转换单位 - * @returns + * @returns */ export const formatMillionYuan = (num, digit = 10000) => { - return num / digit > 1 ? { num: toDecimal2(num / digit), million: true } : { num, million: false } + return num / digit > 1 ? { num: toDecimal2(num / digit), million: true } : { num, million: false } } /** * 数值保留两位小数 - * @param {*} x - * @returns + * @param {*} x + * @returns */ export const toDecimal2 = (x) => { - var f = parseFloat(x); - if (isNaN(f)) { - return 0; + var f = parseFloat(x) + if (isNaN(f)) { + return 0 + } + f = f + '' + let index = f.lastIndexOf('.') + if (index >= 0) { + let decimal = f.substring(index + 1) + if (decimal.length == 1) { + f = f.substring(0, index + 1) + decimal + '0' + } else { + f = f.substring(0, index + 1) + decimal.substring(0, 2) } - f = f + ""; - let index = f.lastIndexOf('.'); - if (index >= 0) { - let decimal = f.substring(index + 1); - if (decimal.length == 1) { - f = f.substring(0, index + 1) + decimal + "0"; - } else { - f = f.substring(0, index + 1) + decimal.substring(0, 2); - } - } - return f; + } + return f } /** * 格式化图片路径 - * @param {*} url + * @param {*} url * @status true|false - * @returns + * @returns */ -export const formatImgUrl = (url ,suffix="!w200") => { - return url? IMG_CND_Prefix +url + suffix:IMG_CND_Prefix +'/mall/no_img.png' +export const formatImgUrl = (url, suffix = '!w200') => { + if (url) { + return url.includes('http') ? url + suffix : IMG_CND_Prefix + url + suffix + } else { + return IMG_CND_Prefix + '/mall/no_img.png' + } } /** - * - * @param {纹理图} imgurl - * @param {rgb} rgb - * @param {} suffix + * + * @param {纹理图} imgurl + * @param {rgb} rgb + * @param {} suffix * @returns 1 有纹理图,2 有rgb 3默认图 */ -export const isLabImage = (imgurl, rgb, suffix="!w200") => { - if(imgurl) { - return {status:1, value: IMG_CND_Prefix+'/'+imgurl+suffix} - } else if(rgb.r != 0 || rgb.g != 0 || rgb.b != 0) { - return {status:2, value: rgb} - } else { - return {status:3, value: IMG_CND_Prefix+'/mall/no_img.png'} - } +export const isLabImage = (imgurl, rgb, suffix = '!w200') => { + if (imgurl) { + return { status: 1, value: IMG_CND_Prefix + '/' + imgurl + suffix } + } else if (rgb.r != 0 || rgb.g != 0 || rgb.b != 0) { + return { status: 2, value: rgb } + } else { + return { status: 3, value: IMG_CND_Prefix + '/mall/no_img.png' } + } } /** - * - * @param {千位分割付} number - * @returns + * + * @param {千位分割付} number + * @returns */ -export const numberWithCommas = ({number = 0, digit = 2}) => { - if(!isNaN(Number(number))) { - // return parseFloat(number).toFixed(digit).replace(/^\B(? { + if (!isNaN(Number(number))) { + // return parseFloat(number).toFixed(digit).replace(/^\B(? { return ( - {(orderDetail?.status != SaleorderstatusWaitingPrePayment.value && ) || } + {(orderDetail?.status != SaleorderstatusWaitingPrePayment.value && ) || ( + + )} - + @@ -310,7 +318,9 @@ export default () => { 订单备注 - {(orderRemark && {orderDetail?.remark}) || 填写备注} + {(orderRemark && {orderDetail?.remark}) || ( + 填写备注 + )} {orderDetail?.status != SaleOrderStatusCancel.value && (