🎈 perf(兼容图片链接带http情况):

This commit is contained in:
czm 2022-07-31 16:20:55 +08:00
parent 9af19370ac
commit 2b15dc578c
2 changed files with 115 additions and 97 deletions

View File

@ -1,15 +1,14 @@
import { IMG_CND_Prefix } from "./constant"; import { IMG_CND_Prefix } from './constant'
/** /**
* 移除井号 * 移除井号
* @param {String} val code 编码 * @param {String} val code 编码
* @returns * @returns
*/ */
export const formatRemoveHashTag = (val = "") => { export const formatRemoveHashTag = (val = '') => {
// console.log('移除标签',val,val.endsWith("#")); // console.log('移除标签',val,val.endsWith("#"));
return val.endsWith("#") ? val.replace("#", "") : val; return val.endsWith('#') ? val.replace('#', '') : val
}; }
/** /**
* 格式化编码+名称显示方式 * 格式化编码+名称显示方式
@ -18,7 +17,7 @@ export const formatRemoveHashTag = (val = "") => {
* @param {*} mode 模式 both:code + 名称 name: 仅显示名称 * @param {*} mode 模式 both:code + 名称 name: 仅显示名称
* @returns * @returns
*/ */
export const formatHashTag = (code = "", name = "", mode = "both") => { export const formatHashTag = (code = '', name = '', mode = 'both') => {
if (mode == 'both') { if (mode == 'both') {
return `${formatRemoveHashTag(code)}# ${name}` return `${formatRemoveHashTag(code)}# ${name}`
} else if (mode == 'name') { } else if (mode == 'name') {
@ -42,7 +41,7 @@ export const weightDigit = 1000
*/ */
export const formatPriceDiv = (val, digit = Digit, priceStatus = false) => { export const formatPriceDiv = (val, digit = Digit, priceStatus = false) => {
let res = strip(Number(val / digit)) || 0 let res = strip(Number(val / digit)) || 0
return priceStatus?numberWithCommas({number: res}):res return priceStatus ? numberWithCommas({ number: res }) : res
} }
/** /**
* 乘以 * 乘以
@ -71,7 +70,7 @@ 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") => { export const formatDateTime = (val, fmt = 'YYYY-MM-DD HH:mm:ss') => {
if (val) { if (val) {
let time = new Date(val) let time = new Date(val)
let Y = time.getFullYear() let Y = time.getFullYear()
@ -81,13 +80,18 @@ export const formatDateTime = (val, fmt = "YYYY-MM-DD HH:mm:ss") => {
let m = time.getMinutes() let m = time.getMinutes()
let s = time.getSeconds() 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')) 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 return fmt
} else { } else {
return val return val
} }
} }
/** /**
@ -97,7 +101,7 @@ export const formatDateTime = (val, fmt = "YYYY-MM-DD HH:mm:ss") => {
* @returns * @returns
*/ */
export const strip = (num, precision = 12) => { export const strip = (num, precision = 12) => {
return +parseFloat(num.toPrecision(precision)); return +parseFloat(num.toPrecision(precision))
} }
/** /**
@ -116,21 +120,21 @@ export const formatMillionYuan = (num, digit = 10000) => {
* @returns * @returns
*/ */
export const toDecimal2 = (x) => { export const toDecimal2 = (x) => {
var f = parseFloat(x); var f = parseFloat(x)
if (isNaN(f)) { if (isNaN(f)) {
return 0; return 0
} }
f = f + ""; f = f + ''
let index = f.lastIndexOf('.'); let index = f.lastIndexOf('.')
if (index >= 0) { if (index >= 0) {
let decimal = f.substring(index + 1); let decimal = f.substring(index + 1)
if (decimal.length == 1) { if (decimal.length == 1) {
f = f.substring(0, index + 1) + decimal + "0"; f = f.substring(0, index + 1) + decimal + '0'
} else { } else {
f = f.substring(0, index + 1) + decimal.substring(0, 2); f = f.substring(0, index + 1) + decimal.substring(0, 2)
} }
} }
return f; return f
} }
/** /**
@ -139,8 +143,12 @@ export const toDecimal2 = (x) => {
* @status true|false * @status true|false
* @returns * @returns
*/ */
export const formatImgUrl = (url ,suffix="!w200") => { export const formatImgUrl = (url, suffix = '!w200') => {
return url? IMG_CND_Prefix +url + suffix:IMG_CND_Prefix +'/mall/no_img.png' if (url) {
return url.includes('http') ? url + suffix : IMG_CND_Prefix + url + suffix
} else {
return IMG_CND_Prefix + '/mall/no_img.png'
}
} }
/** /**
@ -150,13 +158,13 @@ export const formatImgUrl = (url ,suffix="!w200") => {
* @param {} suffix * @param {} suffix
* @returns 1 有纹理图2 有rgb 3默认图 * @returns 1 有纹理图2 有rgb 3默认图
*/ */
export const isLabImage = (imgurl, rgb, suffix="!w200") => { export const isLabImage = (imgurl, rgb, suffix = '!w200') => {
if(imgurl) { if (imgurl) {
return {status:1, value: IMG_CND_Prefix+'/'+imgurl+suffix} return { status: 1, value: IMG_CND_Prefix + '/' + imgurl + suffix }
} else if(rgb.r != 0 || rgb.g != 0 || rgb.b != 0) { } else if (rgb.r != 0 || rgb.g != 0 || rgb.b != 0) {
return {status:2, value: rgb} return { status: 2, value: rgb }
} else { } else {
return {status:3, value: IMG_CND_Prefix+'/mall/no_img.png'} return { status: 3, value: IMG_CND_Prefix + '/mall/no_img.png' }
} }
} }
@ -165,11 +173,11 @@ export const isLabImage = (imgurl, rgb, suffix="!w200") => {
* @param {千位分割付} number * @param {千位分割付} number
* @returns * @returns
*/ */
export const numberWithCommas = ({number = 0, digit = 2}) => { export const numberWithCommas = ({ number = 0, digit = 2 }) => {
if(!isNaN(Number(number))) { if (!isNaN(Number(number))) {
// return parseFloat(number).toFixed(digit).replace(/^\B(?<!\.\d*)(?=(\d{3})+(?!\d))$/g, ","); // return parseFloat(number).toFixed(digit).replace(/^\B(?<!\.\d*)(?=(\d{3})+(?!\d))$/g, ",");
return parseFloat(number).toLocaleString('zh', {minimumFractionDigits: digit}) return parseFloat(number).toLocaleString('zh', { minimumFractionDigits: digit })
} else { } else {
return 0.00 return 0.0
} }
} }

View File

@ -284,9 +284,17 @@ export default () => {
return ( return (
<View className={styles.order_main}> <View className={styles.order_main}>
{(orderDetail?.status != SaleorderstatusWaitingPrePayment.value && <OrderState orderInfo={orderDetail} />) || <AdvanceOrderState orderInfo={orderDetail} onRefresh={refresh} />} {(orderDetail?.status != SaleorderstatusWaitingPrePayment.value && <OrderState orderInfo={orderDetail} />) || (
<AdvanceOrderState orderInfo={orderDetail} onRefresh={refresh} />
)}
<View> <View>
<AddressInfoDetail orderInfo={defaultAddress} onLogistics={getLogistics} onSelect={getAddress} onChangeShipmentMode={getShipmentMode} ref={addressRef} /> <AddressInfoDetail
orderInfo={defaultAddress}
onLogistics={getLogistics}
onSelect={getAddress}
onChangeShipmentMode={getShipmentMode}
ref={addressRef}
/>
</View> </View>
<KindList order={formatPreViewOrderMemo} /> <KindList order={formatPreViewOrderMemo} />
<View className={styles.order_info}> <View className={styles.order_info}>
@ -310,7 +318,9 @@ export default () => {
</View> </View>
<View className={styles.order_desc} onClick={descOpen}> <View className={styles.order_desc} onClick={descOpen}>
<View className={styles.order_desc_con}></View> <View className={styles.order_desc_con}></View>
{(orderRemark && <View className={styles.order_desc_text}>{orderDetail?.remark}</View>) || <View className={styles.order_desc_text_hint}></View>} {(orderRemark && <View className={styles.order_desc_text}>{orderDetail?.remark}</View>) || (
<View className={styles.order_desc_text_hint}></View>
)}
<View className={classnames(styles.miconfont, 'iconfont icon-a-moreback')}></View> <View className={classnames(styles.miconfont, 'iconfont icon-a-moreback')}></View>
</View> </View>
{orderDetail?.status != SaleOrderStatusCancel.value && ( {orderDetail?.status != SaleOrderStatusCancel.value && (