"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_auth = require("../../utils/auth.js"); const utils_api = require("../../utils/api.js"); const _sfc_main = { data() { return { avatarUrl: "/static/images/head.png", nickname: "", phone: "", originalAvatar: "", originalNickname: "" }; }, onLoad() { const loginStatus = utils_auth.isLoggedIn(); console.log("[编辑资料] 登录状态:", loginStatus); this.loadUserInfo(); }, onShow() { common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" }); }, methods: { /** * 加载用户信息 */ loadUserInfo() { const userInfo = utils_auth.getUserInfo(); console.log("[编辑资料] 加载用户信息:", userInfo); if (userInfo) { this.avatarUrl = userInfo.avatar || "/static/images/head.png"; this.nickname = userInfo.nickname || ""; this.phone = userInfo.phone || ""; this.originalAvatar = this.avatarUrl; this.originalNickname = this.nickname; } }, /** * 选择头像 */ onChooseAvatar(e) { const { avatarUrl } = e.detail; this.avatarUrl = avatarUrl; console.log("选择头像:", avatarUrl); }, /** * 保存资料 */ async handleSave() { if (!this.nickname || this.nickname.trim() === "") { common_vendor.index.showToast({ title: "请输入昵称", icon: "none" }); return; } if (this.avatarUrl === this.originalAvatar && this.nickname === this.originalNickname) { common_vendor.index.showToast({ title: "没有修改", icon: "none" }); return; } try { common_vendor.index.showLoading({ title: "保存中..." }); let uploadedAvatarUrl = this.avatarUrl; if (this.avatarUrl !== this.originalAvatar && !this.avatarUrl.startsWith("/static/")) { uploadedAvatarUrl = this.avatarUrl; } const result = await utils_api.updateUserProfile({ nickname: this.nickname, avatar: uploadedAvatarUrl }); console.log("更新成功:", result); const userInfo = utils_auth.getUserInfo(); userInfo.nickname = this.nickname; userInfo.avatar = uploadedAvatarUrl; utils_auth.setUserInfo(userInfo); common_vendor.index.hideLoading(); common_vendor.index.showToast({ title: "保存成功", icon: "success" }); setTimeout(() => { common_vendor.index.navigateBack(); }, 1500); } catch (error) { console.error("保存失败:", error); common_vendor.index.hideLoading(); common_vendor.index.showToast({ title: error.message || "保存失败", icon: "none" }); } } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: $data.avatarUrl, b: common_vendor.o((...args) => $options.onChooseAvatar && $options.onChooseAvatar(...args)), c: $data.nickname, d: common_vendor.o(($event) => $data.nickname = $event.detail.value), e: $data.phone }, $data.phone ? { f: common_vendor.t($data.phone) } : {}, { g: common_vendor.o((...args) => $options.handleSave && $options.handleSave(...args)) }); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-7e5a80f3"], ["__file", "D:/program/gupiao-wx/src/pages/profile/edit.vue"]]); wx.createPage(MiniProgramPage);