personalDetails.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <view class="container">
  3. <u-navbar title="个人信息" leftIconColor="#ffffff" titleStyle="color:#fff" :autoBack="true" placeholder></u-navbar>
  4. <view class="box">
  5. <view class="item">
  6. <view class="item_l">头像:</view>
  7. <view class="item_r">
  8. <button class="headPhoto-btn" type="default" open-type="chooseAvatar" @chooseavatar="getChooseavatar">
  9. <image :src="userInfo.headPhoto" mode="" v-if="userInfo.headPhoto" />
  10. <image src="@/static/default-head-photo.png" mode="" v-else />
  11. </button>
  12. <text class="iconfont icon-jiantou"></text>
  13. </view>
  14. </view>
  15. <view class="item" @click="show=true">
  16. <view class="item_l">昵称:</view>
  17. <view class="item_r">
  18. {{userInfo.nickname}}
  19. <text class="iconfont icon-jiantou"></text>
  20. </view>
  21. </view>
  22. <view class="item">
  23. <view class="item_l">手机号:</view>
  24. <view class="item_r">{{userInfo.mobile}}</view>
  25. </view>
  26. </view>
  27. <u-modal :show="show" title="昵称" show-cancel-button @confirm="modalConfirm" @cancel="modalCancel" confirm-color="#c90700">
  28. <view class="slot-content">
  29. <input type="nickname" v-model="nickname" placeholder-class="placeholderClass" placeholder="请输入昵称" />
  30. </view>
  31. </u-modal>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. storage,
  37. UserInfo
  38. } from "@/utils/tools.js"
  39. import {
  40. userInfo,
  41. updateUserInfo
  42. } from "@/api/user.js"
  43. export default {
  44. data () {
  45. return {
  46. userInfo: {},
  47. show: false,
  48. headPhoto: undefined,
  49. nickname: undefined
  50. }
  51. },
  52. onLoad () {
  53. this.getUserInfo()
  54. },
  55. methods: {
  56. getUserInfo () {
  57. UserInfo().then(res => {
  58. this.userInfo = res
  59. })
  60. },
  61. getChooseavatar (e) {
  62. let that = this;
  63. uni.showLoading({
  64. title: '上传中',
  65. });
  66. // console.log('获取用户头像:' + JSON.stringify(res.detail.avatarUrl));
  67. let apiUrl = uni.$u.http.config.baseURL + '/common/upload';
  68. let a = uni.uploadFile({
  69. url: apiUrl, // 仅为示例,非真实的接口地址
  70. filePath: e.detail.avatarUrl,
  71. header: {
  72. apiToken: storage.get('apiToken')
  73. },
  74. name: 'file',
  75. success: (res) => {
  76. let newdata = JSON.parse(res.data);
  77. if (newdata.code == 200) {
  78. this.headPhoto = newdata.data.url;
  79. this.saveInfo({
  80. headPhoto: newdata.data.url
  81. })
  82. }
  83. },
  84. fail: () => {
  85. uni.$u.toast("上传失败");
  86. },
  87. complete: () => {
  88. uni.hideLoading();
  89. }
  90. });
  91. },
  92. modalConfirm () {
  93. if (!this.nickname) return uni.$u.toast("请先填写昵称");
  94. this.saveInfo({
  95. nickname: this.nickname
  96. })
  97. },
  98. modalCancel () {
  99. this.nickname = null
  100. this.show = false
  101. },
  102. saveInfo (data) {
  103. updateUserInfo(data).then(res => {
  104. this.getUserInfo()
  105. this.modalCancel()
  106. uni.$u.toast("修改成功");
  107. })
  108. }
  109. },
  110. }
  111. </script>
  112. <style lang='scss' scoped>
  113. ::v-deep .u-navbar__content,
  114. ::v-deep .u-status-bar {
  115. background-color: #c90700 !important;
  116. }
  117. .container {
  118. background: #f5f5f5;
  119. min-height: 90vh;
  120. padding: 30rpx;
  121. .box {
  122. background: #ffffff;
  123. border-radius: 30rpx;
  124. padding: 20rpx;
  125. min-height: 80vh;
  126. .item {
  127. border-bottom: 1rpx solid #e6e6e6;
  128. display: flex;
  129. justify-content: space-between;
  130. align-items: center;
  131. height: 100rpx;
  132. .item_l {
  133. font-size: 28rpx;
  134. color: #1a1a1a;
  135. }
  136. .item_r {
  137. font-size: 28rpx;
  138. color: #808080;
  139. display: flex;
  140. align-items: center;
  141. image {
  142. width: 75rpx;
  143. height: 75rpx;
  144. border-radius: 50%;
  145. border: 2rpx solid #ffffff;
  146. }
  147. button {
  148. margin: 0;
  149. font-size: 24rpx;
  150. }
  151. button::after {
  152. border: none;
  153. }
  154. .headPhoto-btn {
  155. background-color: rgba(0, 0, 0, 0);
  156. line-height: inherit;
  157. border-radius: 0;
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. }
  162. }
  163. }
  164. }
  165. }
  166. .slot-content {
  167. padding: 40rpx;
  168. text-align: center;
  169. input {
  170. font-size: 28rpx;
  171. padding: 10rpx 20rpx;
  172. border: 1rpx solid #e6e6e6;
  173. border-radius: 4rpx;
  174. }
  175. ::v-deep .placeholderClass {
  176. font-size: 24rpx;
  177. font-family: FZZhunYuan-M02S;
  178. }
  179. }
  180. </style>