| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- "use strict";
- const common_vendor = require("../common/vendor.js");
- const utils_api = require("../utils/api.js");
- const _sfc_main = {
- data() {
- return {
- visible: false,
- nickname: "",
- avatarUrl: "",
- tempAvatarPath: "",
- // 临时头像路径
- userData: null
- // 后端返回的用户数据
- };
- },
- methods: {
- /**
- * 打开弹窗
- * @param userData 可选,后端返回的用户数据(新流程中不再需要)
- */
- open(userData = null) {
- this.visible = true;
- this.userData = userData;
- this.nickname = "";
- this.avatarUrl = "";
- this.tempAvatarPath = "";
- },
- /**
- * 关闭弹窗
- */
- close() {
- this.visible = false;
- },
- /**
- * 选择头像
- */
- handleChooseAvatar(e) {
- console.log("[用户信息] 选择头像:", e);
- const { avatarUrl } = e.detail;
- this.tempAvatarPath = avatarUrl;
- this.avatarUrl = avatarUrl;
- },
- /**
- * 点击遮罩层
- */
- handleMaskClick() {
- },
- /**
- * 取消
- */
- handleCancel() {
- common_vendor.index.showModal({
- title: "提示",
- content: "取消后将无法完成登录,确定要取消吗?",
- success: (res) => {
- if (res.confirm) {
- this.close();
- }
- }
- });
- },
- /**
- * 确定提交
- */
- async handleConfirm() {
- if (!this.nickname || this.nickname.trim() === "") {
- common_vendor.index.showToast({
- title: "请输入昵称",
- icon: "none"
- });
- return;
- }
- if (!this.avatarUrl) {
- common_vendor.index.showToast({
- title: "请选择头像",
- icon: "none"
- });
- return;
- }
- this.$emit("confirm", {
- nickname: this.nickname.trim(),
- avatarUrl: this.tempAvatarPath || this.avatarUrl,
- tempAvatarPath: this.tempAvatarPath
- // 传递临时路径,供后续上传
- });
- this.close();
- },
- /**
- * 上传头像到OSS
- */
- uploadAvatar(filePath) {
- return new Promise((resolve, reject) => {
- common_vendor.index.uploadFile({
- url: utils_api.uploadFile.url,
- // 从api.js导入
- filePath,
- name: "file",
- header: {
- "Authorization": `Bearer ${common_vendor.index.getStorageSync("user_token") || ""}`
- },
- success: (res) => {
- const data = JSON.parse(res.data);
- if (data.code === 200 && data.data && data.data.url) {
- resolve(data.data.url);
- } else {
- reject(new Error(data.message || "上传失败"));
- }
- },
- fail: (err) => {
- reject(err);
- }
- });
- });
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: $data.visible
- }, $data.visible ? {
- b: $data.avatarUrl || _ctx.getImageUrl("/static/images/head.png"),
- c: common_vendor.o((...args) => $options.handleChooseAvatar && $options.handleChooseAvatar(...args)),
- d: $data.nickname,
- e: common_vendor.o(($event) => $data.nickname = $event.detail.value),
- f: common_vendor.o((...args) => $options.handleCancel && $options.handleCancel(...args)),
- g: common_vendor.o((...args) => $options.handleConfirm && $options.handleConfirm(...args)),
- h: common_vendor.o(() => {
- }),
- i: common_vendor.o((...args) => $options.handleMaskClick && $options.handleMaskClick(...args))
- } : {});
- }
- const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a5b292f7"], ["__file", "D:/program/gupiao/gupiao-wx/src/components/UserInfoPopup.vue"]]);
- wx.createComponent(Component);
|