1 line
5.8 KiB
Plaintext
1 line
5.8 KiB
Plaintext
|
{"version":3,"file":"useModal.js","sources":["../../../../../src/sheep/hooks/useModal.js"],"sourcesContent":["import $store from '@/sheep/store'\r\nimport $helper from '@/sheep/helper'\r\nimport dayjs from 'dayjs'\r\nimport { ref } from 'vue'\r\nimport test from '@/sheep/helper/test.js'\r\nimport AuthUtil from '@/sheep/api/member/auth'\r\n\r\n// 打开授权弹框\r\nexport function showAuthModal(type = 'smsLogin') {\r\n const modal = $store('modal')\r\n if (modal.auth !== '') {\r\n // 注意:延迟修改,保证下面的 closeAuthModal 先执行掉\r\n setTimeout(() => {\r\n modal.$patch((state) => {\r\n state.auth = type\r\n })\r\n }, 500)\r\n closeAuthModal()\r\n } else {\r\n modal.$patch((state) => {\r\n state.auth = type\r\n })\r\n }\r\n}\r\n\r\n// 关闭授权弹框\r\nexport function closeAuthModal() {\r\n $store('modal').$patch((state) => {\r\n state.auth = ''\r\n })\r\n}\r\n\r\n// 打开分享弹框\r\nexport function showShareModal() {\r\n $store('modal').$patch((state) => {\r\n state.share = true\r\n })\r\n}\r\n\r\n// 关闭分享弹框\r\nexport function closeShareModal() {\r\n $store('modal').$patch((state) => {\r\n state.share = false\r\n })\r\n}\r\n\r\n// 打开快捷菜单\r\nexport function showMenuTools() {\r\n $store('modal').$patch((state) => {\r\n state.menu = true\r\n })\r\n}\r\n\r\n// 关闭快捷菜单\r\nexport function closeMenuTools() {\r\n $store('modal').$patch((state) => {\r\n state.menu = false\r\n })\r\n}\r\n\r\n// 发送短信验证码 60秒\r\nexport function getSmsCode(event, mobile) {\r\n const modalStore = $store('modal')\r\n const lastSendTimer = modalStore.lastTimer[event]\r\n if (typeof lastSendTimer === 'undefined') {\r\n $helper.toast('短信发送事件错误')\r\n return\r\n }\r\n\r\n const duration = dayjs().unix() - lastSendTimer\r\n const canSend = duration >= 60\r\n if (!canSend) {\r\n $helper.toast('请稍后再试')\r\n return\r\n }\r\n // 只有 mobile 非空时才校验。因为部分场景(修改密码),不需要输入手机\r\n if (mobile && !test.mobile(mobile)) {\r\n $helper.toast('手机号码格式不正确')\r\n return\r\n }\r\n\r\n // 发送验证码 + 更新上次发送验证码时间\r\n let scene = -1\r\n switch (event) {\r\n case 'resetPassword':\r\n scene = 4\r\n break\r\n case 'changePassword':\r\n scene = 3\r\n break\r\n case 'changeMobile':\r\n scene = 2\r\n break\r\n case 'smsLogin':\r\n scene = 1\r\n break\r\n }\r\n AuthUtil.sendSmsCode(mobile, scene).then((res) => {\r\n if (res.code === 0) {\r\n modalStore.$patch((state) => {\r\n state.lastTimer[event] = dayjs().unix()\r\n })\r\n }\r\n })\r\n}\r\n\r\n// 获取短信验证码倒计时 -- 60秒\r\nexport function getSmsTimer(event, mobile = '') {\r\n const modalStore = $store('modal')\r\n const lastSendTimer = modalStore.lastTimer[event]\r\n\r\n if (typeof lastSendTimer === 'undefined') {\r\n $helper.toast('短信发送事件错误')\r\n return\r\n }\r\n\r\n const duration = ref(dayjs().unix() - lastSendTimer - 60)\r\n const canSend = duration.value >= 0\r\n\r\n if (canSend) {\r\n return '获取验证码'\r\n }\r\n\r\n if (!canSend) {\r\n setTimeout(() => {\r\n duration.value++\r\n }, 1000)\r\n return -duration.value.toString() + ' 秒'\r\n }\r\n}\r\n\r\n// 记录广告弹框历史\r\nexport function saveAdvHistory(adv) {\r\n const modal = $store('modal')\r\n\r\n modal.$patch((state) => {\r\n if (!state.advHistory.includes(adv.imgUrl)) {\r\n state.advHistory.push(adv.imgUrl)\r\n }\r\n })\r\n}\r\n"],"names":["$store","$helper","dayjs","test","AuthUtil","ref"],"mappings":";;;;;;AAQO,SAAS,cAAc,OAAO,YAAY;AAC/C,QAAM,QAAQA,kBAAM,OAAC,OAAO;AAC5B,MAAI,MAAM,SAAS,IAAI;AAErB,eAAW,MAAM;AACf,YAAM,OAAO,CAAC,UAAU;AACtB,cAAM,OAAO;AAAA,MACrB,CAAO;AAAA,IACF,GAAE,GAAG;AACN,mBAAgB;AAAA,EACpB,OAAS;AACL,UAAM,OAAO,CAAC,UAAU;AACtB,YAAM,OAAO;AAAA,IACnB,CAAK;AAAA,EACF;AACH;AAGO,SAAS,iBAAiB;AAC/BA
|