文件编辑
This commit is contained in:
parent
2ff8204189
commit
f5f29bdfd7
@ -1,383 +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 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 class="ml-10px" >
|
|
||||||
<el-link
|
|
||||||
:underline="false"
|
|
||||||
@click="handleView(row.file)"
|
|
||||||
target="_blank"
|
|
||||||
type="primary"
|
|
||||||
>预览
|
|
||||||
</el-link>
|
|
||||||
<!-- <i-frame :src="'https://view.officeapps.live.com/op/view.aspx?src='+encodeURIComponent(row.file.url)"/>-->
|
|
||||||
</div>
|
|
||||||
<div class="ml-10px" >
|
|
||||||
<el-link
|
|
||||||
:underline="false"
|
|
||||||
@click="edit(row)"
|
|
||||||
target="_blank"
|
|
||||||
type="primary"
|
|
||||||
>编辑
|
|
||||||
</el-link>
|
|
||||||
</div>
|
|
||||||
<div class="ml-10px">
|
|
||||||
<el-link
|
|
||||||
:underline="false"
|
|
||||||
target="_blank"
|
|
||||||
@click="downloadFile(row.file)"
|
|
||||||
type="primary"
|
|
||||||
>原文件下载
|
|
||||||
</el-link>
|
|
||||||
</div>
|
|
||||||
<div class="ml-10px" >
|
|
||||||
<el-link
|
|
||||||
:underline="false"
|
|
||||||
@click="download(row)"
|
|
||||||
target="_blank"
|
|
||||||
type="primary"
|
|
||||||
>编辑后下载
|
|
||||||
</el-link>
|
|
||||||
</div>
|
|
||||||
<div class="ml-10px">
|
|
||||||
<el-button link type="danger" @click="handleRemove(row.file)"> 删除</el-button>
|
|
||||||
</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 axios from "axios";
|
|
||||||
import {onlyofApi} from "@/api/only/only";
|
|
||||||
|
|
||||||
defineOptions({ name: 'UploadFile' })
|
|
||||||
|
|
||||||
const message = useMessage() // 消息弹窗
|
|
||||||
const emit = defineEmits(['update:modelValue'])
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
modelValue: propTypes.oneOfType<string | string[]>([String, Array<String>]).isRequired,
|
|
||||||
fileType: propTypes.array.def(['doc', 'xls', 'ppt', 'txt', 'pdf']), // 文件类型, 例如['png', 'jpg', 'jpeg']
|
|
||||||
fileSize: propTypes.number.def(5), // 大小限制(MB)
|
|
||||||
limit: propTypes.number.def(5), // 数量限制
|
|
||||||
autoUpload: propTypes.bool.def(true), // 自动上传
|
|
||||||
drag: propTypes.bool.def(true), // 拖拽上传
|
|
||||||
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 queryParamsOnly = reactive({
|
|
||||||
pageNo: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
fileName: undefined,
|
|
||||||
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 {
|
|
||||||
message.success('正在打开')
|
|
||||||
GotoFile.value=true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 编辑文件
|
|
||||||
const edit = async (row) => {
|
|
||||||
console.log(row)
|
|
||||||
let name = row.file.name.trim()
|
|
||||||
queryParamsOnly.pageNo = 1
|
|
||||||
queryParamsOnly.fileName=name
|
|
||||||
await getList()
|
|
||||||
if (!GotoFile.value){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log(name)
|
|
||||||
const token = getAccessToken();
|
|
||||||
window.open(`http://192.168.1.3:48080/admin-api/only/onlyof/edit?name=${name}&userName=admin&userId=1&token=${token}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 下载文件
|
|
||||||
const download = async (row) => {
|
|
||||||
let name = row.file.name.trim()
|
|
||||||
try {
|
|
||||||
const token = getAccessToken();
|
|
||||||
const response = await axios.get(`http://192.168.1.3: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.3:48080/admin-api/only/onlyof/download?name=v1${name}&token=${token}`;
|
|
||||||
}, 5000);
|
|
||||||
} else {
|
|
||||||
window.location.href = `http://192.168.1.3: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 handleFileSuccess: UploadProps['onSuccess'] = (res: any): void => {
|
|
||||||
message.success('上传成功')
|
|
||||||
|
|
||||||
// 删除自身
|
|
||||||
const index = fileList.value.findIndex((item) => item.response?.data === res.data)
|
|
||||||
fileList.value.splice(index, 1)
|
|
||||||
console.log("res",res)
|
|
||||||
/**
|
|
||||||
* 拼接更加明显的特殊字符串来便于切割
|
|
||||||
* */
|
|
||||||
uploadList.value.push({ name: (res.data[0]+"&&$#$"+res.data[1])+" ", url: (res.data[0]+"&&$#$"+res.data[1])+" "})
|
|
||||||
if (uploadList.value.length == uploadNumber.value) {
|
|
||||||
fileList.value.push(...uploadList.value)
|
|
||||||
MysqlUrl.value.push(...uploadList.value)
|
|
||||||
// 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)
|
|
||||||
// console.log("fileList",fileList.value)
|
|
||||||
// console.log("MysqlUrl",MysqlUrl.value)
|
|
||||||
emitUpdateModelValue2()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//文件预览
|
|
||||||
const handleView = (file)=> {
|
|
||||||
const url = file.url
|
|
||||||
if (!url) {
|
|
||||||
console.error("文件不可预览");
|
|
||||||
}
|
|
||||||
const file2 = url.substring(url.length-5,url.length).trim().toLowerCase()
|
|
||||||
console.log(file2)
|
|
||||||
if (file2==="docx"||file2==="xlsx"||file2==="pptx"){
|
|
||||||
window.open("https://view.officeapps.live.com/op/view.aspx?src="+encodeURIComponent(url),'_blank')
|
|
||||||
}else if(file2===".txt"||file2===".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(
|
|
||||||
() => 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) }))
|
|
||||||
)
|
|
||||||
//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("11111fileList", fileList.value)
|
|
||||||
// console.log("11111MysqlUrl", MysqlUrl.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 = []
|
|
||||||
}
|
|
||||||
|
|
||||||
</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>
|
|
@ -41,27 +41,34 @@
|
|||||||
@click="handleView(row.file)"
|
@click="handleView(row.file)"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
type="primary"
|
type="primary"
|
||||||
>编辑
|
>预览
|
||||||
</el-link>
|
</el-link>
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-10px" >
|
<div class="ml-10px" >
|
||||||
<el-link
|
<el-link
|
||||||
:underline="false"
|
:underline="false"
|
||||||
@click="handleView(row.file)"
|
@click="edit(row)"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
type="primary"
|
type="primary"
|
||||||
>预览
|
>编辑
|
||||||
|
</el-link>
|
||||||
|
</div>
|
||||||
|
<div class="ml-10px">
|
||||||
|
<el-link
|
||||||
|
:underline="false"
|
||||||
|
@click="downloadFile(row.file)"
|
||||||
|
target="_blank"
|
||||||
|
type="primary"
|
||||||
|
>原文件下载
|
||||||
</el-link>
|
</el-link>
|
||||||
<!-- <i-frame :src="'https://view.officeapps.live.com/op/view.aspx?src='+encodeURIComponent(row.file.url)"/>-->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-10px">
|
<div class="ml-10px">
|
||||||
<el-link
|
<el-link
|
||||||
:underline="false"
|
:underline="false"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@click="downloadFile(row.file)"
|
@click="download(row)"
|
||||||
type="primary"
|
type="primary"
|
||||||
>
|
>编辑后下载
|
||||||
下载
|
|
||||||
</el-link>
|
</el-link>
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-10px">
|
<div class="ml-10px">
|
||||||
@ -78,6 +85,11 @@ import type { UploadInstance, UploadProps, UploadRawFile, UploadUserFile } from
|
|||||||
import { isString } from '@/utils/is'
|
import { isString } from '@/utils/is'
|
||||||
import { useUpload } from '@/components/UploadFile/src/useUpload'
|
import { useUpload } from '@/components/UploadFile/src/useUpload'
|
||||||
import { UploadFile } from 'element-plus/es/components/upload/src/upload'
|
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";
|
||||||
|
|
||||||
defineOptions({ name: 'UploadFile' })
|
defineOptions({ name: 'UploadFile' })
|
||||||
|
|
||||||
@ -85,6 +97,7 @@ const message = useMessage() // 消息弹窗
|
|||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
fileId:propTypes.number,
|
||||||
modelValue: propTypes.oneOfType<string | string[]>([String, Array<String>]).isRequired,
|
modelValue: propTypes.oneOfType<string | string[]>([String, Array<String>]).isRequired,
|
||||||
fileType: propTypes.array.def(['doc', 'xls', 'ppt', 'txt', 'pdf']), // 文件类型, 例如['png', 'jpg', 'jpeg']
|
fileType: propTypes.array.def(['doc', 'xls', 'ppt', 'txt', 'pdf']), // 文件类型, 例如['png', 'jpg', 'jpeg']
|
||||||
fileSize: propTypes.number.def(5), // 大小限制(MB)
|
fileSize: propTypes.number.def(5), // 大小限制(MB)
|
||||||
@ -103,7 +116,101 @@ const MysqlUrl = ref<UploadUserFile[]>([])
|
|||||||
const uploadNumber = ref<number>(0)
|
const uploadNumber = ref<number>(0)
|
||||||
|
|
||||||
const { uploadUrl, httpRequest } = useUpload()
|
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 queryParamsOnly = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 2,
|
||||||
|
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 {
|
||||||
|
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) => {
|
const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => {
|
||||||
if (fileList.value.length >= props.limit) {
|
if (fileList.value.length >= props.limit) {
|
||||||
@ -127,25 +234,46 @@ const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => {
|
|||||||
message.error(`上传文件大小不能超过${props.fileSize}MB!`)
|
message.error(`上传文件大小不能超过${props.fileSize}MB!`)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
message.success('正在上传文件,请稍候...')
|
message.success('正在上传文件,请等待列表刷新')
|
||||||
uploadNumber.value++
|
uploadNumber.value++
|
||||||
}
|
}
|
||||||
// 处理上传的文件发生变化
|
// 处理上传的文件发生变化
|
||||||
// const handleFileChange = (uploadFile: UploadFile): void => {
|
// const handleFileChange = (uploadFile: UploadFile): void => {
|
||||||
// uploadRef.value.data.path = uploadFile.name
|
// uploadRef.value.data.path = uploadFile.name
|
||||||
// }
|
// }
|
||||||
|
//定义文件是否重复判断参数
|
||||||
|
const fileVerify = ref(false)
|
||||||
// 文件上传成功
|
// 文件上传成功
|
||||||
const handleFileSuccess: UploadProps['onSuccess'] = (res: any): void => {
|
const handleFileSuccess: UploadProps['onSuccess'] = (res: any): void => {
|
||||||
message.success('上传成功')
|
//文件上传时获取想要的数据
|
||||||
|
// 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)
|
const index = fileList.value.findIndex((item) => item.response?.data === res.data)
|
||||||
fileList.value.splice(index, 1)
|
fileList.value.splice(index, 1)
|
||||||
console.log("res",res)
|
//在删除自身后根据判断来提示
|
||||||
|
if (fileVerify.value){
|
||||||
|
message.error("不能上传同名文件")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
message.success('上传成功')
|
||||||
|
//正常上传后 上传附件
|
||||||
|
upload(res[1])
|
||||||
/**
|
/**
|
||||||
* 拼接更加明显的特殊字符串来便于切割
|
* 拼接更加明显的特殊字符串来便于切割
|
||||||
* */
|
* */
|
||||||
uploadList.value.push({ name: (res.data[0]+"&&$#$"+res.data[1])+" ", url: (res.data[0]+"&&$#$"+res.data[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) {
|
if (uploadList.value.length == uploadNumber.value) {
|
||||||
fileList.value.push(...uploadList.value)
|
fileList.value.push(...uploadList.value)
|
||||||
MysqlUrl.value.push(...uploadList.value)
|
MysqlUrl.value.push(...uploadList.value)
|
||||||
@ -199,6 +327,7 @@ const handleView = (file)=> {
|
|||||||
|
|
||||||
//文件下载时文件名为原来名字
|
//文件下载时文件名为原来名字
|
||||||
const downloadFile = async (file)=> {
|
const downloadFile = async (file)=> {
|
||||||
|
console.log("file",file)
|
||||||
//使用 fetch API 请求文件并返回 Blob 数据
|
//使用 fetch API 请求文件并返回 Blob 数据
|
||||||
const response = await fetch(file.url);
|
const response = await fetch(file.url);
|
||||||
//获取 response blob 属性
|
//获取 response blob 属性
|
||||||
@ -222,7 +351,15 @@ const downloadFile = async (file)=> {
|
|||||||
const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
|
const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
|
||||||
console.log(uploadFile)
|
console.log(uploadFile)
|
||||||
}
|
}
|
||||||
|
//watch 传过来的id又没有改动 有的话重新赋值给filenid
|
||||||
|
watch(
|
||||||
|
() => props.fileId,
|
||||||
|
(val:number) => {
|
||||||
|
// console.log("val",val)
|
||||||
|
fileNid.value=val
|
||||||
|
},
|
||||||
|
{ immediate: true, deep: true }
|
||||||
|
)
|
||||||
// 监听模型绑定值变动
|
// 监听模型绑定值变动
|
||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => props.modelValue,
|
||||||
|
@ -30,7 +30,7 @@ export const useUpload = () => {
|
|||||||
} else {
|
} else {
|
||||||
// 模式二:后端上传
|
// 模式二:后端上传
|
||||||
// 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
|
// 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
|
||||||
return new Promise((resolve, reject) => {
|
const fileData = new Promise((resolve, reject) => {
|
||||||
FileApi.updateFile({ file: options.file })
|
FileApi.updateFile({ file: options.file })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
@ -43,6 +43,8 @@ export const useUpload = () => {
|
|||||||
reject(res)
|
reject(res)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
//返回上传后的文件还有options中的file数据
|
||||||
|
return Promise.all([fileData, options.file]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,9 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="文件路径" prop="filePath">
|
<el-form-item label="文件路径" prop="filePath">
|
||||||
<UploadFile v-model="formData.filePath" />
|
<UploadFile v-model="formData.filePath"
|
||||||
|
:file-id="formData.id"
|
||||||
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<!-- 子表的表单 -->
|
<!-- 子表的表单 -->
|
||||||
@ -134,7 +136,7 @@ const formData = ref({
|
|||||||
userName:'',
|
userName:'',
|
||||||
content: '',
|
content: '',
|
||||||
status: undefined,
|
status: undefined,
|
||||||
filePath: undefined
|
filePath: [] as string[]
|
||||||
})
|
})
|
||||||
const formData_Star2 ={
|
const formData_Star2 ={
|
||||||
kowsmId: 0,
|
kowsmId: 0,
|
||||||
@ -189,13 +191,15 @@ const open = async (type: string, id?: number) => {
|
|||||||
try {
|
try {
|
||||||
formData.value = await KnowledgeApi.getKnowledge(id)
|
formData.value = await KnowledgeApi.getKnowledge(id)
|
||||||
//去除掉储存信息中多余的中括号
|
//去除掉储存信息中多余的中括号
|
||||||
formData.value.filePath[0] = formData.value.filePath[0]
|
const pathLen = formData.value.filePath.length
|
||||||
.replace("[","")
|
if (pathLen === 1){
|
||||||
.replace("]","")
|
formData.value.filePath[0] = formData.value.filePath[0].substring(1)
|
||||||
formData.value.filePath[formData.value.filePath.length-1] = formData.value.filePath[formData.value.filePath.length-1]
|
formData.value.filePath[0] = formData.value.filePath[0].substring(0,formData.value.filePath[0].length-1)
|
||||||
.replace("[","")
|
}else if (pathLen >= 2){
|
||||||
.replace("]","")
|
formData.value.filePath[0] = formData.value.filePath[0].substring(1)
|
||||||
console.log(formData.value)
|
formData.value.filePath[pathLen-1] = formData.value.filePath[pathLen-1].substring(0,formData.value.filePath[pathLen-1].length-1)
|
||||||
|
}
|
||||||
|
// console.log(formData.value)
|
||||||
} finally {
|
} finally {
|
||||||
formLoading.value = false
|
formLoading.value = false
|
||||||
}
|
}
|
||||||
@ -305,11 +309,9 @@ const submitForm = async () => {
|
|||||||
formLoading.value = true
|
formLoading.value = true
|
||||||
try {
|
try {
|
||||||
const data = formData.value as unknown as KnowledgeVO
|
const data = formData.value as unknown as KnowledgeVO
|
||||||
if (data.filePath.length!==0){
|
if (data.filePath &&data.filePath.length!==0){
|
||||||
//去除多余空格
|
//去除多余空格
|
||||||
for (let i = 0; i < data.filePath.length; i++){
|
data.filePath = data.filePath.map(path => path.trimStart());
|
||||||
data.filePath[i] = data.filePath[i].replace(/^\s*/,'');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
console.log(data.filePath)
|
console.log(data.filePath)
|
||||||
// 拼接子表的数据
|
// 拼接子表的数据
|
||||||
|
@ -120,7 +120,8 @@ const formData = ref({
|
|||||||
knowTitle: undefined,
|
knowTitle: undefined,
|
||||||
content: undefined,
|
content: undefined,
|
||||||
status: undefined,
|
status: undefined,
|
||||||
filePath: undefined,
|
//更改类型未数组或字符串数组
|
||||||
|
filePath: [] as string[],
|
||||||
processInstanceId: undefined,
|
processInstanceId: undefined,
|
||||||
userId: undefined,
|
userId: undefined,
|
||||||
flowStatus: undefined
|
flowStatus: undefined
|
||||||
@ -165,6 +166,15 @@ const open = async (type: string, id?: number) => {
|
|||||||
formLoading.value = true
|
formLoading.value = true
|
||||||
try {
|
try {
|
||||||
formData.value = await KnowledgePublicApi.getKnowledgePublic(id)
|
formData.value = await KnowledgePublicApi.getKnowledgePublic(id)
|
||||||
|
//去除掉储存信息中多余的中括号
|
||||||
|
const pathLen = formData.value.filePath.length
|
||||||
|
if (pathLen === 1){
|
||||||
|
formData.value.filePath[0] = formData.value.filePath[0].substring(1)
|
||||||
|
formData.value.filePath[0] = formData.value.filePath[0].substring(0,formData.value.filePath[0].length-1)
|
||||||
|
}else if (pathLen >= 2){
|
||||||
|
formData.value.filePath[0] = formData.value.filePath[0].substring(1)
|
||||||
|
formData.value.filePath[pathLen-1] = formData.value.filePath[pathLen-1].substring(0,formData.value.filePath[pathLen-1].length-1)
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
formLoading.value = false
|
formLoading.value = false
|
||||||
}
|
}
|
||||||
@ -190,6 +200,10 @@ const submitForm = async () => {
|
|||||||
formLoading.value = true
|
formLoading.value = true
|
||||||
try {
|
try {
|
||||||
const data = formData.value as unknown as KnowledgePublicVO
|
const data = formData.value as unknown as KnowledgePublicVO
|
||||||
|
if (data.filePath &&data.filePath.length!==0){
|
||||||
|
//去除多余空格
|
||||||
|
data.filePath = data.filePath.map(path => path.trimStart());
|
||||||
|
}
|
||||||
// 拼接子表的数据
|
// 拼接子表的数据
|
||||||
data.commentPublics = commentPublicFormRef.value.getData()
|
data.commentPublics = commentPublicFormRef.value.getData()
|
||||||
if (formType.value === 'create') {
|
if (formType.value === 'create') {
|
||||||
|
Loading…
Reference in New Issue
Block a user