|
@@ -15,19 +15,155 @@ const _sfc_main = {
|
|
|
regPhone: "",
|
|
|
regCode: "",
|
|
|
regUsername: "",
|
|
|
- regPassword: ""
|
|
|
+ regPassword: "",
|
|
|
+ regCodeTimer: 0,
|
|
|
+ // Countdown timer for registration code
|
|
|
+ isSendingRegCode: false,
|
|
|
+ // Flag to prevent multiple requests
|
|
|
+ loginCodeTimer: 0,
|
|
|
+ // Countdown timer for login code
|
|
|
+ isSendingLoginCode: false
|
|
|
+ // Flag to prevent multiple requests
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
- sendCode() {
|
|
|
- common_vendor.index.showToast({ title: "验证码已发送", icon: "none" });
|
|
|
+ // 处理微信登录
|
|
|
+ async oneClickLogin() {
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/login.vue:92", "WeChat login button clicked");
|
|
|
+ common_vendor.index.getUserProfile({
|
|
|
+ desc: "用于完善用户资料",
|
|
|
+ lang: "zh_CN",
|
|
|
+ success: (userRes) => {
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/login.vue:98", userRes);
|
|
|
+ common_vendor.index.showLoading({ title: "登录中...", mask: true });
|
|
|
+ common_vendor.index.login({
|
|
|
+ provider: "weixin",
|
|
|
+ success: (wx_res) => {
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/login.vue:105", "uni.getUserProfile success:", userRes);
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/login.vue:106", "uni.login success, got code:", wx_res.code);
|
|
|
+ common_vendor.index.request({
|
|
|
+ url: "http://localhost:3333/WeChart/login",
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ code: wx_res.code,
|
|
|
+ weChatLoginDto: userRes.userInfo
|
|
|
+ },
|
|
|
+ header: { "content-type": "application/json" },
|
|
|
+ success: (res) => {
|
|
|
+ var _a;
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ if (res.statusCode === 200 && res.data) {
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/login.vue:119", "Backend login success:", res.data);
|
|
|
+ common_vendor.index.showToast({ title: "登录成功", icon: "success" });
|
|
|
+ setTimeout(() => {
|
|
|
+ common_vendor.index.switchTab({ url: "/pages/home/index" });
|
|
|
+ }, 1500);
|
|
|
+ } else {
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:125", "Backend login failed:", res);
|
|
|
+ common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "登录失败", icon: "none" });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:131", "Backend request failed:", err);
|
|
|
+ common_vendor.index.showToast({ title: "微信登录失败", icon: "none" });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:138", "uni.login failed:", err);
|
|
|
+ common_vendor.index.showToast({ title: "微信登录失败", icon: "none" });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:144", "uni.getUserProfile failed:", err);
|
|
|
+ common_vendor.index.showToast({ title: "获取用户信息失败", icon: "none" });
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
- doLogin() {
|
|
|
+ async sendCode() {
|
|
|
+ var _a;
|
|
|
+ if (this.isSendingLoginCode || this.loginCodeTimer > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.phone) {
|
|
|
+ common_vendor.index.showToast({ title: "请输入手机号", icon: "none" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.isSendingLoginCode = true;
|
|
|
+ common_vendor.index.showLoading({ title: "发送中...", mask: true });
|
|
|
+ try {
|
|
|
+ const res = await common_vendor.index.request({
|
|
|
+ url: "http://localhost:3333/user/code",
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ phone: this.phone
|
|
|
+ },
|
|
|
+ header: { "content-type": "application/json" }
|
|
|
+ });
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.isSendingLoginCode = false;
|
|
|
+ if (res.statusCode === 200 && res.data) {
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/login.vue:175", "Send login code success:", res.data);
|
|
|
+ common_vendor.index.showToast({ title: "验证码已发送", icon: "success" });
|
|
|
+ this.loginCodeTimer = 60;
|
|
|
+ const timerInterval = setInterval(() => {
|
|
|
+ this.loginCodeTimer--;
|
|
|
+ if (this.loginCodeTimer <= 0) {
|
|
|
+ clearInterval(timerInterval);
|
|
|
+ this.loginCodeTimer = 0;
|
|
|
+ }
|
|
|
+ }, 1e3);
|
|
|
+ } else {
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:189", "Send login code failed:", res);
|
|
|
+ common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "发送失败", icon: "none" });
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.isSendingLoginCode = false;
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:195", "Send login code request failed:", err);
|
|
|
+ common_vendor.index.showToast({ title: "发送失败", icon: "none" });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async doLogin() {
|
|
|
+ var _a;
|
|
|
if (!this.agreed) {
|
|
|
common_vendor.index.showToast({ title: "请先同意协议", icon: "none" });
|
|
|
return;
|
|
|
}
|
|
|
- common_vendor.index.showToast({ title: "登录成功", icon: "success" });
|
|
|
+ if (!this.phone || !this.code) {
|
|
|
+ common_vendor.index.showToast({ title: "请填写手机号和验证码", icon: "none" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ common_vendor.index.showLoading({ title: "登录中...", mask: true });
|
|
|
+ try {
|
|
|
+ const res = await common_vendor.index.request({
|
|
|
+ url: "http://localhost:3333/user/login",
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ phone: this.phone,
|
|
|
+ code: this.code
|
|
|
+ },
|
|
|
+ header: { "content-type": "application/json" }
|
|
|
+ });
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ if (res.statusCode === 200 && res.data) {
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/login.vue:225", "Login success:", res.data);
|
|
|
+ common_vendor.index.showToast({ title: "登录成功", icon: "success" });
|
|
|
+ setTimeout(() => {
|
|
|
+ common_vendor.index.switchTab({ url: "/pages/home/index" });
|
|
|
+ }, 1500);
|
|
|
+ } else {
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:232", "Login failed:", res.data);
|
|
|
+ common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "登录失败", icon: "error" });
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:237", "Login request failed:", err);
|
|
|
+ common_vendor.index.showToast({ title: "登录失败", icon: "none" });
|
|
|
+ }
|
|
|
},
|
|
|
toRegister() {
|
|
|
this.showRegisterPopup = true;
|
|
@@ -41,18 +177,93 @@ const _sfc_main = {
|
|
|
openPrivacy() {
|
|
|
common_vendor.index.navigateTo({ url: "/pages/privacy/privacy" });
|
|
|
},
|
|
|
- oneClickLogin() {
|
|
|
- common_vendor.index.showToast({ title: "一键登录", icon: "none" });
|
|
|
- },
|
|
|
qqLogin() {
|
|
|
common_vendor.index.showToast({ title: "QQ登录", icon: "none" });
|
|
|
},
|
|
|
- sendRegCode() {
|
|
|
- common_vendor.index.showToast({ title: "注册验证码已发送", icon: "none" });
|
|
|
+ async sendRegCode() {
|
|
|
+ var _a;
|
|
|
+ if (this.isSendingRegCode || this.regCodeTimer > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.regPhone) {
|
|
|
+ common_vendor.index.showToast({ title: "请输入手机号", icon: "none" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.isSendingRegCode = true;
|
|
|
+ common_vendor.index.showLoading({ title: "发送中...", mask: true });
|
|
|
+ try {
|
|
|
+ const res = await common_vendor.index.request({
|
|
|
+ url: "http://localhost:3333/user/code",
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ phone: this.regPhone
|
|
|
+ // 发送手机号参数
|
|
|
+ },
|
|
|
+ header: { "content-type": "application/json" }
|
|
|
+ });
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.isSendingRegCode = false;
|
|
|
+ if (res.statusCode === 200 && res.data) {
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/login.vue:288", "Send registration code success:", res.data);
|
|
|
+ common_vendor.index.showToast({ title: "验证码已发送", icon: "success" });
|
|
|
+ this.regCodeTimer = 60;
|
|
|
+ const timerInterval = setInterval(() => {
|
|
|
+ this.regCodeTimer--;
|
|
|
+ if (this.regCodeTimer <= 0) {
|
|
|
+ clearInterval(timerInterval);
|
|
|
+ this.regCodeTimer = 0;
|
|
|
+ }
|
|
|
+ }, 1e3);
|
|
|
+ } else {
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:302", "Send registration code failed:", res);
|
|
|
+ common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "发送失败", icon: "none" });
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.isSendingRegCode = false;
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:309", "Send registration code request failed:", err);
|
|
|
+ common_vendor.index.showToast({ title: "发送失败", icon: "none" });
|
|
|
+ }
|
|
|
},
|
|
|
- doRegister() {
|
|
|
- common_vendor.index.showToast({ title: "注册成功", icon: "success" });
|
|
|
- this.showRegisterPopup = false;
|
|
|
+ async doRegister() {
|
|
|
+ var _a;
|
|
|
+ if (!this.regPhone || !this.regCode || !this.regUsername || !this.regPassword) {
|
|
|
+ common_vendor.index.showToast({ title: "请填写所有注册信息", icon: "none" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ common_vendor.index.showLoading({ title: "注册中...", mask: true });
|
|
|
+ try {
|
|
|
+ const res = await common_vendor.index.request({
|
|
|
+ url: "http://localhost:3333/user/register",
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ phone: this.regPhone,
|
|
|
+ code: this.regCode,
|
|
|
+ username: this.regUsername,
|
|
|
+ password: this.regPassword
|
|
|
+ },
|
|
|
+ header: { "content-type": "application/json" }
|
|
|
+ });
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ if (res.statusCode === 200 && res.data) {
|
|
|
+ common_vendor.index.__f__("log", "at pages/login/login.vue:337", "Registration success:", res.data);
|
|
|
+ common_vendor.index.showToast({ title: "注册成功", icon: "success" });
|
|
|
+ this.regPhone = "";
|
|
|
+ this.regCode = "";
|
|
|
+ this.regUsername = "";
|
|
|
+ this.regPassword = "";
|
|
|
+ setTimeout(() => {
|
|
|
+ this.showRegisterPopup = false;
|
|
|
+ }, 1500);
|
|
|
+ } else {
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:349", "Registration failed:", res);
|
|
|
+ common_vendor.index.showToast({ title: ((_a = res.data) == null ? void 0 : _a.message) || "注册失败", icon: "none" });
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ common_vendor.index.__f__("error", "at pages/login/login.vue:354", "Registration request failed:", err);
|
|
|
+ common_vendor.index.showToast({ title: "注册失败", icon: "none" });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -68,37 +279,41 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
g: common_vendor.o(($event) => $data.phone = $event.detail.value),
|
|
|
h: $data.code,
|
|
|
i: common_vendor.o(($event) => $data.code = $event.detail.value),
|
|
|
- j: common_vendor.o((...args) => $options.sendCode && $options.sendCode(...args))
|
|
|
+ j: common_vendor.t($data.loginCodeTimer > 0 ? $data.loginCodeTimer + "s" : "获取验证码"),
|
|
|
+ k: common_vendor.o((...args) => $options.sendCode && $options.sendCode(...args)),
|
|
|
+ l: $data.loginCodeTimer > 0 || $data.isSendingLoginCode
|
|
|
} : {
|
|
|
- k: $data.username,
|
|
|
- l: common_vendor.o(($event) => $data.username = $event.detail.value),
|
|
|
- m: $data.password,
|
|
|
- n: common_vendor.o(($event) => $data.password = $event.detail.value),
|
|
|
- o: common_vendor.o((...args) => $options.toRegister && $options.toRegister(...args)),
|
|
|
- p: common_vendor.o((...args) => $options.toForgot && $options.toForgot(...args))
|
|
|
+ m: $data.username,
|
|
|
+ n: common_vendor.o(($event) => $data.username = $event.detail.value),
|
|
|
+ o: $data.password,
|
|
|
+ p: common_vendor.o(($event) => $data.password = $event.detail.value),
|
|
|
+ q: common_vendor.o((...args) => $options.toRegister && $options.toRegister(...args)),
|
|
|
+ r: common_vendor.o((...args) => $options.toForgot && $options.toForgot(...args))
|
|
|
}, {
|
|
|
- q: !$data.agreed,
|
|
|
- r: common_vendor.o((...args) => $options.doLogin && $options.doLogin(...args)),
|
|
|
- s: $data.agreed,
|
|
|
- t: common_vendor.o(($event) => $data.agreed = !$data.agreed),
|
|
|
- v: common_vendor.o((...args) => $options.openAgreement && $options.openAgreement(...args)),
|
|
|
- w: common_vendor.o((...args) => $options.openPrivacy && $options.openPrivacy(...args)),
|
|
|
- x: common_assets._imports_0$1,
|
|
|
- y: common_vendor.o((...args) => $options.oneClickLogin && $options.oneClickLogin(...args)),
|
|
|
- z: $data.showRegisterPopup
|
|
|
+ s: !$data.agreed,
|
|
|
+ t: common_vendor.o((...args) => $options.doLogin && $options.doLogin(...args)),
|
|
|
+ v: $data.agreed,
|
|
|
+ w: common_vendor.o(($event) => $data.agreed = !$data.agreed),
|
|
|
+ x: common_vendor.o((...args) => $options.openAgreement && $options.openAgreement(...args)),
|
|
|
+ y: common_vendor.o((...args) => $options.openPrivacy && $options.openPrivacy(...args)),
|
|
|
+ z: common_assets._imports_0$1,
|
|
|
+ A: common_vendor.o((...args) => $options.oneClickLogin && $options.oneClickLogin(...args)),
|
|
|
+ B: $data.showRegisterPopup
|
|
|
}, $data.showRegisterPopup ? {
|
|
|
- A: $data.regPhone,
|
|
|
- B: common_vendor.o(($event) => $data.regPhone = $event.detail.value),
|
|
|
- C: $data.regCode,
|
|
|
- D: common_vendor.o(($event) => $data.regCode = $event.detail.value),
|
|
|
- E: common_vendor.o((...args) => $options.sendRegCode && $options.sendRegCode(...args)),
|
|
|
- F: $data.regUsername,
|
|
|
- G: common_vendor.o(($event) => $data.regUsername = $event.detail.value),
|
|
|
- H: $data.regPassword,
|
|
|
- I: common_vendor.o(($event) => $data.regPassword = $event.detail.value),
|
|
|
- J: common_vendor.o((...args) => $options.doRegister && $options.doRegister(...args)),
|
|
|
- K: common_assets._imports_1,
|
|
|
- L: common_vendor.o(($event) => $data.showRegisterPopup = false)
|
|
|
+ C: $data.regPhone,
|
|
|
+ D: common_vendor.o(($event) => $data.regPhone = $event.detail.value),
|
|
|
+ E: $data.regCode,
|
|
|
+ F: common_vendor.o(($event) => $data.regCode = $event.detail.value),
|
|
|
+ G: common_vendor.t($data.regCodeTimer > 0 ? $data.regCodeTimer + "s" : "获取验证码"),
|
|
|
+ H: common_vendor.o((...args) => $options.sendRegCode && $options.sendRegCode(...args)),
|
|
|
+ I: $data.regCodeTimer > 0 || $data.isSendingRegCode,
|
|
|
+ J: $data.regUsername,
|
|
|
+ K: common_vendor.o(($event) => $data.regUsername = $event.detail.value),
|
|
|
+ L: $data.regPassword,
|
|
|
+ M: common_vendor.o(($event) => $data.regPassword = $event.detail.value),
|
|
|
+ N: common_vendor.o((...args) => $options.doRegister && $options.doRegister(...args)),
|
|
|
+ O: common_assets._imports_1,
|
|
|
+ P: common_vendor.o(($event) => $data.showRegisterPopup = false)
|
|
|
} : {});
|
|
|
}
|
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|