WXL
20 小时以前 05c363fdd7ab04e3bd9a753e2c5d5bfff04d681c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const stores_user = require("../../stores/user.js");
const utils_auth = require("../../utils/auth.js");
const utils_crypto = require("../../utils/crypto.js");
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  (_easycom_uni_load_more2 + _easycom_uni_icons2)();
}
const _easycom_uni_load_more = () => "../../node-modules/@dcloudio/uni-ui/lib/uni-load-more/uni-load-more.js";
const _easycom_uni_icons = () => "../../node-modules/@dcloudio/uni-ui/lib/uni-icons/uni-icons.js";
if (!Math) {
  (_easycom_uni_load_more + _easycom_uni_icons)();
}
const _sfc_main = {
  __name: "Login",
  setup(__props) {
    let isAutoLogining = false;
    let hasAutoLogin = false;
    const username = common_vendor.ref("");
    const password = common_vendor.ref("");
    const showPassword = common_vendor.ref(false);
    const redirect = common_vendor.ref("");
    const tabBarPages = [
      "/pages/index/index",
      "/pages/appointment/index",
      "/pages/consultation/index",
      "/pages/my/index"
    ];
    common_vendor.onLoad(async (options) => {
      common_vendor.index.__f__("log", "at pages/login/Login.vue:69", "登录页onLoad,原始参数:", options);
      const launchQuery = common_vendor.index.getLaunchOptionsSync().query || {};
      const allParams = { ...launchQuery, ...options };
      common_vendor.index.__f__("log", "at pages/login/Login.vue:72", "合并后参数:", allParams);
      if (allParams.redirect) {
        redirect.value = decodeURIComponent(allParams.redirect);
      }
      const code = allParams.code;
      if (code) {
        common_vendor.index.__f__("log", "at pages/login/Login.vue:82", "检测到免登码,开始解析:", code);
        common_vendor.index.showLoading({ title: "解析免登信息...", mask: true });
        try {
          const res = await common_vendor.index.$uapi.get("/GiLink/getCode", { code });
          common_vendor.index.hideLoading();
          common_vendor.index.__f__("log", "at pages/login/Login.vue:89", res.data);
          res.data.passWord = res.data.userPhone;
          if (!res.data || !res.data.userName || !res.data.passWord) {
            throw new Error("解析免登码失败");
          }
          let obj = JSON.parse(res.data.extContent);
          common_vendor.index.__f__("log", "at pages/login/Login.vue:96", res.data.userName);
          const userName = res.data.userName;
          const passWord = res.data.passWord;
          const otherParams = {
            id: obj.infoId,
            type: obj.type,
            status: obj.status,
            fcid: obj.id
          };
          common_vendor.index.__f__("log", "at pages/login/Login.vue:106", "解析结果:", { userName, otherParams });
          if (utils_auth.getToken())
            common_vendor.index.removeStorageSync("token");
          await handleSSOLogin(userName, passWord, otherParams);
        } catch (err) {
          common_vendor.index.hideLoading();
          common_vendor.index.__f__("error", "at pages/login/Login.vue:113", "免登码解析失败:", err);
          common_vendor.index.showToast({ title: "免登录失败,请手动登录", icon: "none" });
        }
        return;
      }
      if (utils_auth.getToken()) {
        setTimeout(() => navigateToTarget(), 100);
        return;
      }
      username.value = "";
      password.value = "";
    });
    common_vendor.onShow(() => {
      if (hasAutoLogin)
        hasAutoLogin = false;
    });
    const handleSSOLogin = async (userName, passWord, pageParams = {}) => {
      var _a;
      if (isAutoLogining)
        return;
      isAutoLogining = true;
      common_vendor.index.__f__("log", "at pages/login/Login.vue:140", "开始SSO免登:", { userName, pageParams });
      common_vendor.index.showLoading({ title: "自动登录中...", mask: true });
      try {
        const tokenRes = await common_vendor.index.$uapi.post("/getToken", { userName, passWord });
        common_vendor.index.hideLoading();
        if (!((_a = tokenRes.data) == null ? void 0 : _a.token))
          throw new Error("获取token失败");
        utils_auth.setToken(tokenRes.data.token);
        const userStore = stores_user.useUserStore();
        const userInfo = await common_vendor.index.$uapi.get("/getInfo");
        if (userInfo && userInfo.user) {
          userStore.setUserInfo(userInfo.user);
          if (userInfo.roles)
            userStore.setroleKey(userInfo.roles);
        }
        let targetPage = redirect.value;
        if (!targetPage) {
          const launchOptions = common_vendor.index.getLaunchOptionsSync();
          const originalPath = launchOptions.path;
          if (originalPath && !originalPath.includes("login/Login")) {
            targetPage = "/" + originalPath;
          }
        }
        if (!targetPage)
          targetPage = "/pages/index/index";
        hasAutoLogin = true;
        await navigateToTargetPage(targetPage, pageParams);
      } catch (err) {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("error", "at pages/login/Login.vue:175", "SSO免登失败:", err);
        common_vendor.index.showToast({
          title: err.message || "自动登录失败,请手动登录",
          icon: "none",
          duration: 3e3
        });
        common_vendor.index.removeStorageSync("token");
      } finally {
        isAutoLogining = false;
      }
    };
    const handleLogin = async () => {
      try {
        if (!username.value || !password.value) {
          common_vendor.index.showToast({ title: "请输入账号密码", icon: "none" });
          return;
        }
        common_vendor.index.showLoading({ title: "登录中...", mask: true });
        const userStore = stores_user.useUserStore();
        const encryptedPassword = utils_crypto.encrypt(password.value);
        const encryptedUsername = utils_crypto.encrypt(username.value);
        const loginRes = await common_vendor.index.$uapi.post("/login", {
          username: encryptedUsername,
          password: encryptedPassword
        });
        if (!loginRes || !loginRes.token)
          throw new Error("登录失败");
        utils_auth.setToken(loginRes.token);
        const userInfo = await common_vendor.index.$uapi.get("/getInfo");
        if (userInfo && userInfo.user) {
          userStore.setUserInfo(userInfo.user);
          if (userInfo.roles)
            userStore.setroleKey(userInfo.roles);
        }
        common_vendor.index.hideLoading();
        await navigateToTarget();
      } catch (err) {
        common_vendor.index.hideLoading();
        common_vendor.index.__f__("error", "at pages/login/Login.vue:221", "登录失败:", err);
        common_vendor.index.showToast({
          title: err.message || "登录失败",
          icon: "none",
          duration: 3e3
        });
      }
    };
    const navigateToTarget = () => {
      if (redirect.value) {
        return navigateToTargetPage(redirect.value, {});
      } else {
        common_vendor.index.__f__("log", "at pages/login/Login.vue:237", "没有目标页面,跳转首页");
        common_vendor.index.switchTab({ url: "/pages/index/index" });
        return Promise.resolve(true);
      }
    };
    const navigateToTargetPage = (targetPage, pageParams = {}) => {
      return new Promise((resolve) => {
        if (!targetPage) {
          common_vendor.index.__f__("log", "at pages/login/Login.vue:251", "目标页为空,跳转首页");
          common_vendor.index.switchTab({ url: "/pages/index/index" });
          resolve(true);
          return;
        }
        let finalUrl = targetPage;
        const paramKeys = Object.keys(pageParams).filter(
          (key) => pageParams[key] !== void 0 && pageParams[key] !== null
        );
        if (paramKeys.length > 0) {
          const queryStr = paramKeys.map((key) => `${key}=${encodeURIComponent(pageParams[key])}`).join("&");
          finalUrl += (finalUrl.includes("?") ? "&" : "?") + queryStr + "&sso=1";
        }
        common_vendor.index.__f__("log", "at pages/login/Login.vue:268", "最终跳转目标URL:", finalUrl);
        const baseUrl = finalUrl.split("?")[0];
        const isTabBar = tabBarPages.includes(baseUrl);
        setTimeout(() => {
          if (isTabBar) {
            common_vendor.index.switchTab({
              url: baseUrl,
              success: () => resolve(true),
              fail: (err) => {
                common_vendor.index.__f__("error", "at pages/login/Login.vue:279", "switchTab失败:", err);
                common_vendor.index.switchTab({ url: "/pages/index/index" });
                resolve(false);
              }
            });
          } else {
            common_vendor.index.redirectTo({
              url: finalUrl,
              success: () => resolve(true),
              fail: (err) => {
                common_vendor.index.__f__("error", "at pages/login/Login.vue:289", "redirectTo失败:", err);
                common_vendor.index.switchTab({ url: "/pages/index/index" });
                resolve(false);
              }
            });
          }
        }, 300);
      });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.unref(isAutoLogining)
      }, common_vendor.unref(isAutoLogining) ? {
        b: common_vendor.p({
          status: "loading",
          ["content-text"]: {
            contentdown: "自动登录中..."
          }
        })
      } : {}, {
        c: common_assets._imports_0,
        d: common_vendor.p({
          type: "contact",
          size: "24",
          color: "#409EFF"
        }),
        e: username.value,
        f: common_vendor.o(($event) => username.value = $event.detail.value),
        g: common_vendor.p({
          type: "locked",
          size: "24",
          color: "#409EFF"
        }),
        h: !showPassword.value,
        i: password.value,
        j: common_vendor.o(($event) => password.value = $event.detail.value),
        k: common_vendor.o(($event) => showPassword.value = !showPassword.value),
        l: common_vendor.p({
          type: showPassword.value ? "eye" : "eye-slash",
          size: "22",
          color: "#999"
        }),
        m: username.value && password.value ? 1 : "",
        n: common_vendor.o(handleLogin),
        o: common_vendor.gei(_ctx, "")
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-0a03bc64"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/Login.js.map