profile.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view class="container">
  3. <view class="user-info">
  4. <view class="info-item">
  5. <view class="label">头像:</view>
  6. <view class="info" @click="handleAvatarClick">
  7. <u-avatar size="60" :src="userInfo.avatar"></u-avatar>
  8. <u-icon class="btn" name="arrow-right"></u-icon>
  9. </view>
  10. </view>
  11. <view class="info-item">
  12. <view class="label">昵称:</view>
  13. <view class="info">
  14. <view class="value">{{ userInfo.nickname }}</view>
  15. <u-icon class="btn" name="edit-pen"></u-icon>
  16. </view>
  17. </view>
  18. <view class="info-item">
  19. <view class="label">手机:</view>
  20. <view class="info">
  21. <view class="value">{{ userInfo.mobile }}</view>
  22. <u-icon class="btn" name="edit-pen"></u-icon>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { getUserInfo, updateAvatar } from '../../common/api'
  30. export default {
  31. data() {
  32. return {
  33. userInfo: {
  34. nickname: '',
  35. avatar: '',
  36. mobile: ''
  37. },
  38. avatarFiles: []
  39. }
  40. },
  41. onLoad() {
  42. this.loadUserInfoData()
  43. },
  44. methods: {
  45. loadUserInfoData() {
  46. getUserInfo()
  47. .then(res => {
  48. this.userInfo = res.data
  49. })
  50. .catch(err => {
  51. //console.log(err)
  52. })
  53. },
  54. handleAvatarClick() {
  55. uni.chooseImage({
  56. success: chooseImageRes => {
  57. const tempFilePaths = chooseImageRes.tempFilePaths
  58. console.log(tempFilePaths)
  59. updateAvatar(tempFilePaths[0])
  60. .then(res => {
  61. console.log(res)
  62. })
  63. .catch(err => {
  64. //console.log(err)
  65. })
  66. }
  67. })
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .user-info {
  74. .info-item {
  75. padding: 20rpx 60rpx;
  76. border-bottom: $custom-border-style;
  77. @include flex-space-between;
  78. .label {
  79. font-size: 30rpx;
  80. }
  81. .info {
  82. @include flex-right;
  83. .value {
  84. font-size: 30rpx;
  85. }
  86. .btn {
  87. margin-left: 30rpx;
  88. }
  89. }
  90. }
  91. }
  92. </style>