personInfo.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view >
  3. <view class="content">
  4. <view class="info-item">
  5. <view class="label">头像</view>
  6. <view class="right">
  7. <image class="head" :src="user.avatar==null?'https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/22cb9518a55040dea74d8f730551a7a2.jpg':user.avatar" mode=""></image>
  8. <button class="wx-head" type="balanced" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  9. </button>
  10. </view>
  11. </view>
  12. <view class="info-item">
  13. <view class="label">昵称</view>
  14. <view class="right">
  15. <input type="nickname" @blur="bindblur" @input="bindinput" v-model="user.nickName" class="input" />
  16. <image class="image" src="/static/images/icon_edit.png" mode=""></image>
  17. </view>
  18. </view>
  19. <view class="info-item">
  20. <view class="label">手机号</view>
  21. <view class="right">
  22. <text class="text" v-if="user!=null">{{$parsePhone(user.phone)}}</text>
  23. <image class="image" src="/static/images/icon_lock.png" mode=""></image>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="btn-box">
  28. <view class="btn" @click="submit()">保存修改</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {getUserInfo,editUser} from '@/api/user.js'
  34. export default {
  35. data() {
  36. return {
  37. user:{
  38. avatar:null,
  39. phone:""
  40. }
  41. }
  42. },
  43. onLoad() {
  44. this.getUserInfo()
  45. },
  46. methods: {
  47. bindblur(e) {
  48. this.user.nickName = e.detail.value; // 获取微信昵称
  49. },
  50. bindinput(e){
  51. this.user.nickName = e.detail.value; //这里要注意如果只用blur方法的话用户在输入玩昵称后直接点击保存按钮,会出现修改不成功的情况。
  52. },
  53. onChooseAvatar(e){
  54. let {
  55. avatarUrl
  56. } = e.detail;
  57. uni.uploadFile({
  58. url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
  59. filePath: avatarUrl,
  60. name: 'file',
  61. formData: {
  62. 'user': 'test' // 上传附带参数
  63. },
  64. success: (uploadFileRes) => {
  65. this.user.avatar =JSON.parse(uploadFileRes.data).url
  66. }
  67. });
  68. },
  69. // chooseImage() {
  70. // var that = this;
  71. // uni.chooseImage({
  72. // count: 1, // 默认9
  73. // sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  74. // sourceType: ['album', 'camera'], //从相册选择
  75. // success: (res) => {
  76. // uni.uploadFile({
  77. // url: uni.getStorageSync('requestPath')+'/api/common/uploadOSS', //仅为示例,非真实的接口地址
  78. // filePath: res.tempFilePaths[0],
  79. // name: 'file',
  80. // formData: {
  81. // 'user': 'test' // 上传附带参数
  82. // },
  83. // success: (uploadFileRes) => {
  84. // console.log(uploadFileRes)
  85. // this.user.avatar =JSON.parse(uploadFileRes.data).data.url
  86. // }
  87. // });
  88. // }
  89. // });
  90. // },
  91. submit(){
  92. this.user.isWeixinAuth=1;
  93. editUser(this.user).then(
  94. res => {
  95. if(res.code==200){
  96. uni.setStorageSync('avatar',this.avatar);
  97. uni.setStorageSync('nickName',this.nickName);
  98. uni.showToast({
  99. icon:'success',
  100. title: "修改成功",
  101. });
  102. //修改IM个人信息
  103. this.getUserInfo()
  104. }else{
  105. uni.showToast({
  106. icon:'none',
  107. title: "请求失败",
  108. });
  109. }
  110. },
  111. rej => {}
  112. );
  113. },
  114. getUserInfo(){
  115. getUserInfo().then(
  116. res => {
  117. if(res.code==200){
  118. if(res.user!=null){
  119. this.user=res.user;
  120. }
  121. else{
  122. this.utils.loginOut();
  123. }
  124. }else{
  125. uni.showToast({
  126. icon:'none',
  127. title: "请求失败",
  128. });
  129. }
  130. },
  131. rej => {}
  132. );
  133. },
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .content{
  139. padding-top: 20rpx;
  140. border-top: 1px solid #F5F6FA;
  141. }
  142. .info-item{
  143. height: 104upx;
  144. background: #FFFFFF;
  145. padding: 0 30upx;
  146. display: flex;
  147. align-items: center;
  148. justify-content: space-between;
  149. border-bottom: 1px solid #F5F6FA;
  150. &:last-child{
  151. border-bottom: none;
  152. }
  153. .label{
  154. min-width: 200rpx;
  155. font-size: 30upx;
  156. font-family: PingFang SC;
  157. font-weight: 400;
  158. color: #0F1826;
  159. }
  160. .right{
  161. display: flex;
  162. align-items: center;
  163. justify-content: center;
  164. .text{
  165. font-size: 30upx;
  166. font-family: PingFang SC;
  167. font-weight: 400;
  168. color: #0F1826;
  169. }
  170. .image{
  171. min-width: 30rpx;
  172. margin-left: 10upx;
  173. width: 30upx;
  174. height: 30upx;
  175. }
  176. .input{
  177. text-align: right;
  178. font-size: 30upx;
  179. font-family: PingFang SC;
  180. font-weight: 400;
  181. color: #0F1826;
  182. }
  183. .wx-head{
  184. position: absolute;
  185. margin-left: 10upx;
  186. width: 30upx;
  187. height: 30upx;
  188. opacity: 0;
  189. }
  190. }
  191. .head{
  192. border-radius: 50%;
  193. width: 80upx;
  194. height: 80upx;
  195. }
  196. .arrow{
  197. width: 30upx;
  198. height: 30upx;
  199. }
  200. .text{
  201. font-size: 30upx;
  202. font-family: PingFang SC;
  203. font-weight: 400;
  204. color: #0F1826;
  205. }
  206. .input{
  207. text-align: right;
  208. font-size: 30upx;
  209. font-family: PingFang SC;
  210. font-weight: 400;
  211. color: #0F1826;
  212. }
  213. &.password{
  214. margin-top: 20upx;
  215. .right{
  216. display: flex;
  217. align-items: center;
  218. .text{
  219. font-size: 30upx;
  220. font-family: PingFang SC;
  221. font-weight: 400;
  222. color: #0F1826;
  223. margin-right: 15upx;
  224. }
  225. }
  226. }
  227. }
  228. .btn-box{
  229. height: 140upx;
  230. z-index: 9999;
  231. width: 100%;
  232. padding: 0rpx 30upx;
  233. position: fixed;
  234. bottom: 0;
  235. left: 0;
  236. box-sizing: border-box;
  237. background-color: #ffffff;
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. .btn{
  242. width: 100%;
  243. height: 88upx;
  244. line-height: 88upx;
  245. text-align: center;
  246. font-size: 34upx;
  247. font-family: PingFang SC;
  248. font-weight: 400;
  249. color: #FFFFFF;
  250. background: #C39A58;
  251. border-radius: 10upx;
  252. }
  253. }
  254. </style>