avatar.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. fileService.upload(filePath).then((data)=>{
  50. userService.saveInfo({
  51. id: this.userInfo.id,
  52. photo: data
  53. })
  54. })
  55. }
  56. }
  57. }
  58. </script>
  59. <style>
  60. .btn-logout {
  61. margin-top: 100upx;
  62. width: 80%;
  63. border-radius: 50upx;
  64. font-size: 16px;
  65. color: #fff;
  66. background: linear-gradient(to right, #365fff, #36bbff);
  67. }
  68. .btn-logout-hover {
  69. background: linear-gradient(to right, #365fdd, #36bbfa);
  70. }
  71. </style>