Files
mini-yu/unpackage/dist/dev/mp-weixin/pages/login/login.js
lingxiao865 c5af079d8c first commit
2026-02-10 08:05:03 +08:00

173 lines
6.0 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_api = require("../../utils/api.js");
if (!Array) {
const _easycom_t_input2 = common_vendor.resolveComponent("t-input");
const _easycom_t_button2 = common_vendor.resolveComponent("t-button");
(_easycom_t_input2 + _easycom_t_button2)();
}
const _easycom_t_input = () => "../../uni_modules/tdesign-uniapp/components/input/input.js";
const _easycom_t_button = () => "../../uni_modules/tdesign-uniapp/components/button/button.js";
if (!Math) {
(_easycom_t_input + _easycom_t_button)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "login",
setup(__props) {
const phone = common_vendor.ref("13777777777");
const code = common_vendor.ref("");
const loginType = common_vendor.ref("one-click");
const loading = common_vendor.ref(false);
const codeDisabled = common_vendor.ref(false);
const countdown = common_vendor.ref(0);
const codeButtonText = common_vendor.ref("发送验证码");
const toggleLoginType = () => {
loginType.value = loginType.value === "code" ? "one-click" : "code";
};
const sendCode = async () => {
common_vendor.index.__f__("log", "at pages/login/login.vue:74", phone.value);
if (!phone.value || phone.value.length !== 11) {
common_vendor.index.showToast({
title: "请输入正确的手机号",
icon: "none"
});
return;
}
try {
await utils_api.api.auth.sendCode("+86" + phone.value);
common_vendor.index.showToast({
title: "验证码已发送",
icon: "success"
});
codeDisabled.value = true;
countdown.value = 60;
const timer = setInterval(() => {
countdown.value--;
codeButtonText.value = `${countdown.value}秒后重发`;
if (countdown.value <= 0) {
clearInterval(timer);
codeDisabled.value = false;
codeButtonText.value = "发送验证码";
}
}, 1e3);
} catch (error) {
common_vendor.index.__f__("error", "at pages/login/login.vue:103", "发送验证码失败", error);
}
};
const codeLogin = async () => {
if (!phone.value || phone.value.length !== 11) {
common_vendor.index.showToast({
title: "请输入正确的手机号",
icon: "none"
});
return;
}
if (!code.value || code.value.length !== 6) {
common_vendor.index.showToast({
title: "请输入验证码",
icon: "none"
});
return;
}
loading.value = true;
try {
const res = await utils_api.api.auth.verificationLogin("+86" + phone.value, code.value);
common_vendor.index.setStorageSync("token", res.token);
common_vendor.index.setStorageSync("user", res.user);
common_vendor.index.showToast({
title: "登录成功",
icon: "success"
});
common_vendor.index.reLaunch({ url: "/pages/index/index" });
} catch (error) {
common_vendor.index.__f__("error", "at pages/login/login.vue:139", "登录失败", error);
} finally {
loading.value = false;
}
};
const oneClickLogin = async () => {
if (!phone.value || phone.value.length !== 11) {
common_vendor.index.showToast({
title: "请输入正确的手机号",
icon: "none"
});
return;
}
loading.value = true;
try {
const res = await utils_api.api.auth.oneClickLogin("+86" + phone.value);
common_vendor.index.setStorageSync("token", res.token);
common_vendor.index.setStorageSync("user", res.user);
common_vendor.index.showToast({
title: "登录成功",
icon: "success"
});
common_vendor.index.reLaunch({ url: "/pages/index/index" });
} catch (error) {
common_vendor.index.__f__("error", "at pages/login/login.vue:169", "登录失败", error);
} finally {
loading.value = false;
}
};
const goToRegister = () => {
common_vendor.index.navigateTo({ url: "/pages/register/register" });
};
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.o(($event) => phone.value = $event),
b: common_vendor.p({
placeholder: "请输入手机号",
type: "number",
maxlength: 11,
clearable: true,
value: phone.value
}),
c: loginType.value === "code"
}, loginType.value === "code" ? {
d: common_vendor.t(codeButtonText.value),
e: common_vendor.o(sendCode),
f: common_vendor.p({
size: "small",
variant: "text",
disabled: codeDisabled.value
}),
g: common_vendor.o(($event) => code.value = $event),
h: common_vendor.p({
placeholder: "请输入验证码",
type: "number",
maxlength: 6,
clearable: true,
value: code.value
})
} : {}, {
i: loginType.value === "code"
}, loginType.value === "code" ? {
j: common_vendor.o(codeLogin),
k: common_vendor.p({
["t-class"]: "btn-primary",
theme: "primary",
size: "large",
block: true,
loading: loading.value
})
} : {
l: common_vendor.o(oneClickLogin),
m: common_vendor.p({
["t-class"]: "btn-primary",
theme: "primary",
size: "large",
block: true,
loading: loading.value
})
}, {
n: common_vendor.t(loginType.value === "code" ? "使用一键登录" : "使用验证码登录"),
o: common_vendor.o(toggleLoginType),
p: common_vendor.o(goToRegister)
});
};
}
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-e4e4508d"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/login.js.map