index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="page">
  3. <view class="outView">
  4. <form @submit="inputValue">
  5. <view class="flex-row justify-between bordBot" >
  6. <view class="key flex-col justify-center ">
  7. <text>头像</text>
  8. </view>
  9. <button class="photoView" open-type="chooseAvatar" @chooseavatar="chooseavatar">
  10. <image class="photoImage" :src="userInfo.selfPhotoUrl || '/static/me/u4.png'"></image>
  11. </button>
  12. </view>
  13. <view class="flex-row justify-between bordBot" >
  14. <view class="key flex-col justify-center ">
  15. <text>昵称</text>
  16. </view>
  17. <view class="nikeName flex-col justify-center">
  18. <input type="nickname" name="nickname" v-model="userInfo.ncikName" placeholder="请输入昵称"/>
  19. </view>
  20. </view>
  21. <view class="flex-row justify-between bordBot" >
  22. <view class="key flex-col justify-center ">
  23. <text>性别</text>
  24. </view>
  25. <picker class="picker" @change="genderChange" mode='selector' range-key="gender" :value="genderIndex" :range="genderList">
  26. <view class="flex-row justify-end groupItemContent">
  27. <text v-if="userInfo.sex == 0">男</text>
  28. <text v-else-if="userInfo.sex == 1">女</text>
  29. <text v-else-if="userInfo.sex == 2">未知</text>
  30. <text v-else>请选择性别</text>
  31. <u-icon name="arrow-right" color="#666" size="18"></u-icon>
  32. </view>
  33. </picker>
  34. </view>
  35. <view class="flex-row justify-between bordBot" >
  36. <view class="key flex-col justify-center ">
  37. <text>生日</text>
  38. </view>
  39. <picker class="picker" @change="birthdayChange" mode='date' range-key="label" >
  40. <view class="flex-row justify-end groupItemContent">
  41. <text>{{userInfo.birthday || '请选择出生日期' }}</text>
  42. <u-icon name="arrow-right" color="#666" size="18"></u-icon>
  43. </view>
  44. </picker>
  45. </view>
  46. <view class="flex-row justify-between bordBot" >
  47. <view class="key flex-col justify-center ">
  48. <text>实名认证</text>
  49. </view>
  50. <view class="flex-row justify-end groupItemContent" @click="gotoRealNameAuth">
  51. <text>{{userInfo.isAttestation? '已认证' : '未实名认证,去认证' }}</text>
  52. <u-icon name="arrow-right" color="#666" size="18"></u-icon>
  53. </view>
  54. </view>
  55. <button class="updateButton" formType="submit">
  56. <text>保存</text>
  57. </button>
  58. </form>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. export default {
  64. data() {
  65. return {
  66. photoUrl:'',
  67. userInfo: {},
  68. genderIndex:0,
  69. genderList: [{gender:'男',id:'0'},
  70. {gender:'女',id:'1'},
  71. {gender:'未知',id:'2'}],
  72. };
  73. },
  74. mounted() {
  75. },
  76. onLoad() {
  77. // 用户信息
  78. this.userInfo = uni.getStorageSync('userInfo')
  79. if (this.userInfo.selfPhoto){
  80. this.getImgUrlByOssId(this.userInfo.selfPhoto)
  81. }
  82. },
  83. methods: {
  84. inputValue(e){
  85. console.log('+++++++++++++inputValue+++++++++++',e)
  86. this.userInfo.ncikName = e.detail.value.nickname
  87. this.saveUserInfo()
  88. },
  89. // 选择性别
  90. genderChange(e){
  91. console.log(e.detail.value)
  92. this.userInfo.sex = e.detail.value
  93. },
  94. //选择的日期
  95. birthdayChange(e){
  96. console.log(e.detail.value)
  97. this.userInfo.birthday = e.detail.value
  98. },
  99. // 去实名认证
  100. gotoRealNameAuth(){
  101. uni.navigateTo({
  102. url: '/myPages/realNameAuth/index',
  103. })
  104. },
  105. // 保存用户信息
  106. saveUserInfo(){
  107. // 保存数据
  108. this.$api.saveUserInfo(this.userInfo).then((res)=>{
  109. console.log(res)
  110. // 刷新用户信息
  111. this.getUserInfo();
  112. uni.showToast({
  113. title: "操作成功"
  114. })
  115. // setTimeout(res=>{
  116. // uni.switchTab({
  117. // url: '/pages/index/index',
  118. // },2000)
  119. // })
  120. }).catch(() =>{
  121. uni.showToast({
  122. title: "操作失败"
  123. })
  124. });
  125. },
  126. getUserInfo(){
  127. this.$api.getUserInfo().then(res=>{
  128. console.log('++++++++++++获取用户信息++++++++++++++++++',res)
  129. uni.setStorageSync('userInfo',res.data.data)
  130. this.userInfo = res.data.data
  131. if (this.userInfo.selfPhoto){
  132. this.getImgUrlByOssId(this.userInfo.selfPhoto)
  133. }
  134. })
  135. },
  136. getImgUrlByOssId(Id){
  137. this.$api.getImage(Id).then(res=>{
  138. this.userInfo.selfPhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
  139. this.$set(this.userInfo)
  140. });
  141. },
  142. //头像上传
  143. chooseavatar(e){
  144. let that = this
  145. let avatarUrl =e.detail.avatarUrl
  146. console.log(e.detail.avatarUrl)
  147. uni.uploadFile({
  148. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  149. filePath:avatarUrl,
  150. name: 'file',
  151. header: {
  152. // "Content-Type": "multipart/form-data",
  153. // 'X-Access-Token': uni.getStorageSync('token'),
  154. 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
  155. },
  156. success: (uploadFileRes) => {
  157. let res = JSON.parse(uploadFileRes.data)
  158. console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++',uploadFileRes.data)
  159. that.userInfo.selfPhoto=res.data.ossId
  160. that.userInfo.selfPhotoUrl = res.data.url.replace(/^http:/, "https:")
  161. }
  162. });
  163. },
  164. }
  165. };
  166. </script>
  167. <style lang="scss">
  168. @import '/common/css/common.css';
  169. @import './index.rpx.css';
  170. </style>