index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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(`/material/applet/upload`, 'file', tempFile[0], 'file');
  43. that.$emit('uplSuc', {
  44. data: {
  45. name: arr.name,
  46. uri: arr.uri,
  47. url: serverFile + arr.uri
  48. },
  49. name: that.name
  50. })
  51. }
  52. });
  53. },
  54. // 删除图片
  55. uplDel(index, e) {
  56. const that = this;
  57. that.$emit('uplDel', {
  58. data: {
  59. file: e,
  60. index: index
  61. },
  62. name: that.name
  63. })
  64. },
  65. // 图片预览
  66. toView(index, e) {
  67. const that = this;
  68. uni.previewImage({
  69. current: index,
  70. urls: [e.url]
  71. })
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. .upload {
  78. padding: 0 2vw;
  79. .upload_1 {
  80. display: flex;
  81. flex-direction: row;
  82. flex-wrap: wrap;
  83. .list {
  84. position: relative;
  85. width: 30vw;
  86. height: 28vw;
  87. text-align: center;
  88. margin: 0 3vw 2vw 0;
  89. border-radius: 5px;
  90. box-shadow: 0 0 2px var(--f85Color);
  91. .image {
  92. width: 100%;
  93. height: 100%;
  94. border-radius: 5px;
  95. }
  96. .add {
  97. position: relative;
  98. top: 20px;
  99. }
  100. .del {
  101. position: absolute;
  102. right: 0;
  103. top: 0;
  104. }
  105. }
  106. .list:nth-child(3n) {
  107. margin: 0 0 2vw 0;
  108. }
  109. }
  110. }
  111. </style>