myDetail.vue 4.4 KB

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