acdr-ui/dist/dev/mp-weixin/modules/mall/sheep/hooks/useModal.js

123 lines
3.6 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"use strict";
2024-10-01 09:15:35 +08:00
const modules_mall_sheep_store_index = require("../store/index.js");
const modules_mall_sheep_helper_index = require("../helper/index.js");
const common_vendor = require("../../../../common/vendor.js");
const modules_mall_sheep_helper_test = require("../helper/test.js");
const modules_mall_sheep_api_member_auth = require("../api/member/auth.js");
2024-09-19 07:20:14 +08:00
function showAuthModal(type = "smsLogin") {
2024-10-01 09:15:35 +08:00
const modal = modules_mall_sheep_store_index.$store("modal");
2024-09-19 07:20:14 +08:00
if (modal.auth !== "") {
setTimeout(() => {
modal.$patch((state) => {
state.auth = type;
});
}, 500);
closeAuthModal();
} else {
modal.$patch((state) => {
state.auth = type;
});
}
}
function closeAuthModal() {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_store_index.$store("modal").$patch((state) => {
2024-09-19 07:20:14 +08:00
state.auth = "";
});
}
function showShareModal() {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_store_index.$store("modal").$patch((state) => {
2024-09-19 07:20:14 +08:00
state.share = true;
});
}
function closeShareModal() {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_store_index.$store("modal").$patch((state) => {
2024-09-19 07:20:14 +08:00
state.share = false;
});
}
function showMenuTools() {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_store_index.$store("modal").$patch((state) => {
2024-09-19 07:20:14 +08:00
state.menu = true;
});
}
function closeMenuTools() {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_store_index.$store("modal").$patch((state) => {
2024-09-19 07:20:14 +08:00
state.menu = false;
});
}
function getSmsCode(event, mobile) {
2024-10-01 09:15:35 +08:00
const modalStore = modules_mall_sheep_store_index.$store("modal");
2024-09-19 07:20:14 +08:00
const lastSendTimer = modalStore.lastTimer[event];
if (typeof lastSendTimer === "undefined") {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_helper_index.$helper.toast("短信发送事件错误");
2024-09-19 07:20:14 +08:00
return;
}
const duration = common_vendor.dayjs().unix() - lastSendTimer;
const canSend = duration >= 60;
if (!canSend) {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_helper_index.$helper.toast("请稍后再试");
2024-09-19 07:20:14 +08:00
return;
}
2024-10-01 09:15:35 +08:00
if (mobile && !modules_mall_sheep_helper_test.test.mobile(mobile)) {
modules_mall_sheep_helper_index.$helper.toast("手机号码格式不正确");
2024-09-19 07:20:14 +08:00
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;
}
2024-10-01 09:15:35 +08:00
modules_mall_sheep_api_member_auth.AuthUtil.sendSmsCode(mobile, scene).then((res) => {
2024-09-19 07:20:14 +08:00
if (res.code === 0) {
modalStore.$patch((state) => {
state.lastTimer[event] = common_vendor.dayjs().unix();
});
}
});
}
function getSmsTimer(event, mobile = "") {
2024-10-01 09:15:35 +08:00
const modalStore = modules_mall_sheep_store_index.$store("modal");
2024-09-19 07:20:14 +08:00
const lastSendTimer = modalStore.lastTimer[event];
if (typeof lastSendTimer === "undefined") {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_helper_index.$helper.toast("短信发送事件错误");
2024-09-19 07:20:14 +08:00
return;
}
const duration = common_vendor.ref(common_vendor.dayjs().unix() - lastSendTimer - 60);
const canSend = duration.value >= 0;
if (canSend) {
return "获取验证码";
}
if (!canSend) {
setTimeout(() => {
duration.value++;
}, 1e3);
return -duration.value.toString() + " 秒";
}
}
function saveAdvHistory(adv) {
2024-10-01 09:15:35 +08:00
const modal = modules_mall_sheep_store_index.$store("modal");
2024-09-19 07:20:14 +08:00
modal.$patch((state) => {
if (!state.advHistory.includes(adv.imgUrl)) {
state.advHistory.push(adv.imgUrl);
}
});
}
exports.closeAuthModal = closeAuthModal;
exports.closeMenuTools = closeMenuTools;
exports.closeShareModal = closeShareModal;
exports.getSmsCode = getSmsCode;
exports.getSmsTimer = getSmsTimer;
exports.saveAdvHistory = saveAdvHistory;
exports.showAuthModal = showAuthModal;
exports.showMenuTools = showMenuTools;
exports.showShareModal = showShareModal;