"use strict"; const common_vendor = require("../../common/vendor.js"); const common_assets = require("../../common/assets.js"); const api_loginApi = require("../../api/loginApi.js"); if (!Array) { const _component_transition = common_vendor.resolveComponent("transition"); _component_transition(); } const _sfc_main = { __name: "code", setup(__props) { const mobile = common_vendor.ref(""); const hkcode = common_vendor.ref(""); const captcha = common_vendor.ref(["", "", "", ""]); const focusedIndex = common_vendor.ref(-1); const isFadingOut = common_vendor.ref(false); const maskColor = common_vendor.ref("rgba(0, 0, 0, 0.5)"); function closeModal() { isFadingOut.value = false; } function filterToSingleDigit(number) { if (typeof number === "number") { return number % 10; } return number; } const handleInput = (index, event) => { const val = event.detail.value || ""; common_vendor.index.__f__("log", "at pages/login/code.vue:101", "??????", event); if (val.length == 4) { const codeStr = event.detail.value.toString().padStart(4, "0"); captcha.value = codeStr.split(""); focusedIndex.value = 3; common_vendor.nextTick$1(() => { submitCaptcha(); }); } else if (val.length == 2) { captcha.value[index] = filterToSingleDigit(captcha.value[index]); if (captcha.value[index]) { if (index < 3) { focusedIndex.value = index + 1; } } let isFour = true; captcha.value.forEach((number) => { if (!number) { isFour = false; } }); common_vendor.nextTick$1(() => { if (isFour) { submitCaptcha(); } }); } else { if (captcha.value[index]) { if (index < 3) { focusedIndex.value = index + 1; } } let isFour = true; captcha.value.forEach((number) => { if (!number) { isFour = false; } }); common_vendor.nextTick$1(() => { if (isFour) { submitCaptcha(); } }); } }; const handleKeydown = (index, event) => { if (event.key === "Backspace" && !captcha.value[index]) { if (index > 0) { focusedIndex.value = index - 1; } } }; const rightCode = common_vendor.ref(""); const submitCaptcha = () => { const code = captcha.value.join(""); if (code.length === 4) { common_vendor.index.__f__("log", "at pages/login/code.vue:163", "提交验证码:", code); if (rightCode.value != code) { rightCode.value = code; api_loginApi.checkPhoneCode({ mobile: mobile.value, openId: common_vendor.index.getStorageSync("openid").openid, smscode: code }).then((res) => { if (res.success) { common_vendor.index.redirectTo({ url: `/pages/login/threeselectone` }); } else { common_vendor.index.showToast({ title: "验证码错误", icon: "none", // 不显示图标(提示信息) duration: 2e3 // 显示时长(毫秒) }); } }); } } else { common_vendor.index.__f__("log", "at pages/login/code.vue:186", "验证码未输入完整"); } }; const getcode = () => { api_loginApi.smsCode({ mobile: mobile.value, hkcode: hkcode.value, smsmode: 1 }).then((res) => { if (res.success) { common_vendor.index.showToast({ title: "发送成功", icon: "none", // 不显示图标(提示信息) duration: 2e3 // 显示时长(毫秒) }); focusedIndex.value = 0; countdown.value = 60; timerId = setInterval(() => { if (countdown.value > 0) { countdown.value--; } else { clearInterval(timerId); timerId = null; } }, 1e3); } else { common_vendor.index.showToast({ title: res.message, icon: "none", // 不显示图标(提示信息) duration: 2e3 // 显示时长(毫秒) }); } }); }; const countdown = common_vendor.ref(0); let timerId = null; common_vendor.onUnmounted(() => { if (timerId) { clearInterval(timerId); } }); common_vendor.onLoad((options) => { mobile.value = options.mobile; hkcode.value = options.hkcode; getcode(); }); return (_ctx, _cache) => { return common_vendor.e({ a: common_assets._imports_0, b: common_assets._imports_1, c: common_assets._imports_2, d: common_vendor.t(mobile.value), e: common_vendor.f(captcha.value, (digit, index, i0) => { return { a: index < 3 ? "" : " ", b: common_vendor.o([($event) => captcha.value[index] = $event.detail.value, index, ($event) => handleInput(index, $event), index], index), c: common_vendor.o(($event) => handleKeydown(index, $event), index), d: focusedIndex.value === index, e: captcha.value[index], f: index }; }), f: !countdown.value, g: common_vendor.o(getcode), h: common_vendor.t(countdown.value), i: countdown.value, j: common_vendor.o(($event) => isFadingOut.value = true), k: isFadingOut.value }, isFadingOut.value ? { l: common_vendor.o(closeModal), m: maskColor.value } : {}, { n: common_vendor.p({ name: "fade" }), o: isFadingOut.value }, isFadingOut.value ? {} : {}, { p: common_vendor.p({ name: "slide-up" }) }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-7f72106f"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/code.js.map