123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_assets = require("../../common/assets.js");
- const _sfc_main = {
- data() {
- return {
- isAgreed: false,
- showServiceAgreement: false,
- showPrivacyPolicy: false
- };
- },
- methods: {
- // 处理协议勾选
- handleAgreementChange(e) {
- this.isAgreed = e.detail.value.length > 0;
- },
- // 微信登录
- handleWechatLogin() {
- if (!this.isAgreed) {
- common_vendor.index.showToast({ title: "请先同意用户协议和隐私政策", icon: "none" });
- return;
- }
- common_vendor.wx$1.getUserProfile({
- desc: "用于登录和完善个人信息",
- // 清晰的授权用途说明
- success: async (userRes) => {
- const { encryptedData, iv } = userRes;
- common_vendor.index.__f__("log", "at pages/login/index.vue:76", userRes);
- const loginResult = await new Promise((resolve, reject) => {
- common_vendor.wx$1.login({ success: resolve, fail: reject });
- });
- if (!loginResult.code) {
- common_vendor.index.showToast({ title: "登录凭证获取失败", icon: "none" });
- return;
- }
- const code = loginResult.code;
- common_vendor.index.__f__("log", "at pages/login/index.vue:87", code);
- const avatar_url = userRes.userInfo.avatarUrl;
- const nickname = userRes.userInfo.nickName;
- try {
- const loginRes = await common_vendor.index.request({
- url: "http://localhost:9527/api/wx-login",
- method: "POST",
- data: { code, encryptedData, iv, avatar_url, nickname },
- header: { "content-type": "application/json" }
- });
- common_vendor.index.__f__("log", "at pages/login/index.vue:98", loginRes);
- if (loginRes.statusCode !== 200 || loginRes.data.errcode) {
- throw new Error(loginRes.data.errmsg || "登录失败");
- }
- common_vendor.index.setStorageSync("uid", loginRes.data.data.id);
- common_vendor.index.setStorageSync("token", loginRes.data.data.token);
- common_vendor.index.setStorageSync("userInfo", loginRes.data.data.userInfo);
- common_vendor.index.switchTab({ url: "/pages/discover/index" });
- } catch (error) {
- common_vendor.index.__f__("error", "at pages/login/index.vue:111", "登录接口调用失败:", error);
- common_vendor.index.showToast({ title: "登录失败,请重试", icon: "none" });
- }
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/login/index.vue:116", "用户授权失败:", err);
- if (err.errCode === 10004) {
- common_vendor.index.showToast({ title: "请授权后再登录", icon: "none" });
- }
- }
- });
- },
- // 跳转到验证码登录页面
- navigateToVerifyCodeLogin() {
- common_vendor.index.navigateTo({
- url: "/pages/login/verify-code"
- });
- },
- // 打开服务协议
- openServiceAgreement() {
- common_vendor.index.navigateTo({
- url: "/pages/agreement/service"
- });
- },
- // 打开隐私政策
- openPrivacyPolicy() {
- common_vendor.index.navigateTo({
- url: "/pages/agreement/privacy"
- });
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return {
- a: common_assets._imports_0,
- b: common_vendor.o((...args) => $options.handleWechatLogin && $options.handleWechatLogin(...args)),
- c: common_vendor.o((...args) => $options.navigateToVerifyCodeLogin && $options.navigateToVerifyCodeLogin(...args)),
- d: $data.isAgreed,
- e: common_vendor.o((...args) => $options.openServiceAgreement && $options.openServiceAgreement(...args)),
- f: common_vendor.o((...args) => $options.openPrivacyPolicy && $options.openPrivacyPolicy(...args)),
- g: common_vendor.o((...args) => $options.handleAgreementChange && $options.handleAgreementChange(...args))
- };
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/index.js.map
|