index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="upload">
  3. <view class="upload_1">
  4. <view class="button" v-if="list&&list.length<count" @tap="uplSuc()">
  5. <button style="background-color:#007AFF" type="primary" size="mini">选择文件</button>
  6. </view>
  7. <view class="list" v-for="(item,index) in list" :key="index">
  8. <text class="name" @click="toView(index,item)">{{item.name}} </text>
  9. <uni-icons class="del" type="close" size="20" color="#007AFF" @click="uplDel(index,item)"></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(`/web/cxyy_applet/upload`, 'POST', tempFile[0],
  43. 'file');
  44. if (arr.errcode == '0') {
  45. that.$emit('uplSuc', {
  46. data: {
  47. id: arr.id,
  48. name: arr.name,
  49. uri: arr.uri,
  50. url: arr.uri
  51. },
  52. name: that.name
  53. })
  54. } else {
  55. uni.showToast({
  56. title: arr.errmsg,
  57. icon: 'none'
  58. });
  59. }
  60. }
  61. });
  62. },
  63. // 删除图片
  64. uplDel(index, e) {
  65. const that = this;
  66. that.$emit('uplDel', {
  67. data: {
  68. file: e,
  69. index: index
  70. },
  71. name: that.name
  72. })
  73. },
  74. // 图片预览
  75. toView(index, e) {
  76. const that = this;
  77. uni.previewImage({
  78. current: index,
  79. urls: [that.$config.serverFile + e.url]
  80. })
  81. },
  82. // 图片处理
  83. getUrl(e) {
  84. const that = this;
  85. if (e) return that.$config.serverFile + e
  86. },
  87. }
  88. }
  89. </script>
  90. <style lang="scss">
  91. .upload {
  92. padding: 0 2vw;
  93. .upload_1 {
  94. .list {
  95. display: flex;
  96. .name {
  97. font-size: 14px;
  98. color: #666;
  99. margin-right: 5px;
  100. word-break: break-all;
  101. word-wrap: break-word;
  102. }
  103. }
  104. }
  105. }
  106. </style>