You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

217 lines
4.6 KiB

  1. <template>
  2. <view>
  3. <view class="user-section">
  4. <image class="bg" src="/static/user-bg.jpg"></image>
  5. <text class="bg-upload-btn yticon icon-paizhao"></text>
  6. <view class="portrait-box">
  7. <image class="portrait" :src="avatar ? avatar : '/static/missing-face.png'"></image>
  8. <text class="pt-upload-btn yticon icon-paizhao"></text>
  9. <button class="button" open-type="getUserInfo" @getuserinfo="getAvatar"></button>
  10. </view>
  11. </view>
  12. <!-- #ifdef MP-WEIXIN -->
  13. <view class="yt-list-cell">
  14. <view class="cell-tit clamp">用户名
  15. <input class="input" type="text" v-model="username" />
  16. <button class="input username" open-type="getUserInfo" @getuserinfo="getUserInfo">获取微信名称</button>
  17. </view>
  18. </view>
  19. <view class="yt-list-cell">
  20. <view class="cell-tit clamp">登陆密码
  21. <input v-if="password" disabled="true" class="input" type="text" v-model="password" />
  22. <!-- <button v-else class="input" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">授权获取微信绑定的手机号码</button> -->
  23. </view>
  24. </view>
  25. <!-- #endif -->
  26. <!-- #ifndef MP-WEIXIN -->
  27. <view class="yt-list-cell">
  28. <view class="cell-tit clamp">user
  29. <input class="input" type="text" v-model="username" />
  30. </view>
  31. </view>
  32. <view class="yt-list-cell">
  33. <view class="cell-tit clamp">password
  34. <input class="input" type="password" v-model="password" />
  35. </view>
  36. </view>
  37. <!-- #endif -->
  38. <view class="yt-list-cell">
  39. <button type="primary" @click="submit">Submit And Save</button>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. mapState,
  46. mapMutations
  47. } from 'vuex';
  48. export default {
  49. data() {
  50. return {
  51. username: '',
  52. password: '',
  53. avatar: ''
  54. };
  55. },
  56. computed: {
  57. ...mapState(['userInfo'])
  58. },
  59. onLoad() {
  60. this.username = this.userInfo.username;
  61. this.password = '';
  62. this.avatar = this.userInfo.avatar ? this.userInfo.avatar : '';
  63. },
  64. methods: {
  65. ...mapMutations(['setUserInfo']),
  66. getAvatar(e) {
  67. this.avatar = e.detail.userInfo.avatarUrl;
  68. },
  69. getUserInfo(e) {
  70. this.username = e.detail.userInfo.nickName;
  71. },
  72. // async getPhoneNumber(e) {
  73. // let data = await this.$api.request('/user/decryptData', 'POST', {
  74. // encryptedData: e.detail.encryptedData,
  75. // iv: e.detail.iv
  76. // });
  77. // if (data) {
  78. // this.password = data.phoneNumber;
  79. // }
  80. // },
  81. async submit() {
  82. if (this.username == '') {
  83. this.$api.msg('用户名称不能为空');
  84. return;
  85. }
  86. // if (this.username == this.userInfo.username &&
  87. // this.password == this.userInfo.password &&
  88. // this.avatar == this.userInfo.avatar) {
  89. // this.$api.msg('已修改');
  90. // return;
  91. // }
  92. let data = await this.$api.request('/user/edit', 'POST', {
  93. username: this.username,
  94. password: this.password,
  95. avatar: this.avatar
  96. });
  97. if (data) {
  98. let userInfo = this.userInfo;
  99. userInfo.username = this.username;
  100. // userInfo.password = this.password;
  101. userInfo.avatar = this.avatar;
  102. this.setUserInfo(userInfo);
  103. }
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss">
  109. page {
  110. background: $page-color-base;
  111. }
  112. .user-section {
  113. display: flex;
  114. align-items: center;
  115. justify-content: center;
  116. height: 460upx;
  117. padding: 40upx 30upx 0;
  118. position: relative;
  119. .bg {
  120. position: absolute;
  121. left: 0;
  122. top: 0;
  123. width: 100%;
  124. height: 100%;
  125. filter: blur(1px);
  126. opacity: .7;
  127. }
  128. .portrait-box {
  129. width: 200upx;
  130. height: 200upx;
  131. border: 6upx solid #fff;
  132. border-radius: 50%;
  133. position: relative;
  134. z-index: 2;
  135. .button {
  136. position: absolute;
  137. width: 100%;
  138. height: 100%;
  139. top: 0;
  140. opacity: 0;
  141. }
  142. }
  143. .portrait {
  144. position: relative;
  145. width: 100%;
  146. height: 100%;
  147. border-radius: 50%;
  148. }
  149. .yticon {
  150. position: absolute;
  151. line-height: 1;
  152. z-index: 5;
  153. font-size: 48upx;
  154. color: #fff;
  155. padding: 4upx 6upx;
  156. border-radius: 6upx;
  157. background: rgba(0, 0, 0, .4);
  158. }
  159. .pt-upload-btn {
  160. right: 0;
  161. bottom: 10upx;
  162. }
  163. .bg-upload-btn {
  164. right: 20upx;
  165. bottom: 16upx;
  166. }
  167. }
  168. .yt-list-cell {
  169. margin-top: 16rpx;
  170. background: #fff;
  171. display: flex;
  172. align-items: center;
  173. padding: 10rpx 30rpx;
  174. line-height: 70rpx;
  175. position: relative;
  176. .cell-tit {
  177. flex: 1;
  178. font-size: 26rpx;
  179. color: #000000;
  180. margin-right: 10rpx;
  181. .input {
  182. display: inline-block;
  183. vertical-align: middle;
  184. margin-left: 20rpx;
  185. width: 540rpx;
  186. float: right;
  187. line-height: 70rpx !important;
  188. height: 70rpx !important;
  189. }
  190. .username {
  191. width: 300rpx;
  192. position: absolute;
  193. right: 30rpx;
  194. z-index: 100;
  195. }
  196. }
  197. }
  198. </style>