acdr-ui/dist/dev/mp-weixin/sheep/hooks/useGoods.js.map

1 line
16 KiB
Plaintext
Raw Normal View History

2024-09-19 07:20:14 +08:00
{"version":3,"file":"useGoods.js","sources":["../../../../../src/sheep/hooks/useGoods.js"],"sourcesContent":["import { ref } from 'vue'\r\nimport dayjs from 'dayjs'\r\nimport $url from '@/sheep/url'\r\nimport { formatDate } from '@/sheep/util'\r\n\r\n/**\r\n * 格式化销量\r\n * @param {'exact' | string} type 格式类型exact=精确值,其它=大致数量\r\n * @param {number} num 销量\r\n * @return {string} 格式化后的销量字符串\r\n */\r\nexport function formatSales(type, num) {\r\n const prefix = type !== 'exact' && num < 10 ? '销量' : '已售'\r\n return formatNum(prefix, type, num)\r\n}\r\n\r\n/**\r\n * 格式化兑换量\r\n * @param {'exact' | string} type 格式类型exact=精确值,其它=大致数量\r\n * @param {number} num 销量\r\n * @return {string} 格式化后的销量字符串\r\n */\r\nexport function formatExchange(type, num) {\r\n return formatNum('已兑换', type, num)\r\n}\r\n\r\n/**\r\n * 格式化库存\r\n * @param {'exact' | any} type 格式类型exact=精确值,其它=大致数量\r\n * @param {number} num 销量\r\n * @return {string} 格式化后的销量字符串\r\n */\r\nexport function formatStock(type, num) {\r\n return formatNum('库存', type, num)\r\n}\r\n\r\n/**\r\n * 格式化数字\r\n * @param {string} prefix 前缀\r\n * @param {'exact' | string} type 格式类型exact=精确值,其它=大致数量\r\n * @param {number} num 销量\r\n * @return {string} 格式化后的销量字符串\r\n */\r\nexport function formatNum(prefix, type, num) {\r\n num = num || 0\r\n // 情况一:精确数值\r\n if (type === 'exact') {\r\n return prefix + num\r\n }\r\n // 情况二:小于等于 10\r\n if (num < 10) {\r\n return `${prefix}≤10`\r\n }\r\n // 情况三:大于 10除第一位外其它位都显示为0\r\n // 例如100 - 199 显示为 100+\r\n // 9000 - 9999 显示为 9000+\r\n const numStr = num.toString()\r\n const first = numStr[0]\r\n const other = '0'.repeat(numStr.length - 1)\r\n return `${prefix}${first}${other}+`\r\n}\r\n\r\n// 格式化价格\r\nexport function formatPrice(e) {\r\n return e.length === 1 ? e[0] : e.join('~')\r\n}\r\n\r\n// 视频格式后缀列表\r\nconst VIDEO_SUFFIX_LIST = ['.avi', '.mp4']\r\n\r\n/**\r\n * 转换商品轮播的链接列表:根据链接的后缀,判断是视频链接还是图片链接\r\n *\r\n * @param {string[]} urlList 链接列表\r\n * @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表\r\n */\r\nexport function formatGoodsSwiper(urlList) {\r\n return (\r\n urlList\r\n ?.filter((url) => url)\r\n .map((url, key) => {\r\n const isVideo = VIDEO_SUFFIX_LIST.some((suffix) => url.includes(suffix))\r\n const type = isVideo ? 'video' : 'image'\r\n const src = $url.cdn(url)\r\n return { type, src }\r\n }) || []\r\n )\r\n}\r\n\r\n/**\r\n * 格式化订单状态的颜色\r\n *\r\n * @param order 订单\r\n * @return {string} 颜色的 class 名称\r\n */\r\nexport function formatOrderColor(order) {\r\n if (order.status === 0) {\r\n return 'info-color'\r\n }\r\n if (order.status === 10 || order.status === 20 || (order.status === 30 && !order.commentStatus)) {\r\n return 'warning-color'\r\n }\r\n if (order.status === 30 && order.commentStatus) {\r\n return 'success-color'\r\n }\r\n return 'danger-color'\r\n}\r\n\r\n/**\r\n * 格式化订单状态\r\n *\r\n * @param order 订单\r\n */\r\nexport function formatOrderStatus(order) {\r\n if (order.status === 0) {\r\n return '待付款'\r\n }\r\n if (order.status === 10 && order.deliveryType === 1) {\r\n return '待发货'\r\n }\r\n if (order.status === 10 && order.deliveryType === 2) {\r\n return '待核销'\r\n }\r\n if (order.status === 20) {\r\n return '待收货'\r\n }\r\n if (order.status === 30 && !order.commentStatus) {\r\n return '待评价'\r\n }\r\n if (order.status === 30 && order.commentStatus) {\r\n return '已完成'\r\n }\r\n return '已关闭'\r\n}\r\n\r\n/**\r\n * 格式化订单状<E58D95>