userInfo.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const store_user = require("../../store/user.js");
  4. const utils_file = require("../../utils/file.js");
  5. const utils_utils = require("../../utils/utils.js");
  6. const _sfc_main = {
  7. __name: "userInfo",
  8. setup(__props) {
  9. const userStore = store_user.useUserStore();
  10. const genderOptions = [
  11. { value: "male", label: "男" },
  12. { value: "female", label: "女" }
  13. ];
  14. const formData = common_vendor.ref({
  15. avatar: "",
  16. nickname: "",
  17. gender: "male",
  18. // 默认选中男
  19. birthday: "",
  20. phone: "1510987760"
  21. });
  22. common_vendor.onMounted(() => {
  23. const userInfo = userStore.getUserInfo;
  24. if (userInfo) {
  25. formData.value = {
  26. avatar: userInfo.avatar || "",
  27. nickname: userInfo.nickname || "",
  28. gender: userInfo.gender || "male",
  29. birthday: userInfo.birthday || "",
  30. phone: userInfo.phone || "1510987760"
  31. };
  32. }
  33. });
  34. const handleAvatarClick = () => {
  35. common_vendor.index.showActionSheet({
  36. itemList: ["微信头像", "从相册选择", "拍照"],
  37. success: (res) => {
  38. if (res.tapIndex === 0) {
  39. handleWechatAvatar();
  40. } else if (res.tapIndex === 1) {
  41. handleChooseAlbum();
  42. } else if (res.tapIndex === 2) {
  43. handleTakePhoto();
  44. }
  45. },
  46. fail: (err) => {
  47. common_vendor.index.__f__("log", "at pages/personal/userInfo.vue:136", "取消选择", err);
  48. }
  49. });
  50. };
  51. const handleWechatAvatar = () => {
  52. const userInfo = userStore.getUserInfo;
  53. if (userInfo && userInfo.avatar) {
  54. formData.value.avatar = userInfo.avatar;
  55. common_vendor.index.showToast({
  56. title: "已使用微信头像",
  57. icon: "success"
  58. });
  59. return;
  60. }
  61. common_vendor.wx$1.getUserProfile({
  62. desc: "用于完善个人资料",
  63. success: (res) => {
  64. if (res.userInfo && res.userInfo.avatarUrl) {
  65. formData.value.avatar = res.userInfo.avatarUrl;
  66. common_vendor.index.showToast({
  67. title: "获取成功",
  68. icon: "success"
  69. });
  70. }
  71. },
  72. fail: (err) => {
  73. common_vendor.index.__f__("log", "at pages/personal/userInfo.vue:168", "获取微信头像失败", err);
  74. common_vendor.index.showToast({
  75. title: "获取头像失败",
  76. icon: "none"
  77. });
  78. }
  79. });
  80. };
  81. const handleChooseAlbum = () => {
  82. common_vendor.index.chooseImage({
  83. count: 1,
  84. sizeType: ["original", "compressed"],
  85. sourceType: ["album"],
  86. success: (res) => {
  87. const tempFilePath = res.tempFilePaths[0];
  88. formData.value.avatar = tempFilePath;
  89. },
  90. fail: (err) => {
  91. common_vendor.index.__f__("log", "at pages/personal/userInfo.vue:199", "选择相册失败", err);
  92. }
  93. });
  94. };
  95. const handleTakePhoto = () => {
  96. common_vendor.index.chooseImage({
  97. count: 1,
  98. sizeType: ["original", "compressed"],
  99. sourceType: ["camera"],
  100. success: (res) => {
  101. const tempFilePath = res.tempFilePaths[0];
  102. formData.value.avatar = tempFilePath;
  103. },
  104. fail: (err) => {
  105. common_vendor.index.__f__("log", "at pages/personal/userInfo.vue:217", "拍照失败", err);
  106. }
  107. });
  108. };
  109. const handleBirthdayChange = (e) => {
  110. formData.value.birthday = e.detail.value;
  111. };
  112. const handleChangePhone = () => {
  113. utils_utils.go("/pages/personal/setPhone");
  114. };
  115. return (_ctx, _cache) => {
  116. return {
  117. a: formData.value.avatar || common_vendor.unref(utils_file.getFileUrl)("img/personal/userDemo.png"),
  118. b: formData.value.avatar ? "aspectFill" : "widthFix",
  119. c: common_vendor.o(handleAvatarClick),
  120. d: formData.value.nickname,
  121. e: common_vendor.o(($event) => formData.value.nickname = $event.detail.value),
  122. f: common_vendor.f(genderOptions, (item, k0, i0) => {
  123. return {
  124. a: common_vendor.unref(utils_file.getFileUrl)(formData.value.gender === item.value ? "img/personal/sele2.png" : "img/personal/sele1.png"),
  125. b: common_vendor.t(item.label),
  126. c: item.value,
  127. d: formData.value.gender === item.value ? 1 : "",
  128. e: common_vendor.o(($event) => formData.value.gender = item.value, item.value)
  129. };
  130. }),
  131. g: common_vendor.t(formData.value.birthday || "请选择生日"),
  132. h: common_vendor.n({
  133. placeholder: !formData.value.birthday
  134. }),
  135. i: formData.value.birthday,
  136. j: common_vendor.o(handleBirthdayChange),
  137. k: common_vendor.t(formData.value.phone || "1510987760"),
  138. l: common_vendor.o(handleChangePhone)
  139. };
  140. };
  141. }
  142. };
  143. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2ef1855d"]]);
  144. wx.createPage(MiniProgramPage);
  145. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/personal/userInfo.js.map