editAvatar.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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: this.$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.deptListurl.avatarUrl = result
  54. }
  55. )
  56. }
  57. });
  58. } else {
  59. }
  60. },
  61. submit(){
  62. this.deptListurl.id = this.userInfo.id
  63. this.$request.baseRequest('post', '/commonUser/editUserInfo', this.deptListurl).then(res => {
  64. uni.showToast({
  65. title: '修改成功!',
  66. icon: 'success',
  67. duration: 2000,
  68. success() {
  69. setTimeout(()=>{
  70. that.userInfo.avatarUrl = that.deptListurl.avatarUrl
  71. var _student = uni.getStorageSync('userInfo');
  72. _student.avatarUrl = that.deptListurl.avatarUrl;
  73. uni.setStorageSync('userInfo', _student);
  74. var name = 'userInfo';
  75. var value = _student;
  76. that.$store.commit('$uStore', {
  77. name,
  78. value
  79. });
  80. // this.$api.msg('修改成功2!')
  81. uni.navigateBack({
  82. delta:1
  83. })
  84. },2000)
  85. }
  86. })
  87. })
  88. .catch(res => {
  89. uni.$u.toast( res.message);
  90. });
  91. }
  92. }
  93. }
  94. </script>
  95. <style>
  96. .content{
  97. background: white;
  98. padding: 20rpx;
  99. }
  100. .left-text {
  101. width: 290rpx;
  102. color: #333333;
  103. display: flex;
  104. align-items: center;
  105. }
  106. .picture {
  107. margin-top: 20rpx;
  108. background: #F5F6FA;
  109. width: 212rpx;
  110. height: 212rpx;
  111. border-radius: 10rpx;
  112. display: flex;
  113. flex-direction: column;
  114. justify-content: center;
  115. align-items: center;
  116. color: #6A7282;
  117. }
  118. .xj-image {
  119. width: 100rpx;
  120. height: 100rpx;
  121. }
  122. .submit{
  123. margin-top: 20rpx;
  124. background: #2772FB;
  125. border-radius: 50rpx;
  126. padding: 20rpx 0;
  127. color: white;
  128. text-align: center;
  129. }
  130. </style>