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 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(userInfo);
  65. if (data.code != 200) {
  66. uni.hideLoading();
  67. return this.$toast('上传失败');
  68. }
  69. let url = JSON.parse(userInfo).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. async init() {
  92. let userInfo = await getUserInfoById(this.user.userId);
  93. if (userInfo.state) {
  94. this.user = userInfo;
  95. this.user['userName'] = userInfo.name;
  96. this.user['userId'] = userInfo.id;
  97. this.user.organizedName = userInfo.mgrOrganization && userInfo.mgrOrganization.name;
  98. this.$store.dispatch('app/changeUser', userInfo);
  99. }
  100. },
  101. logout() {
  102. uni.showModal({
  103. title: '有极提示',
  104. content: '是否退出登录',
  105. success: res => {
  106. if (res.confirm) {
  107. this.$chat.disConnect();
  108. uni.removeStorageSync('token');
  109. uni.removeStorageSync('chatToken');
  110. uni.removeStorageSync('vuex_state');
  111. this.$store.dispatch('app/changeOrganization', {});
  112. this.$store.dispatch('app/changeUser', {});
  113. uni.removeTabBarBadge({
  114. index: 1
  115. })
  116. this.$toast('退出成功');
  117. setTimeout(() => {
  118. uni.navigateBack();
  119. }, 400)
  120. }
  121. }
  122. });
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .detail-content {
  129. padding: 30rpx;
  130. .detail-avatar {
  131. width: 80rpx;
  132. height: 80rpx;
  133. border-radius: 50%;
  134. }
  135. .detail-box {
  136. background: #fff;
  137. border-radius: 16rpx;
  138. padding: 30rpx;
  139. box-shadow: 0px 1px 12px rgba(3, 3, 3, 0.08);
  140. }
  141. .detail-label {
  142. color: $uv-content-color;
  143. font-weight: 300;
  144. margin-bottom: 10rpx;
  145. }
  146. .detail-value {
  147. font-size: 32rpx;
  148. }
  149. .detail-item {
  150. margin-bottom: 20rpx;
  151. }
  152. .logout {
  153. margin-top: 40rpx;
  154. background: $uv-error;
  155. color: #fff;
  156. height: 68rpx;
  157. line-height: 68rpx;
  158. border-radius: 68rpx;
  159. text-align: center;
  160. }
  161. }
  162. </style>