editProfile.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view>
  3. <u-navbar title="编辑个人信息" >
  4. <view class="slot-wrap" @click="save">
  5. 保存
  6. </view>
  7. </u-navbar>
  8. <view class="photo" @click="uploadPhoto">
  9. <u-avatar v-if="form.headImg != null" class="avatar"
  10. :src="form.headImg+'?x-oss-process=image/resize,m_fill,w_256,h_256'" size="160">
  11. <img src="" alt="">
  12. </u-avatar>
  13. <view class="edit-photo">
  14. <img src="../../../assets/img/md-camera_alt@1x(1).png" alt="">
  15. </view>
  16. </view>
  17. <view class="change">
  18. 点击更换头像
  19. </view>
  20. <view class="pet-name">
  21. <view class="title">
  22. 昵称
  23. </view>
  24. <view class="name">
  25. <input type="text" name="" id="" v-model="form.nickName" style="text-align: right;">
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import * as loginApi from '@/apis/login.js'
  32. import * as mineApi from '@/apis/parents/mine.js'
  33. export default {
  34. data() {
  35. return {
  36. form: {
  37. headImg: '',
  38. nickName: ''
  39. }
  40. }
  41. },
  42. onReady() {
  43. this.getParentsInfo();
  44. },
  45. methods: {
  46. getParentsInfo() {
  47. uni.showLoading({
  48. title: "加载中",
  49. mask: true,
  50. })
  51. loginApi.findByOpenId({
  52. openId: this.carhelp.getOpenId()
  53. }).then((response) => {
  54. uni.hideLoading();
  55. this.form.headImg = response.data.regUser.headImg;
  56. this.form.nickName = response.data.regUser.nickName;
  57. }).catch(error => {
  58. uni.showToast({
  59. title: error,
  60. icon: "none"
  61. })
  62. })
  63. },
  64. save() {
  65. uni.showLoading({
  66. title: "加载中",
  67. mask: true,
  68. })
  69. mineApi.updateRegUser(this.form).then((response) => {
  70. uni.hideLoading();
  71. uni.navigateBack({
  72. })
  73. }).catch(error => {
  74. uni.showToast({
  75. title: error,
  76. icon: "none"
  77. })
  78. })
  79. },
  80. uploadPhoto() {
  81. let _self = this;
  82. const crop = {
  83. quality: 100,
  84. width: 600,
  85. height: 600,
  86. resize: true
  87. };
  88. // 上传图片
  89. uni.chooseImage({
  90. count: 1,
  91. crop,
  92. success: async (res) => {
  93. //(res);
  94. let tempFile = res.tempFiles[0],
  95. avatar_file = {
  96. // #ifdef H5
  97. extname: tempFile.name.split('.')[tempFile.name.split('.').length - 1],
  98. // #endif
  99. // #ifndef H5
  100. extname: tempFile.path.split('.')[tempFile.path.split('.').length - 1]
  101. // #endif
  102. },
  103. filePath = res.tempFilePaths[0]
  104. // #ifndef APP-PLUS
  105. //(`filePath=${filePath}`)
  106. //非app端用前端组件剪裁头像,app端用内置的原生裁剪
  107. let fileData = await new Promise((callback) => {
  108. uni.navigateTo({
  109. url: '/pages/components/cropImage?path=' + filePath +
  110. `&options=${JSON.stringify(crop)}`,
  111. animationType: "fade-in",
  112. events: {
  113. success: url => {
  114. callback(url)
  115. }
  116. }
  117. });
  118. })
  119. // #endif
  120. //返回 base64 图片
  121. //(fileData);
  122. var token = _self.carhelp.getToken()
  123. uni.showLoading({
  124. title: '上传中'
  125. });
  126. uni.request({
  127. url: process.car.BASE_URL + "/mobile/student/uploadBase64",
  128. method: 'POST',
  129. data: {
  130. photoBase64Data: fileData
  131. },
  132. header: {
  133. 'Authorization': token,
  134. 'content-type': 'application/x-www-form-urlencoded'
  135. },
  136. success: (res) => {
  137. let jsonData = res.data;
  138. _self.form.headImg = jsonData.data;
  139. // _self.save();
  140. uni.hideLoading();
  141. }
  142. });
  143. }
  144. });
  145. },
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. page{
  151. background-color: #fff;
  152. }
  153. /deep/.u-slot-content{
  154. justify-content: end;
  155. margin-right: 32rpx;
  156. color: rgba(13, 186, 199, 1);
  157. }
  158. .photo{
  159. margin: 20px auto 8px;
  160. width: 160rpx;
  161. height: 160rpx;
  162. position: relative;
  163. img{
  164. width: 100%;
  165. height: 100%;
  166. border-radius: 999px;
  167. }
  168. }
  169. .edit-photo{
  170. width: 56rpx;
  171. height: 56rpx;
  172. background-color: rgba(78, 141, 246, 1);
  173. border: 4rpx solid rgba(255, 255, 255, 1);
  174. text-align: center;
  175. border-radius: 999px;
  176. z-index: 999;
  177. position: absolute;
  178. right: 0;
  179. bottom: 0;
  180. img{
  181. width: 32rpx;
  182. height: 32rpx;
  183. margin-top: 8rpx;
  184. }
  185. }
  186. .change{
  187. color: rgba(13, 186, 199, 1);
  188. text-align: center;
  189. }
  190. .pet-name{
  191. margin-top: 20px;
  192. padding: 15px;
  193. border-bottom: 1px solid rgba(244, 244, 244, 1);
  194. display: flex;
  195. justify-content: space-between;
  196. .title{
  197. color: rgba(16, 16, 16, 1);
  198. font-weight: bold;
  199. }
  200. .name{
  201. color: rgba(136, 136, 136, 1);
  202. }
  203. }
  204. </style>