2017-01-19 16:26:31 +08:00
|
|
|
<template>
|
2017-01-22 14:48:38 +08:00
|
|
|
<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
|
|
|
|
type="ios-close-empty"
|
|
|
|
:class="[prefixCls + '-list-remove']"
|
|
|
|
v-show="file.status === 'finished'"
|
2017-03-02 14:41:28 +08:00
|
|
|
@click.native="handleRemove(file)"></Icon>
|
|
|
|
<transition name="fade">
|
2017-03-14 11:25:21 +08:00
|
|
|
<i-progress
|
2017-03-02 14:41:28 +08:00
|
|
|
v-if="file.showProgress"
|
|
|
|
:stroke-width="2"
|
|
|
|
:percent="parsePercentage(file.percentage)"
|
2017-03-14 11:25:21 +08:00
|
|
|
:status="file.status === 'finished' && file.showProgress ? 'success' : 'normal'"></i-progress>
|
2017-03-02 14:41:28 +08:00
|
|
|
</transition>
|
2017-01-22 14:48:38 +08:00
|
|
|
</li>
|
|
|
|
</ul>
|
2017-01-19 16:26:31 +08:00
|
|
|
</template>
|
|
|
|
<script>
|
2017-01-22 14:48:38 +08:00
|
|
|
import Icon from '../icon/icon.vue';
|
2017-03-14 11:25:21 +08:00
|
|
|
import iProgress from '../progress/progress.vue';
|
2017-01-22 14:48:38 +08:00
|
|
|
const prefixCls = 'ivu-upload';
|
|
|
|
|
2017-01-19 16:26:31 +08:00
|
|
|
export default {
|
2017-03-02 17:40:19 +08:00
|
|
|
name: 'UploadList',
|
2017-03-14 11:25:21 +08:00
|
|
|
components: { Icon, iProgress },
|
2017-01-22 14:48:38 +08:00
|
|
|
props: {
|
|
|
|
files: {
|
|
|
|
type: Array,
|
|
|
|
default() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-01-19 16:26:31 +08:00
|
|
|
data () {
|
2017-01-22 14:48:38 +08:00
|
|
|
return {
|
|
|
|
prefixCls: prefixCls
|
|
|
|
};
|
2017-01-19 16:26:31 +08:00
|
|
|
},
|
2017-01-22 14:48:38 +08:00
|
|
|
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() || '';
|
|
|
|
let type = 'document';
|
|
|
|
|
|
|
|
if (['gif','jpg','jpeg','png','bmp','webp'].indexOf(format) > -1) {
|
|
|
|
type = 'image';
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
type = 'document-text';
|
|
|
|
}
|
|
|
|
if (['numbers','csv','xls','xlsx'].indexOf(format) > -1) {
|
|
|
|
type = 'stats-bars';
|
|
|
|
}
|
|
|
|
if (['keynote','ppt','pptx'].indexOf(format) > -1) {
|
|
|
|
type = 'ios-videocam';
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
},
|
|
|
|
parsePercentage (val) {
|
|
|
|
return parseInt(val, 10);
|
|
|
|
}
|
|
|
|
}
|
2017-01-19 16:26:31 +08:00
|
|
|
};
|
|
|
|
</script>
|