avatar.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view class=" bg-white">
  3. <cu-custom bgColor="bg-gradual-blue" :isBack="true"><block slot="backText">返回</block><block slot="content">上传头像</block></cu-custom>
  4. <view class="cu-form-group">
  5. <view class="grid text-center col-4 grid-square flex-sub">
  6. <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
  7. <image :src="imgList[index]" mode="aspectFill"></image>
  8. </view>
  9. <view class="solids" @tap="ChooseImage">
  10. <text class='cuIcon-cameraadd'></text>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="cu-bar btn-group " style="margin-top: 100upx;">
  15. <button class=" btn-logout cu-btn shadow-blur round lg" @click="upload">退出登录</button>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import UserService from "@/api/sys/UserService"
  21. export default {
  22. data() {
  23. return {
  24. imgList: []
  25. }
  26. },
  27. methods: {
  28. ChooseImage() {
  29. uni.chooseImage({
  30. count: 4, //默认9
  31. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  32. sourceType: ['album'], //从相册选择
  33. success: (res) => {
  34. if (this.imgList.length != 0) {
  35. this.imgList = this.imgList.concat(res.tempFilePaths)
  36. } else {
  37. this.imgList = res.tempFilePaths
  38. }
  39. }
  40. });
  41. },
  42. ViewImage(e) {
  43. uni.previewImage({
  44. urls: this.imgList,
  45. current: e.currentTarget.dataset.url
  46. });
  47. },
  48. upload() {
  49. new UserService().imageUpload(this.imgList[0])
  50. }
  51. }
  52. }
  53. </script>
  54. <style>
  55. .btn-logout {
  56. margin-top: 100upx;
  57. width: 80%;
  58. border-radius: 50upx;
  59. font-size: 16px;
  60. color: #fff;
  61. background: linear-gradient(to right, #365fff, #36bbff);
  62. }
  63. .btn-logout-hover {
  64. background: linear-gradient(to right, #365fdd, #36bbfa);
  65. }
  66. </style>