editProfile.vue 4.6 KB

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