reactor:utils 挪到 helper 目录下
parent
dfe4a33e2d
commit
01adbff523
|
@ -69,7 +69,7 @@
|
|||
import sheep from '@/sheep';
|
||||
import _ from 'lodash-es';
|
||||
import { formatOrderColor } from '@/sheep/hooks/useGoods';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
import CombinationApi from '@/sheep/api/promotion/combination';
|
||||
|
||||
// 数据
|
||||
|
|
|
@ -47,9 +47,8 @@
|
|||
import MessageListItem from '@/pages/chat/components/messageListItem.vue';
|
||||
import { reactive, ref } from 'vue';
|
||||
import KeFuApi from '@/sheep/api/promotion/kefu';
|
||||
import { isEmpty } from '@/sheep/helper/utils';
|
||||
import { isEmpty, formatDate } from '@/sheep/helper/utils';
|
||||
import sheep from '@/sheep';
|
||||
import { formatDate } from '@/sheep/util';
|
||||
|
||||
const sys_navBar = sheep.$platform.navbar;
|
||||
const messageList = ref([]); // 消息列表
|
||||
|
|
|
@ -71,7 +71,9 @@
|
|||
<div class="ss-m-b-10">
|
||||
<GoodsItem
|
||||
:goodsData="getMessageContent(message)"
|
||||
@tap="sheep.$router.go('/pages/goods/index', { id: getMessageContent(message).spuId })"
|
||||
@tap="
|
||||
sheep.$router.go('/pages/goods/index', { id: getMessageContent(message).spuId })
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -103,7 +105,7 @@
|
|||
import { KeFuMessageContentTypeEnum, UserTypeEnum } from '@/pages/chat/util/constants';
|
||||
import { emojiList } from '@/pages/chat/util/emoji';
|
||||
import sheep from '@/sheep';
|
||||
import { formatDate, jsonParse } from '@/sheep/util';
|
||||
import { formatDate, jsonParse } from '@/sheep/helper/utils';
|
||||
import GoodsItem from '@/pages/chat/components/goods.vue';
|
||||
import OrderItem from '@/pages/chat/components/order.vue';
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
import FileApi from '@/sheep/api/infra/file';
|
||||
import KeFuApi from '@/sheep/api/promotion/kefu';
|
||||
import { useWebSocket } from '@/sheep/hooks/useWebSocket';
|
||||
import { jsonParse } from '@/sheep/util';
|
||||
import { jsonParse } from '@/sheep/helper/utils';
|
||||
|
||||
const sys_navBar = sheep.$platform.navbar;
|
||||
|
||||
|
@ -118,7 +118,7 @@
|
|||
setTimeout(() => {
|
||||
chat.toolsMode = mode;
|
||||
chat.showTools = true;
|
||||
}, 200)
|
||||
}, 200);
|
||||
}
|
||||
|
||||
function onShowSelect(mode) {
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
import BrokerageApi from '@/sheep/api/trade/brokerage';
|
||||
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
||||
import _ from 'lodash-es';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
|
||||
const tabMaps = ['周排行', '月排行'];
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
import { onLoad, onPageScroll, onReachBottom } from '@dcloudio/uni-app';
|
||||
import { reactive } from 'vue';
|
||||
import _ from 'lodash-es';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
import BrokerageApi from '@/sheep/api/trade/brokerage';
|
||||
import { fen2yuan } from '../../sheep/hooks/useGoods';
|
||||
|
||||
|
@ -131,7 +131,7 @@
|
|||
pageNo: state.pagination.pageNo,
|
||||
bizType: 1, // 获得推广佣金
|
||||
status: tab.value,
|
||||
}
|
||||
};
|
||||
if (tab.value < 0) {
|
||||
delete queryParams.status;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||
import { reactive } from 'vue';
|
||||
import _ from 'lodash-es';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
import BrokerageApi from '@/sheep/api/trade/brokerage';
|
||||
|
||||
const tabMaps = ['周排行', '月排行'];
|
||||
|
|
|
@ -153,7 +153,7 @@
|
|||
import _ from 'lodash-es';
|
||||
import BrokerageApi from '@/sheep/api/trade/brokerage';
|
||||
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
|
||||
const headerBg = sheep.$url.css('/static/img/shop/user/wallet_card_bg.png');
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@
|
|||
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
||||
import SpuApi from '@/sheep/api/product/spu';
|
||||
import CategoryApi from '@/sheep/api/product/category';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
|
||||
const state = reactive({
|
||||
id: 0, // 优惠劵模版编号 templateId
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||
import { reactive } from 'vue';
|
||||
import _ from 'lodash-es';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
import CouponApi from '@/sheep/api/promotion/coupon';
|
||||
|
||||
// 数据
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||
import sheep from '@/sheep';
|
||||
import _ from 'lodash-es';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
import SpuApi from '@/sheep/api/product/spu';
|
||||
import OrderApi from '@/sheep/api/trade/order';
|
||||
import { appendSettlementProduct } from '@/sheep/hooks/useGoods';
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import { computed, reactive } from 'vue';
|
||||
import _ from 'lodash-es';
|
||||
import { handleTree } from '@/sheep/util';
|
||||
import { handleTree } from '@/sheep/helper/utils';
|
||||
|
||||
const state = reactive({
|
||||
style: 'second_one', // first_one(一级 - 样式一), first_two(二级 - 样式二), second_one(二级)
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
handleAfterSaleButtons,
|
||||
} from '@/sheep/hooks/useGoods';
|
||||
import AfterSaleApi from '@/sheep/api/trade/afterSale';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
|
||||
const state = reactive({
|
||||
currentTab: 0,
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
import _ from 'lodash-es';
|
||||
import { isEmpty } from 'lodash-es';
|
||||
import OrderApi from '@/sheep/api/trade/order';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
|
||||
// 数据
|
||||
const state = reactive({
|
||||
|
|
|
@ -104,7 +104,7 @@
|
|||
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||
import _ from 'lodash-es';
|
||||
import FavoriteApi from '@/sheep/api/product/favorite';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
|
||||
const sys_navBar = sheep.$platform.navbar;
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
import _ from 'lodash-es';
|
||||
import PayWalletApi from '@/sheep/api/pay/wallet';
|
||||
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
|
||||
const headerBg = sheep.$url.css('/static/img/shop/user/wallet_card_bg.png');
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
import _ from 'lodash-es';
|
||||
import dayjs from 'dayjs';
|
||||
import PointApi from '@/sheep/api/member/point';
|
||||
import { resetPagination } from '@/sheep/util';
|
||||
import { resetPagination } from '@/sheep/helper/utils';
|
||||
|
||||
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
|
||||
const userInfo = computed(() => sheep.$store('user').userInfo);
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
import CouponApi from '@/sheep/api/promotion/coupon';
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { CouponTemplateValidityTypeEnum, PromotionDiscountTypeEnum } from '@/sheep/helper/const';
|
||||
import { floatToFixed2, formatDate } from '@/sheep/util';
|
||||
import { floatToFixed2, formatDate } from '@/sheep/helper/utils';
|
||||
|
||||
const props = defineProps({
|
||||
data: {
|
||||
|
|
|
@ -35,7 +35,7 @@ export function isEmpty(value) {
|
|||
return Object.keys(value).length === 0;
|
||||
}
|
||||
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isBoolean(value) {
|
||||
|
@ -170,3 +170,143 @@ export function isWxBrowser() {
|
|||
export function range(min = 0, max = 0, value = 0) {
|
||||
return Math.max(min, Math.min(max, Number(value)));
|
||||
}
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
/**
|
||||
* 将一个整数转换为分数保留两位小数
|
||||
* @param {number | string | undefined} num 整数
|
||||
* @return {number} 分数
|
||||
*/
|
||||
export const formatToFraction = (num) => {
|
||||
if (typeof num === 'undefined') return 0;
|
||||
const parsedNumber = typeof num === 'string' ? parseFloat(num) : num;
|
||||
return parseFloat((parsedNumber / 100).toFixed(2));
|
||||
};
|
||||
|
||||
/**
|
||||
* 将一个数转换为 1.00 这样
|
||||
* 数据呈现的时候使用
|
||||
*
|
||||
* @param {number | string | undefined} num 整数
|
||||
* @return {string} 分数
|
||||
*/
|
||||
export const floatToFixed2 = (num) => {
|
||||
let str = '0.00';
|
||||
if (typeof num === 'undefined') {
|
||||
return str;
|
||||
}
|
||||
const f = formatToFraction(num);
|
||||
const decimalPart = f.toString().split('.')[1];
|
||||
const len = decimalPart ? decimalPart.length : 0;
|
||||
switch (len) {
|
||||
case 0:
|
||||
str = f.toString() + '.00';
|
||||
break;
|
||||
case 1:
|
||||
str = f.toString() + '.0';
|
||||
break;
|
||||
case 2:
|
||||
str = f.toString();
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
* 时间日期转换
|
||||
* @param {dayjs.ConfigType} date 当前时间,new Date() 格式
|
||||
* @param {string} format 需要转换的时间格式字符串
|
||||
* @description format 字符串随意,如 `YYYY-mm、YYYY-mm-dd`
|
||||
* @description format 季度:"YYYY-mm-dd HH:MM:SS QQQQ"
|
||||
* @description format 星期:"YYYY-mm-dd HH:MM:SS WWW"
|
||||
* @description format 几周:"YYYY-mm-dd HH:MM:SS ZZZ"
|
||||
* @description format 季度 + 星期 + 几周:"YYYY-mm-dd HH:MM:SS WWW QQQQ ZZZ"
|
||||
* @returns {string} 返回拼接后的时间字符串
|
||||
*/
|
||||
export function formatDate(date, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||
// 日期不存在,则返回空
|
||||
if (!date) {
|
||||
return '';
|
||||
}
|
||||
// 日期存在,则进行格式化
|
||||
if (format === undefined) {
|
||||
format = 'YYYY-MM-DD HH:mm:ss';
|
||||
}
|
||||
return dayjs(date).format(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造树型结构数据
|
||||
*
|
||||
* @param {*} data 数据源
|
||||
* @param {*} id id字段 默认 'id'
|
||||
* @param {*} parentId 父节点字段 默认 'parentId'
|
||||
* @param {*} children 孩子节点字段 默认 'children'
|
||||
* @param {*} rootId 根Id 默认 0
|
||||
*/
|
||||
export function handleTree(
|
||||
data,
|
||||
id = 'id',
|
||||
parentId = 'parentId',
|
||||
children = 'children',
|
||||
rootId = 0,
|
||||
) {
|
||||
// 对源数据深度克隆
|
||||
const cloneData = JSON.parse(JSON.stringify(data));
|
||||
// 循环所有项
|
||||
const treeData = cloneData.filter((father) => {
|
||||
let branchArr = cloneData.filter((child) => {
|
||||
//返回每一项的子级数组
|
||||
return father[id] === child[parentId];
|
||||
});
|
||||
branchArr.length > 0 ? (father.children = branchArr) : '';
|
||||
//返回第一层
|
||||
return father[parentId] === rootId;
|
||||
});
|
||||
return treeData !== '' ? treeData : data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置分页对象
|
||||
*
|
||||
* @param pagination 分页对象
|
||||
*/
|
||||
export function resetPagination(pagination) {
|
||||
pagination.list = [];
|
||||
pagination.total = 0;
|
||||
pagination.pageNo = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将值复制到目标对象,且以目标对象属性为准,例:target: {a:1} source:{a:2,b:3} 结果为:{a:2}
|
||||
* @param target 目标对象
|
||||
* @param source 源对象
|
||||
*/
|
||||
export const copyValueToTarget = (target, source) => {
|
||||
const newObj = Object.assign({}, target, source);
|
||||
// 删除多余属性
|
||||
Object.keys(newObj).forEach((key) => {
|
||||
// 如果不是target中的属性则删除
|
||||
if (Object.keys(target).indexOf(key) === -1) {
|
||||
delete newObj[key];
|
||||
}
|
||||
});
|
||||
// 更新目标对象值
|
||||
Object.assign(target, newObj);
|
||||
};
|
||||
|
||||
/**
|
||||
* 解析 JSON 字符串
|
||||
*
|
||||
* @param str
|
||||
*/
|
||||
export function jsonParse(str) {
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch (e) {
|
||||
console.warn(`str[${str}] 不是一个 JSON 字符串`);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
// TODO @芋艿:融合下;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { ref } from 'vue';
|
||||
import dayjs from 'dayjs';
|
||||
import $url from '@/sheep/url';
|
||||
import { formatDate } from '@/sheep/util';
|
||||
import { formatDate } from '@/sheep/helper/utils';
|
||||
|
||||
/**
|
||||
* 格式化销量
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { onBeforeUnmount, reactive, ref } from 'vue';
|
||||
import { baseUrl, websocketPath } from '@/sheep/config';
|
||||
import { copyValueToTarget } from '@/sheep/util';
|
||||
import { copyValueToTarget } from '@/sheep/helper/utils';
|
||||
import { getRefreshToken } from '@/sheep/request';
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
import dayjs from 'dayjs';
|
||||
|
||||
/**
|
||||
* 将一个整数转换为分数保留两位小数
|
||||
* @param {number | string | undefined} num 整数
|
||||
* @return {number} 分数
|
||||
*/
|
||||
export const formatToFraction = (num) => {
|
||||
if (typeof num === 'undefined') return 0;
|
||||
const parsedNumber = typeof num === 'string' ? parseFloat(num) : num;
|
||||
return parseFloat((parsedNumber / 100).toFixed(2));
|
||||
};
|
||||
|
||||
/**
|
||||
* 将一个数转换为 1.00 这样
|
||||
* 数据呈现的时候使用
|
||||
*
|
||||
* @param {number | string | undefined} num 整数
|
||||
* @return {string} 分数
|
||||
*/
|
||||
export const floatToFixed2 = (num) => {
|
||||
let str = '0.00';
|
||||
if (typeof num === 'undefined') {
|
||||
return str;
|
||||
}
|
||||
const f = formatToFraction(num);
|
||||
const decimalPart = f.toString().split('.')[1];
|
||||
const len = decimalPart ? decimalPart.length : 0;
|
||||
switch (len) {
|
||||
case 0:
|
||||
str = f.toString() + '.00';
|
||||
break;
|
||||
case 1:
|
||||
str = f.toString() + '.0';
|
||||
break;
|
||||
case 2:
|
||||
str = f.toString();
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
* 时间日期转换
|
||||
* @param {dayjs.ConfigType} date 当前时间,new Date() 格式
|
||||
* @param {string} format 需要转换的时间格式字符串
|
||||
* @description format 字符串随意,如 `YYYY-mm、YYYY-mm-dd`
|
||||
* @description format 季度:"YYYY-mm-dd HH:MM:SS QQQQ"
|
||||
* @description format 星期:"YYYY-mm-dd HH:MM:SS WWW"
|
||||
* @description format 几周:"YYYY-mm-dd HH:MM:SS ZZZ"
|
||||
* @description format 季度 + 星期 + 几周:"YYYY-mm-dd HH:MM:SS WWW QQQQ ZZZ"
|
||||
* @returns {string} 返回拼接后的时间字符串
|
||||
*/
|
||||
export function formatDate(date, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||
// 日期不存在,则返回空
|
||||
if (!date) {
|
||||
return '';
|
||||
}
|
||||
// 日期存在,则进行格式化
|
||||
if (format === undefined) {
|
||||
format = 'YYYY-MM-DD HH:mm:ss';
|
||||
}
|
||||
return dayjs(date).format(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造树型结构数据
|
||||
*
|
||||
* @param {*} data 数据源
|
||||
* @param {*} id id字段 默认 'id'
|
||||
* @param {*} parentId 父节点字段 默认 'parentId'
|
||||
* @param {*} children 孩子节点字段 默认 'children'
|
||||
* @param {*} rootId 根Id 默认 0
|
||||
*/
|
||||
export function handleTree(
|
||||
data,
|
||||
id = 'id',
|
||||
parentId = 'parentId',
|
||||
children = 'children',
|
||||
rootId = 0,
|
||||
) {
|
||||
// 对源数据深度克隆
|
||||
const cloneData = JSON.parse(JSON.stringify(data));
|
||||
// 循环所有项
|
||||
const treeData = cloneData.filter((father) => {
|
||||
let branchArr = cloneData.filter((child) => {
|
||||
//返回每一项的子级数组
|
||||
return father[id] === child[parentId];
|
||||
});
|
||||
branchArr.length > 0 ? (father.children = branchArr) : '';
|
||||
//返回第一层
|
||||
return father[parentId] === rootId;
|
||||
});
|
||||
return treeData !== '' ? treeData : data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置分页对象
|
||||
*
|
||||
* @param pagination 分页对象
|
||||
*/
|
||||
export function resetPagination(pagination) {
|
||||
pagination.list = [];
|
||||
pagination.total = 0;
|
||||
pagination.pageNo = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将值复制到目标对象,且以目标对象属性为准,例:target: {a:1} source:{a:2,b:3} 结果为:{a:2}
|
||||
* @param target 目标对象
|
||||
* @param source 源对象
|
||||
*/
|
||||
export const copyValueToTarget = (target, source) => {
|
||||
const newObj = Object.assign({}, target, source);
|
||||
// 删除多余属性
|
||||
Object.keys(newObj).forEach((key) => {
|
||||
// 如果不是target中的属性则删除
|
||||
if (Object.keys(target).indexOf(key) === -1) {
|
||||
delete newObj[key];
|
||||
}
|
||||
});
|
||||
// 更新目标对象值
|
||||
Object.assign(target, newObj);
|
||||
};
|
||||
|
||||
/**
|
||||
* 解析 JSON 字符串
|
||||
*
|
||||
* @param str
|
||||
*/
|
||||
export function jsonParse(str) {
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch (e) {
|
||||
console.warn(`str[${str}] 不是一个 JSON 字符串`);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
// TODO @芋艿:融合下;
|
Loading…
Reference in New Issue