myDetail.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view class="detail-content">
  3. <view class="detail-box">
  4. <view class="detail-item">
  5. <view class="detail-label">头像</view>
  6. <image class="detail-avatar" :src="user.portrait" mode="aspectFill" @click="updateAvatar"></image>
  7. </view>
  8. <view class="detail-item">
  9. <view class="detail-label">姓名</view>
  10. <view class="detail-value">{{user.userName}}</view>
  11. </view>
  12. <view class="detail-item">
  13. <view class="detail-label">所属组织</view>
  14. <view class="detail-value">{{user.organizedName || '-'}}</view>
  15. </view>
  16. <view class="detail-item">
  17. <view class="detail-label">手机号</view>
  18. <view class="detail-value">{{user.phone}}</view>
  19. </view>
  20. <view class="detail-item">
  21. <view class="detail-label">性别</view>
  22. <view class="detail-value">{{user.sex === 'W'?'女':'男'}}</view>
  23. </view>
  24. </view>
  25. <view class="logout" @click="logout">退出登录</view>
  26. </view>
  27. </template>
  28. <script>
  29. import config from "@/config";
  30. import {
  31. updateUserDetails,
  32. getUserInfoById
  33. } from '@/request/api/my.js'
  34. export default {
  35. data() {
  36. return {
  37. user: {}
  38. }
  39. },
  40. onShow() {
  41. this.user = this.$store.getters.user;
  42. this.user.organizedName = this.$store.getters.organization && this.$store.getters.organization.name;
  43. this.init();
  44. },
  45. methods: {
  46. updateAvatar() {
  47. uni.chooseImage({
  48. count: 1, //默认9
  49. success: file => {
  50. uni.showLoading();
  51. uni.uploadFile({
  52. url: config.baseUrl + '/file/filenode/-1', // 仅为示例,非真实的接口地址
  53. filePath: file.tempFilePaths[0],
  54. name: 'uploadFile',
  55. success: (res) => {
  56. if (res.statusCode != 200) {
  57. uni.hideLoading();
  58. return this.$toast('上传失败');
  59. }
  60. let data = JSON.parse(res.data);
  61. if (data.code != 200) {
  62. uni.hideLoading();
  63. return this.$toast('上传失败');
  64. }
  65. let url = JSON.parse(res.data).data.node.url;
  66. updateUserDetails({
  67. id: this.$store.getters.user.userId,
  68. portrait: url
  69. }).then(node => {
  70. uni.hideLoading();
  71. if (node.code == 200) {
  72. this.$toast('修改成功');
  73. this.init()
  74. } else {
  75. return this.$toast('修改失败');
  76. }
  77. })
  78. },
  79. fail: () => {
  80. uni.hideLoading();
  81. this.$toast('上传失败');
  82. }
  83. });
  84. }
  85. });
  86. },
  87. init() {
  88. getUserInfoById(this.user.userId).then(res => {
  89. if (res.code == 200) {
  90. this.user = res.data;
  91. this.user['userName'] = res.data.name;
  92. this.user['userId'] = res.data.id;
  93. this.user.organizedName = res.data.mgrOrganization && res.data.mgrOrganization.name;
  94. this.$store.dispatch('app/changeUser', res.data);
  95. }
  96. })
  97. },
  98. logout() {
  99. uni.showModal({
  100. title: '有极提示',
  101. content: '是否退出登录',
  102. success: res => {
  103. if (res.confirm) {
  104. this.$chat.disConnect();
  105. uni.removeStorageSync('token');
  106. uni.removeStorageSync('chatToken');
  107. uni.removeStorageSync('vuex_state');
  108. this.$store.dispatch('app/changeOrganization', {});
  109. this.$store.dispatch('app/changeProject', {});
  110. this.$store.dispatch('app/changeUser', {});
  111. this.$store.dispatch('app/changeIdentity', {});
  112. uni.removeTabBarBadge({
  113. index: 1
  114. })
  115. this.$toast('退出成功');
  116. setTimeout(() => {
  117. this.$navigateBack();
  118. }, 400)
  119. }
  120. }
  121. });
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss">
  127. .detail-content {
  128. padding: 30rpx;
  129. .detail-avatar {
  130. width: 80rpx;
  131. height: 80rpx;
  132. border-radius: 50%;
  133. }
  134. .detail-box {
  135. background: #fff;
  136. border-radius: 16rpx;
  137. padding: 30rpx;
  138. box-shadow: 0px 1px 12px rgba(3, 3, 3, 0.08);
  139. }
  140. .detail-label {
  141. color: $uni-secondary-color;
  142. font-weight: 300;
  143. margin-bottom: 10rpx;
  144. }
  145. .detail-value {
  146. font-size: 32rpx;
  147. color: $uni-base-color;
  148. }
  149. .detail-item {
  150. margin-bottom: 20rpx;
  151. }
  152. .logout {
  153. margin-top: 40rpx;
  154. background: $uni-error;
  155. color: #fff;
  156. height: 68rpx;
  157. line-height: 68rpx;
  158. border-radius: 68rpx;
  159. text-align: center;
  160. }
  161. }
  162. </style>