Browse Source

支持多文件上传和文件夹上传

pull/1/head
han2015 4 months ago
parent
commit
4f03211b4f
  1. 133
      src/views/doc/space.vue

133
src/views/doc/space.vue

@ -1,7 +1,7 @@
<!--
@ 作者: han2015
@ 时间: 2025-05-12 15:39:13
@ 备注: 文档管理组件
@ 备注: 共享空间组件
-->
<script lang="ts" setup>
import { getFileIcon, readableSize,fileType} from "./tools"
@ -9,22 +9,18 @@ import sharePermission from './sharePermission.vue';
import { matterPage,matterInfo} from "@/api/doc/type"
import { doAccessManage,getSpaceMatterList,doCreateSpaceDir,doDelSpaceMatter,doDelSpace,
doAiTraining ,doCreateAiagent,doFileUpload} from "@/api/doc/space"
import { h, proxyRefs } from 'vue'
import { h } from 'vue'
import {
Delete,
View,
Download,
Plus,
Edit,
CircleCheckFilled,
Promotion,
Folder,
} from '@element-plus/icons-vue'
import {ElMessage,UploadFile,UploadFiles,ElPagination} from "element-plus";
import preview from './preview.vue';
import aiagent from './agent.vue';
import router from "@/router";
import { formToJSON } from "axios";
const matterList = ref<matterInfo[]>([])
const newdir=ref("") //
@ -37,10 +33,11 @@ const currentNode=ref<matterInfo>({}) //打开的路径层次
const dynamicVNode = ref<VNode | null>(null) //permission
const paginInfo = ref({ page: 0, total: 0 })
const filesUpload=ref()
//
const filesUpload=ref() //
const uploadDirRef = ref() //
//-----------AI---------------------
const aiAgentVNode = ref<VNode | null>(null) //ai chat
//const agent=ref<{model:boolean,name:string}>({})
const currentAgent=ref<{model:boolean,name:string,uuid:string}>({})
@ -236,37 +233,93 @@ function handleSigLoadErr(error: Error, uploadFile: UploadFile, uploadFiles:Uplo
ElMessage.error(JSON.parse(error.message).msg)
}
function onCustomUpload(files:any){
console.log(files)
console.log(fileList.value,"<<<<<<<<<<<<<")
//
async function onCustomUpload(file:UploadFile){
const fields=new FormData()
fields.append("space",uploadFormData.value.space)
fields.append("puuid",uploadFormData.value.puuid)
fields.append("file",file.raw)
if (fileList.value.length === 0) {
alert('请先选择文件')
}
console.log("sdfsdfsdf")
return
for (const file of fileList.value) {
const formData = new FormData()
formData.append('file', file)
const fields=new FormData()
fields.append("space",uploadFormData.value.space)
fields.append("puuid",uploadFormData.value.puuid)
fields.append("file","uploadFormData.value.space")
try {
doFileUpload(fields,'/hxpan/api/space/upload')
} catch (err) {
console.error('上传失败:', err)
}
const res = await doFileUpload(fields,'/hxpan/api/space/upload')
if(res.code!=200){
console.log(file.name+"上传失败! ")
alert(file.name+"上传失败! ")
}
//AI
handleAiUpload(res.data)
//
fileList.value = []
filesUpload.value.clearFiles()
}
//
async function uploadFolder(e:Event){
const files = e.target!.files??[]
for(let f of files){
await handleFolderFile(f)
}
onLoadMatterList() //
}
async function handleFolderFile(option:File){
//
const _path = option.webkitRelativePath
const _dir=_path.replace(/\/[^/]+\w+$/,"") //,[^/]
const node = matterList.value.filter((item)=>{
return item.dir && item.path?.endsWith(_dir)
})
let puuid=""
//
if(node.length==0){
const subs= await doCreateMultyDir(_dir,currentNode.value.uuid)
matterList.value.push(...subs) //
const newnodes=matterList.value.filter((item)=>{
return item.dir && item.path?.endsWith(_dir)
})
if(newnodes.length>0){
puuid=newnodes[0].uuid
}else{
console.log(_path+"上传失败! ")
alert(_path +" 上传失败! ")
return
}
}else{
puuid=node[0].uuid
}
const fields = new FormData()
fields.append('file', option)
fields.append("space",uploadFormData.value.space)
fields.append("puuid",puuid)
const res = await doFileUpload(fields,'/hxpan/api/space/upload')
if(res.code!=200){
console.log(_path+"上传失败! ")
alert(_path +" 上传失败! ")
}
//AIhandleAiUpload
handleAiUpload(res.data)
}
//matterinfos
async function doCreateMultyDir(path:string,uuid:string){
const list=[];
const dirs=path.split("/")
for(let i=0;i<dirs.length;i++){
await doCreateSpaceDir(props.uid,{
puuid:uuid,
name:dirs[i],
space:props.spaceid,
roles:props.roles,
}).then((resp)=> {
uuid=resp.data.uuid //uuid, puuid
list.push(resp.data)
})
}
return list
}
//-------------------------AI section--------------
//
@ -295,7 +348,8 @@ function onAiAgent(){
})
}
function handleAiUpload(info:matterInfo){
if (currentNode.value.puuid){
//
if (currentNode.value.agent){
doAiTraining(`/agents/${currentAgent.value.uuid}/updates`,{"matter":info.uuid}).then(resp=>{
console.log(resp)
})
@ -347,6 +401,7 @@ onMounted(() => {
currentNode.value.uuid="root"
//AI
currentAgent.value={name:"通用AI",model:false,uuid:"5bd9b0e9-d3f4-4089-670a-880009e925a8"}
onLoadMatterList()
});
@ -381,11 +436,19 @@ function isOwner(){
:data="uploadFormData"
:on-change="onCustomUpload"
:show-file-list="true"
multiple
:limit="2"
:action="apiURL+'/space/upload'">
multiple>
<span>上传文件</span>
</el-upload>
<div class="el-button el-button--default" style="position: relative;">
<input type="file" class="el-button el-button--default" style="position: absolute;opacity: 0;width: 55px;"
ref="uploadDirRef"
@change="uploadFolder"
webkitdirectory
multiple
/>
文件夹上传
</div>
<el-button @click="createDir">新建目录</el-button>
<el-button type="danger" plain @click="onDelMatter({uuid:currentNode.uuid,name:currentNode.name,dir:true,
puuid:currentNode.puuid,path:currentNode.path})">删除目录</el-button>

Loading…
Cancel
Save