"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_api = require("../../utils/api.js"); const _sfc_main = { data() { return { username: "", password: "", showPassword: false, isLoading: false }; }, onLoad(options) { if (options.username) { this.username = decodeURIComponent(options.username); common_vendor.index.showToast({ title: "注册成功,请输入密码登录", icon: "success", duration: 2e3 }); } }, computed: { canLogin() { return this.username.trim().length > 0 && this.password.length > 0 && !this.isLoading; } }, methods: { togglePassword() { this.showPassword = !this.showPassword; }, handleLogin() { if (!this.canLogin) { common_vendor.index.showToast({ title: "请填写完整信息", icon: "none" }); return; } this.isLoading = true; common_vendor.index.showLoading({ title: "登录中...", mask: true }); utils_api.login(this.username.trim(), this.password).then((res) => { common_vendor.index.hideLoading(); this.isLoading = false; if (res.code === 200 && res.data) { try { const userInfo = res.data.user || {}; common_vendor.index.setStorageSync("userInfo", { id: userInfo.id, username: userInfo.username, nickname: userInfo.nickname, avatar: userInfo.avatar, gender: userInfo.gender, birthday: userInfo.birthday, bio: userInfo.bio, phone: userInfo.phone, email: userInfo.email, isVip: userInfo.isVip, token: res.data.token, loginTime: (/* @__PURE__ */ new Date()).getTime() }); common_vendor.index.setStorageSync("isLogin", true); } catch (e) { common_vendor.index.__f__("error", "at pages/login/login.vue:153", "保存用户信息失败", e); } common_vendor.index.showToast({ title: "登录成功", icon: "success" }); setTimeout(() => { common_vendor.index.switchTab({ url: "/pages/index/index" }); }, 1500); } else { common_vendor.index.showToast({ title: res.message || "登录失败", icon: "none" }); } }).catch((err) => { common_vendor.index.hideLoading(); this.isLoading = false; common_vendor.index.__f__("error", "at pages/login/login.vue:177", "登录失败:", err); common_vendor.index.showToast({ title: err.message || "登录失败,请检查网络连接", icon: "none", duration: 2e3 }); }); }, loginWithWeChat() { common_vendor.index.showToast({ title: "微信登录", icon: "none" }); }, loginWithQQ() { common_vendor.index.showToast({ title: "QQ登录", icon: "none" }); }, loginWithWeibo() { common_vendor.index.showToast({ title: "微博登录", icon: "none" }); }, goToRegister() { common_vendor.index.navigateTo({ url: "/pages/register/register" }); } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return { a: $data.username, b: common_vendor.o(($event) => $data.username = $event.detail.value), c: $data.showPassword ? "text" : "password", d: $data.password, e: common_vendor.o(($event) => $data.password = $event.detail.value), f: common_vendor.t($data.showPassword ? "隐藏" : "显示"), g: common_vendor.o((...args) => $options.togglePassword && $options.togglePassword(...args)), h: common_vendor.t($data.isLoading ? "登录中..." : "登录"), i: common_vendor.o((...args) => $options.handleLogin && $options.handleLogin(...args)), j: !$options.canLogin, k: common_vendor.o((...args) => $options.goToRegister && $options.goToRegister(...args)), l: common_vendor.o((...args) => $options.loginWithWeChat && $options.loginWithWeChat(...args)), m: common_vendor.o((...args) => $options.loginWithQQ && $options.loginWithQQ(...args)), n: common_vendor.o((...args) => $options.loginWithWeibo && $options.loginWithWeibo(...args)) }; } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-e4e4508d"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/login.js.map