info.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='用户信息'></cus-header>
  4. <div class="info">
  5. <div class="item">
  6. <div class="left">头像</div>
  7. <div class="right" @tap="changeAvatar">
  8. <image :src="userInfo.headUrl||avatar" mode=""></image>
  9. <u-icon name="arrow-right" color="#198CFF" size="32" style="margin-left: 10rpx;"></u-icon>
  10. </div>
  11. </div>
  12. <div class="item">
  13. <div class="left">姓名</div>
  14. <div class="right">
  15. <input type="text" v-model="userInfo.realName" placeholder="请输入姓名">
  16. </div>
  17. </div>
  18. <div class="item">
  19. <div class="left">性别</div>
  20. <div class="right" @tap="sexShow = true">
  21. {{userInfo.gender===0?'男':(userInfo.gender==1?'女':'保密')}}
  22. <u-icon name="arrow-right" color="#198CFF" size="32" style="margin-left: 10rpx;"></u-icon>
  23. </div>
  24. </div>
  25. <div class="item">
  26. <div class="left">邮箱</div>
  27. <div class="right">
  28. <input type="text" v-model="userInfo.email" placeholder="请输入邮箱">
  29. </div>
  30. </div>
  31. </div>
  32. <div class="btn" @tap="confirm">确定</div>
  33. <u-picker :show="sexShow" :columns="sexColumns" title="性别" keyName="name" @cancel="sexShow = false;" @confirm="sexConfirm"></u-picker>
  34. </view>
  35. </template>
  36. <script>
  37. const baseApi = require("@/http/baseApi.js");
  38. export default {
  39. data(){
  40. return {
  41. avatar:this.$imgBase+'home/home_avator.png',
  42. userInfo:{},
  43. sexShow:false,
  44. sexColumns:[[{id:0,name:'男'},{id:1,name:'女'},{id:2,name:'保密'}]]
  45. }
  46. },
  47. created() {
  48. this.userInfo = JSON.parse(uni.getStorageSync('userInfo')||'{}');
  49. },
  50. methods:{
  51. sexConfirm(e){
  52. this.userInfo.gender = e.value[0].id;
  53. this.sexShow = false;
  54. },
  55. confirm(){
  56. if(!this.$reg.email(this.userInfo?.email)) return this.$showToast('请输入正确的邮箱');
  57. this.$api.put('/user',this.userInfo).then(res=>{
  58. if(res.data.code===0){
  59. uni.setStorageSync('userInfo',JSON.stringify(this.userInfo));
  60. this.$showToast('编辑成功');
  61. setTimeout(()=>{
  62. uni.navigateBack()
  63. },1500)
  64. }else this.$showToast(res.data.msg)
  65. })
  66. },
  67. // 上传头像
  68. changeAvatar() {
  69. uni.chooseImage({
  70. sourceType: ['album'], //从相册选择
  71. success: chooseImageRes => {
  72. const tempFilePaths = chooseImageRes.tempFilePaths;
  73. uni.uploadFile({
  74. url: baseApi.BaseApi + '/uploadFile',
  75. filePath: tempFilePaths[0],
  76. name: 'file',
  77. header: {
  78. token: uni.getStorageSync('token')
  79. },
  80. success: res => {
  81. let data = JSON.parse(res.data);
  82. this.userInfo.headUrl = data.data;
  83. }
  84. });
  85. },
  86. fail: err => {
  87. this.$showToast('图片上传失败');
  88. }
  89. });
  90. },
  91. }
  92. }
  93. </script>
  94. <style scoped lang="less">
  95. .page{
  96. background: #F4F8FB;
  97. box-sizing: border-box;
  98. .info{
  99. width: 100%;
  100. margin-top: 20rpx;
  101. .item{
  102. padding: 24rpx 25rpx;
  103. background: #FFFFFF;
  104. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #ECECEC;
  105. display: flex;
  106. align-items: center;
  107. justify-content: space-between;
  108. .left{
  109. font-family: PingFangSC, PingFang SC;
  110. font-weight: 400;
  111. font-size: 30rpx;
  112. color: #1D2129;
  113. line-height: 42rpx;
  114. text-align: left;
  115. }
  116. .right{
  117. display: flex;
  118. align-items: center;
  119. image{
  120. width: 96rpx;
  121. height: 96rpx;
  122. border-radius: 50%;
  123. }
  124. input{
  125. font-family: PingFangSC, PingFang SC;
  126. font-weight: 400;
  127. font-size: 30rpx;
  128. color: #4E5969;
  129. line-height: 42rpx;
  130. text-align: right;
  131. outline: none;
  132. border: none;
  133. }
  134. }
  135. }
  136. }
  137. .btn{
  138. width: calc(100% - 108rpx);
  139. height: 88rpx;
  140. background: #198CFF;
  141. border-radius: 16rpx;
  142. margin: 240rpx 54rpx 0;
  143. font-family: PingFang-SC, PingFang-SC;
  144. font-weight: bold;
  145. font-size: 32rpx;
  146. color: #FFFFFF;
  147. line-height: 88rpx;
  148. text-align: center;
  149. letter-spacing: 2rpx;
  150. }
  151. }
  152. </style>