index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="page_container">
  3. <custom-nav-bar title="个人资料" />
  4. <view class="info_wrap">
  5. <info-item
  6. :loading="loadingState.faceURL"
  7. @click="updateAvatar"
  8. title="头像"
  9. >
  10. <my-avatar
  11. :src="selfInfo.faceURL"
  12. :desc="selfInfo.nickname"
  13. size="30"
  14. slot="value"
  15. />
  16. </info-item>
  17. <info-item
  18. @click="updateNickname"
  19. title="姓名"
  20. :content="selfInfo.nickname"
  21. />
  22. <info-item
  23. :loading="loadingState.gender"
  24. @click="updateGender"
  25. title="性别"
  26. :content="getGender"
  27. />
  28. <info-item
  29. :loading="loadingState.birth"
  30. @click="() => (showDatePicker = true)"
  31. title="生日"
  32. :content="getBirth"
  33. />
  34. </view>
  35. <view class="info_wrap">
  36. <info-item
  37. :showArrow="false"
  38. title="手机号码"
  39. :content="selfInfo.phoneNumber || '-'"
  40. />
  41. <info-item
  42. :showArrow="false"
  43. title="邮箱"
  44. :content="selfInfo.email || '-'"
  45. />
  46. </view>
  47. <u-datetime-picker
  48. :minDate="0"
  49. :maxDate="nowDate"
  50. :show="showDatePicker"
  51. @confirm="confirmDate"
  52. @cancel="() => (showDatePicker = false)"
  53. v-model="selfInfo.birth"
  54. mode="date"
  55. />
  56. </view>
  57. </template>
  58. <script>
  59. import { businessInfoUpdate } from "../../..//api/login";
  60. import IMSDK from "openim-uniapp-polyfill";
  61. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  62. import MyAvatar from "../../../components/MyAvatar/index.vue";
  63. import dayjs from "dayjs";
  64. import InfoItem from "./InfoItem.vue";
  65. import { getPurePath } from "../../../util/common";
  66. export default {
  67. components: {
  68. CustomNavBar,
  69. MyAvatar,
  70. InfoItem,
  71. },
  72. data() {
  73. return {
  74. showDatePicker: false,
  75. loadingState: {
  76. faceURL: false,
  77. gender: false,
  78. birth: false,
  79. },
  80. nowDate: Date.now(),
  81. };
  82. },
  83. computed: {
  84. selfInfo() {
  85. return this.$store.getters.storeSelfInfo;
  86. },
  87. getGender() {
  88. if (this.selfInfo.gender === 0) {
  89. return "保密";
  90. }
  91. if (this.selfInfo.gender === 1) {
  92. return "男";
  93. }
  94. return "女";
  95. },
  96. getBirth() {
  97. const birth = this.selfInfo.birth ?? 0;
  98. return dayjs(birth).format("YYYY-MM-DD");
  99. },
  100. },
  101. methods: {
  102. updateNickname() {
  103. uni.navigateTo({
  104. url: `/pages/common/markOrIDPage/index?isSelfNickname=true&sourceInfo=${JSON.stringify(
  105. this.selfInfo,
  106. )}`,
  107. });
  108. },
  109. updateGender() {
  110. uni.showActionSheet({
  111. itemList: ["男", "女"],
  112. success: async ({ tapIndex }) => {
  113. this.loadingState.gender = true;
  114. await this.updateSelfInfo(
  115. {
  116. gender: tapIndex + 1,
  117. },
  118. "gender",
  119. );
  120. },
  121. });
  122. },
  123. updateAvatar() {
  124. uni.chooseImage({
  125. count: 1,
  126. sizeType: ["compressed"],
  127. success: async ({ tempFilePaths }) => {
  128. const path = tempFilePaths[0];
  129. const nameIdx = path.lastIndexOf("/") + 1;
  130. const typeIdx = path.lastIndexOf(".") + 1;
  131. const fileName = path.slice(nameIdx);
  132. const fileType = path.slice(typeIdx);
  133. this.loadingState.faceURL = true;
  134. const {
  135. data: { url },
  136. } = await IMSDK.asyncApi(IMSDK.IMMethods.UploadFile, IMSDK.uuid(), {
  137. filepath: getPurePath(tempFilePaths[0]),
  138. name: fileName,
  139. contentType: fileType,
  140. uuid: IMSDK.uuid(),
  141. });
  142. console.log(url);
  143. this.updateSelfInfo(
  144. {
  145. faceURL: url,
  146. },
  147. "faceURL",
  148. );
  149. this.loadingState.faceURL = false;
  150. },
  151. });
  152. },
  153. toQrCode() {
  154. uni.navigateTo({
  155. url: `/pages/common/userOrGroupQrCode/index`,
  156. });
  157. },
  158. copyID() {
  159. uni.setClipboardData({
  160. data: this.selfInfo.userID,
  161. success: () => {
  162. uni.hideToast();
  163. this.$nextTick(() => {
  164. uni.$u.toast("复制成功");
  165. });
  166. },
  167. });
  168. },
  169. async updateSelfInfo(data, key) {
  170. try {
  171. await businessInfoUpdate({
  172. userID: this.selfInfo.userID,
  173. ...data,
  174. });
  175. await this.$store.dispatch("user/updateBusinessInfo");
  176. uni.$u.toast("修改成功");
  177. } catch (e) {
  178. console.log(e);
  179. uni.$u.toast("修改失败");
  180. }
  181. this.loadingState[key] = false;
  182. },
  183. confirmDate({ value }) {
  184. this.loadingState.birth = true;
  185. this.updateSelfInfo(
  186. {
  187. birth: value,
  188. },
  189. "birth",
  190. );
  191. this.showDatePicker = false;
  192. },
  193. },
  194. };
  195. </script>
  196. <style lang="scss" scoped>
  197. .page_container {
  198. background-color: #f8f8f8;
  199. .info_wrap {
  200. margin: 24rpx 24rpx 0 24rpx;
  201. background: #fff;
  202. border-radius: 6px;
  203. .qr_icon {
  204. width: 22px;
  205. height: 23px;
  206. }
  207. }
  208. }
  209. </style>