发布v1.0.3

This commit is contained in:
kele
2022-11-22 15:45:36 +08:00
commit 01f091fcd8
525 changed files with 80922 additions and 0 deletions
View File
+137
View File
@@ -0,0 +1,137 @@
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));
}
}
+128
View File
@@ -0,0 +1,128 @@
import $store from '@/sheep/store';
import $helper from '@/sheep/helper';
import dayjs from 'dayjs';
import { ref } from 'vue';
import test from '@/sheep/helper/test.js';
import $api from '@/sheep/api';
// 打开授权弹框
export function showAuthModal(type = 'accountLogin') {
const modal = $store('modal');
if (modal.auth !== '') {
closeAuthModal();
setTimeout(() => {
modal.$patch((state) => {
state.auth = type;
});
}, 100);
} else {
modal.$patch((state) => {
state.auth = type;
});
}
}
// 关闭授权弹框
export function closeAuthModal() {
$store('modal').$patch((state) => {
state.auth = '';
});
}
// 打开分享弹框
export function showShareModal() {
$store('modal').$patch((state) => {
state.share = true;
});
}
// 关闭分享弹框
export function closeShareModal() {
$store('modal').$patch((state) => {
state.share = false;
});
}
// 打开快捷菜单
export function showMenuTools() {
$store('modal').$patch((state) => {
state.menu = true;
});
}
// 关闭快捷菜单
export function closeMenuTools() {
$store('modal').$patch((state) => {
state.menu = false;
});
}
// 发送短信验证码 60秒
export function getSmsCode(event, mobile = '') {
const modalStore = $store('modal');
const lastSendTimer = modalStore.lastTimer[event];
if (typeof lastSendTimer === 'undefined') {
$helper.toast('短信发送事件错误');
return;
}
const duration = dayjs().unix() - lastSendTimer;
const canSend = duration >= 60;
if (!canSend) {
$helper.toast('请稍后再试');
return;
}
if (!test.mobile(mobile)) {
$helper.toast('手机号码格式不正确');
return;
}
// 发送验证码 + 更新上次发送验证码时间
$api.app.sendSms({ mobile, event }).then((res) => {
if (res.error === 0) {
modalStore.$patch((state) => {
state.lastTimer[event] = dayjs().unix();
});
}
});
}
// 获取短信验证码倒计时 -- 60秒
export function getSmsTimer(event, mobile = '') {
const modalStore = $store('modal');
const lastSendTimer = modalStore.lastTimer[event];
if (typeof lastSendTimer === 'undefined') {
$helper.toast('短信发送事件错误');
return;
}
const duration = ref(dayjs().unix() - lastSendTimer - 60);
const canSend = duration.value >= 0;
if (canSend) {
return '获取验证码';
}
if (!canSend) {
setTimeout(() => {
duration.value++;
}, 1000);
return -duration.value.toString() + ' 秒';
}
}
// 记录广告弹框历史
export function saveAdvHistory(adv) {
const modal = $store('modal');
modal.$patch((state) => {
if (!state.advHistory.includes(adv.src)) {
state.advHistory.push(adv.src);
}
});
}