"use strict"; const common_vendor = require("../../common/vendor.js"); const common_assets = require("../../common/assets.js"); if (!Array) { const _component_transition = common_vendor.resolveComponent("transition"); _component_transition(); } const _sfc_main = { __name: "code", setup(__props) { const phonenumber = common_vendor.ref(""); const captcha = common_vendor.ref(["", "", "", ""]); const focusedIndex = common_vendor.ref(0); const isFadingOut = common_vendor.ref(false); const maskColor = common_vendor.ref("rgba(0, 0, 0, 0.5)"); function closeModal() { isFadingOut.value = false; } const handleInput = (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(); } }); }; const handleKeydown = (index, event) => { if (event.key === "Backspace" && !captcha.value[index]) { if (index > 0) { focusedIndex.value = index - 1; } } }; const submitCaptcha = () => { const code = captcha.value.join(""); if (code.length === 4) { common_vendor.index.__f__("log", "at pages/login/code.vue:118", "提交验证码:", code); common_vendor.index.reLaunch({ url: `/pages/index/index` }); } else { common_vendor.index.__f__("log", "at pages/login/code.vue:125", "验证码未输入完整"); } }; const getcode = () => { const url = `https://www.focusnu.com/nursing-unit/sys/randomImage/${Date.now()}`; fetch(url).then((res) => res.json()).then((data) => { common_vendor.index.__f__("log", "at pages/login/code.vue:152", "code测试", data); }); }; const countdown = common_vendor.ref(60); let timerId = null; common_vendor.onUnmounted(() => { if (timerId) { clearInterval(timerId); } }); common_vendor.onLoad((options) => { phonenumber.value = options.phonenumber; getcode(); countdown.value = 60; timerId = setInterval(() => { if (countdown.value > 0) { countdown.value--; } else { clearInterval(timerId); timerId = null; } }, 1e3); }); 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(phonenumber.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), 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.t(countdown.value), h: countdown.value, i: common_vendor.o(($event) => isFadingOut.value = true), j: isFadingOut.value }, isFadingOut.value ? { k: common_vendor.o(closeModal), l: maskColor.value } : {}, { m: common_vendor.p({ name: "fade" }), n: isFadingOut.value }, isFadingOut.value ? {} : {}, { o: 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