user-info.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view>
  3. <!-- 头像区域 -->
  4. <view class="avatar-region">
  5. <view class="flex-items">
  6. <view class="font32 mar-l-20">
  7. 头像
  8. </view>
  9. <view class="mar-l-auto mar-r-20">
  10. <u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="1" :maxCount="1">
  11. <view class="flex-items">
  12. <image class="avatar" :src="user.avatar||'../../static/images/login.png'" mode="aspectFill">
  13. </image>
  14. <uni-icons color="#d0d7df" type="right" size="30"></uni-icons>
  15. </view>
  16. </u-upload>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 基本信息区域 -->
  21. <view class="info-region">
  22. <view class="font-gray mar-l-20 mar-b-30">
  23. 基本信息
  24. </view>
  25. <view class="flex-items mar-b-50">
  26. <view class="font32 mar-l-20">
  27. 昵称
  28. </view>
  29. <view class="mar-l-auto mar-r-20" @click="changeAccount">
  30. <view class="flex-items">
  31. <view class="font32 font-gray">
  32. {{user.account}}
  33. </view>
  34. <view>
  35. <uni-icons color="#d0d7df" type="right" size="20"></uni-icons>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="flex-items mar-b-50">
  41. <view class="font32 mar-l-20 ">
  42. 生日
  43. </view>
  44. <view class="mar-l-auto mar-r-20" @click="changeBirthday">
  45. <view class="flex-items">
  46. <view class="font32 font-gray">
  47. {{user.birthday}}
  48. </view>
  49. <uni-icons color="#d0d7df" type="right" size="20"></uni-icons>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="flex-items ">
  54. <view class="font32 mar-l-20 ">
  55. 性别
  56. </view>
  57. <view class="mar-l-auto mar-r-20" @click="changeSex">
  58. <view class="flex-items">
  59. <view class="font32 font-gray" v-if="user.sex==0">
  60. </view>
  61. <view class="font32 font-gray" v-if="user.sex==1">
  62. </view>
  63. <view class="font32 font-gray " v-if="user.sex==2">
  64. 其他
  65. </view>
  66. <uni-icons color="#d0d7df" type="right" size="20"></uni-icons>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- <view class="flex-items mar-b-20">
  71. <view class="font32 mar-l-20 ">
  72. 国家/地区
  73. </view>
  74. <view class="mar-l-auto mar-r-20">
  75. <view class="flex-items">
  76. <view class="font32 font-gray">
  77. {{user.nation}}
  78. </view>
  79. <uni-icons color="#d0d7df" type="right" size="20"></uni-icons>
  80. </view>
  81. </view>
  82. </view> -->
  83. </view>
  84. <view class=" flex-center">
  85. <!-- <button class="loginBtn" style="background-color: #3C86F7;" type="primary"
  86. @click="handlerLogout">退出登录</button> -->
  87. <button @click="handlerLogout" class="logout-button">
  88. 退出登录
  89. </button>
  90. </view>
  91. </view>
  92. </template>
  93. <script>
  94. import {
  95. memberDetail,
  96. memberUpdate
  97. } from '../../config/api';
  98. import {
  99. mapMutations,
  100. mapActions,
  101. mapGetters
  102. } from 'vuex';
  103. import {
  104. UPLOAD_URL
  105. } from '../../common/config.js'
  106. export default {
  107. data() {
  108. return {
  109. fileList: [],
  110. user: {},
  111. token: "",
  112. };
  113. },
  114. computed: {
  115. ...mapGetters(['userInfo'])
  116. },
  117. onLoad() {
  118. this.token = uni.getStorageSync('access_token')
  119. },
  120. onShow() {
  121. this.detail()
  122. console.log(this.user)
  123. },
  124. methods: {
  125. ...mapActions(['logout']),
  126. handlerLogout() {
  127. this.logout()
  128. uni.$u.toast("退出登录")
  129. uni.navigateBack({
  130. delta: 1 // delta 表示返回的页面数,1 表示返回上一页
  131. });
  132. },
  133. changeSex() {
  134. this.$route('/packageUser/pages/user-info/sex-change?id=' + this.user.sex + '&id=' + this.user.id)
  135. },
  136. changeAccount() {
  137. this.$route('/packageUser/pages/user-info/account-change?id=' + this.user.account + '&id=' + this.user.id)
  138. },
  139. changeBirthday() {
  140. this.$route('/packageUser/pages/user-info/birthday-change?account=' + this.user.birthdat + '&id=' + this
  141. .user.id)
  142. },
  143. // 删除图片
  144. deletePic(event) {
  145. this.fileList.splice(event.index, 1)
  146. },
  147. // 新增图片
  148. async afterRead(event) {
  149. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  150. let lists = [].concat(event.file)
  151. console.log(lists, "list")
  152. let fileListLen = this.fileList.length
  153. for (let i = 0; i < lists.length; i++) {
  154. const result = await this.uploadFilePromise(lists[i].thumb)
  155. this.user.avatar = result.data.link
  156. let item = this.fileList[fileListLen]
  157. }
  158. memberUpdate(this.user)
  159. },
  160. uploadFilePromise(url) {
  161. return new Promise((resolve, reject) => {
  162. let a = uni.uploadFile({
  163. url: UPLOAD_URL,
  164. filePath: url,
  165. header: {
  166. "Blade-Auth": this.token
  167. },
  168. name: 'file',
  169. formData: {
  170. user: 'test'
  171. },
  172. success: (res) => {
  173. resolve(JSON.parse(res.data))
  174. }
  175. });
  176. })
  177. },
  178. async detail() {
  179. const data = await memberDetail()
  180. if (data.code == 200) {
  181. this.user = data.data
  182. uni.setStorageSync('user', this.user)
  183. }
  184. },
  185. goPage() {
  186. // this.$Router.push({ path: '/pages/user/set-avatar' });
  187. }
  188. },
  189. };
  190. </script>
  191. <style>
  192. .arrow {
  193. width: 32rpx;
  194. height: 32rpx;
  195. margin-top: 13rpx;
  196. }
  197. .h28 {
  198. height: 56rpx;
  199. }
  200. .avatar-region {
  201. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  202. border-radius: 40rpx;
  203. width: 700rpx;
  204. height: auto;
  205. padding-bottom: 30rpx;
  206. padding-top: 30rpx;
  207. background-color: white;
  208. margin-top: 30rpx;
  209. margin-bottom: 30rpx;
  210. margin-left: 25rpx;
  211. }
  212. .info-region {
  213. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  214. border-radius: 40rpx;
  215. width: 700rpx;
  216. height: auto;
  217. padding-bottom: 30rpx;
  218. padding-top: 30rpx;
  219. background-color: white;
  220. margin-top: 30rpx;
  221. margin-bottom: 30rpx;
  222. margin-left: 25rpx;
  223. }
  224. .avatar-container {
  225. margin-left: 50rpx;
  226. margin-right: 50rpx;
  227. }
  228. .avatar {
  229. width: 130rpx;
  230. height: 130rpx;
  231. border-radius: 50%;
  232. overflow: hidden;
  233. }
  234. .logout-button {
  235. width: 686rpx;
  236. height: 88rpx;
  237. background: #FF4748;
  238. border-radius: 44rpx;
  239. font-size: 32rpx;
  240. color: #FFFFFF;
  241. margin-top: 100rpx;
  242. }
  243. </style>