appointment_system/unpackage/dist/dev/mp-weixin/pages/login/login-page.js
2025-12-15 23:42:31 +08:00

269 lines
9.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
const common_vendor = require("../../common/vendor.js");
const modules_api_AppServer = require("../../modules/api/AppServer.js");
const utils_auth = require("../../utils/auth.js");
const modules_Config = require("../../modules/Config.js");
const common_assets = require("../../common/assets.js");
const _sfc_main = {
data() {
return {
isLoading: false,
agreeToTerms: false,
showAgreementModal: false,
showPrivacyModal: false,
userAgreementContent: this.getUserAgreementContent(),
privacyPolicyContent: this.getPrivacyPolicyContent(),
statusBarHeight: 0,
appLogo: ""
};
},
onLoad() {
const systemInfo = common_vendor.index.getSystemInfoSync();
this.statusBarHeight = systemInfo.statusBarHeight || 0;
this.loadConfig();
},
methods: {
back() {
common_vendor.index.navigateBack({
delta: 1
});
},
// Handle WeChat login
async handleWechatLogin() {
if (this.isLoading) {
return;
}
if (!this.agreeToTerms) {
common_vendor.index.showToast({
title: this.$t("login.mustAgreeToTerms"),
icon: "none"
});
return;
}
this.isLoading = true;
try {
const loginRes = await this.getWechatLoginCode();
common_vendor.index.__f__("log", "at pages/login/login-page.vue:134", "微信登录 code:", loginRes);
if (!loginRes || !loginRes.code) {
common_vendor.index.showToast({
title: this.$t("login.wechatLoginFailed"),
icon: "none"
});
this.isLoading = false;
return;
}
const appserver = new modules_api_AppServer.AppServer();
const data = await appserver.WechatLogin(loginRes.code);
common_vendor.index.__f__("log", "at pages/login/login-page.vue:149", "登录接口返回:", data);
if (!data) {
common_vendor.index.__f__("error", "at pages/login/login-page.vue:153", "登录接口无响应");
common_vendor.index.showToast({
title: this.$t("login.loginFailed"),
icon: "none"
});
this.isLoading = false;
return;
}
if (data.code !== 0) {
common_vendor.index.__f__("error", "at pages/login/login-page.vue:164", "登录失败code:", data.code, "message:", data.message);
common_vendor.index.showToast({
title: data.message || this.$t("login.loginFailed"),
icon: "none"
});
this.isLoading = false;
return;
}
if (!data.data || !data.data.token) {
common_vendor.index.__f__("error", "at pages/login/login-page.vue:175", "Token 数据缺失:", data.data);
common_vendor.index.showToast({
title: this.$t("login.loginFailed"),
icon: "none"
});
this.isLoading = false;
return;
}
common_vendor.index.__f__("log", "at pages/login/login-page.vue:184", "登录成功,保存认证信息");
const token = "Bearer " + data.data.token;
utils_auth.saveAuthData(token, data.data.refreshToken, data.data.user);
common_vendor.index.showToast({
title: this.$t("login.loginSuccess") || "登录成功",
icon: "success",
duration: 1500
});
setTimeout(() => {
this.redirectToHome();
}, 500);
} catch (error) {
common_vendor.index.__f__("error", "at pages/login/login-page.vue:203", "登录异常:", error);
common_vendor.index.__f__("error", "at pages/login/login-page.vue:204", "错误堆栈:", error.stack);
common_vendor.index.showToast({
title: this.$t("login.loginError") + ": " + (error.message || ""),
icon: "none",
duration: 3e3
});
} finally {
this.isLoading = false;
}
},
// 获取微信登录codePromise封装
getWechatLoginCode() {
return new Promise((resolve, reject) => {
common_vendor.index.login({
provider: "weixin",
success: (res) => {
resolve(res);
},
fail: (err) => {
common_vendor.index.__f__("error", "at pages/login/login-page.vue:224", "uni.login 失败:", err);
reject(err);
}
});
});
},
// 登录成功后跳转到首页
redirectToHome() {
const app = getApp();
if (app.globalData) {
app.globalData.shouldRefresh = true;
app.globalData.loginTime = Date.now();
}
common_vendor.index.switchTab({
url: "/pages/index/index",
success: () => {
common_vendor.index.__f__("log", "at pages/login/login-page.vue:244", "登录成功,已跳转到首页");
},
fail: (err) => {
common_vendor.index.__f__("error", "at pages/login/login-page.vue:247", "跳转首页失败:", err);
common_vendor.index.reLaunch({
url: "/pages/index/index"
});
}
});
},
// Handle agreement checkbox change
handleAgreementChange(e) {
this.agreeToTerms = e.detail.value.includes("agree");
},
// Show user agreement
showUserAgreement() {
this.showAgreementModal = true;
},
// Close user agreement
closeUserAgreement() {
this.showAgreementModal = false;
},
// Show privacy policy
showPrivacyPolicy() {
this.showPrivacyModal = true;
},
// Close privacy policy
closePrivacyPolicy() {
this.showPrivacyModal = false;
},
// Get user agreement content
getUserAgreementContent() {
return this.$t("login.userAgreementContent") || `
用户协议
欢迎使用本应用。本协议规定了您使用本应用的条款和条件。
1. 服务条款
用户同意遵守本协议的所有条款和条件。
2. 用户责任
用户对其账户的安全负责,并同意不与他人共享登录凭证。
3. 禁止行为
用户不得进行任何非法或有害的活动。
4. 免责声明
本应用按"现状"提供,不提供任何明示或暗示的保证。
5. 修改权利
我们保留随时修改本协议的权利。
`;
},
// Get privacy policy content
getPrivacyPolicyContent() {
return this.$t("login.privacyPolicyContent") || `
隐私政策
我们重视您的隐私。本政策说明我们如何收集、使用和保护您的信息。
1. 信息收集
我们收集您在使用本应用时提供的信息,包括账户信息和使用数据。
2. 信息使用
我们使用收集的信息来改进服务、进行分析和提供个性化体验。
3. 信息保护
我们采取适当的安全措施来保护您的个人信息。
4. 第三方共享
我们不会将您的个人信息出售给第三方。
5. 联系我们
如有隐私问题,请通过应用内的联系方式与我们联系。
`;
},
// 加载配置
async loadConfig() {
try {
const config = await modules_Config.Config.getPublicConfig();
if (config.app_logo) {
this.appLogo = modules_Config.Config.getImageUrl(config.app_logo);
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/login/login-page.vue:337", "加载配置失败:", error);
}
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_assets._imports_0,
b: common_vendor.o((...args) => $options.back && $options.back(...args)),
c: common_vendor.t(_ctx.$t("login.title")),
d: common_vendor.o((...args) => _ctx.markAllRead && _ctx.markAllRead(...args)),
e: $data.appLogo
}, $data.appLogo ? {
f: $data.appLogo
} : {}, {
g: common_vendor.t(_ctx.$t("login.oneClickLogin")),
h: common_vendor.o((...args) => $options.handleWechatLogin && $options.handleWechatLogin(...args)),
i: $data.isLoading,
j: $data.agreeToTerms,
k: common_vendor.t(_ctx.$t("login.agreeToTerms")),
l: common_vendor.t(_ctx.$t("login.userAgreement")),
m: common_vendor.o((...args) => $options.showUserAgreement && $options.showUserAgreement(...args)),
n: common_vendor.t(_ctx.$t("login.and")),
o: common_vendor.t(_ctx.$t("login.privacyPolicy")),
p: common_vendor.o((...args) => $options.showPrivacyPolicy && $options.showPrivacyPolicy(...args)),
q: common_vendor.o((...args) => $options.handleAgreementChange && $options.handleAgreementChange(...args)),
r: $data.showAgreementModal
}, $data.showAgreementModal ? {
s: common_vendor.t(_ctx.$t("login.userAgreement")),
t: common_vendor.o((...args) => $options.closeUserAgreement && $options.closeUserAgreement(...args)),
v: common_vendor.t($data.userAgreementContent),
w: common_vendor.t(_ctx.$t("login.agree")),
x: common_vendor.o((...args) => $options.closeUserAgreement && $options.closeUserAgreement(...args)),
y: common_vendor.o(() => {
}),
z: common_vendor.o((...args) => $options.closeUserAgreement && $options.closeUserAgreement(...args))
} : {}, {
A: $data.showPrivacyModal
}, $data.showPrivacyModal ? {
B: common_vendor.t(_ctx.$t("login.privacyPolicy")),
C: common_vendor.o((...args) => $options.closePrivacyPolicy && $options.closePrivacyPolicy(...args)),
D: common_vendor.t($data.privacyPolicyContent),
E: common_vendor.t(_ctx.$t("login.agree")),
F: common_vendor.o((...args) => $options.closePrivacyPolicy && $options.closePrivacyPolicy(...args)),
G: common_vendor.o(() => {
}),
H: common_vendor.o((...args) => $options.closePrivacyPolicy && $options.closePrivacyPolicy(...args))
} : {});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-6337d1cb"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/login-page.js.map