{"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,YAA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