mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-06-19 14:52:00 +08:00
refactor: 重构文件目录系统
This commit is contained in:
parent
83fc308eeb
commit
10726d7c4e
@ -12,7 +12,7 @@ export interface CategoryVO {
|
|||||||
// 文件目录 API
|
// 文件目录 API
|
||||||
export const CategoryApi = {
|
export const CategoryApi = {
|
||||||
// 查询文件目录列表
|
// 查询文件目录列表
|
||||||
getCategoryList: async (params) => {
|
getCategoryList: async (params?: any) => {
|
||||||
return await request.get({ url: `/infra/category/list`, params })
|
return await request.get({ url: `/infra/category/list`, params })
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ export const CategoryApi = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 导出文件目录 Excel
|
// 导出文件目录 Excel
|
||||||
exportCategory: async (params) => {
|
exportCategory: async (params?: any) => {
|
||||||
return await request.download({ url: `/infra/category/export-excel`, params })
|
return await request.download({ url: `/infra/category/export-excel`, params })
|
||||||
},
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ export interface FilePageReqVO extends PageParam {
|
|||||||
path?: string
|
path?: string
|
||||||
type?: string
|
type?: string
|
||||||
createTime?: Date[]
|
createTime?: Date[]
|
||||||
|
categoryId?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件预签名地址 Response VO
|
// 文件预签名地址 Response VO
|
||||||
@ -45,6 +46,6 @@ export const updateFile = (data: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 上传文件
|
// 上传文件
|
||||||
export const updateFileEx = (data: any) => {
|
export const updateFileEx = (data: any, params?: any) => {
|
||||||
return request.upload({ url: '/infra/file/uploadEx', data })
|
return request.upload({ url: '/infra/file/uploadEx', params, data })
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ export const useUpload = () => {
|
|||||||
// 是否使用前端直连上传
|
// 是否使用前端直连上传
|
||||||
const isClientUpload = UPLOAD_TYPE.CLIENT === import.meta.env.VITE_UPLOAD_TYPE
|
const isClientUpload = UPLOAD_TYPE.CLIENT === import.meta.env.VITE_UPLOAD_TYPE
|
||||||
// 重写ElUpload上传方法
|
// 重写ElUpload上传方法
|
||||||
const httpRequest = async (options: UploadRequestOptions) => {
|
const httpRequest = async (options: UploadRequestOptions, params?: any) => {
|
||||||
// 模式一:前端上传
|
// 模式一:前端上传
|
||||||
if (isClientUpload) {
|
if (isClientUpload) {
|
||||||
// 1.1 生成文件名称
|
// 1.1 生成文件名称
|
||||||
@ -22,21 +22,23 @@ export const useUpload = () => {
|
|||||||
// 1.2 获取文件预签名地址
|
// 1.2 获取文件预签名地址
|
||||||
const presignedInfo = await FileApi.getFilePresignedUrl(fileName)
|
const presignedInfo = await FileApi.getFilePresignedUrl(fileName)
|
||||||
// 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio 不支持)
|
// 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio 不支持)
|
||||||
return axios.put(presignedInfo.uploadUrl, options.file, {
|
return axios
|
||||||
headers: {
|
.put(presignedInfo.uploadUrl, options.file, {
|
||||||
'Content-Type': options.file.type,
|
headers: {
|
||||||
}
|
'Content-Type': options.file.type
|
||||||
}).then(() => {
|
}
|
||||||
// 1.4. 记录文件信息到后端(异步)
|
})
|
||||||
createFile(presignedInfo, fileName, options.file)
|
.then(() => {
|
||||||
// 通知成功,数据格式保持与后端上传的返回结果一致
|
// 1.4. 记录文件信息到后端(异步)
|
||||||
return { data: presignedInfo.url }
|
createFile(presignedInfo, fileName, options.file)
|
||||||
})
|
// 通知成功,数据格式保持与后端上传的返回结果一致
|
||||||
|
return { data: presignedInfo.url }
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// 模式二:后端上传
|
// 模式二:后端上传
|
||||||
// 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
|
// 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
FileApi.updateFileEx({ file: options.file })
|
FileApi.updateFileEx({ file: options.file }, params)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
resolve(res)
|
resolve(res)
|
||||||
|
@ -62,13 +62,13 @@ const formRef = ref() // 表单 Ref
|
|||||||
const categoryTree = ref() // 树形结构
|
const categoryTree = ref() // 树形结构
|
||||||
|
|
||||||
/** 打开弹窗 */
|
/** 打开弹窗 */
|
||||||
const open = async (type: string, id?: number) => {
|
const open = async (type: string, id: number) => {
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
dialogTitle.value = t('action.' + type)
|
dialogTitle.value = t('action.' + type)
|
||||||
formType.value = type
|
formType.value = type
|
||||||
resetForm()
|
resetForm()
|
||||||
// 修改时,设置数据
|
// 修改时,设置数据
|
||||||
if (id) {
|
if (type === 'update') {
|
||||||
formLoading.value = true
|
formLoading.value = true
|
||||||
try {
|
try {
|
||||||
formData.value = await CategoryApi.getCategory(id)
|
formData.value = await CategoryApi.getCategory(id)
|
||||||
@ -76,6 +76,10 @@ const open = async (type: string, id?: number) => {
|
|||||||
formLoading.value = false
|
formLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 新增时,设置默认上一级
|
||||||
|
else{
|
||||||
|
formData.value.parentId = id;
|
||||||
|
}
|
||||||
await getCategoryTree()
|
await getCategoryTree()
|
||||||
}
|
}
|
||||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||||
|
201
src/views/infra/category/FolderTree.vue
Normal file
201
src/views/infra/category/FolderTree.vue
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
<template>
|
||||||
|
<div className="folder-header" v-if="folderList && folderList.length > 0">
|
||||||
|
<el-input v-model="folderName" class="!w-240px" clearable placeholder="请输入文件夹名称">
|
||||||
|
<template #prefix>
|
||||||
|
<Icon icon="ep:search" />
|
||||||
|
</template>
|
||||||
|
</el-input>
|
||||||
|
<el-space>
|
||||||
|
<el-button
|
||||||
|
type="success"
|
||||||
|
plain
|
||||||
|
@click="handleExport"
|
||||||
|
:loading="exportLoading"
|
||||||
|
v-hasPermi="['infra:category:export']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||||
|
</el-button>
|
||||||
|
<el-button type="danger" plain @click="toggleExpandAll">
|
||||||
|
<Icon icon="ep:sort" class="mr-5px" /> 展开/折叠
|
||||||
|
</el-button>
|
||||||
|
</el-space>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<el-tree
|
||||||
|
ref="treeRef"
|
||||||
|
v-if="refreshTable"
|
||||||
|
:load="folderLoading"
|
||||||
|
:data="folderList"
|
||||||
|
:expand-on-click-node="false"
|
||||||
|
:filter-node-method="filterNode"
|
||||||
|
:props="defaultProps"
|
||||||
|
:default-expand-all="isExpandAll"
|
||||||
|
highlight-current
|
||||||
|
node-key="id"
|
||||||
|
@node-click="handleNodeClick"
|
||||||
|
>
|
||||||
|
<template #default="{ node, data }">
|
||||||
|
<span class="custom-tree-node">
|
||||||
|
<span>{{ node.label }}</span>
|
||||||
|
<span>
|
||||||
|
<el-button type="primary" size="small" plain @click="appendFolder(data)"
|
||||||
|
>新增</el-button
|
||||||
|
>
|
||||||
|
<el-button
|
||||||
|
style="margin-left: 8px"
|
||||||
|
type="warning"
|
||||||
|
size="small"
|
||||||
|
plain
|
||||||
|
@click="updateFolder(data)"
|
||||||
|
>修改</el-button
|
||||||
|
>
|
||||||
|
<el-button
|
||||||
|
:class="{ hidden: data.children !== undefined }"
|
||||||
|
style="margin-left: 8px"
|
||||||
|
type="danger"
|
||||||
|
size="small"
|
||||||
|
plain
|
||||||
|
@click="deleteFolder(data)"
|
||||||
|
>删除</el-button
|
||||||
|
>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #empty>
|
||||||
|
<el-button type="primary" plain @click="appendFolder({ id: 0 })">新增文件夹</el-button>
|
||||||
|
</template>
|
||||||
|
</el-tree>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 表单弹窗:添加/修改 -->
|
||||||
|
<CategoryForm ref="formRef" @success="getFolderList" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ElTree } from 'element-plus'
|
||||||
|
import { defaultProps, handleTree } from '@/utils/tree'
|
||||||
|
import { CategoryApi, CategoryVO } from '@/api/infra/category'
|
||||||
|
import CategoryForm from './CategoryForm.vue'
|
||||||
|
import download from '@/utils/download'
|
||||||
|
|
||||||
|
defineOptions({ name: 'CategoryFolderTree' })
|
||||||
|
const emits = defineEmits(['node-click'])
|
||||||
|
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
|
const folderLoading = ref(false)
|
||||||
|
const folderName = ref('')
|
||||||
|
const folderList = ref<Tree[]>([])
|
||||||
|
const refreshTable = ref(true) // 重新渲染表格状态
|
||||||
|
const exportLoading = ref(false) // 导出的加载中
|
||||||
|
const isExpandAll = ref(true) // 是否展开,默认全部展开
|
||||||
|
|
||||||
|
const treeRef = ref<InstanceType<typeof ElTree>>()
|
||||||
|
const formRef = ref()
|
||||||
|
|
||||||
|
/** 查询文件夹列表 */
|
||||||
|
const getFolderList = async () => {
|
||||||
|
folderLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = await CategoryApi.getCategoryList()
|
||||||
|
folderList.value = handleTree(data, 'id', 'parentId')
|
||||||
|
// 重载树
|
||||||
|
refreshTable.value = false
|
||||||
|
await nextTick()
|
||||||
|
refreshTable.value = true
|
||||||
|
} finally {
|
||||||
|
folderLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理部门被点击 */
|
||||||
|
const handleNodeClick = async (row: { [key: string]: any }) => {
|
||||||
|
emits('node-click', row)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 基于名字过滤 */
|
||||||
|
const filterNode = (name: string, data: Tree) => {
|
||||||
|
if (!name) return true
|
||||||
|
return data.name.includes(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 监听过滤项 */
|
||||||
|
watch(folderName, (val) => {
|
||||||
|
treeRef.value!.filter(val)
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 新增文件夹 */
|
||||||
|
const appendFolder = (data: Tree) => {
|
||||||
|
formRef.value.open('create', data.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 修改文件夹 */
|
||||||
|
const updateFolder = (data: Tree) => {
|
||||||
|
formRef.value.open('update', data.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除文件夹 */
|
||||||
|
const deleteFolder = async (data: Tree) => {
|
||||||
|
try {
|
||||||
|
// 删除的二次确认
|
||||||
|
await message.delConfirm()
|
||||||
|
// 发起删除
|
||||||
|
await CategoryApi.deleteCategory(data.id)
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
// 刷新列表
|
||||||
|
getFolderList()
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出按钮操作 */
|
||||||
|
const handleExport = async () => {
|
||||||
|
try {
|
||||||
|
// 导出的二次确认
|
||||||
|
await message.exportConfirm()
|
||||||
|
// 发起导出
|
||||||
|
exportLoading.value = true
|
||||||
|
const data = await CategoryApi.exportCategory()
|
||||||
|
download.excel(data, '文件目录.xls')
|
||||||
|
} catch {
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 展开/折叠操作 */
|
||||||
|
const toggleExpandAll = async () => {
|
||||||
|
refreshTable.value = false
|
||||||
|
isExpandAll.value = !isExpandAll.value
|
||||||
|
await nextTick()
|
||||||
|
refreshTable.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// invoke
|
||||||
|
getFolderList()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.folder-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-tree-node {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
font-size: 14px;
|
||||||
|
padding-right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-tree-node__children) {
|
||||||
|
margin-top: 7px;
|
||||||
|
}
|
||||||
|
</style>
|
@ -1,199 +1,186 @@
|
|||||||
<template>
|
<template>
|
||||||
<ContentWrap>
|
<el-row :gutter="20">
|
||||||
<!-- 搜索工作栏 -->
|
<!-- 左侧文件夹树 -->
|
||||||
<el-form
|
<el-col :span="6" :xs="24">
|
||||||
class="-mb-15px"
|
<ContentWrap class="h-1/1">
|
||||||
:model="queryParams"
|
<FolderTree @node-click="handleNodeClick" />
|
||||||
ref="queryFormRef"
|
</ContentWrap>
|
||||||
:inline="true"
|
</el-col>
|
||||||
label-width="68px"
|
<el-col :span="18" :xs="24">
|
||||||
>
|
<!-- 搜索 -->
|
||||||
<el-form-item label="文件夹名称" prop="name">
|
<ContentWrap>
|
||||||
<el-input
|
<el-form
|
||||||
v-model="queryParams.name"
|
class="-mb-15px"
|
||||||
placeholder="请输入文件夹名称"
|
:model="queryParams"
|
||||||
clearable
|
ref="queryFormRef"
|
||||||
@keyup.enter="handleQuery"
|
:inline="true"
|
||||||
class="!w-240px"
|
label-width="68px"
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="编号" prop="code">
|
|
||||||
<el-input
|
|
||||||
v-model="queryParams.code"
|
|
||||||
placeholder="请输入编号"
|
|
||||||
clearable
|
|
||||||
@keyup.enter="handleQuery"
|
|
||||||
class="!w-240px"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item>
|
|
||||||
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
|
||||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
|
||||||
<el-button
|
|
||||||
type="primary"
|
|
||||||
plain
|
|
||||||
@click="openForm('create')"
|
|
||||||
v-hasPermi="['infra:category:create']"
|
|
||||||
>
|
>
|
||||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
<el-form-item label="文件名" prop="name">
|
||||||
</el-button>
|
<el-input
|
||||||
<el-button
|
v-model="queryParams.name"
|
||||||
type="success"
|
placeholder="请输入用户名称"
|
||||||
plain
|
clearable
|
||||||
@click="handleExport"
|
@keyup.enter="handleQuery"
|
||||||
:loading="exportLoading"
|
class="!w-240px"
|
||||||
v-hasPermi="['infra:category:export']"
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="创建时间" prop="createTime">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="queryParams.createTime"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
type="datetimerange"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
|
||||||
|
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
|
||||||
|
<el-upload
|
||||||
|
v-if="curCategoryId"
|
||||||
|
:show-file-list="false"
|
||||||
|
style="margin-left: 12px"
|
||||||
|
:action="uploadUrl"
|
||||||
|
:http-request="handleRequest"
|
||||||
|
multiple
|
||||||
|
>
|
||||||
|
<el-button type="primary" plain> <Icon icon="ep:plus" /> 新增 </el-button>
|
||||||
|
</el-upload>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</ContentWrap>
|
||||||
|
<!-- 文件列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
<el-table
|
||||||
|
v-loading="fileListLoading"
|
||||||
|
:data="fileList"
|
||||||
|
:stripe="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
row-key="id"
|
||||||
>
|
>
|
||||||
<Icon icon="ep:download" class="mr-5px" /> 导出
|
<el-table-column label="id" align="center" prop="id" width="150" />
|
||||||
</el-button>
|
<el-table-column label="文件名称" align="center" prop="name" />
|
||||||
<el-button type="danger" plain @click="toggleExpandAll">
|
<el-table-column label="文件地址" align="center" prop="url" />
|
||||||
<Icon icon="ep:sort" class="mr-5px" /> 展开/折叠
|
<el-table-column
|
||||||
</el-button>
|
label="创建时间"
|
||||||
</el-form-item>
|
align="center"
|
||||||
</el-form>
|
prop="createTime"
|
||||||
</ContentWrap>
|
:formatter="dateFormatter"
|
||||||
|
width="180"
|
||||||
<!-- 列表 -->
|
/>
|
||||||
<ContentWrap>
|
<el-table-column label="操作" align="center" width="200">
|
||||||
<el-table
|
<template #default="scope">
|
||||||
v-loading="loading"
|
<el-button link type="primary" @click="downloadFile(scope.row.url)"> 下载 </el-button>
|
||||||
:data="list"
|
<el-button link type="danger" @click="deleteFile(scope.row.id)"> 删除 </el-button>
|
||||||
:stripe="true"
|
</template>
|
||||||
:show-overflow-tooltip="true"
|
</el-table-column>
|
||||||
row-key="id"
|
</el-table>
|
||||||
:default-expand-all="isExpandAll"
|
<!-- 分页 -->
|
||||||
v-if="refreshTable"
|
<Pagination
|
||||||
>
|
:total="total"
|
||||||
<el-table-column label="id" align="center" prop="id" />
|
v-model:page="queryParams.pageNo"
|
||||||
<el-table-column label="文件夹名称" align="center" prop="name" />
|
v-model:limit="queryParams.pageSize"
|
||||||
<el-table-column label="编号" align="center" prop="code" />
|
@pagination="getFileList"
|
||||||
<el-table-column label="上一级id" align="center" prop="parentId" />
|
/>
|
||||||
<el-table-column label="描述" align="center" prop="description" />
|
</ContentWrap>
|
||||||
<el-table-column label="操作" align="center">
|
</el-col>
|
||||||
<template #default="scope">
|
</el-row>
|
||||||
<el-button
|
|
||||||
link
|
|
||||||
type="primary"
|
|
||||||
@click="openForm('update', scope.row.id)"
|
|
||||||
v-hasPermi="['infra:category:update']"
|
|
||||||
>
|
|
||||||
编辑
|
|
||||||
</el-button>
|
|
||||||
<el-button
|
|
||||||
link
|
|
||||||
type="danger"
|
|
||||||
@click="handleDelete(scope.row.id)"
|
|
||||||
v-hasPermi="['infra:category:delete']"
|
|
||||||
>
|
|
||||||
删除
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
<!-- 分页 -->
|
|
||||||
<Pagination
|
|
||||||
:total="total"
|
|
||||||
v-model:page="queryParams.pageNo"
|
|
||||||
v-model:limit="queryParams.pageSize"
|
|
||||||
@pagination="getList"
|
|
||||||
/>
|
|
||||||
</ContentWrap>
|
|
||||||
|
|
||||||
<!-- 表单弹窗:添加/修改 -->
|
|
||||||
<CategoryForm ref="formRef" @success="getList" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { handleTree } from '@/utils/tree'
|
|
||||||
import download from '@/utils/download'
|
|
||||||
import { CategoryApi, CategoryVO } from '@/api/infra/category'
|
import { CategoryApi, CategoryVO } from '@/api/infra/category'
|
||||||
import CategoryForm from './CategoryForm.vue'
|
import * as FileApi from '@/api/infra/file'
|
||||||
|
import FolderTree from './FolderTree.vue'
|
||||||
|
import { ElTree, UploadRequestOptions } from 'element-plus'
|
||||||
|
import { useUpload, ResponseFile } from '@/components/UploadFile/src/useUpload'
|
||||||
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
|
|
||||||
/** 文件目录 列表 */
|
/** 文件目录 列表 */
|
||||||
defineOptions({ name: 'Category' })
|
defineOptions({ name: 'Category' })
|
||||||
|
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
|
const { uploadUrl, httpRequest } = useUpload()
|
||||||
|
|
||||||
const loading = ref(true) // 列表的加载中
|
|
||||||
const list = ref<CategoryVO[]>([]) // 列表的数据
|
|
||||||
const queryParams = reactive({
|
|
||||||
code: undefined,
|
|
||||||
name: undefined,
|
|
||||||
})
|
|
||||||
const queryFormRef = ref() // 搜索的表单
|
const queryFormRef = ref() // 搜索的表单
|
||||||
const exportLoading = ref(false) // 导出的加载中
|
|
||||||
|
|
||||||
/** 查询列表 */
|
const queryParams = reactive({
|
||||||
const getList = async () => {
|
pageNo: 1,
|
||||||
loading.value = true
|
pageSize: 10,
|
||||||
try {
|
createTime: [],
|
||||||
const data = await CategoryApi.getCategoryList(queryParams)
|
name: undefined
|
||||||
list.value = handleTree(data, 'id', 'parentId')
|
})
|
||||||
} finally {
|
const total = ref<number>(0)
|
||||||
loading.value = false
|
|
||||||
}
|
// 当前文件夹id
|
||||||
}
|
const curCategoryId = ref<number>()
|
||||||
|
const fileList = ref([])
|
||||||
|
const fileListLoading = ref(false)
|
||||||
|
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
const handleQuery = () => {
|
const handleQuery = () => {
|
||||||
queryParams.pageNo = 1
|
queryParams.pageNo = 1
|
||||||
getList()
|
getFileList()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 重置按钮操作 */
|
/** 重置按钮操作 */
|
||||||
const resetQuery = () => {
|
const resetQuery = () => {
|
||||||
queryFormRef.value.resetFields()
|
queryFormRef.value?.resetFields()
|
||||||
handleQuery()
|
handleQuery()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 添加/修改操作 */
|
/** 获取文件列表 */
|
||||||
const formRef = ref()
|
const getFileList = async () => {
|
||||||
const openForm = (type: string, id?: number) => {
|
fileListLoading.value = true
|
||||||
formRef.value.open(type, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 删除按钮操作 */
|
|
||||||
const handleDelete = async (id: number) => {
|
|
||||||
try {
|
try {
|
||||||
// 删除的二次确认
|
const data = await FileApi.getFilePage({
|
||||||
await message.delConfirm()
|
...queryParams,
|
||||||
// 发起删除
|
categoryId: curCategoryId.value
|
||||||
await CategoryApi.deleteCategory(id)
|
})
|
||||||
message.success(t('common.delSuccess'))
|
fileList.value = data.list
|
||||||
// 刷新列表
|
total.value = data.total
|
||||||
await getList()
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 导出按钮操作 */
|
|
||||||
const handleExport = async () => {
|
|
||||||
try {
|
|
||||||
// 导出的二次确认
|
|
||||||
await message.exportConfirm()
|
|
||||||
// 发起导出
|
|
||||||
exportLoading.value = true
|
|
||||||
const data = await CategoryApi.exportCategory(queryParams)
|
|
||||||
download.excel(data, '文件目录.xls')
|
|
||||||
} catch {
|
|
||||||
} finally {
|
} finally {
|
||||||
exportLoading.value = false
|
fileListLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 展开/折叠操作 */
|
/** 处理文件夹被点击 */
|
||||||
const isExpandAll = ref(true) // 是否展开,默认全部展开
|
const handleNodeClick = async (data: Tree) => {
|
||||||
const refreshTable = ref(true) // 重新渲染表格状态
|
curCategoryId.value = data.id
|
||||||
const toggleExpandAll = async () => {
|
getFileList()
|
||||||
refreshTable.value = false
|
|
||||||
isExpandAll.value = !isExpandAll.value
|
|
||||||
await nextTick()
|
|
||||||
refreshTable.value = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 初始化 **/
|
/** 上传文件 */
|
||||||
onMounted(() => {
|
const handleRequest = async (f: UploadRequestOptions) => {
|
||||||
getList()
|
if (!curCategoryId.value) {
|
||||||
})
|
message.error('请先选择一个文件目录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await httpRequest(f, { categoryId: curCategoryId.value })
|
||||||
|
message.success('新增成功')
|
||||||
|
getFileList()
|
||||||
|
} catch (e) {
|
||||||
|
message.error('上传文件失败')
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 下载文件 */
|
||||||
|
const downloadFile = (url: string) => {
|
||||||
|
window.open(url, '_blank')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除文件 */
|
||||||
|
const deleteFile = async (id: number) => {
|
||||||
|
// 删除的二次确认
|
||||||
|
await message.delConfirm()
|
||||||
|
// 发起删除
|
||||||
|
await FileApi.deleteFile(id)
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
// 刷新列表
|
||||||
|
getFileList()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user