data.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view>
  3. <ujp-navbar title="个人资料"></ujp-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="昵称" :label-style="elderStatus ? {fontSize: '16px'} : {}"><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. elderStatus: false,
  32. }
  33. },
  34. onReady() {
  35. this.getUserInfo();
  36. if(this.carhelp.get("getElderModeClass") == "长辈模式") {
  37. this.elderStatus = true;
  38. } else {
  39. this.elderStatus = false;
  40. }
  41. },
  42. methods: {
  43. getUserInfo() {
  44. uni.showLoading({
  45. title: "加载中",
  46. mask: true,
  47. })
  48. loginApi.findByOpenId({
  49. openId: this.carhelp.getOpenId()
  50. }).then((res) => {
  51. uni.hideLoading();
  52. this.form.nickName = res.data.regUser.nickName;
  53. this.form.headImg = res.data.regUser.headImg;
  54. }).catch(error => {
  55. uni.showToast({
  56. title: error,
  57. icon: "none"
  58. })
  59. })
  60. },
  61. uploadPhoto() {
  62. let _self = this;
  63. const crop = {
  64. quality: 100,
  65. width: 600,
  66. height: 600,
  67. resize: true
  68. };
  69. // 上传图片
  70. uni.chooseImage({
  71. count: 1,
  72. crop,
  73. success: async (res) => {
  74. //(res);
  75. let tempFile = res.tempFiles[0],
  76. avatar_file = {
  77. // #ifdef H5
  78. extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1],
  79. // #endif
  80. // #ifndef H5
  81. extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1]
  82. // #endif
  83. },
  84. filePath = res.tempFilePaths[0]
  85. // #ifndef APP-PLUS
  86. //(`filePath=${filePath}`)
  87. //非app端用前端组件剪裁头像,app端用内置的原生裁剪
  88. let fileData = await new Promise((callback) => {
  89. uni.navigateTo({
  90. url: '/pages/user/cropImage?path=' + filePath +
  91. `&options=${JSON.stringify(crop)}`,
  92. animationType: "fade-in",
  93. events: {
  94. success: url => {
  95. callback(url)
  96. }
  97. }
  98. });
  99. })
  100. // #endif
  101. //返回 base64 图片
  102. //(fileData);
  103. var token = _self.carhelp.getToken()
  104. uni.showLoading({
  105. title: '上传中'
  106. });
  107. uni.request({
  108. url: process.car.BASE_URL + "uploadBase64",
  109. method: 'POST',
  110. data: {
  111. photoBase64Data: fileData,
  112. branchParameter:process.car.branchParameter
  113. },
  114. header: {
  115. 'Authorization': token,
  116. 'content-type': 'application/x-www-form-urlencoded'
  117. },
  118. success: (res) => {
  119. let jsonData = res.data;
  120. _self.form.headImg = jsonData.data;
  121. uni.hideLoading();
  122. }
  123. });
  124. }
  125. });
  126. },
  127. submit() {
  128. uni.showLoading({
  129. title: "加载中",
  130. mask: true,
  131. })
  132. userApi.updatePersonInformation(this.form).then((res) => {
  133. uni.hideLoading();
  134. uni.navigateBack({
  135. url: '/pages/user/index'
  136. })
  137. }).catch(error => {
  138. uni.showToast({
  139. title: error,
  140. icon: "none"
  141. })
  142. })
  143. }
  144. }
  145. }
  146. </script>
  147. <style>
  148. page{
  149. background: #fff;
  150. }
  151. </style>
  152. <style lang="scss" scoped>
  153. .data-icon{
  154. height: 28px;
  155. width: 28px;
  156. background-color: #00B962;
  157. border-radius: 14px;
  158. border: 2px solid #fff;
  159. text-align: center;
  160. line-height: 24px;
  161. position: absolute;
  162. z-index: 999;
  163. right: 0;
  164. bottom:0px
  165. }
  166. .data-img{
  167. margin: 30px auto;
  168. height: 108px;
  169. width: 108px;
  170. position: relative;
  171. }
  172. .data-input{
  173. margin: 0 40px;
  174. }
  175. .login-btn {
  176. margin: 28px ;
  177. background-color:#00B962!important;
  178. border-color: #00B962!important;
  179. color:#fff!important;
  180. }
  181. </style>