index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="upload">
  3. <view class="upload_1">
  4. <view class="list" v-for="(item,index) in list" :key="index">
  5. <image class="image" :src="item.url" @click="toView(index,item)"></image>
  6. <uni-icons class="del" type="close" size="30" color="#007AFF" @click="uplDel(index,item)"></uni-icons>
  7. </view>
  8. <view class="list" v-if="list&&list.length<count" @tap="uplSuc()">
  9. <uni-icons class="add" type="plusempty" size="55" color="#007AFF"></uni-icons>
  10. </view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. list: {
  18. type: Array,
  19. },
  20. name: {
  21. type: String,
  22. },
  23. count: {
  24. type: Number,
  25. default: 1
  26. }
  27. },
  28. data() {
  29. return {
  30. };
  31. },
  32. methods: {
  33. uplSuc() {
  34. const that = this;
  35. let serverFile = that.$config.serverFile;
  36. uni.chooseImage({
  37. count: 1,
  38. sizeType: ['original', 'compressed'],
  39. sourceType: ['album', 'camera'],
  40. success: async function(res) {
  41. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  42. const arr = await that.$apifile(`/travel/applet/upload`, 'file', tempFile[0],
  43. 'file');
  44. that.$emit('uplSuc', {
  45. data: {
  46. name: arr.name,
  47. uri: arr.uri,
  48. url: serverFile + arr.uri
  49. },
  50. name: that.name
  51. })
  52. }
  53. });
  54. },
  55. // 删除图片
  56. uplDel(index, e) {
  57. const that = this;
  58. that.$emit('uplDel', {
  59. data: {
  60. file: e,
  61. index: index
  62. },
  63. name: that.name
  64. })
  65. },
  66. // 图片预览
  67. toView(index, e) {
  68. const that = this;
  69. uni.previewImage({
  70. current: index,
  71. urls: [e.url]
  72. })
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss">
  78. .upload {
  79. padding: 0 2vw;
  80. .upload_1 {
  81. display: flex;
  82. flex-wrap: wrap;
  83. .list {
  84. position: relative;
  85. width: 25vw;
  86. height: 25vw;
  87. text-align: center;
  88. margin: 1vw;
  89. border: 1px solid var(--f99Color);
  90. .image {
  91. width: 100%;
  92. height: 100%;
  93. }
  94. .add {
  95. position: relative;
  96. top: 20px;
  97. }
  98. .del {
  99. position: absolute;
  100. right: 0;
  101. top: 0;
  102. }
  103. }
  104. }
  105. }
  106. </style>