| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 | 
							- import $store from '@/sheep/store';
 
- import $helper from '@/sheep/helper';
 
- import dayjs from 'dayjs';
 
- import { ref,computed } from 'vue';
 
- import test from '@/sheep/helper/test.js';
 
- import AuthUtil from '@/sheep/api/member/auth';
 
- import sheep from '@/sheep';
 
- import SignInApi from '@/sheep/api/member/signin';
 
- let time = 30;
 
- let timer = null;
 
- // 登录
 
- async function onSign() {
 
-   const {
 
-     code,
 
-     data
 
-   } = await SignInApi.createSignInRecord();
 
-   if (code === 0) {
 
-     showSignUpModal(data)
 
-     clearInterval(timer);
 
-     uni.setStorageSync('isRun', false);
 
-     uni.setStorageSync('isSign', true);
 
-   }
 
- }
 
- // 每日重置签到状态
 
- export function resetSignStatusIfNeeded() {
 
-   const today = new Date().toISOString().slice(0, 10);  // 获取当前日期,格式为 YYYY-MM-DD
 
-   const lastCheckDate = uni.getStorageSync('lastCheckDate');
 
-   if (today !== lastCheckDate) {
 
-     // 如果跨天了,重置 isSign
 
-     uni.setStorageSync('isSign', false);
 
-     uni.setStorageSync('lastCheckDate', today);  // 更新最后检查的日期
 
-   }
 
- }
 
- // 自动签到
 
- export function autoSign(){
 
-   resetSignStatusIfNeeded();
 
-   const isLogin = computed(() => sheep.$store('user').isLogin);
 
-   // 如果登录了才开始倒计时
 
-   if (isLogin.value) {
 
-     // 倒计时是否在进行
 
-     uni.setStorageSync('isRun', true);
 
-     if (uni.getStorageSync('isRun')&& !uni.getStorageSync('isSign')) {
 
-       console.log('开始倒计时')
 
-       // 开始一个新的定时器
 
-       timer = setInterval(() => {
 
-         time--;
 
-         console.log("time", time);
 
-         if (time <= 0) {
 
-           // onSign()
 
-           return 
 
-         }
 
-       }, 1000);
 
-     }
 
-   } 
 
- }
 
- // 取消自动签到
 
- export function cancelAutoSign() {
 
-   console.log("取消")
 
-   if (timer) {
 
-     clearInterval(timer);
 
-   }
 
-   time = 30;
 
-   uni.setStorageSync('isRun', false);
 
- }
 
- // 打开签到弹框
 
- export function showSignUpModal(obj) {
 
-   $store('modal').$patch((state) => {
 
-     state.signUp = true;
 
-     state.signUpInfo = obj;
 
-   });
 
- }
 
- // 关闭签到弹框
 
- export function colseSignUpModal() {
 
-   $store('modal').$patch((state) => {
 
-     state.signUp = false;
 
-   });
 
- }
 
- // 打开授权弹框
 
- export function showAuthModal(type = 'smsLogin',isActive = 'smsLogin') {
 
-   const modal = $store('modal');
 
-   if (modal.auth !== '') {
 
-     closeAuthModal();
 
-     setTimeout(() => {
 
-       modal.$patch((state) => {
 
-         state.auth = type;
 
- 		    state.isActive = isActive;
 
-       });
 
-     }, 100);
 
-   } else {
 
-     modal.$patch((state) => {
 
-       state.auth = type;
 
- 	    state.isActive = isActive;
 
-     });
 
-   }
 
- }
 
- // 关闭授权弹框
 
- 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;
 
-   }
 
-   // 只有 mobile 非空时才校验。因为部分场景(修改密码),不需要输入手机
 
-   if (mobile && !test.mobile(mobile)) {
 
-     $helper.toast('手机号码格式不正确');
 
-     return;
 
-   }
 
-   // 发送验证码 + 更新上次发送验证码时间
 
-   let scene = -1;
 
-   switch (event) {
 
-     case 'resetPassword':
 
-       scene = 4;
 
-       break;
 
-     case 'changePassword':
 
-       scene = 3;
 
-       break;
 
-     case 'changeMobile':
 
-       scene = 2;
 
-       break;
 
-     case 'smsLogin':
 
-       scene = 1;
 
-       break;
 
-   }
 
-   AuthUtil.sendSmsCode(mobile, scene).then((res) => {
 
-     if (res.code === 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.imgUrl)) {
 
-       state.advHistory.push(adv.imgUrl);
 
-     }
 
-   });
 
- }
 
 
  |