公共知识库开发
This commit is contained in:
parent
6f9a2e3f2a
commit
5e09620269
@ -1,645 +0,0 @@
|
||||
<template>
|
||||
<div class="upload-file">
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
v-model:file-list="fileList"
|
||||
:action="uploadUrl"
|
||||
:auto-upload="autoUpload"
|
||||
:before-upload="beforeUpload"
|
||||
:disabled="disabled"
|
||||
:drag="drag"
|
||||
:http-request="httpRequest"
|
||||
:limit="props.limit"
|
||||
:multiple="props.limit > 1"
|
||||
:on-error="excelUploadError"
|
||||
:on-exceed="handleExceed"
|
||||
:on-preview="handlePreview"
|
||||
:on-remove="handleRemove"
|
||||
:on-success="handleFileSuccess"
|
||||
:show-file-list="true"
|
||||
class="upload-file-uploader"
|
||||
name="file"
|
||||
>
|
||||
<el-button v-if="!disabled" type="primary">
|
||||
<Icon icon="ep:upload-filled" />
|
||||
选取文件
|
||||
</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>
|
||||
<div style="font-size: 8px">
|
||||
格式为 <b style="color: #f56c6c">{{ fileType.join('/') }}</b> 的文件
|
||||
</div>
|
||||
</template>
|
||||
<template #file="row">
|
||||
<div class="flex items-center">
|
||||
<span>{{ row.file.name }}</span>
|
||||
<div v-if="dataT=='001'||dataT=='005'||dataT=='007'" class="ml-10px" >
|
||||
<el-link
|
||||
:underline="false"
|
||||
@click="handleView(row.file)"
|
||||
target="_blank"
|
||||
type="primary"
|
||||
>预览
|
||||
</el-link>
|
||||
</div>
|
||||
<div v-if="dataT=='003'||dataT=='006'||dataT=='007'" class="ml-10px" >
|
||||
<el-link
|
||||
:underline="false"
|
||||
@click="edit(row)"
|
||||
target="_blank"
|
||||
type="primary"
|
||||
>编辑
|
||||
</el-link>
|
||||
</div>
|
||||
<div v-if="dataT=='002'||dataT=='005'||dataT=='007'" class="ml-10px">
|
||||
<el-link
|
||||
:underline="false"
|
||||
@click="downloadFile(row.file)"
|
||||
target="_blank"
|
||||
type="primary"
|
||||
>原文件下载
|
||||
</el-link>
|
||||
</div>
|
||||
<div v-if="dataT=='004'||dataT=='006'||dataT=='007'" class="ml-10px">
|
||||
<el-link
|
||||
:underline="false"
|
||||
target="_blank"
|
||||
@click="download(row)"
|
||||
type="primary"
|
||||
>编辑后下载
|
||||
</el-link>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { propTypes } from '@/utils/propTypes'
|
||||
import type { UploadInstance, UploadProps, UploadRawFile, UploadUserFile } from 'element-plus'
|
||||
import { isString } from '@/utils/is'
|
||||
import { useUpload } from '@/components/UploadFile/src/useUpload'
|
||||
import { UploadFile } from 'element-plus/es/components/upload/src/upload'
|
||||
import {getAccessToken} from "@/utils/auth";
|
||||
import {onlyofApi} from "@/api/only/only";
|
||||
import axios from "axios";
|
||||
import {ref} from "vue";
|
||||
import {integer} from "vue-types";
|
||||
import {getConfigKey} from "@/api/infra/config";
|
||||
import {config} from '@/config/axios/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','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(false), // 拖拽上传
|
||||
isShowTip: propTypes.bool.def(true), // 是否显示提示
|
||||
disabled: propTypes.bool.def(false) // 是否禁用上传组件 ==> 非必传(默认为 false)
|
||||
})
|
||||
|
||||
// ========== 上传相关 ==========
|
||||
const uploadRef = ref<UploadInstance>()
|
||||
const uploadList = ref<UploadUserFile[]>([])
|
||||
const fileList = ref<UploadUserFile[]>([])
|
||||
const MysqlUrl = ref<UploadUserFile[]>([])
|
||||
const uploadNumber = ref<number>(0)
|
||||
|
||||
const { uploadUrl, httpRequest } = useUpload()
|
||||
// 上传文件
|
||||
const upload = async (myFile:any) => {
|
||||
//获取当前id
|
||||
// console.log("id",fileNid.value)
|
||||
// console.log("myFile",myFile)
|
||||
// const iid = fileNid.value.toString()
|
||||
const formData = new FormData();
|
||||
const token = getAccessToken();
|
||||
//设置配置
|
||||
const configs = {
|
||||
headers: { 'Authorization': `Bearer ${token}`,'Content-Type': 'multipart/form-data' }
|
||||
}
|
||||
//拿到的信息来加入form
|
||||
formData.append('file', myFile);
|
||||
// formData.append('fileId', iid.toString());
|
||||
try {
|
||||
const response = await axios.post('http://192.168.1.15:48080/admin-api/only/onlyof/update', formData, configs);
|
||||
console.log(response);
|
||||
} catch (error) {
|
||||
console.error('Upload failed:', error);
|
||||
}
|
||||
};
|
||||
const lod = ref(true)
|
||||
const upDing = ref(false)
|
||||
//根据不同值拿到不同字体颜色
|
||||
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 () => {
|
||||
if (upDing.value){
|
||||
message.error("文件正在同步中!")
|
||||
}
|
||||
lod.value=true
|
||||
// console.log("fileList.value",fileList.value)
|
||||
//判断是上传列表是否为空
|
||||
if (fileList.value.length==0){
|
||||
message.error("同步文件为空! ")
|
||||
}
|
||||
upDing.value=true
|
||||
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_ppt',
|
||||
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(`${config.ai_url}/${add}?path=${filePath}`)
|
||||
const response = await axios.post(`${config.ai_url}/${add}?path=${filePath}`);
|
||||
upDing.value=false
|
||||
console.log("response",response)
|
||||
await delay(100);
|
||||
fName.page = 100;
|
||||
fName.lodTxt="完成"
|
||||
} catch (error) {
|
||||
upDing.value=false
|
||||
await delay(200);
|
||||
fName.page = 10;
|
||||
message.error("同步错误!")
|
||||
fName.lodTxt="错误 "
|
||||
console.error("同 步 错 误 :", error);
|
||||
}
|
||||
}
|
||||
message.success("同步完成! ")
|
||||
emitUpdatePage()
|
||||
}
|
||||
const emitUpdatePage = () => {
|
||||
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: 1,
|
||||
fileName: '',
|
||||
fileSize: undefined,
|
||||
fileType: undefined,
|
||||
filePath: undefined,
|
||||
uploadDate: [],
|
||||
status: undefined,
|
||||
createTime: [],
|
||||
})
|
||||
/** 查询列表 */
|
||||
const GotoFile = ref(false)
|
||||
/**
|
||||
* 查询列表看看没有上传过文件这个文件 后端我改为了精准查询
|
||||
*/
|
||||
const getList = async () => {
|
||||
const data = await onlyofApi.getonlyofPage(queryParamsOnly)
|
||||
GotoFile.value=false
|
||||
//查询库中有没有同名文件
|
||||
if (data.total<=0){
|
||||
message.error('未找到文件请重新上传')
|
||||
GotoFile.value=false
|
||||
}else {
|
||||
GotoFile.value=true
|
||||
}
|
||||
}
|
||||
//定义储存当前数据id
|
||||
const fileNid = ref(integer)
|
||||
// 编辑文件
|
||||
const edit = async (row) => {
|
||||
//原本想根据id来指定文件后来想不查看是否有重复文件
|
||||
// console.log("id",fileNid.value)
|
||||
// const iid = fileNid.value.toString()
|
||||
// let name = fileNid.value+row.file.name.trim()
|
||||
let name = row.file.name.trim()
|
||||
// console.log(name)
|
||||
queryParamsOnly.pageNo = 1
|
||||
queryParamsOnly.fileName=name
|
||||
//设置完查询的值去查询
|
||||
await getList()
|
||||
if (!GotoFile.value){
|
||||
return;
|
||||
}
|
||||
const token = getAccessToken();
|
||||
// window.open(`http://192.168.1.15:48080/admin-api/only/onlyof/edit?name=${name}&userName=admin&userId=1&id=${iid}&token=${token}`);
|
||||
window.open(`http://192.168.1.15:48080/admin-api/only/onlyof/edit?name=${name}&userName=admin&userId=1&token=${token}`);
|
||||
};
|
||||
|
||||
// 下载文件
|
||||
const download = async (row) => {
|
||||
// 这些原本都想要用id
|
||||
// let name = fileNid.value+row.file.name.trim()
|
||||
let name = row.file.name.trim()
|
||||
//拿到名字
|
||||
// const iid = fileNid.value.toString()
|
||||
// console.log("name",name)
|
||||
try {
|
||||
const token = getAccessToken();
|
||||
//拿文件状态
|
||||
const response = await axios.get(`http://192.168.1.15:48080/admin-api/only/onlyof/editStatus?name=${name}&token=${token}`);
|
||||
if (response.data.error === 0) {
|
||||
alert('文档正在编辑,5秒后开始下载最新版!');
|
||||
setTimeout(() => {
|
||||
window.location.href = `http://192.168.1.15:48080/admin-api/only/onlyof/download?name=v1${name}&token=${token}`;
|
||||
}, 5000);
|
||||
} else {
|
||||
message.success('正在下载文件! ')
|
||||
window.location.href = `http://192.168.1.15:48080/admin-api/only/onlyof/download?name=${name}&token=${token}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Download failed:', error);
|
||||
}
|
||||
};
|
||||
// 文件上传之前判断
|
||||
const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => {
|
||||
if (fileList.value.length >= props.limit) {
|
||||
message.error(`上传文件数量不能超过${props.limit}个!`)
|
||||
return false
|
||||
}
|
||||
let fileExtension = ''
|
||||
if (file.name.lastIndexOf('.') > -1) {
|
||||
fileExtension = file.name.slice(file.name.lastIndexOf('.') + 1)
|
||||
}
|
||||
const isImg = props.fileType.some((type: string) => {
|
||||
if (file.type.indexOf(type) > -1) return true
|
||||
return !!(fileExtension && fileExtension.indexOf(type) > -1)
|
||||
})
|
||||
const isLimit = file.size < props.fileSize * 1024 * 1024
|
||||
if (!isImg) {
|
||||
message.error(`文件格式不正确, 请上传${props.fileType.join('/')}格式!`)
|
||||
return false
|
||||
}
|
||||
if (!isLimit) {
|
||||
message.error(`上传文件大小不能超过${props.fileSize}MB!`)
|
||||
return false
|
||||
}
|
||||
message.success('正在上传文件,请等待列表刷新')
|
||||
uploadNumber.value++
|
||||
}
|
||||
// 处理上传的文件发生变化
|
||||
// const handleFileChange = (uploadFile: UploadFile): void => {
|
||||
// uploadRef.value.data.path = uploadFile.name
|
||||
// }
|
||||
//定义文件是否重复判断参数
|
||||
const fileVerify = ref(false)
|
||||
// 文件上传成功
|
||||
const handleFileSuccess: UploadProps['onSuccess'] = (res: any): void => {
|
||||
//文件上传时获取想要的数据
|
||||
// console.log("res0",res[0])
|
||||
// console.log("fileList",fileList.value)
|
||||
const resName = res[0].data[0]
|
||||
fileVerify.value = false;
|
||||
//判断是不是有相同名字文件
|
||||
for (let i = 0; i <fileList.value.length-1; i++){
|
||||
// console.log("list",fileList.value[i].name)
|
||||
const fileName = fileList.value[i].name
|
||||
if (resName===fileName){
|
||||
fileVerify.value = true
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 删除自身
|
||||
const index = fileList.value.findIndex((item) => item.response?.data === res.data)
|
||||
fileList.value.splice(index, 1)
|
||||
//在删除自身后根据判断来提示
|
||||
if (fileVerify.value){
|
||||
message.error("不能上传同名文件")
|
||||
return;
|
||||
}
|
||||
message.success('上传成功')
|
||||
//正常上传后 上传附件
|
||||
upload(res[1])
|
||||
/**
|
||||
* 拼接更加明显的特殊字符串来便于切割
|
||||
* */
|
||||
uploadList.value.push({ name: (res[0].data[0]+"&&$#$"+res[0].data[1])+" ", url: (res[0].data[0]+"&&$#$"+res[0].data[1])+" "})
|
||||
if (uploadList.value.length == uploadNumber.value) {
|
||||
fileList.value.push(...uploadList.value)
|
||||
MysqlUrl.value.push(...uploadList.value)
|
||||
const updatedFileStatus = [...props.fileStatus];
|
||||
updatedFileStatus.push(10);
|
||||
emit('update:fileStatus', updatedFileStatus);
|
||||
// console.log("updatedFileStatus",updatedFileStatus)
|
||||
// console.log("fileList.value",fileList.value)
|
||||
// console.log("MysqlUrl.value",MysqlUrl.value)
|
||||
uploadList.value = []
|
||||
uploadNumber.value = 0
|
||||
emitUpdateModelValue()
|
||||
}
|
||||
}
|
||||
|
||||
// 文件数超出提示
|
||||
const handleExceed: UploadProps['onExceed'] = (): void => {
|
||||
message.error(`上传文件数量不能超过${props.limit}个!`)
|
||||
}
|
||||
|
||||
// 上传错误提示
|
||||
const excelUploadError: UploadProps['onError'] = (): void => {
|
||||
message.error('导入数据失败,请您重新上传!')
|
||||
}
|
||||
|
||||
// 删除上传文件
|
||||
const handleRemove = (file: UploadFile) => {
|
||||
const index = fileList.value.map((f) => f.name).indexOf(file.name)
|
||||
if (index > -1) {
|
||||
//删除文件链接已选择删除的链接索引
|
||||
fileList.value.splice(index, 1)
|
||||
MysqlUrl.value.splice(index,1)
|
||||
const updatedFileStatus = [...props.fileStatus];
|
||||
updatedFileStatus.splice(index, 1);
|
||||
emit('update:fileStatus', updatedFileStatus);
|
||||
// console.log("updatedFileStatus",updatedFileStatus)
|
||||
// console.log("fileList",fileList.value)
|
||||
// console.log("MysqlUrl",MysqlUrl.value)
|
||||
emitUpdateModelValue2()
|
||||
}
|
||||
}
|
||||
|
||||
//文件预览
|
||||
const handleView = (file)=> {
|
||||
const url = file.url
|
||||
if (!url) {
|
||||
console.error("文件不可预览");
|
||||
}
|
||||
const fileExt = url.substring(url.length-5,url.length).trim().toLowerCase()
|
||||
// console.log(fileExt)
|
||||
if (fileExt==="docx"||fileExt==="xlsx"||fileExt==="pptx"){
|
||||
window.open("https://view.officeapps.live.com/op/view.aspx?src="+encodeURIComponent(url),'_blank')
|
||||
}else if(fileExt===".txt"||fileExt===".pdf"){
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
}
|
||||
|
||||
//文件下载时文件名为原来名字
|
||||
const downloadFile = async (file)=> {
|
||||
// console.log("file",file)
|
||||
//使用 fetch API 请求文件并返回 Blob 数据
|
||||
const response = await fetch(file.url);
|
||||
//获取 response blob 属性
|
||||
const blob = await response.blob();
|
||||
//创建一个 <a> 元素
|
||||
const link = document.createElement('a')
|
||||
//创建一个临时的对象 URL,指向该 Blob。
|
||||
link.href = URL.createObjectURL(blob);
|
||||
//指定下载时的文件名,此时浏览器将强制使用这个名称。
|
||||
link.download = file.name
|
||||
//添加下载link
|
||||
document.body.appendChild(link);
|
||||
//手动触发点击事件,开始下载文件。
|
||||
link.click();
|
||||
//移除下载link
|
||||
document.body.removeChild(link);
|
||||
//下载完成后,释放创建的对象 URL,避免内存泄漏
|
||||
URL.revokeObjectURL(link.href);
|
||||
}
|
||||
|
||||
const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
|
||||
console.log(uploadFile)
|
||||
}
|
||||
//watch 传过来的id又没有改动 有的话重新赋值给filenid
|
||||
// watch(
|
||||
// () => props.fileId,
|
||||
// (val:number) => {
|
||||
// // console.log("valFileId",val)
|
||||
// // fileNid.value=val
|
||||
// },
|
||||
// { immediate: true, deep: true }
|
||||
// )
|
||||
// 监听模型绑定值变动
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val: string | string[]) => {
|
||||
// console.log("val",val)
|
||||
if (!val) {
|
||||
fileList.value = [] // fix:处理掉缓存,表单重置后上传组件的内容并没有重置
|
||||
return
|
||||
}
|
||||
fileList.value = [] // 保障数据为空
|
||||
// 情况1:字符串
|
||||
if (isString(val)) {
|
||||
fileList.value.push(
|
||||
...val.split(',').map((url) => ({ name: url.substring(url.lastIndexOf('/') + 1), url }))
|
||||
)
|
||||
return
|
||||
}
|
||||
// 情况2:数组 利用拼接的特殊字符串来切割
|
||||
fileList.value.push(
|
||||
...(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]==""){
|
||||
fileList.value = []
|
||||
}
|
||||
//val数据为空 val不为空 MysqlUrl长度为空时给MysqlUrl push val内的所有文件链接
|
||||
if (val[0]!==""&&val.length>0&&MysqlUrl.value.length==0){
|
||||
MysqlUrl.value.push(
|
||||
...(val as string[]).map((url) => ({ name: url,url: url}))
|
||||
);
|
||||
}
|
||||
// console.log("fileList", fileList.value)
|
||||
// console.log("MysqlUrl", MysqlUrl.value)
|
||||
},
|
||||
{ immediate: true, deep: true }
|
||||
)
|
||||
watch(
|
||||
() => props.fileStatus,
|
||||
(val:number[]) => {
|
||||
if (!val) {
|
||||
lod.value=false;
|
||||
return;
|
||||
}
|
||||
val.forEach((item, index) => {
|
||||
fileList.value[index].page = item
|
||||
if (item == 10 ){
|
||||
fileList.value[index].lodTxt = "错误"
|
||||
}else{
|
||||
fileList.value[index].lodTxt = "完成"
|
||||
}
|
||||
});
|
||||
// console.log("fileList int",fileList.value)
|
||||
},
|
||||
{ immediate: true, deep: true }
|
||||
)
|
||||
// 发送文件链接列表更新用于上传文件后
|
||||
const emitUpdateModelValue = () => {
|
||||
// 情况1:数组结果
|
||||
let result: string | string[] = MysqlUrl.value.map((file) => file.url!)
|
||||
// 情况2:逗号分隔的字符串
|
||||
if (props.limit === 1 || isString(props.modelValue)) {
|
||||
result = result.join(',')
|
||||
}
|
||||
// console.log("result",result)
|
||||
emit('update:modelValue', result)
|
||||
}
|
||||
|
||||
// 发送文件链接列表更新用于删除文件后
|
||||
const emitUpdateModelValue2 = () => {
|
||||
// 情况1:数组结果
|
||||
let result: string | string[] = MysqlUrl.value.map((file) => file.url!)
|
||||
// 情况2:逗号分隔的字符串
|
||||
if (props.limit === 1 || isString(props.modelValue)) {
|
||||
result = result.join(',')
|
||||
}
|
||||
// console.log("result",result)
|
||||
emit('update:modelValue', result)
|
||||
// 多了一步就是清空就文件链接以便于再次删除后不会出现重复
|
||||
MysqlUrl.value = []
|
||||
}
|
||||
const dataT = ref(null)
|
||||
onMounted( () => {
|
||||
getConfigKey("file:open:controller").then((res) => {
|
||||
if (!res || res.length === 0){
|
||||
return
|
||||
}
|
||||
dataT.value = res;
|
||||
})
|
||||
})
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.upload-file-uploader {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
:deep(.upload-file-list .el-upload-list__item) {
|
||||
position: relative;
|
||||
margin-bottom: 10px;
|
||||
line-height: 2;
|
||||
border: 1px solid #e4e7ed;
|
||||
}
|
||||
|
||||
:deep(.el-upload-list__item-file-name) {
|
||||
max-width: 250px;
|
||||
}
|
||||
|
||||
:deep(.upload-file-list .ele-upload-list__item-content) {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
:deep(.ele-upload-list__item-content-action .el-link) {
|
||||
margin-right: 10px;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user