| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 | 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);    }  });}
 |