diff --git a/src/api/v1/files.ts b/src/api/v1/files.ts index a5ab909..d2eb845 100644 --- a/src/api/v1/files.ts +++ b/src/api/v1/files.ts @@ -16,14 +16,24 @@ export const downloadFilesByFilepath = (data: any) => { return http.request('get', `files/downloadFilesByFilepath`, { params: data, responseType: 'blob' }); }; +/** 系统文件管理---获取所有文件类型 */ +export const fetchGetAllMediaTypes = () => { + return http.request>('get', `files/getAllMediaTypes`); +}; + +/** 系统文件管理---获取所有文件类型 */ +export const fetchGetAllFilesStoragePath = () => { + return http.request>('get', `files/getAllFilesStoragePath`); +}; + /** 系统文件管理---添加系统文件管理 */ export const fetchAddFiles = (data: any) => { - return http.request>('post', 'files/addFiles', { data }); + return http.request>('post', 'files/addFiles', { data }, { headers: { 'Content-Type': 'multipart/form-data' } }); }; /** 系统文件管理---更新系统文件管理 */ export const fetchUpdateFiles = (data: any) => { - return http.request>('put', 'files/updateFiles', { data }); + return http.request>('put', 'files/updateFiles', { data }, { headers: { 'Content-Type': 'multipart/form-data' } }); }; /** 系统文件管理---删除系统文件管理 */ diff --git a/src/store/monitor/files.ts b/src/store/monitor/files.ts index 9d83e98..ac14dbc 100644 --- a/src/store/monitor/files.ts +++ b/src/store/monitor/files.ts @@ -1,5 +1,5 @@ import { defineStore } from 'pinia'; -import { fetchAddFiles, fetchDeleteFiles, fetchGetFilesList, fetchUpdateFiles } from '@/api/v1/files'; +import { fetchAddFiles, fetchDeleteFiles, fetchGetAllFilesStoragePath, fetchGetAllMediaTypes, fetchGetFilesList, fetchUpdateFiles } from '@/api/v1/files'; import { pageSizes } from '@/enums/baseConstant'; import { storeMessage } from '@/utils/message'; import { storePagination } from '@/store/useStorePagination'; @@ -12,6 +12,10 @@ export const useFilesStore = defineStore('filesStore', { return { // 系统文件表列表 datalist: [], + // 所有文件类型 + allMediaTypes: [], + // 所有文件存储路径 + allFilesStoragePath: [], // 查询表单 form: { // 文件的名称 @@ -52,6 +56,22 @@ export const useFilesStore = defineStore('filesStore', { return pagination(result); }, + /** 获取所有文件类型 */ + async getAllMediaTypes() { + const result = await fetchGetAllMediaTypes(); + if (result.code === 200) { + this.allMediaTypes = result.data; + } + }, + + /** 获取所有文件类型 */ + async getAllFilesStoragePath() { + const result = await fetchGetAllFilesStoragePath(); + if (result.code === 200) { + this.allFilesStoragePath = result.data; + } + }, + /** 添加系统文件表 */ async addFiles(data: any) { const result = await fetchAddFiles(data); diff --git a/src/views/monitor/files/files-dialog.vue b/src/views/monitor/files/files-dialog.vue index ea48e95..fe7cced 100644 --- a/src/views/monitor/files/files-dialog.vue +++ b/src/views/monitor/files/files-dialog.vue @@ -1,9 +1,11 @@ diff --git a/src/views/monitor/files/utils/columns.ts b/src/views/monitor/files/utils/columns.ts index 813a292..fa315cb 100644 --- a/src/views/monitor/files/utils/columns.ts +++ b/src/views/monitor/files/utils/columns.ts @@ -21,11 +21,17 @@ export const columns: TableColumnList = [ ]; // 添加规则 -export const rules = reactive({ - // 文件的名称 - filename: [{ required: true, message: `${$t('input')}${$t('files_filename')}`, trigger: 'blur' }], +export const addRules = reactive({ // 文件在服务器上的存储路径 filepath: [{ required: true, message: `${$t('input')}${$t('files_filepath')}`, trigger: 'blur' }], + // 文件列表 + files: [{ required: true, message: `${$t('files')}`, trigger: 'blur' }], +}); + +// 上传规则 +export const uploadRules = reactive({ + // 文件的名称 + filename: [{ required: true, message: `${$t('input')}${$t('files_filename')}`, trigger: 'blur' }], // 文件的MIME类型 fileType: [{ required: true, message: `${$t('input')}${$t('files_fileType')}`, trigger: 'blur' }], }); diff --git a/src/views/monitor/files/utils/hooks.ts b/src/views/monitor/files/utils/hooks.ts index 6af9700..2d499e2 100644 --- a/src/views/monitor/files/utils/hooks.ts +++ b/src/views/monitor/files/utils/hooks.ts @@ -7,6 +7,7 @@ import type { FormItemProps } from '@/views/monitor/files/utils/types'; import { $t } from '@/plugins/i18n'; import { downloadFilesByFileId, downloadFilesByFilepath } from '@/api/v1/files'; import { download } from '@/utils/sso'; +import type { UploadFiles } from 'element-plus'; // 选择的row列表 export const selectRows = ref([]); @@ -31,10 +32,10 @@ export function onAdd() { width: '30%', props: { formInline: { - filename: undefined, filepath: undefined, - fileType: undefined, - downloadCount: undefined, + downloadCount: 0, + files: [], + isAdd: false, }, }, draggable: true, @@ -46,7 +47,12 @@ export function onAdd() { formRef.value.formRef.validate(async (valid: any) => { if (!valid) return; - const result = await filesStore.addFiles(form); + // 添加文件 + form.files = (form.files as UploadFiles).map(file => file.raw); + const data = { filepath: form.filepath, downloadCount: form.downloadCount, files: form.files }; + const result = await filesStore.addFiles(data); + + // 成功后关闭窗口 if (!result) return; done(); await onSearch(); @@ -66,9 +72,10 @@ export function onUpdate(row: any) { props: { formInline: { filename: row.filename, - filepath: row.filepath, fileType: row.fileType, + filepath: row.filepath, downloadCount: row.downloadCount, + isUpload: true, }, }, draggable: true, @@ -80,7 +87,11 @@ export function onUpdate(row: any) { formRef.value.formRef.validate(async (valid: any) => { if (!valid) return; + // 更新文件 + form.files = (form.files as UploadFiles).map(file => file.raw); const result = await filesStore.updateFiles({ ...form, id: row.id }); + + // 更新完成 if (!result) return; done(); await onSearch(); @@ -89,9 +100,7 @@ export function onUpdate(row: any) { }); } -/** - * * 删除系统文件表 - */ +/** 删除系统文件表 */ export const onDelete = async (row: any) => { const id = row.id; diff --git a/src/views/monitor/files/utils/types.ts b/src/views/monitor/files/utils/types.ts index ef4653a..fd56987 100644 --- a/src/views/monitor/files/utils/types.ts +++ b/src/views/monitor/files/utils/types.ts @@ -8,6 +8,10 @@ export interface FormItemProps { fileType: string; // 下载数量 downloadCount: number; + // 文件内容 + files: any; + // 是否是上传 + isUpload: boolean; } // 添加或修改表单Props diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue index c7a886e..bf76345 100644 --- a/src/views/system/dept/index.vue +++ b/src/views/system/dept/index.vue @@ -10,9 +10,10 @@ import EditPen from '@iconify-icons/ep/edit-pen'; import Refresh from '@iconify-icons/ep/refresh'; import { selectUserinfo } from '@/components/Table/Userinfo/columns'; import { $t } from '@/plugins/i18n'; -import { useDeptStore } from '@/store/system/dept.ts'; +import { useDeptStore } from '@/store/system/dept'; import { useRenderIcon } from '@/components/CommonIcon/src/hooks'; import { handleTree } from '@/utils/tree'; +import { FormInstance } from 'element-plus'; const tableRef = ref(); const formRef = ref(); @@ -48,7 +49,7 @@ const onSelectionChange = (rows: Array) => { * 重置表单 * @param formEl */ -const resetForm = async formEl => { +const resetForm = async (formEl: FormInstance | undefined) => { if (!formEl) return; formEl.resetFields(); await onSearch(); diff --git a/src/views/system/dept/user-select-search.vue b/src/views/system/dept/user-select-search.vue index 869f155..b159648 100644 --- a/src/views/system/dept/user-select-search.vue +++ b/src/views/system/dept/user-select-search.vue @@ -3,20 +3,19 @@ import { $t } from '@/plugins/i18n'; import { ref } from 'vue'; import LoadingSvg from '@/assets/svg/loading.svg'; import { useAdminUserStore } from '@/store/system/adminUser'; - -// 添加或者修改表单元素 -interface FormItemProps { - username: string; - manager: string; -} - -// 添加或修改表单Props -interface FormProps { - formInline: FormItemProps; -} +import { FormProps } from '@/views/system/dept/utils/types'; const props = withDefaults(defineProps(), { - formInline: () => ({}), + formInline: () => ({ + // 父级id + parentId: undefined, + // 管理者id + manager: undefined, + // 部门名称 + deptName: undefined, + // 部门简介 + summary: undefined, + }), }); const adminUserStore = useAdminUserStore(); diff --git a/src/views/system/dept/utils/types.ts b/src/views/system/dept/utils/types.ts index 7882b2a..c7b3027 100644 --- a/src/views/system/dept/utils/types.ts +++ b/src/views/system/dept/utils/types.ts @@ -8,8 +8,6 @@ export interface FormItemProps { deptName: string; // 部门简介 summary: string; - // 备注信息 - remarks: string; } // 添加或修改表单Props