myInfo.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.name">
  7. <u--input v-model="userInfo.name" border="none"></u--input>
  8. </u-form-item>
  9. <u-form-item label="头像" prop="userInfo.avg">
  10. <view slot="right" class="flex-row" @click="onInfo">
  11. <u-avatar :src="getFilePath(userInfo.avg ? userInfo.avg : 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. methods: {
  69. uploadAvator() { // 上传头像
  70. uni.chooseImage({
  71. success: (file) => {
  72. uni.showLoading({
  73. title: '请稍后',
  74. })
  75. // 上传头像文件
  76. uni.uploadFile({
  77. url: `${this.serverPath}/resource/oss/upload`,
  78. name: 'file',
  79. filePath: file.tempFilePaths[0],
  80. header: {
  81. tenantId: this.tenantId
  82. },
  83. success: async (response) => {
  84. const data = JSON.parse(response.data)
  85. // 更新用户头像
  86. const result = await this.$request('post',
  87. '/userinfo/account/update', {
  88. avatarUrl: data.data.url,
  89. aid: this.userdata.aid
  90. }, false, true)
  91. if (result) {
  92. // 记录埋点
  93. this.$setPoint('user_update_avatarUrl', {
  94. avatarUrl: data.data.url
  95. })
  96. uni.showToast({
  97. title: '上传成功',
  98. icon: 'success'
  99. })
  100. this.userdata.avatarUrl = data.data.url
  101. this.setStoreData('vuex_user', this.userdata)
  102. }
  103. },
  104. fail: (e) => {
  105. }
  106. })
  107. },
  108. fail: (e) => {
  109. }
  110. })
  111. },
  112. },
  113. }
  114. </script>
  115. <style scoped lang="less">
  116. .cart-bottom {
  117. width: 100%;
  118. position: fixed;
  119. left: 0;
  120. bottom: 0;
  121. height: 130rpx;
  122. box-sizing: border-box;
  123. background-color: #FFF;
  124. z-index: 10;
  125. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
  126. .go-cart {
  127. height: 80%;
  128. box-sizing: border-box;
  129. border: solid 1px #BBBBBB;
  130. font-size: 14px;
  131. color: #000;
  132. border-radius: 50upx;
  133. margin: 0 10px;
  134. width: 45%;
  135. }
  136. .go-buy {
  137. height: 80%;
  138. width: 45%;
  139. background-color: #FF0000;
  140. color: #FFF;
  141. border-radius: 50upx;
  142. font-size: 14px;
  143. }
  144. }
  145. .flex-row {
  146. display: flex;
  147. align-items: center;
  148. }
  149. .flex-grow-1 {
  150. flex-grow: 1;
  151. margin-left: 10px;
  152. }
  153. </style>