myInfo.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view>
  3. <view style="margin: 20px; background-color: #fff;">
  4. <!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
  5. <u--form labelPosition="left" :model="userInfo" :rules="rules" ref="uForm">
  6. <u-form-item label="姓名" prop="userInfo.nickName">
  7. <u--input v-model="userInfo.nickName" border="none"></u--input>
  8. </u-form-item>
  9. <u-form-item label="头像" prop="userInfo.avatarUrl">
  10. <view slot="right" class="flex-row" @click="onInfo">
  11. <u-avatar :src="userInfo.avatarUrl ? userInfo.avatarUrl : null" size="50"
  12. @click="uploadAvator"></u-avatar>
  13. <view class="flex-grow-1">
  14. <u-icon name="arrow-right" color="#96989e"></u-icon>
  15. </view>
  16. </view>
  17. </u-form-item>
  18. <u-form-item label="生日" prop="userInfo.birthday">
  19. <u--input v-model="userInfo.birthday" border="none" placeholder="请选择生日"></u--input>
  20. <u-icon slot="right" name="arrow-right" color="#96989e"></u-icon>
  21. </u-form-item>
  22. <u-form-item label="手机号" prop="userInfo.phone" labelWidth="100px">
  23. <u--input v-model="userInfo.phone" border="none"></u--input>
  24. <u-button type="primary" shape="circle" size="small" slot="right"
  25. color="linear-gradient(to right, #F54319, #FF6D20)" text="解绑">
  26. </u-button>
  27. </u-form-item>
  28. </u--form>
  29. </view>
  30. <view class="cart-bottom padding-sm dflex-b">
  31. <view class="go-cart dflex-c">保存编辑</view>
  32. <view class="go-buy dflex-c background-gradient">退出登录</view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. userInfo: {
  41. name: 'uView UI',
  42. avg: '',
  43. birthday: '',
  44. phone: ''
  45. },
  46. rules: {
  47. // 字段名称
  48. phone: [{
  49. required: true,
  50. message: '请输入手机号',
  51. trigger: ['change', 'blur'],
  52. },
  53. {
  54. // 自定义验证函数,见上说明
  55. validator: (rule, value, callback) => {
  56. // 上面有说,返回true表示校验通过,返回false表示不通过
  57. // uni.$u.test.phone()就是返回true或者false的
  58. return uni.$u.test.phone(value);
  59. },
  60. message: '手机号码不正确',
  61. // 触发器可以同时用blur和change
  62. trigger: ['change', 'blur'],
  63. }
  64. ]
  65. }
  66. }
  67. },
  68. onLoad() {
  69. this.fatchDate()
  70. },
  71. methods: {
  72. fatchDate() {
  73. wx.getUserInfo({
  74. success: (res)=>{
  75. console.log(res)
  76. this.userInfo = res.userInfo
  77. console.log(res.userInfo)
  78. }
  79. })
  80. // const result = await this.$request('post',
  81. // '/auth/getUserInfo', true)
  82. // wx.getUserProfile({
  83. // desc: '获取用户信息',
  84. // success: (res) => {
  85. // console.log('res', res)
  86. // },
  87. // })
  88. },
  89. uploadAvator() { // 上传头像
  90. uni.chooseImage({
  91. success: (file) => {
  92. uni.showLoading({
  93. title: '请稍后',
  94. })
  95. // 上传头像文件
  96. uni.uploadFile({
  97. url: `${this.serverPath}/resource/oss/upload`,
  98. name: 'file',
  99. filePath: file.tempFilePaths[0],
  100. header: {
  101. tenantId: this.tenantId
  102. },
  103. success: async (response) => {
  104. const data = JSON.parse(response.data)
  105. // 更新用户头像
  106. const result = await this.$request('post',
  107. '/userinfo/account/update', {
  108. avatarUrl: data.data.url,
  109. aid: this.userdata.aid
  110. }, false, true)
  111. if (result) {
  112. // 记录埋点
  113. this.$setPoint('user_update_avatarUrl', {
  114. avatarUrl: data.data.url
  115. })
  116. uni.showToast({
  117. title: '上传成功',
  118. icon: 'success'
  119. })
  120. this.userdata.avatarUrl = data.data.url
  121. this.setStoreData('vuex_user', this.userdata)
  122. }
  123. },
  124. fail: (e) => {
  125. }
  126. })
  127. },
  128. fail: (e) => {
  129. }
  130. })
  131. },
  132. },
  133. }
  134. </script>
  135. <style scoped lang="less">
  136. .cart-bottom {
  137. width: 100%;
  138. position: fixed;
  139. left: 0;
  140. bottom: 0;
  141. height: 130rpx;
  142. box-sizing: border-box;
  143. background-color: #FFF;
  144. z-index: 10;
  145. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
  146. .go-cart {
  147. height: 80%;
  148. box-sizing: border-box;
  149. border: solid 1px #BBBBBB;
  150. font-size: 14px;
  151. color: #000;
  152. border-radius: 50upx;
  153. margin: 0 10px;
  154. width: 45%;
  155. }
  156. .go-buy {
  157. height: 80%;
  158. width: 45%;
  159. background-color: #FF0000;
  160. color: #FFF;
  161. border-radius: 50upx;
  162. font-size: 14px;
  163. }
  164. }
  165. .flex-row {
  166. display: flex;
  167. align-items: center;
  168. }
  169. .flex-grow-1 {
  170. flex-grow: 1;
  171. margin-left: 10px;
  172. }
  173. </style>