huangye-parking/miniapp/unpackage/dist/dev/mp-weixin/pages/mine/profile.js
2026-03-03 23:31:28 +08:00

100 lines
3.3 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const api_user = require("../../api/user.js");
const NavBar = () => "../../components/NavBar.js";
const _sfc_main = {
components: { NavBar },
data() {
return {
avatar: "",
nickname: "",
uid: "",
saving: false
};
},
onLoad() {
this.loadProfile();
},
methods: {
/** 加载用户资料 */
async loadProfile() {
try {
const res = await api_user.getProfile();
const data = res.data || res || {};
this.avatar = data.avatar || "";
this.nickname = data.nickname || "";
this.uid = data.uid || "";
} catch (err) {
common_vendor.index.__f__("error", "at pages/mine/profile.vue:70", "加载个人资料失败:", err);
}
},
/** 选择微信头像回调 */
async onChooseAvatar(e) {
const tempFilePath = e.detail.avatarUrl;
if (!tempFilePath)
return;
common_vendor.index.showLoading({ title: "上传中..." });
try {
const url = await api_user.uploadImage(tempFilePath);
this.avatar = url;
common_vendor.index.showToast({ title: "头像已更换", icon: "success" });
} catch (err) {
common_vendor.index.__f__("error", "at pages/mine/profile.vue:85", "上传头像失败:", err);
common_vendor.index.showToast({ title: "上传失败", icon: "none" });
} finally {
common_vendor.index.hideLoading();
}
},
/** 昵称输入框失焦,获取微信昵称 */
onNicknameBlur(e) {
if (e.detail.value) {
this.nickname = e.detail.value;
}
},
/** 保存个人资料 */
async saveProfile() {
if (!this.nickname.trim()) {
common_vendor.index.showToast({ title: "请输入昵称", icon: "none" });
return;
}
this.saving = true;
try {
await api_user.updateProfile({
nickname: this.nickname.trim(),
avatar: this.avatar
});
common_vendor.index.showToast({ title: "保存成功", icon: "success" });
setTimeout(() => {
common_vendor.index.navigateBack();
}, 1e3);
} catch (err) {
common_vendor.index.__f__("error", "at pages/mine/profile.vue:116", "保存个人资料失败:", err);
} finally {
this.saving = false;
}
}
}
};
if (!Array) {
const _component_NavBar = common_vendor.resolveComponent("NavBar");
_component_NavBar();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return {
a: common_vendor.p({
title: "个人资料"
}),
b: $data.avatar || "/static/logo.png",
c: common_vendor.o((...args) => $options.onChooseAvatar && $options.onChooseAvatar(...args)),
d: common_vendor.o((...args) => $options.onNicknameBlur && $options.onNicknameBlur(...args)),
e: $data.nickname,
f: common_vendor.o(($event) => $data.nickname = $event.detail.value),
g: common_vendor.t($data.uid),
h: common_vendor.o((...args) => $options.saveProfile && $options.saveProfile(...args)),
i: $data.saving
};
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-935803c6"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/mine/profile.js.map