mine-edit.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <view class="page mine-edit">
  3. <nav-bar back>修改我的信息</nav-bar>
  4. <view class="form">
  5. <view class="form-item">
  6. <view class="label">头像</view>
  7. <image-upload class="value" :isPermanent="true" :onSuccess="onUnloadImageSuccess">
  8. <image :src="userInfo.headImageThumb" class="head-image"></image>
  9. </image-upload>
  10. </view>
  11. <view class="form-item">
  12. <view class="label">用户名</view>
  13. <view class="value">{{userInfo.userName}}</view>
  14. </view>
  15. <view class="form-item">
  16. <view class="label">昵称</view>
  17. <input class="input" maxlength="20" v-model="userInfo.nickName" placeholder="请输入您的昵称" />
  18. </view>
  19. <view class="form-item">
  20. <view class="label">性别</view>
  21. <radio-group class="radio-group" @change="onSexChange">
  22. <radio class="radio" :value="0" :checked="userInfo.sex==0">男</radio>
  23. <radio class="radio" :value="1" :checked="userInfo.sex==1">女</radio>
  24. </radio-group>
  25. </view>
  26. <view class="form-item">
  27. <view class="label">个性签名</view>
  28. <textarea class="signature" maxlength="64" auto-height v-model="userInfo.signature"
  29. :style="{'text-align': signTextAlign}" @linechange="onLineChange"
  30. placeholder="编辑个性签名,展示我的独特态度"></textarea>
  31. </view>
  32. </view>
  33. <button type="primary" class="bottom-btn" @click="onSubmit()">提交</button>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. signTextAlign: 'right',
  41. userInfo: {}
  42. }
  43. },
  44. methods: {
  45. onSexChange(e) {
  46. this.userInfo.sex = e.detail.value;
  47. },
  48. onUnloadImageSuccess(file, res) {
  49. this.userInfo.headImage = res.data.originUrl;
  50. this.userInfo.headImageThumb = res.data.thumbUrl;
  51. },
  52. onSubmit() {
  53. this.$http({
  54. url: "/user/update",
  55. method: "PUT",
  56. data: this.userInfo
  57. }).then(() => {
  58. this.userStore.setUserInfo(this.userInfo);
  59. uni.showToast({
  60. title: "修改成功",
  61. icon: 'none'
  62. });
  63. })
  64. },
  65. onLineChange(e) {
  66. this.signTextAlign = e.detail.lineCount > 1 ? "left" : "right";
  67. }
  68. },
  69. onLoad() {
  70. // 深拷贝一份数据
  71. let mine = this.userStore.userInfo;
  72. this.userInfo = JSON.parse(JSON.stringify(mine));
  73. }
  74. }
  75. </script>
  76. <style scoped lang="scss">
  77. .mine-edit {
  78. .form {
  79. margin-top: 20rpx;
  80. .form-item {
  81. padding: 0 40rpx;
  82. display: flex;
  83. background: white;
  84. align-items: center;
  85. margin-bottom: 2rpx;
  86. .label {
  87. width: 200rpx;
  88. line-height: 100rpx;
  89. font-size: $im-font-size;
  90. }
  91. .value {
  92. flex: 1;
  93. text-align: right;
  94. line-height: 100rpx;
  95. color: $im-text-color-lighter;
  96. font-size: $im-font-size-small;
  97. }
  98. .radio-group {
  99. flex: 1;
  100. text-align: right;
  101. .radio {
  102. margin-left: 50rpx;
  103. }
  104. }
  105. .input {
  106. flex: 1;
  107. text-align: right;
  108. line-height: 100rpx;
  109. font-size: $im-font-size-small;
  110. }
  111. .signature {
  112. flex: 1;
  113. font-size: $im-font-size-small;
  114. max-height: 160rpx;
  115. padding: 14rpx 0;
  116. text-align: right;
  117. }
  118. .head-image {
  119. width: 120rpx;
  120. height: 120rpx;
  121. border-radius: 50%;
  122. border: 1px solid #ccc;
  123. }
  124. }
  125. }
  126. }
  127. </style>