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.
 
 
 
 
 
 

223 lines
4.8 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. <view class="yt-list-cell">
  38. <view class="cell-tit">
  39. Uppercase and lowercase English letters and numbers,More than eight digits.
  40. </view>
  41. </view>
  42. <!-- #endif -->
  43. <view class="yt-list-cell">
  44. <button type="primary" @click="submit">Submit And Save</button>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. mapState,
  51. mapMutations
  52. } from 'vuex';
  53. export default {
  54. data() {
  55. return {
  56. username: '',
  57. password: '',
  58. avatar: ''
  59. };
  60. },
  61. computed: {
  62. ...mapState(['userInfo'])
  63. },
  64. onLoad() {
  65. this.username = this.userInfo.username;
  66. this.password = '';
  67. this.avatar = this.userInfo.avatar ? this.userInfo.avatar : '';
  68. },
  69. methods: {
  70. ...mapMutations(['setUserInfo']),
  71. getAvatar(e) {
  72. this.avatar = e.detail.userInfo.avatarUrl;
  73. },
  74. getUserInfo(e) {
  75. this.username = e.detail.userInfo.nickName;
  76. },
  77. // async getPhoneNumber(e) {
  78. // let data = await this.$api.request('/user/decryptData', 'POST', {
  79. // encryptedData: e.detail.encryptedData,
  80. // iv: e.detail.iv
  81. // });
  82. // if (data) {
  83. // this.password = data.phoneNumber;
  84. // }
  85. // },
  86. async submit() {
  87. if (this.username == '') {
  88. this.$api.msg('用户名称不能为空');
  89. return;
  90. }
  91. // if (this.username == this.userInfo.username &&
  92. // this.password == this.userInfo.password &&
  93. // this.avatar == this.userInfo.avatar) {
  94. // this.$api.msg('已修改');
  95. // return;
  96. // }
  97. let data = await this.$api.request('/user/edit', 'POST', {
  98. username: this.username,
  99. password: this.password,
  100. avatar: this.avatar
  101. });
  102. if (data) {
  103. let userInfo = this.userInfo;
  104. userInfo.username = this.username;
  105. // userInfo.password = this.password;
  106. userInfo.avatar = this.avatar;
  107. this.setUserInfo(userInfo);
  108. }
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss">
  114. page {
  115. background: $page-color-base;
  116. }
  117. .user-section {
  118. display: flex;
  119. align-items: center;
  120. justify-content: center;
  121. height: 460upx;
  122. padding: 40upx 30upx 0;
  123. position: relative;
  124. .bg {
  125. position: absolute;
  126. left: 0;
  127. top: 0;
  128. width: 100%;
  129. height: 100%;
  130. filter: blur(1px);
  131. opacity: .7;
  132. }
  133. .portrait-box {
  134. width: 200upx;
  135. height: 200upx;
  136. border: 6upx solid #fff;
  137. border-radius: 50%;
  138. position: relative;
  139. z-index: 2;
  140. .button {
  141. position: absolute;
  142. width: 100%;
  143. height: 100%;
  144. top: 0;
  145. opacity: 0;
  146. }
  147. }
  148. .portrait {
  149. position: relative;
  150. width: 100%;
  151. height: 100%;
  152. border-radius: 50%;
  153. }
  154. .yticon {
  155. position: absolute;
  156. line-height: 1;
  157. z-index: 5;
  158. font-size: 48upx;
  159. color: #fff;
  160. padding: 4upx 6upx;
  161. border-radius: 6upx;
  162. background: rgba(0, 0, 0, .4);
  163. }
  164. .pt-upload-btn {
  165. right: 0;
  166. bottom: 10upx;
  167. }
  168. .bg-upload-btn {
  169. right: 20upx;
  170. bottom: 16upx;
  171. }
  172. }
  173. .yt-list-cell {
  174. margin-top: 16rpx;
  175. background: #fff;
  176. display: flex;
  177. align-items: center;
  178. padding: 10rpx 30rpx;
  179. line-height: 70rpx;
  180. position: relative;
  181. .cell-tit {
  182. flex: 1;
  183. font-size: 26rpx;
  184. color: #000000;
  185. margin-right: 10rpx;
  186. .input {
  187. display: inline-block;
  188. vertical-align: middle;
  189. margin-left: 20rpx;
  190. width: 540rpx;
  191. float: right;
  192. line-height: 70rpx !important;
  193. height: 70rpx !important;
  194. }
  195. .username {
  196. width: 300rpx;
  197. position: absolute;
  198. right: 30rpx;
  199. z-index: 100;
  200. }
  201. }
  202. }
  203. </style>