editAvatar.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="content">
  3. <view @click="upload" class="picture">
  4. <image class="xj-image" v-if="!deptListurl.avatarUrl" src="@/static/images/common/tianjiazhaopian@2x.png"></image>
  5. <image class="xj-image" :src="deptListurl.avatarUrl" v-if="deptListurl.avatarUrl"></image>
  6. </view>
  7. <view @click="submit" class="submit">提交</view>
  8. <u-action-sheet :actions="$helper.imgTypeList" :title="$helper.imgType" :show="isShowimgType"
  9. @select="imgTypeSelect" :closeOnClickOverlay="true" :closeOnClickAction="true"
  10. @close="isShowimgType=false">
  11. </u-action-sheet>
  12. </view>
  13. </template>
  14. <script>
  15. import uploadImage from '@/components/ossutil/uploadFile.js';
  16. import {
  17. mapState
  18. } from 'vuex';
  19. var that
  20. export default {
  21. data() {
  22. return {
  23. isShowimgType:false,
  24. imgSrc:'',
  25. deptListurl:{
  26. avatarUrl:'',
  27. id:''
  28. }
  29. }
  30. },
  31. onLoad() {
  32. that = this
  33. },
  34. computed: {
  35. ...mapState(['hasLogin', 'userInfo'])
  36. },
  37. methods: {
  38. upload() {
  39. this.isShowimgType = true
  40. },
  41. imgTypeSelect(val) {
  42. console.log(val)
  43. if (val.name == '相册') {
  44. uni.chooseImage({
  45. count: 1,
  46. sourceType: that.$helper.chooseImage.sourceType,
  47. success: function(res) {
  48. console.log(JSON.stringify(res.tempFilePaths));
  49. uploadImage(res.tempFilePaths[0], 'appData/',
  50. result => {
  51. // 上传成功
  52. console.log('图片地址', result)
  53. that.$request.baseRequest('get', '/BDAccessToken/getAuth', {
  54. apiKey: 'yNWLRW6unoUxo2KXiCZxOxGS',
  55. secretKey: 'E8hqzKWdFdTGnFnpAwZ7ixtL89SN3deR'
  56. }).then(res => {
  57. that.$request.baseRequest('get', '/commonUser/getUserDefinedBean', {
  58. accessToken: res.data,
  59. imagePath : result
  60. }).then(res1 => {
  61. that.deptListurl.avatarUrl = result
  62. })
  63. .catch(res => {
  64. uni.$u.toast( res.message);
  65. });
  66. })
  67. .catch(res => {
  68. uni.$u.toast( res.message);
  69. });
  70. }
  71. )
  72. }
  73. });
  74. } else {
  75. }
  76. },
  77. submit(){
  78. this.deptListurl.id = this.userInfo.id
  79. // this.$request.baseRequest('post', '/commonUser/editUserInfo', this.deptListurl).then(res => {
  80. // uni.showToast({
  81. // title: '修改成功!',
  82. // icon: 'success',
  83. // duration: 2000,
  84. // success() {
  85. // setTimeout(()=>{
  86. // that.userInfo.avatarUrl = that.deptListurl.avatarUrl
  87. // var _student = uni.getStorageSync('userInfo');
  88. // _student.avatarUrl = that.deptListurl.avatarUrl;
  89. // uni.setStorageSync('userInfo', _student);
  90. // var name = 'userInfo';
  91. // var value = _student;
  92. // that.$store.commit('$uStore', {
  93. // name,
  94. // value
  95. // });
  96. // // this.$api.msg('修改成功2!')
  97. // uni.navigateBack({
  98. // delta:1
  99. // })
  100. // },2000)
  101. // }
  102. // })
  103. // })
  104. // .catch(res => {
  105. // uni.$u.toast( res.message);
  106. // });
  107. }
  108. }
  109. }
  110. </script>
  111. <style>
  112. .content{
  113. background: white;
  114. padding: 20rpx;
  115. }
  116. .left-text {
  117. width: 290rpx;
  118. color: #333333;
  119. display: flex;
  120. align-items: center;
  121. }
  122. .picture {
  123. margin-top: 20rpx;
  124. background: #F5F6FA;
  125. width: 212rpx;
  126. height: 212rpx;
  127. border-radius: 10rpx;
  128. display: flex;
  129. flex-direction: column;
  130. justify-content: center;
  131. align-items: center;
  132. color: #6A7282;
  133. }
  134. .xj-image {
  135. width: 100rpx;
  136. height: 100rpx;
  137. }
  138. .submit{
  139. margin-top: 20rpx;
  140. background: #2772FB;
  141. border-radius: 50rpx;
  142. padding: 20rpx 0;
  143. color: white;
  144. text-align: center;
  145. }
  146. </style>