UserInfoPopup.js 3.7 KB

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