upload-list.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <transition-group
  3. tag="ul"
  4. :class="[
  5. 'el-upload-list',
  6. 'el-upload-list--' + listType,
  7. { 'is-disabled': disabled }
  8. ]"
  9. name="el-list"
  10. >
  11. <li
  12. v-for="(file, index) in files"
  13. :class="['el-upload-list__item', 'is-' + file.status]"
  14. :key="index"
  15. >
  16. <img
  17. class="el-upload-list__item-thumbnail"
  18. v-if="file.status !== 'uploading' && ['picture-card', 'picture'].indexOf(listType) > -1"
  19. :src="file.url" alt=""
  20. >
  21. <a class="el-upload-list__item-name" @click="handleClick(file)">
  22. <i class="el-icon-document"></i>{{file.name}}
  23. </a>
  24. <label class="el-upload-list__item-status-label">
  25. <i :class="{
  26. 'el-icon-upload-success': true,
  27. 'el-icon-circle-check': listType === 'text',
  28. 'el-icon-check': ['picture-card', 'picture'].indexOf(listType) > -1
  29. }"></i>
  30. </label>
  31. <i class="el-icon-close" v-if="!disabled" @click="$emit('remove', file)"></i>
  32. <el-progress
  33. v-if="file.status === 'uploading'"
  34. :type="listType === 'picture-card' ? 'circle' : 'line'"
  35. :stroke-width="listType === 'picture-card' ? 6 : 2"
  36. :percentage="parsePercentage(file.percentage)">
  37. </el-progress>
  38. <span class="el-upload-list__item-actions" v-if="listType === 'picture-card'">
  39. <span
  40. class="el-upload-list__item-preview"
  41. v-if="handlePreview && listType === 'picture-card'"
  42. @click="handlePreview(file)"
  43. >
  44. <i class="el-icon-view"></i>
  45. </span>
  46. <span
  47. v-if="!disabled"
  48. class="el-upload-list__item-delete"
  49. @click="$emit('remove', file)"
  50. >
  51. <i class="el-icon-delete2"></i>
  52. </span>
  53. </span>
  54. </li>
  55. </transition-group>
  56. </template>
  57. <script>
  58. import Locale from 'element-ui/src/mixins/locale';
  59. import ElProgress from 'element-ui/packages/progress';
  60. export default {
  61. mixins: [Locale],
  62. components: { ElProgress },
  63. props: {
  64. files: {
  65. type: Array,
  66. default() {
  67. return [];
  68. }
  69. },
  70. disabled: {
  71. type: Boolean,
  72. default: false
  73. },
  74. handlePreview: Function,
  75. listType: String
  76. },
  77. methods: {
  78. parsePercentage(val) {
  79. return parseInt(val, 10);
  80. },
  81. handleClick(file) {
  82. this.handlePreview && this.handlePreview(file);
  83. }
  84. }
  85. };
  86. </script>