文件同步状态

This commit is contained in:
XaoLi717 2024-10-08 15:33:27 +08:00
parent 19b9acbbf4
commit c3e17e254e

View File

@ -25,6 +25,12 @@
选取文件
</el-button>
<template v-if="isShowTip && !disabled" #tip>
<div>
<el-button type="primary" @click="SyncFiles">
<Icon icon="ep:upload-filled" />
同步文件
</el-button>
</div>
<div style="font-size: 8px">
大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b>
</div>
@ -74,6 +80,21 @@
<div class="ml-10px">
<el-button link type="danger" @click="handleRemove(row.file)"> 删除</el-button>
</div>
<div class="ml-10px" v-if="lod">
<el-progress
type="dashboard"
:percentage="row.file.page"
:stroke-width="3"
:width="20"
:color="colors"
:show-text="false"
style="margin-top: -10px;"
/>
</div>
<div class="ml-10px" v-if="lod"
:style="{ marginLeft: '30px', color: getColor(row.file.page) }">
{{row.file.lodTxt}}
</div>
</div>
</template>
</el-upload>
@ -93,18 +114,30 @@ import {integer} from "vue-types";
import {getConfigKey} from "@/api/infra/config";
defineOptions({ name: 'UploadFile' })
const colors = [
{ color: '#f56c6c', percentage: 10 },
{ color: '#df7c71', percentage: 20 },
{ color: '#c98d76', percentage: 30 },
{ color: '#b49d7b', percentage: 40 },
{ color: '#9ead80', percentage: 50 },
{ color: '#88be84', percentage: 60 },
{ color: '#72ce89', percentage: 70 },
{ color: '#5dde8e', percentage: 80 },
{ color: '#47ef93', percentage: 90 },
{ color: '#31ff98', percentage: 100 },
]
const message = useMessage() //
const emit = defineEmits(['update:modelValue'])
const emit = defineEmits(['update:modelValue','update:fileStatus'])
const props = defineProps({
fileId:propTypes.number,//id
fileStatus: propTypes.arrayOf(Number).def([]),//
modelValue: propTypes.oneOfType<string | string[]>([String, Array<String>]).isRequired,
fileType: propTypes.array.def(['doc', 'xls', 'ppt', 'txt', 'pdf', 'wps']), // , ['png', 'jpg', 'jpeg']
fileSize: propTypes.number.def(5), // (MB)
limit: propTypes.number.def(5), //
autoUpload: propTypes.bool.def(true), //
drag: propTypes.bool.def(true), //
drag: propTypes.bool.def(false), //
isShowTip: propTypes.bool.def(true), //
disabled: propTypes.bool.def(false) // ==> false
})
@ -139,9 +172,125 @@ const upload = async (myFile:any) => {
console.error('Upload failed:', error);
}
};
const lod = ref(true)
//
const getColor = (per:number) => {
const colorObj = colors.find(c => per == c.percentage);
return colorObj ? colorObj.color : '#f56c6c';
}
//
const getPage = async (fileName:string) => {
queryParamsOnly.pageSize = 1;
queryParamsOnly.fileName = fileName;
const data = await onlyofApi.getonlyofPage(queryParamsOnly);
return data.list[0]?.filePath
}
//
const SyncFiles = async () => {
lod.value=true
// console.log("fileList.value",fileList.value)
//
if (fileList.value.length==0){
message.error("同步文件为空! ")
}
for (const Name of fileList.value) {
const fName = Name as UploadUserFile & {page?: number,lodTxt?: String};
fName.lodTxt="10%"
if (fName.page==100){
fName.lodTxt="完成"
continue
}
//
await delay(100);
fName.page = 20;
fName.lodTxt="20%"
//
const fileName = fName.name.trim();
//
try {
const path = await getPage(fileName)
fName.page = 30;
fName.lodTxt="30%"
let filePath
if (path){
filePath = path +fileName;
fName.page = 40;
fName.lodTxt="40%"
}else {
message.error("文件路径获取失败!")
continue;
}
//\/
filePath = filePath.replace(/\\/g, "/");
await delay(100);
fName.page = 50;
fName.lodTxt="50%"
//
const fileExt = getFileExtension(fileName) || '';
fName.page = 60;
// console.log(fileExt)
fName.lodTxt="60%"
//
const addMap = {
docx: 'add_docs',
xlsx: 'add_excel',
pptx: 'add_pppt',
pdf: 'add_pdfs',
md: 'add_mds',
txt: 'add_texts',
html: 'add_html',
};
await delay(100);
fName.page = 70;
fName.lodTxt="70%"
const add = addMap[fileExt] || ''; //
fName.page = 90;
fName.lodTxt="90%"
// console.log(`http://192.168.1.15:8000/${add}?path=${filePath}`)
const response = await axios.post(`http://192.168.1.15:8000/${add}?path=${filePath}`);
console.log("response",response)
await delay(100);
fName.page = 100;
fName.lodTxt="完成"
} catch (error) {
await delay(200);
fName.page = 10;
message.error("同步错误!")
fName.lodTxt="错误 "
console.error("同 步 错 误 :", error);
}
}
console.log("fileList.value完成",fileList.value)
message.success("同步完成! ")
emitUpdatePage()
}
const emitUpdatePage = () => {
console.log("emitUpdatePage",fileList.value)
let result:number[] = [];
for (const pe of fileList.value){
const pa = pe as UploadUserFile & {page?: number};
if (pa.page != null) {
result.push(pa.page)
}
console.log(result)
}
emit('update:fileStatus', result)
}
//
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
//
const getFileExtension = (fileName: string) => {
let fileLast: string | undefined;
const parts = fileName.split('.');
if (parts.length > 1) {
return fileLast = parts.pop()?.toLowerCase()||''; //
} else {
message.error("获取文件后缀名失败,请重试! ")
}
};
const queryParamsOnly = reactive({
pageNo: 1,
pageSize: 2,
pageSize: 1,
fileName: '',
fileSize: undefined,
fileType: undefined,
@ -352,14 +501,14 @@ const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
console.log(uploadFile)
}
//watch id filenid
watch(
() => props.fileId,
(val:number) => {
// console.log("val",val)
fileNid.value=val
},
{ immediate: true, deep: true }
)
// watch(
// () => props.fileId,
// (val:number) => {
// // console.log("valFileId",val)
// // fileNid.value=val
// },
// { immediate: true, deep: true }
// )
//
watch(
() => props.modelValue,
@ -379,7 +528,7 @@ watch(
}
// 2
fileList.value.push(
...(val as string[]).map((url) => ({ name: url.substring(0,url.indexOf("&&$#")),url:url.substring(url.indexOf("&&$#")+5,url.length) }))
...(val as string[]).map((url) => ({ name: url.substring(0,url.indexOf("&&$#")),url:url.substring(url.indexOf("&&$#")+5,url.length) ,page:0,lodTxt:"准备.."}))
)
//val
if (val[0]==""){
@ -391,12 +540,47 @@ watch(
...(val as string[]).map((url) => ({ name: url,url: url}))
);
}
// console.log("11111fileList", fileList.value)
// console.log("11111MysqlUrl", MysqlUrl.value)
console.log("fileList", fileList.value)
console.log("props.fileStatus", props.fileStatus)
// console.log("MysqlUrl", MysqlUrl.value)
if (!props.fileStatus) {
lod.value=false;
console.log("为空", val);
return; // val
}
// props.fileStatus.forEach((item, index) => {
// fileList.value[index].page = item
// if (item == 10 ){
// fileList.value[index].lodTxt = ""
// }else{
// fileList.value[index].lodTxt = ""
// }
// });
},
{ immediate: true, deep: true }
)
watch(
() => props.fileStatus,
(val:number[]) => {
if (!val) {
lod.value=false;
console.log("为空", val);
return; // val
}
console.log("ileList.value",fileList.value)
val.forEach((item, index) => {
fileList.value[index].page = item
if (item == 10 ){
fileList.value[index].lodTxt = "错误"
}else{
fileList.value[index].lodTxt = "完成"
}
});
console.log("ileList.value",fileList.value)
},
{ immediate: true, deep: true }
)
//
const emitUpdateModelValue = () => {
// 1
@ -429,7 +613,6 @@ onMounted( () => {
return
}
dataT.value = res;
console.log("data",dataT.value)
})
})
</script>