data.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view>
  3. <u-navbar title="个人资料"></u-navbar>
  4. <view class="data">
  5. <view class="data-img">
  6. <view class="data-icon">
  7. <u-icon name="camera-fill" custom-prefix="custom-icon" color="#fff" size="32"></u-icon>
  8. </view>
  9. <u-avatar :src="form.headImg+'?x-oss-process=image/resize,m_fill,w_256,h_256'" size="216" @click="uploadPhoto"></u-avatar>
  10. </view>
  11. <view class="data-input">
  12. <u-form :model="form" ref="uForm" >
  13. <u-form-item label-position="top" label="昵称"><u-input v-model="form.nickName" /></u-form-item>
  14. </u-form>
  15. </view>
  16. <u-button class="login-btn" type="success" shape="circle" @click="submit">提交</u-button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import * as userApi from '@/apis/user.js'
  22. import * as loginApi from '@/apis/login.js'
  23. export default {
  24. data() {
  25. return {
  26. userId: '',
  27. form: {
  28. nickName: '',
  29. headImg: '',
  30. },
  31. }
  32. },
  33. onReady() {
  34. this.getUserInfo();
  35. },
  36. methods: {
  37. getUserInfo() {
  38. uni.showLoading({
  39. title: "加载中",
  40. mask: true,
  41. })
  42. loginApi.findByOpenId({
  43. openId: this.carhelp.getOpenId()
  44. }).then((res) => {
  45. uni.hideLoading();
  46. this.form.nickName = res.data.regUser.nickName;
  47. this.form.headImg = res.data.regUser.headImg;
  48. }).catch(error => {
  49. uni.showToast({
  50. title: error,
  51. icon: "none"
  52. })
  53. })
  54. },
  55. uploadPhoto() {
  56. // 上传图片
  57. let _self = this;
  58. uni.chooseImage({
  59. count: 1, //默认9
  60. sourceType: ['album', 'camera'], //从相册选择
  61. success: (res) => {
  62. let imgFile = res.tempFilePaths;
  63. var token = this.carhelp.getToken()
  64. for (let i = 0; i < imgFile.length; i++) {
  65. wx.uploadFile({
  66. url: process.car.BASE_URL + "uploadPicture",
  67. name: 'photoFile',
  68. header: {
  69. 'Authorization': token,
  70. 'accept': 'application/json',
  71. //#ifdef MP-WEIXIN
  72. "Content-Type": "multipart/form-data", //记得设置
  73. //#endif
  74. },
  75. filePath: imgFile[0],
  76. success: function(result) {
  77. let imgUrls = JSON.parse(result.data)
  78. _self.form.headImg = imgUrls.data;
  79. }
  80. })
  81. }
  82. },
  83. });
  84. },
  85. submit() {
  86. uni.showLoading({
  87. title: "加载中",
  88. mask: true,
  89. })
  90. userApi.updatePersonInformation(this.form).then((res) => {
  91. uni.hideLoading();
  92. uni.redirectTo({
  93. url: '/pages/user/index'
  94. })
  95. }).catch(error => {
  96. uni.showToast({
  97. title: error,
  98. icon: "none"
  99. })
  100. })
  101. }
  102. }
  103. }
  104. </script>
  105. <style>
  106. page{
  107. background: #fff;
  108. }
  109. </style>
  110. <style lang="scss" scoped>
  111. .data-icon{
  112. height: 28px;
  113. width: 28px;
  114. background-color: #00B962;
  115. border-radius: 14px;
  116. border: 2px solid #fff;
  117. text-align: center;
  118. line-height: 24px;
  119. position: absolute;
  120. z-index: 999;
  121. right: 0;
  122. bottom:0px
  123. }
  124. .data-img{
  125. margin: 30px auto;
  126. height: 108px;
  127. width: 108px;
  128. position: relative;
  129. }
  130. .data-input{
  131. margin: 0 40px;
  132. }
  133. .login-btn {
  134. margin: 28px ;
  135. background-color:#00B962!important;
  136. border-color: #00B962!important;
  137. color:#fff!important;
  138. }
  139. </style>