| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 | import { ref } from 'vue';import dayjs from 'dayjs';import $url from '@/sheep/url';// 格式化销量export function formatSales(type, num) {  num = num + '';  if (type === 'exact') {    return '已售' + num;  } else {    if (num < 10) {      return '销量≤10';    } else {      let a = Math.pow(10, num.length - 1);      return '已售' + parseInt(num / a) * a + '+';    }  }}// 格式化兑换量export function formatExchange(type, num) {  num = num + '';  if (type === 'exact') {    return '已兑换' + num;  } else {    if (num < 10) {      return '已兑换≤10';    } else {      let a = Math.pow(10, num.length - 1);      return '已兑换' + parseInt(num / a) * a + '+';    }  }}// 格式化库存export function formatStock(type, num) {  num = num + '';  if (type === 'exact') {    return '库存' + num;  } else {    if (num < 10) {      return '库存≤10';    } else {      let a = Math.pow(10, num.length - 1);      return '库存 ' + parseInt(num / a) * a + '+';    }  }}// 格式化价格export function formatPrice(e) {  return e.length === 1 ? e[0] : e.join('~');}// 格式化商品轮播export function formatGoodsSwiper(list) {  let swiper = [];  list.forEach((item, key) => {    if (item.indexOf('.avi') !== -1 || item.indexOf('.mp4') !== -1) {      swiper.push({        src: $url.cdn(item),        type: 'video',      });    } else {      swiper.push({        src: $url.cdn(item),        type: 'image',      });    }  });  return swiper;}export function formatOrderColor(type) {  if (    type === 'apply_refund' ||    type === 'groupon_ing' ||    type === 'nocomment' ||    type === 'noget' ||    type === 'nosend'  ) {    return 'warning-color';  } else if (    type === 'closed' ||    type === 'groupon_invalid' ||    type === 'cancel' ||    type === 'refund_agree'  ) {    return 'danger-color';  } else if (type === 'completed') {    return 'success-color';  } else if (type === 'unpaid') {    return 'info-color';  }}// 计算相隔时间export function useDurationTime(toTime, fromTime = '') {  toTime = getDayjsTime(toTime);  if (fromTime === '') {    fromTime = dayjs();  }  let duration = ref(toTime - fromTime);  if (duration.value > 0) {    setTimeout(() => {      if (duration.value > 0) {        duration.value -= 1000;      }    }, 1000);  }  let durationTime = dayjs.duration(duration.value);  return {    h: (durationTime.months() * 30 * 24 + durationTime.days() * 24 + durationTime.hours())      .toString()      .padStart(2, '0'),    m: durationTime.minutes().toString().padStart(2, '0'),    s: durationTime.seconds().toString().padStart(2, '0'),    ms: durationTime.$ms,  };}function getDayjsTime(time) {  time = time.toString();  if (time.indexOf('-') > 0) {    // 'date'    return dayjs(time);  }  if (time.length > 10) {    // 'timestamp'    return dayjs(parseInt(time));  }  if (time.length === 10) {    // 'unixtime'    return dayjs.unix(parseInt(time));  }}
 |