Files
threeonecheck_web/unpackage/dist/dev/mp-weixin/pages/login/forget.js
2026-01-18 16:06:37 +08:00

169 lines
4.7 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
if (!Array) {
const _component_cu_custom = common_vendor.resolveComponent("cu-custom");
_component_cu_custom();
}
const _sfc_main = {
__name: "forget",
setup(__props) {
const phone = common_vendor.ref("");
const password = common_vendor.ref("");
const code = common_vendor.ref("");
const second = common_vendor.ref(0);
const showPassword = common_vendor.ref(false);
let timer = null;
const codeText = common_vendor.computed(() => {
if (second.value === 0) {
return "获取验证码";
} else {
const secondStr = second.value < 10 ? `0${second.value}` : second.value;
return `重新获取${secondStr}`;
}
});
const togglePassword = () => {
showPassword.value = !showPassword.value;
};
const getCode = () => {
if (phone.value.length !== 11) {
common_vendor.index.showToast({
icon: "none",
title: "手机号不正确"
});
return;
}
if (second.value > 0) {
return;
}
second.value = 60;
startCountdown();
common_vendor.index.request({
url: "http://example.com/api/code",
data: {
phone: phone.value,
type: "forget"
},
method: "POST",
dataType: "json",
success: (res) => {
if (res.data.code != 200) {
common_vendor.index.showToast({
title: res.data.msg || "获取验证码失败",
icon: "none"
});
second.value = 0;
clearCountdown();
} else {
common_vendor.index.showToast({
title: res.data.msg || "验证码已发送"
});
}
},
fail: () => {
common_vendor.index.showToast({
title: "网络请求失败",
icon: "none"
});
second.value = 0;
clearCountdown();
}
});
};
const startCountdown = () => {
clearCountdown();
timer = setInterval(() => {
second.value--;
if (second.value === 0) {
clearCountdown();
}
}, 1e3);
};
const clearCountdown = () => {
if (timer) {
clearInterval(timer);
timer = null;
}
};
const handleReset = () => {
if (phone.value.length !== 11) {
common_vendor.index.showToast({
icon: "none",
title: "手机号不正确"
});
return;
}
if (password.value.length < 6) {
common_vendor.index.showToast({
icon: "none",
title: "密码不正确"
});
return;
}
if (code.value.length !== 4) {
common_vendor.index.showToast({
icon: "none",
title: "验证码不正确"
});
return;
}
common_vendor.index.request({
url: "http://example.com/api/forget",
data: {
phone: phone.value,
password: password.value,
code: code.value
},
method: "POST",
dataType: "json",
success: (res) => {
if (res.data.code != 200) {
common_vendor.index.showToast({
title: res.data.msg || "修改密码失败",
icon: "none"
});
} else {
common_vendor.index.showToast({
title: res.data.msg || "修改密码成功"
});
setTimeout(() => {
common_vendor.index.navigateBack();
}, 1500);
}
},
fail: () => {
common_vendor.index.showToast({
title: "网络请求失败",
icon: "none"
});
}
});
};
common_vendor.onUnmounted(() => {
clearCountdown();
});
return (_ctx, _cache) => {
return {
a: common_vendor.p({
isBack: true
}),
b: common_assets._imports_0$4,
c: phone.value,
d: common_vendor.o(($event) => phone.value = $event.detail.value),
e: common_assets._imports_1$2,
f: !showPassword.value,
g: password.value,
h: common_vendor.o(($event) => password.value = $event.detail.value),
i: showPassword.value ? 1 : "",
j: common_vendor.o(togglePassword),
k: common_vendor.t(codeText.value),
l: second.value > 0 ? 1 : "",
m: common_vendor.o(getCode),
n: common_vendor.o(handleReset)
};
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-79044ba6"]]);
wx.createPage(MiniProgramPage);