UserInfoPopup.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const utils_api = require("../utils/api.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. visible: false,
  8. nickname: "",
  9. avatarUrl: "",
  10. tempAvatarPath: "",
  11. // 临时头像路径
  12. userData: null
  13. // 后端返回的用户数据
  14. };
  15. },
  16. methods: {
  17. /**
  18. * 打开弹窗
  19. */
  20. open(userData) {
  21. this.visible = true;
  22. this.userData = userData;
  23. this.nickname = "";
  24. this.avatarUrl = "";
  25. this.tempAvatarPath = "";
  26. },
  27. /**
  28. * 关闭弹窗
  29. */
  30. close() {
  31. this.visible = false;
  32. },
  33. /**
  34. * 选择头像
  35. */
  36. handleChooseAvatar(e) {
  37. console.log("[用户信息] 选择头像:", e);
  38. const { avatarUrl } = e.detail;
  39. this.tempAvatarPath = avatarUrl;
  40. this.avatarUrl = avatarUrl;
  41. },
  42. /**
  43. * 点击遮罩层
  44. */
  45. handleMaskClick() {
  46. },
  47. /**
  48. * 取消
  49. */
  50. handleCancel() {
  51. common_vendor.index.showModal({
  52. title: "提示",
  53. content: "取消后将无法完成登录,确定要取消吗?",
  54. success: (res) => {
  55. if (res.confirm) {
  56. this.close();
  57. }
  58. }
  59. });
  60. },
  61. /**
  62. * 确定提交
  63. */
  64. async handleConfirm() {
  65. if (!this.nickname || this.nickname.trim() === "") {
  66. common_vendor.index.showToast({
  67. title: "请输入昵称",
  68. icon: "none"
  69. });
  70. return;
  71. }
  72. if (!this.avatarUrl) {
  73. common_vendor.index.showToast({
  74. title: "请选择头像",
  75. icon: "none"
  76. });
  77. return;
  78. }
  79. this.$emit("confirm", {
  80. nickname: this.nickname.trim(),
  81. avatarUrl: this.tempAvatarPath || this.avatarUrl,
  82. tempAvatarPath: this.tempAvatarPath
  83. // 传递临时路径,供后续上传
  84. });
  85. this.close();
  86. },
  87. /**
  88. * 上传头像到OSS
  89. */
  90. uploadAvatar(filePath) {
  91. return new Promise((resolve, reject) => {
  92. common_vendor.index.uploadFile({
  93. url: utils_api.uploadFile.url,
  94. // 从api.js导入
  95. filePath,
  96. name: "file",
  97. header: {
  98. "Authorization": `Bearer ${common_vendor.index.getStorageSync("user_token") || ""}`
  99. },
  100. success: (res) => {
  101. const data = JSON.parse(res.data);
  102. if (data.code === 200 && data.data && data.data.url) {
  103. resolve(data.data.url);
  104. } else {
  105. reject(new Error(data.message || "上传失败"));
  106. }
  107. },
  108. fail: (err) => {
  109. reject(err);
  110. }
  111. });
  112. });
  113. }
  114. }
  115. };
  116. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  117. return common_vendor.e({
  118. a: $data.visible
  119. }, $data.visible ? {
  120. b: $data.avatarUrl || "/static/images/head.png",
  121. c: common_vendor.o((...args) => $options.handleChooseAvatar && $options.handleChooseAvatar(...args)),
  122. d: $data.nickname,
  123. e: common_vendor.o(($event) => $data.nickname = $event.detail.value),
  124. f: common_vendor.o((...args) => $options.handleCancel && $options.handleCancel(...args)),
  125. g: common_vendor.o((...args) => $options.handleConfirm && $options.handleConfirm(...args)),
  126. h: common_vendor.o(() => {
  127. }),
  128. i: common_vendor.o((...args) => $options.handleMaskClick && $options.handleMaskClick(...args))
  129. } : {});
  130. }
  131. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a5b292f7"], ["__file", "D:/program/gupiao-wx/src/components/UserInfoPopup.vue"]]);
  132. wx.createComponent(Component);