爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
6.3 KiB

  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const pages_mixins_pullRefreshMixin = require("../mixins/pullRefreshMixin.js");
  4. const utils_ossUpload_oss_index = require("../../utils/oss-upload/oss/index.js");
  5. const _sfc_main = {
  6. mixins: [pages_mixins_pullRefreshMixin.pullRefreshMixin],
  7. data() {
  8. return {
  9. statusBarHeight: 0,
  10. navBarHeight: 44,
  11. // px
  12. navBarHeightRpx: 88,
  13. // rpx
  14. userInfo: {
  15. nickname: "吴彦谋",
  16. phone: "15888977617",
  17. avatar: "",
  18. newAvatar: "/static/logo.png"
  19. },
  20. uploadStatus: {
  21. show: false,
  22. type: "loading"
  23. // loading, success, error
  24. },
  25. showPhone: false
  26. };
  27. },
  28. computed: {
  29. maskedPhone() {
  30. return this.userInfo.phone ? "●".repeat(this.userInfo.phone.length) : "";
  31. },
  32. infoContainerStyle() {
  33. return {
  34. marginTop: this.navBarHeightRpx + "rpx"
  35. };
  36. }
  37. },
  38. onLoad() {
  39. const sysInfo = common_vendor.index.getSystemInfoSync();
  40. this.statusBarHeight = sysInfo.statusBarHeight;
  41. let navBarHeight = 44;
  42. try {
  43. const menuButtonInfo = common_vendor.index.getMenuButtonBoundingClientRect();
  44. navBarHeight = menuButtonInfo.bottom + menuButtonInfo.top - sysInfo.statusBarHeight;
  45. } catch (e) {
  46. }
  47. this.navBarHeight = navBarHeight;
  48. this.navBarHeightRpx = Math.round(navBarHeight * 750 / sysInfo.windowWidth);
  49. if (common_vendor.index.getStorageSync("token")) {
  50. this.$api("getUserByToken", {}, (res) => {
  51. if (res.code === 200 && res.result) {
  52. this.userInfo.nickname = res.result.nickName || "";
  53. this.userInfo.phone = res.result.phone || "";
  54. this.userInfo.avatar = res.result.headImage || "";
  55. }
  56. });
  57. }
  58. },
  59. methods: {
  60. async onRefresh() {
  61. await new Promise((resolve) => setTimeout(resolve, 1e3));
  62. common_vendor.index.stopPullRefresh();
  63. },
  64. goBack() {
  65. common_vendor.index.navigateBack();
  66. },
  67. async chooseImage(res) {
  68. try {
  69. this.uploadStatus = { show: true, type: "loading" };
  70. const url = await utils_ossUpload_oss_index.OSS.ossUpload(res.target.avatarUrl);
  71. common_vendor.index.__f__("log", "at pages/subcomponent/edit_profile.vue:151", url, "url");
  72. this.userInfo.avatar = url;
  73. this.uploadStatus.type = "success";
  74. setTimeout(() => {
  75. this.uploadStatus.show = false;
  76. }, 1e3);
  77. } catch (error) {
  78. this.uploadStatus = { show: true, type: "error" };
  79. setTimeout(() => {
  80. this.uploadStatus.show = false;
  81. }, 1e3);
  82. }
  83. },
  84. saveProfile() {
  85. if (!this.userInfo.avatar)
  86. return common_vendor.index.showToast({ title: "请上传头像", icon: "none" });
  87. if (!this.userInfo.nickname)
  88. return common_vendor.index.showToast({ title: "请填写昵称", icon: "none" });
  89. if (!this.userInfo.phone)
  90. return common_vendor.index.showToast({ title: "请填写手机号", icon: "none" });
  91. this.uploadStatus = { show: true, type: "loading" };
  92. common_vendor.index.__f__("log", "at pages/subcomponent/edit_profile.vue:166", this.userInfo, "this.userInfo");
  93. this.$api("updateInfo", {
  94. avatarUrl: this.userInfo.avatar,
  95. nickName: this.userInfo.nickname,
  96. phone: this.userInfo.phone
  97. }, (res) => {
  98. if (res.code === 200) {
  99. setTimeout(() => {
  100. common_vendor.index.$emit("refreshUserInfo");
  101. common_vendor.index.showToast({ title: "保存成功", icon: "success" });
  102. setTimeout(() => {
  103. common_vendor.index.navigateBack();
  104. }, 1e3);
  105. }, 1e3);
  106. } else {
  107. this.uploadStatus.type = "error";
  108. setTimeout(() => {
  109. this.uploadStatus.show = false;
  110. }, 1e3);
  111. }
  112. });
  113. }
  114. }
  115. };
  116. if (!Array) {
  117. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  118. _easycom_uni_icons2();
  119. }
  120. const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  121. if (!Math) {
  122. _easycom_uni_icons();
  123. }
  124. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  125. return common_vendor.e({
  126. a: common_vendor.p({
  127. type: "left",
  128. size: "20",
  129. color: "#222"
  130. }),
  131. b: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  132. c: $data.statusBarHeight + 88 + "rpx",
  133. d: $data.statusBarHeight + "px",
  134. e: $data.userInfo.nickname,
  135. f: common_vendor.o(($event) => $data.userInfo.nickname = $event.detail.value),
  136. g: $data.showPhone ? $data.userInfo.phone : $options.maskedPhone,
  137. h: !$data.showPhone,
  138. i: common_vendor.o((e) => {
  139. if ($data.showPhone)
  140. $data.userInfo.phone = e.detail.value;
  141. }),
  142. j: common_vendor.o(($event) => $data.showPhone = !$data.showPhone),
  143. k: common_vendor.p({
  144. type: $data.showPhone ? "eye" : "eye-slash",
  145. size: "20",
  146. color: "#999"
  147. }),
  148. l: !$data.userInfo.avatar
  149. }, !$data.userInfo.avatar ? {
  150. m: common_vendor.p({
  151. type: "reload",
  152. size: "24",
  153. color: "#999"
  154. })
  155. } : {
  156. n: $data.userInfo.avatar
  157. }, {
  158. o: common_vendor.o((...args) => $options.chooseImage && $options.chooseImage(...args)),
  159. p: $data.userInfo.newAvatar
  160. }, $data.userInfo.newAvatar ? {
  161. q: $data.userInfo.newAvatar
  162. } : {}, {
  163. r: common_vendor.s($options.infoContainerStyle),
  164. s: $data.uploadStatus.show
  165. }, $data.uploadStatus.show ? common_vendor.e({
  166. t: $data.uploadStatus.type === "loading"
  167. }, $data.uploadStatus.type === "loading" ? {} : $data.uploadStatus.type === "success" ? {
  168. w: common_vendor.p({
  169. type: "checkmark",
  170. size: "24",
  171. color: "#fff"
  172. })
  173. } : $data.uploadStatus.type === "error" ? {
  174. y: common_vendor.p({
  175. type: "closeempty",
  176. size: "24",
  177. color: "#fff"
  178. })
  179. } : {}, {
  180. v: $data.uploadStatus.type === "success",
  181. x: $data.uploadStatus.type === "error"
  182. }) : {}, {
  183. z: common_vendor.o((...args) => $options.saveProfile && $options.saveProfile(...args)),
  184. A: $data.navBarHeightRpx + "rpx"
  185. });
  186. }
  187. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-c93de0a0"]]);
  188. wx.createPage(MiniProgramPage);
  189. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/subcomponent/edit_profile.js.map