personInfo.vue 5.8 KB

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