myInfo.vue 5.0 KB

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