123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const _sfc_main = {
- data() {
- return {
- loading: false,
- userInfo: null,
- rawData: null
- };
- },
- mounted() {
- this.initWechat();
- },
- methods: {
- initWechat() {
- common_vendor.index.__f__("log", "at pages/login/index.vue:39", "跳过依赖 WeixinJSBridge 的初始化");
- },
- handleGetUserProfile() {
- common_vendor.wx$1.showLoading({
- title: "获取信息中...",
- // 缩短提示文字
- mask: true
- });
- common_vendor.wx$1.getUserProfile({
- desc: "用于完善会员资料",
- success: (res) => {
- this.userInfo = res.userInfo;
- this.rawData = res.rawData;
- common_vendor.index.__f__("log", "at pages/login/index.vue:51", "获取到的 rawData:", this.rawData);
- common_vendor.wx$1.hideLoading();
- },
- fail: (err) => {
- common_vendor.index.__f__("error", "at pages/login/index.vue:55", "获取用户信息失败:", err);
- common_vendor.wx$1.showToast({ title: "请授权后再登录", icon: "none" });
- common_vendor.wx$1.hideLoading();
- }
- });
- },
- // 处理获取手机号事件
- handleGetPhoneNumber: async function(e) {
- if (e.detail.errMsg === "getPhoneNumber:ok") {
- if (!this.rawData) {
- common_vendor.index.__f__("error", "at pages/login/index.vue:65", "请先授权获取用户信息");
- common_vendor.wx$1.showToast({ title: "请先授权获取用户信息", icon: "none" });
- return;
- }
- try {
- common_vendor.wx$1.showLoading({
- title: "登录中...",
- // 缩短提示文字
- mask: true
- });
- this.loading = true;
- const encryptedData = e.detail.encryptedData;
- const iv = e.detail.iv;
- const { code } = await new Promise((resolve, reject) => {
- common_vendor.wx$1.login({
- success: (res) => resolve(res),
- fail: (err) => reject(err)
- });
- });
- const response = await new Promise((resolve, reject) => {
- common_vendor.wx$1.request({
- url: "http://localhost:8080/api/auth/wechat/login",
- method: "POST",
- data: {
- code,
- encryptedData,
- iv,
- rawData: this.rawData
- // 使用获取到的 rawData
- },
- success: (res) => resolve(res),
- fail: (err) => {
- if (err.errMsg.includes("request:fail url not in domain list")) {
- common_vendor.wx$1.showToast({
- title: "请求域名未配置,请联系管理员",
- icon: "none",
- duration: 3e3
- });
- }
- common_vendor.index.__f__("error", "at pages/login/index.vue:104", "网络请求失败:", err);
- reject(err);
- }
- });
- });
- common_vendor.index.__f__("log", "at pages/login/index.vue:110", "后端返回的完整数据:", response.data);
- if (response.data) {
- if (response.data.wxNickname && response.data.wxAvatarUrl) {
- common_vendor.wx$1.setStorageSync("userToken", response.data.token);
- common_vendor.wx$1.setStorageSync("userInfo", {
- userId: response.data.userId,
- wxNickname: response.data.wxNickname,
- wxAvatarUrl: response.data.wxAvatarUrl
- });
- common_vendor.wx$1.navigateTo({
- url: "/pages/home/index"
- });
- } else {
- common_vendor.index.__f__("error", "at pages/login/index.vue:124", "后端未返回微信昵称或头像信息:", response.data);
- common_vendor.wx$1.showToast({ title: "获取用户信息失败,请重试", icon: "none" });
- }
- } else {
- common_vendor.index.__f__("error", "at pages/login/index.vue:128", "登录响应数据为空:", response);
- common_vendor.wx$1.showToast({ title: "登录失败,请重试", icon: "none" });
- }
- } catch (error) {
- common_vendor.index.__f__("error", "at pages/login/index.vue:132", "登录过程出错:", error);
- common_vendor.wx$1.showToast({ title: "登录失败,请重试", icon: "none" });
- } finally {
- this.loading = false;
- common_vendor.wx$1.hideLoading();
- }
- } else {
- common_vendor.index.__f__("error", "at pages/login/index.vue:139", "用户拒绝授权", e.detail.errMsg);
- common_vendor.wx$1.showToast({ title: "请授权后再登录", icon: "none" });
- }
- }
- }
- };
- if (!Array) {
- const _component_uni_spinner = common_vendor.resolveComponent("uni-spinner");
- _component_uni_spinner();
- }
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.o((...args) => $options.handleGetPhoneNumber && $options.handleGetPhoneNumber(...args)),
- b: common_vendor.o((...args) => $options.handleGetUserProfile && $options.handleGetUserProfile(...args)),
- c: $data.loading
- }, $data.loading ? {
- d: common_vendor.p({
- type: "circular",
- color: "#07c160",
- size: "40"
- })
- } : {});
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-d08ef7d4"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/index.js.map
|