| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const utils_api = require("../../utils/api.js");
- const defaultAvatar = "https://picsum.photos/seed/avatar/200/200";
- const _sfc_main = {
- data() {
- return {
- userInfo: null,
- menuItems: [
- {
- name: "消息",
- icon: "💬",
- action: "messages"
- },
- {
- name: "笔记",
- icon: "📝",
- action: "notes"
- },
- {
- name: "阅读排行",
- icon: "🏆",
- action: "readingRank"
- },
- {
- name: "浏览记录",
- icon: "🕐",
- action: "browsingHistory"
- },
- {
- name: "开通VIP记录",
- icon: "💰",
- action: "vipRecords"
- },
- {
- name: "意见反馈",
- icon: "❓",
- action: "feedback"
- }
- ]
- };
- },
- computed: {
- displayAvatar() {
- if (this.userInfo && this.userInfo.avatar) {
- return this.userInfo.avatar;
- }
- return defaultAvatar;
- }
- },
- onLoad() {
- this.loadUserInfo();
- },
- onShow() {
- this.loadUserInfo();
- },
- methods: {
- loadUserInfo() {
- try {
- const storedUser = common_vendor.index.getStorageSync("userInfo");
- const isLogin = common_vendor.index.getStorageSync("isLogin");
- if (!storedUser || !storedUser.id || !isLogin) {
- this.userInfo = null;
- return;
- }
- this.userInfo = storedUser;
- this.fetchRemoteUser(storedUser.id);
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/profile/profile.vue:108", "读取用户信息失败", e);
- this.userInfo = null;
- }
- },
- async fetchRemoteUser(userId) {
- try {
- const res = await utils_api.getUserProfile(userId);
- if (res && res.code === 200 && res.data) {
- this.userInfo = {
- ...this.userInfo,
- ...res.data
- };
- common_vendor.index.setStorageSync("userInfo", this.userInfo);
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/profile/profile.vue:123", "刷新用户信息失败", e);
- }
- },
- editProfile() {
- common_vendor.index.navigateTo({
- url: "/pages/edit-profile/edit-profile"
- });
- },
- goToLogin() {
- common_vendor.index.navigateTo({
- url: "/pages/login/login"
- });
- },
- goToSettings() {
- common_vendor.index.navigateTo({
- url: "/pages/settings/settings"
- });
- },
- goToVip() {
- common_vendor.index.navigateTo({
- url: "/pages/vip/vip"
- });
- },
- handleMenuClick(item) {
- switch (item.action) {
- case "messages":
- common_vendor.index.navigateTo({
- url: "/pages/messages/messages"
- });
- break;
- case "notes":
- common_vendor.index.navigateTo({
- url: "/pages/notes/notes"
- });
- break;
- case "readingRank":
- common_vendor.index.navigateTo({
- url: "/pages/reading-rank/reading-rank"
- });
- break;
- case "browsingHistory":
- common_vendor.index.navigateTo({
- url: "/pages/browsing-history/browsing-history"
- });
- break;
- case "vipRecords":
- common_vendor.index.navigateTo({
- url: "/pages/vip-records/vip-records"
- });
- break;
- case "feedback":
- common_vendor.index.navigateTo({
- url: "/pages/feedback/feedback"
- });
- break;
- }
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: $options.displayAvatar,
- b: common_vendor.t($data.userInfo ? $data.userInfo.nickname || $data.userInfo.username : "未登录"),
- c: $data.userInfo
- }, $data.userInfo ? {
- d: common_vendor.o((...args) => $options.editProfile && $options.editProfile(...args))
- } : {
- e: common_vendor.o((...args) => $options.goToLogin && $options.goToLogin(...args))
- }, {
- f: common_vendor.o((...args) => $options.goToSettings && $options.goToSettings(...args)),
- g: common_vendor.o((...args) => $options.goToVip && $options.goToVip(...args)),
- h: $data.userInfo
- }, $data.userInfo ? {
- i: common_vendor.f($data.menuItems, (item, index, i0) => {
- return {
- a: common_vendor.t(item.icon),
- b: common_vendor.t(item.name),
- c: index,
- d: common_vendor.o(($event) => $options.handleMenuClick(item), index)
- };
- })
- } : {});
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-dd383ca2"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/profile/profile.js.map
|