Blame view

src/components/upload/upload-list.vue 3.11 KB
3affd6f3   梁灏   init upload compo...
1
  <template>
ddef2bb3   梁灏   update Upload
2
3
4
5
6
7
8
9
10
      <ul :class="[prefixCls + '-list']">
          <li
              v-for="file in files"
              :class="fileCls(file)"
              @click="handleClick(file)">
              <span @click="handlePreview(file)">
                  <Icon :type="format(file)"></Icon> {{ file.name }}
              </span>
              <Icon
a2d36d21   梁灏   update Upload Icons
11
                  type="ios-close"
ddef2bb3   梁灏   update Upload
12
13
                  :class="[prefixCls + '-list-remove']"
                  v-show="file.status === 'finished'"
5d08ddf2   梁灏   support Progress ...
14
15
                  @click.native="handleRemove(file)"></Icon>
              <transition name="fade">
8ac8d1ed   梁灏   修复警告
16
                  <i-progress
5d08ddf2   梁灏   support Progress ...
17
18
19
                      v-if="file.showProgress"
                      :stroke-width="2"
                      :percent="parsePercentage(file.percentage)"
8ac8d1ed   梁灏   修复警告
20
                      :status="file.status === 'finished' && file.showProgress ? 'success' : 'normal'"></i-progress>
5d08ddf2   梁灏   support Progress ...
21
              </transition>
ddef2bb3   梁灏   update Upload
22
23
          </li>
      </ul>
3affd6f3   梁灏   init upload compo...
24
25
  </template>
  <script>
ddef2bb3   梁灏   update Upload
26
      import Icon from '../icon/icon.vue';
8ac8d1ed   梁灏   修复警告
27
      import iProgress from '../progress/progress.vue';
ddef2bb3   梁灏   update Upload
28
29
      const prefixCls = 'ivu-upload';
  
3affd6f3   梁灏   init upload compo...
30
      export default {
34ee7b4a   梁灏   support Tree & ad...
31
          name: 'UploadList',
8ac8d1ed   梁灏   修复警告
32
          components: { Icon, iProgress },
ddef2bb3   梁灏   update Upload
33
34
35
36
37
38
39
40
          props: {
              files: {
                  type: Array,
                  default() {
                      return [];
                  }
              }
          },
3affd6f3   梁灏   init upload compo...
41
          data () {
ddef2bb3   梁灏   update Upload
42
43
44
              return {
                  prefixCls: prefixCls
              };
3affd6f3   梁灏   init upload compo...
45
          },
ddef2bb3   梁灏   update Upload
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
          methods: {
              fileCls (file) {
                  return [
                      `${prefixCls}-list-file`,
                      {
                          [`${prefixCls}-list-file-finish`]: file.status === 'finished'
                      }
                  ];
              },
              handleClick (file) {
                  this.$emit('on-file-click', file);
              },
              handlePreview (file) {
                  this.$emit('on-file-preview', file);
              },
              handleRemove (file) {
                  this.$emit('on-file-remove', file);
              },
              format (file) {
                  const format = file.name.split('.').pop().toLocaleLowerCase() || '';
a2d36d21   梁灏   update Upload Icons
66
                  let type = 'ios-document-outline';
ddef2bb3   梁灏   update Upload
67
68
  
                  if (['gif','jpg','jpeg','png','bmp','webp'].indexOf(format) > -1) {
a2d36d21   梁灏   update Upload Icons
69
                      type = 'ios-image';
ddef2bb3   梁灏   update Upload
70
71
72
73
74
75
76
77
                  }
                  if (['mp4','m3u8','rmvb','avi','swf','3gp','mkv','flv'].indexOf(format) > -1) {
                      type = 'ios-film';
                  }
                  if (['mp3','wav','wma','ogg','aac','flac'].indexOf(format) > -1) {
                      type = 'ios-musical-notes';
                  }
                  if (['doc','txt','docx','pages','epub','pdf'].indexOf(format) > -1) {
a2d36d21   梁灏   update Upload Icons
78
                      type = 'md-document';
ddef2bb3   梁灏   update Upload
79
80
                  }
                  if (['numbers','csv','xls','xlsx'].indexOf(format) > -1) {
a2d36d21   梁灏   update Upload Icons
81
                      type = 'ios-stats';
ddef2bb3   梁灏   update Upload
82
83
84
85
86
87
88
89
90
91
92
                  }
                  if (['keynote','ppt','pptx'].indexOf(format) > -1) {
                      type = 'ios-videocam';
                  }
  
                  return type;
              },
              parsePercentage (val) {
                  return parseInt(val, 10);
              }
          }
3affd6f3   梁灏   init upload compo...
93
94
      };
  </script>