150 lines
4.9 KiB
HTML
150 lines
4.9 KiB
HTML
<template id="file-upload">
|
|
<v-container class="fullScreen d-flex flex-column pa-xs-0 pa-0">
|
|
<v-file-input multiple v-model="inputFile" hide-input dense filled single-line style="width: 10px;" color="red"
|
|
label="请选择文件"></v-file-input>
|
|
<v-card outlined class="mt-2" v-if="value && value.length > 0">
|
|
<v-data-table :headers="headers" :items="value"
|
|
:footer-props="{ itemsPerPageOptions: [20, 40, 60, 100, -1] }" :items-per-page="100" :loading="isTableLoading"
|
|
mobile-breakpoint="0" :class="{'mx-2': isMobile}"
|
|
class="elevation-0 mt-0 flex-fill d-flex flex-column">
|
|
<template v-slot:item.download-path="{ item }">
|
|
<preview-file-group :file-list="[item]" />
|
|
</template>
|
|
<template v-slot:item.action="{ item, index }">
|
|
<span role="button" class="success--text font-weight-medium font-size-2"
|
|
@click="doUiAction('deleteItem', { item, index })">
|
|
<v-icon size="14" class="success--text">mdi-trash-can-outline</v-icon>删除
|
|
</span>
|
|
</template>
|
|
<template v-slot:item.operationAt="{ item }">
|
|
{{ item.operationAt && dayjs(item.operationAt).format('YYYY-MM-DD HH:mm:ss') }}
|
|
</template>
|
|
</v-data-table>
|
|
</v-card>
|
|
|
|
</v-container>
|
|
</template>
|
|
|
|
{% include 'component/common/previewFileGroup.html' %}
|
|
|
|
<script type="module">
|
|
Vue.component("file-upload", {
|
|
template: '#file-upload',
|
|
props: {
|
|
fileBizId: {
|
|
type: Array,
|
|
default: null,
|
|
},
|
|
value: {
|
|
type: Array,
|
|
default: () => [],
|
|
},
|
|
},
|
|
vuetify: new Vuetify(),
|
|
data: () => ({
|
|
isMobile: window.innerWidth < 600,
|
|
|
|
serverSearchInput: {
|
|
rowStatus: ['正常']
|
|
},
|
|
// 表格相关数据
|
|
requireRules: [v => !!v || '必填'],
|
|
constantCollection: {},
|
|
isTableLoading: false,
|
|
headers: [
|
|
{ text: "文件预览/下载", value: "download-path", align: 'center', sortable: false, width: 150, },
|
|
{ text: "文件名", value: "filename", width: 120, class: 'fixed' },
|
|
{ text: "文件大小(KB)", value: "binarySize", width: 100 },
|
|
{ text: '操作', value: 'action', align: 'center', sortable: false, width: 150, },
|
|
],
|
|
|
|
inputFile: [],
|
|
}),
|
|
computed: {
|
|
isMobile() {
|
|
return window.innerWidth < 600;
|
|
},
|
|
},
|
|
watch: {
|
|
'inputFile':{
|
|
handler(newVal,oldVal){
|
|
console.log('inputFile', newVal);
|
|
newVal.forEach(element => {
|
|
this.uploadFn(element)
|
|
});
|
|
}
|
|
}
|
|
},
|
|
async created() {
|
|
},
|
|
mounted() {
|
|
},
|
|
methods: {
|
|
async doUiAction(uiActionId, uiActionData) {
|
|
switch (uiActionId) {
|
|
case 'deleteItem':
|
|
await this.confirmDeleteItemDialog(uiActionData);
|
|
await this.doDeleteItem(uiActionData);
|
|
break;
|
|
default:
|
|
console.error("[doUiAction] uiActionId not find", { uiActionId });
|
|
break;
|
|
}
|
|
},
|
|
|
|
async uploadFn(file){
|
|
this.isTableLoading = true
|
|
const fileBizId = this.fileBizId;
|
|
await window.vtoast.loading("保存中");
|
|
window.vtoast.loading(`${file.name} 上传进度: 0.00%`);
|
|
const result = await window.jianghuAxios.httpUploadByStream({
|
|
file,
|
|
fileDirectory: `test`,
|
|
onProgress: (total, loaded) => {
|
|
const progress = Number((loaded * 100 / total).toFixed(2));
|
|
window.vtoast.loading(`${file.name} 上传进度: ${progress}%`);
|
|
if (loaded === total) {
|
|
window.vtoast.success(`${file.name} 上传进度: 100%`);
|
|
}
|
|
}
|
|
})
|
|
console.log('uploadFn', result);
|
|
|
|
const { filename, downloadPath, binarySize } = result.data.appData.resultData;
|
|
this.$emit('input', [...this.value, {filename, downloadPath, binarySize}]);
|
|
|
|
const { status } = result.data;
|
|
if (status === 'success') {
|
|
await window.jianghuAxios({
|
|
data: {
|
|
appData: {
|
|
pageId: 'allPage',
|
|
actionId: 'insertItem',
|
|
actionData: { filename, downloadPath, binarySize }
|
|
}
|
|
}
|
|
})
|
|
} else {
|
|
// this.uploadFail++
|
|
await window.vtoast.fail(filename + "上传失败");
|
|
}
|
|
this.isTableLoading = false
|
|
},
|
|
|
|
// deleteItem
|
|
async confirmDeleteItemDialog({ item:{ filename } }) {
|
|
if (await window.confirmDialog({ title: "删除", content: "确定删除文件" + filename + "吗?" }) === false) {
|
|
throw new Error("[confirmDeleteItemDialog] 否");
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 删除数据
|
|
*/
|
|
// TODO::只是删除了value的数据,并没有删除文件
|
|
async doDeleteItem({index}) {
|
|
this.$emit('input', this.value.filter((f, i) => index != i))
|
|
},
|
|
}
|
|
})
|
|
</script> |