248 lines
8.8 KiB
JavaScript
248 lines
8.8 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const utils_router = require("../../utils/router.js");
|
|
const api_auth_auth = require("../../api/auth/auth.js");
|
|
require("../../utils/request.js");
|
|
const api_article_article = require("../../api/article/article.js");
|
|
const enum_commonEnum = require("../../enum/commonEnum.js");
|
|
const utils_loadingManager = require("../../utils/loading-manager.js");
|
|
const _sfc_main = {
|
|
data() {
|
|
return {
|
|
loginLoading: false,
|
|
hasAgreed: false,
|
|
hasReadServiceTerms: false,
|
|
hasReadPrivacyPolicy: false,
|
|
showServiceTermsPopup: false,
|
|
showPrivacyPolicyPopup: false,
|
|
serviceTermsContent: "",
|
|
privacyPolicyContent: "",
|
|
scrollTop: 0
|
|
};
|
|
},
|
|
computed: {
|
|
CommonEnum() {
|
|
return enum_commonEnum.commonEnum;
|
|
}
|
|
},
|
|
onLoad() {
|
|
this.pageLoading = new utils_loadingManager.AutoLoadingManager();
|
|
},
|
|
onUnload() {
|
|
utils_loadingManager.forceHideLoading();
|
|
if (this.pageLoading) {
|
|
this.pageLoading.destroy();
|
|
}
|
|
},
|
|
methods: {
|
|
toggleAgreement() {
|
|
if (this.hasReadServiceTerms && this.hasReadPrivacyPolicy) {
|
|
this.hasAgreed = !this.hasAgreed;
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: "请先阅读服务条款和隐私政策",
|
|
icon: "none"
|
|
});
|
|
}
|
|
},
|
|
async showServiceTerms() {
|
|
try {
|
|
const res = await api_article_article.getServiceTerms();
|
|
if (res.code === 200 && res.data) {
|
|
let content = res.data.content || "暂无服务条款内容";
|
|
content = content.replace(/\n/g, "<br/>");
|
|
content = `<div style="word-wrap: break-word; word-break: break-all; line-height: 1.8; font-size: 28rpx; color: #333; padding: 0; margin: 0;">${content}</div>`;
|
|
this.serviceTermsContent = content;
|
|
this.showServiceTermsPopup = true;
|
|
this.scrollTop = 0;
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: "获取服务条款失败",
|
|
icon: "none"
|
|
});
|
|
}
|
|
} catch (error) {
|
|
common_vendor.index.__f__("error", "at pages/login/login.vue:134", "获取服务条款失败:", error);
|
|
common_vendor.index.showToast({
|
|
title: "获取服务条款失败",
|
|
icon: "none"
|
|
});
|
|
}
|
|
},
|
|
async showPrivacyPolicy() {
|
|
try {
|
|
const res = await api_article_article.getPrivacyPolicy();
|
|
if (res.code === 200 && res.data) {
|
|
let content = res.data.content || "暂无隐私政策内容";
|
|
content = content.replace(/\n/g, "<br/>");
|
|
content = `<div style="word-wrap: break-word; word-break: break-all; line-height: 1.8; font-size: 28rpx; color: #333; padding: 0; margin: 0;">${content}</div>`;
|
|
this.privacyPolicyContent = content;
|
|
this.showPrivacyPolicyPopup = true;
|
|
this.scrollTop = 0;
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: "获取隐私政策失败",
|
|
icon: "none"
|
|
});
|
|
}
|
|
} catch (error) {
|
|
common_vendor.index.__f__("error", "at pages/login/login.vue:159", "获取隐私政策失败:", error);
|
|
common_vendor.index.showToast({
|
|
title: "获取隐私政策失败",
|
|
icon: "none"
|
|
});
|
|
}
|
|
},
|
|
closeServiceTermsPopup() {
|
|
this.showServiceTermsPopup = false;
|
|
},
|
|
closePrivacyPolicyPopup() {
|
|
this.showPrivacyPolicyPopup = false;
|
|
},
|
|
async agreeServiceTerms() {
|
|
this.hasReadServiceTerms = true;
|
|
this.closeServiceTermsPopup();
|
|
this.checkAgreementStatus();
|
|
if (!this.hasReadPrivacyPolicy) {
|
|
setTimeout(() => {
|
|
this.showPrivacyPolicy();
|
|
}, 500);
|
|
}
|
|
},
|
|
async agreePrivacyPolicy() {
|
|
this.hasReadPrivacyPolicy = true;
|
|
this.closePrivacyPolicyPopup();
|
|
this.checkAgreementStatus();
|
|
if (!this.hasReadServiceTerms) {
|
|
setTimeout(() => {
|
|
this.showServiceTerms();
|
|
}, 500);
|
|
}
|
|
},
|
|
checkAgreementStatus() {
|
|
if (this.hasReadServiceTerms && this.hasReadPrivacyPolicy) {
|
|
this.hasAgreed = true;
|
|
}
|
|
},
|
|
async showUnreadTerms() {
|
|
if (!this.hasReadServiceTerms) {
|
|
await this.showServiceTerms();
|
|
return;
|
|
}
|
|
if (!this.hasReadPrivacyPolicy) {
|
|
await this.showPrivacyPolicy();
|
|
return;
|
|
}
|
|
},
|
|
getPhoneNumber() {
|
|
if (!this.hasReadServiceTerms || !this.hasReadPrivacyPolicy) {
|
|
common_vendor.index.showToast({
|
|
title: "请先阅读服务条款和隐私政策",
|
|
icon: "none",
|
|
duration: 2e3
|
|
});
|
|
this.showUnreadTerms();
|
|
return;
|
|
}
|
|
let that = this;
|
|
common_vendor.index.login({
|
|
success(res) {
|
|
if (res.code) {
|
|
common_vendor.index.__f__("log", "at pages/login/login.vue:233", "登录!", res);
|
|
let data = {
|
|
loginCode: res.code,
|
|
appId: 1
|
|
};
|
|
if (that.pageLoading) {
|
|
that.pageLoading.show("登录中...");
|
|
}
|
|
api_auth_auth.wxLogin(data).then((res2) => {
|
|
if (that.pageLoading) {
|
|
that.pageLoading.hide();
|
|
}
|
|
utils_loadingManager.forceHideLoading();
|
|
if (res2.code == 200) {
|
|
common_vendor.index.__f__("log", "at pages/login/login.vue:250", res2, "resres");
|
|
common_vendor.index.setStorageSync("token", res2.token);
|
|
common_vendor.index.showToast({
|
|
title: "登录成功",
|
|
icon: "success",
|
|
duration: 1500
|
|
});
|
|
setTimeout(() => {
|
|
that.ceshi();
|
|
}, 1500);
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: res2.msg || "登录失败",
|
|
icon: "none"
|
|
});
|
|
}
|
|
}).catch((error) => {
|
|
if (that.pageLoading) {
|
|
that.pageLoading.hide();
|
|
}
|
|
utils_loadingManager.forceHideLoading();
|
|
common_vendor.index.__f__("error", "at pages/login/login.vue:272", "登录失败:", error);
|
|
common_vendor.index.showToast({
|
|
title: "登录失败",
|
|
icon: "none"
|
|
});
|
|
});
|
|
}
|
|
},
|
|
fail(err) {
|
|
common_vendor.index.__f__("error", "at pages/login/login.vue:281", "微信登录失败:", err);
|
|
common_vendor.index.showToast({
|
|
title: "微信登录失败",
|
|
icon: "none"
|
|
});
|
|
}
|
|
});
|
|
},
|
|
async ceshi() {
|
|
if (this.pageLoading) {
|
|
this.pageLoading.hide();
|
|
}
|
|
utils_loadingManager.forceHideLoading();
|
|
utils_router.navigateToPage("index");
|
|
}
|
|
}
|
|
};
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
return common_vendor.e({
|
|
a: $options.CommonEnum.LOGIN_SRC,
|
|
b: common_vendor.t($data.loginLoading ? "登录中..." : "微信用户一键登录"),
|
|
c: common_vendor.o((...args) => $options.getPhoneNumber && $options.getPhoneNumber(...args)),
|
|
d: $data.loginLoading,
|
|
e: $data.hasAgreed
|
|
}, $data.hasAgreed ? {} : {}, {
|
|
f: $data.hasAgreed ? 1 : "",
|
|
g: common_vendor.o((...args) => $options.toggleAgreement && $options.toggleAgreement(...args)),
|
|
h: common_vendor.o((...args) => $options.showServiceTerms && $options.showServiceTerms(...args)),
|
|
i: common_vendor.o((...args) => $options.showPrivacyPolicy && $options.showPrivacyPolicy(...args)),
|
|
j: $data.showServiceTermsPopup
|
|
}, $data.showServiceTermsPopup ? {
|
|
k: common_vendor.o((...args) => $options.closeServiceTermsPopup && $options.closeServiceTermsPopup(...args)),
|
|
l: $data.serviceTermsContent,
|
|
m: $data.scrollTop,
|
|
n: common_vendor.o((...args) => $options.agreeServiceTerms && $options.agreeServiceTerms(...args)),
|
|
o: common_vendor.o(() => {
|
|
}),
|
|
p: common_vendor.o((...args) => $options.closeServiceTermsPopup && $options.closeServiceTermsPopup(...args))
|
|
} : {}, {
|
|
q: $data.showPrivacyPolicyPopup
|
|
}, $data.showPrivacyPolicyPopup ? {
|
|
r: common_vendor.o((...args) => $options.closePrivacyPolicyPopup && $options.closePrivacyPolicyPopup(...args)),
|
|
s: $data.privacyPolicyContent,
|
|
t: $data.scrollTop,
|
|
v: common_vendor.o((...args) => $options.agreePrivacyPolicy && $options.agreePrivacyPolicy(...args)),
|
|
w: common_vendor.o(() => {
|
|
}),
|
|
x: common_vendor.o((...args) => $options.closePrivacyPolicyPopup && $options.closePrivacyPolicyPopup(...args))
|
|
} : {});
|
|
}
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/login.js.map
|