editAvatar.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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">
  5. </image>
  6. <image class="xj-image" :src="deptListurl.avatarUrl" v-if="deptListurl.avatarUrl"></image>
  7. </view>
  8. <view @click="$u.throttle(submit, 1000)" class="submit">提交</view>
  9. <u-action-sheet :actions="$helper.imgTypeList" :title="$helper.imgType" :show="isShowimgType"
  10. @select="imgTypeSelect" :closeOnClickOverlay="true" :closeOnClickAction="true" @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. this.imgTypeSelect()
  41. },
  42. imgTypeSelect(val) {
  43. console.log(val)
  44. // if (val.name == '相册') {
  45. uni.chooseImage({
  46. count: 1,
  47. sizeType: ['compressed'],
  48. // sourceType: this.$helper.chooseImage.sourceType,
  49. success: function(res) {
  50. console.log(JSON.stringify(res.tempFilePaths));
  51. uploadImage('image', res.tempFilePaths[0], 'appData/',
  52. result => {
  53. // 上传成功
  54. console.log('图片地址', result)
  55. that.deptListurl.avatarUrl = result
  56. }
  57. )
  58. }
  59. });
  60. // } else {
  61. // }
  62. },
  63. submit() {
  64. this.deptListurl.id = this.userInfo.id
  65. this.$request.baseRequest('post', '/commonUser/editUserInfo', this.deptListurl).then(res => {
  66. uni.showToast({
  67. title: '修改成功!',
  68. icon: 'success',
  69. duration: 2000,
  70. success() {
  71. setTimeout(() => {
  72. that.userInfo.avatarUrl = that.deptListurl.avatarUrl
  73. var _student = uni.getStorageSync('userInfo');
  74. _student.avatarUrl = that.deptListurl.avatarUrl;
  75. uni.setStorageSync('userInfo', _student);
  76. var name = 'userInfo';
  77. var value = _student;
  78. that.$store.commit('$uStore', {
  79. name,
  80. value
  81. });
  82. // this.$api.msg('修改成功2!')
  83. uni.navigateBack({
  84. delta: 1
  85. })
  86. }, 2000)
  87. }
  88. })
  89. })
  90. .catch(res => {
  91. uni.$u.toast(res.message);
  92. });
  93. }
  94. }
  95. }
  96. </script>
  97. <style>
  98. .content {
  99. background: white;
  100. padding: 20rpx;
  101. }
  102. .left-text {
  103. width: 290rpx;
  104. color: #333333;
  105. display: flex;
  106. align-items: center;
  107. }
  108. .picture {
  109. margin-top: 20rpx;
  110. background: #F5F6FA;
  111. width: 212rpx;
  112. height: 212rpx;
  113. border-radius: 10rpx;
  114. display: flex;
  115. flex-direction: column;
  116. justify-content: center;
  117. align-items: center;
  118. color: #6A7282;
  119. }
  120. .xj-image {
  121. width: 100%;
  122. height: 100%;
  123. }
  124. .submit {
  125. margin-top: 20rpx;
  126. background: #F5BA3C;
  127. border-radius: 50rpx;
  128. padding: 20rpx 0;
  129. color: white;
  130. text-align: center;
  131. }
  132. </style>