feat: 附件存储加入业务模块和业务记录id冗余,方便追踪文件来源

This commit is contained in:
louis 2024-03-08 13:19:09 +08:00
parent e7cdafc6f1
commit 4d281cd1cf
13 changed files with 120 additions and 11 deletions

View File

@ -1,5 +1,3 @@
// @ts-ignore
/* eslint-disable */
import { request, type RequestOptions } from '@/utils/request'; import { request, type RequestOptions } from '@/utils/request';
/** 上传 POST /api/tools/upload */ /** 上传 POST /api/tools/upload */

View File

@ -315,6 +315,10 @@ declare namespace API {
type FileUploadDto = { type FileUploadDto = {
/** 文件 */ /** 文件 */
file: Buffer; file: Buffer;
/** 业务模块 */
bussinessModule?: string;
/** 业务记录ID */
bussinessRecordId?: number;
}; };
type FlowInfo = { type FlowInfo = {
@ -928,6 +932,10 @@ declare namespace API {
createdAt: string; createdAt: string;
/** 上传者 */ /** 上传者 */
username: string; username: string;
/** 关联模块 */
bussinessModule: string;
/** 关联模块记录ID */
bussinessRecordId: string;
}; };
type StorageListParams = { type StorageListParams = {

View File

@ -26,11 +26,18 @@
name: 'AttachmentUpload', name: 'AttachmentUpload',
}); });
const emit = defineEmits(['close']); const emit = defineEmits(['close']);
const { afterUploadCallback } = defineProps({ const { afterUploadCallback, bussinessModule, bussinessRecordId } = defineProps({
afterUploadCallback: { afterUploadCallback: {
type: Function, type: Function,
default: () => ({}), default: () => ({}),
}, },
bussinessModule: {
type: String,
default: '',
},
bussinessRecordId: {
type: Number,
},
}); });
const [DynamicTable] = useTable(); const [DynamicTable] = useTable();
@ -67,13 +74,17 @@
const res = await Promise.all( const res = await Promise.all(
uploadFileList.map(async (item) => { uploadFileList.map(async (item) => {
try { try {
const itemRes = await Api.toolsUpload.uploadUpload({ file: item.file }, undefined, { const itemRes = await Api.toolsUpload.uploadUpload(
{ file: item.file, bussinessModule, bussinessRecordId },
undefined,
{
onUploadProgress(progressEvent) { onUploadProgress(progressEvent) {
const complete = ((progressEvent.loaded / progressEvent.total!) * 100) | 0; const complete = ((progressEvent.loaded / progressEvent.total!) * 100) | 0;
item.percent = complete; item.percent = complete;
item.status = UploadResultStatus.UPLOADING; item.status = UploadResultStatus.UPLOADING;
}, },
}); },
);
item.status = UploadResultStatus.SUCCESS; item.status = UploadResultStatus.SUCCESS;
return itemRes; return itemRes;
} catch (error) { } catch (error) {

View File

@ -0,0 +1,7 @@
export enum StorageBussinessModuleEnum {
Contract = 'contract',
Company = 'company',
MaterialsInOut = 'materialsInOut',
Product = 'product',
Project = 'project',
}

View File

@ -101,6 +101,8 @@
content: () => { content: () => {
return ( return (
<AttachmentUpload <AttachmentUpload
bussinessModule="contract"
bussinessRecordId={record.id}
onClose={handleUploadClose} onClose={handleUploadClose}
afterUploadCallback={(files) => { afterUploadCallback={(files) => {
afterUploadCallback(files, record.id); afterUploadCallback(files, record.id);

View File

@ -99,6 +99,8 @@
content: () => { content: () => {
return ( return (
<AttachmentUpload <AttachmentUpload
bussinessModule="company"
bussinessRecordId={record.id}
onClose={handleUploadClose} onClose={handleUploadClose}
afterUploadCallback={(files) => { afterUploadCallback={(files) => {
afterUploadCallback(files, record.id); afterUploadCallback(files, record.id);

View File

@ -2,6 +2,8 @@ import type { TableColumn } from '@/components/core/dynamic-table';
import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum'; import { MaterialsInOutEnum } from '@/enums/materialsInventoryEnum';
import { formatToDate } from '@/utils/dateUtil'; import { formatToDate } from '@/utils/dateUtil';
import { Tag } from 'ant-design-vue'; import { Tag } from 'ant-design-vue';
import { getProjectOptions } from './formSchemas';
import { debounce } from 'lodash-es';
export type TableListItem = API.MaterialsInOutEntity; export type TableListItem = API.MaterialsInOutEntity;
export type TableQueryItem = API.MaterialsInOutListParams; export type TableQueryItem = API.MaterialsInOutListParams;
@ -22,10 +24,50 @@ export const baseColumns: TableColumnItem[] = [
{ {
title: '项目', title: '项目',
width: 80, width: 80,
dataIndex: 'project', dataIndex: 'projectId',
customRender: ({ record }) => { customRender: ({ record }) => {
return record?.project?.name || ''; return record?.project?.name || '';
}, },
formItemProps: {
component:'Select',
componentProps: ({ formInstance, schema, formModel }) => ({
showSearch: true,
filterOption: false,
fieldNames: {
label: 'label',
value: 'value',
},
getPopupContainer: () => document.body,
defaultActiveFirstOption: true,
onClear: async () => {
const newSchema = {
field: schema.field,
componentProps: {
options: [] as LabelValueOptions,
},
};
const options = await getProjectOptions().finally(() => (schema.loading = false));
newSchema.componentProps.options = options;
formInstance?.updateSchema([newSchema]);
},
request: () => {
return getProjectOptions();
},
onSearch: debounce(async (keyword) => {
schema.loading = true;
const newSchema = {
field: schema.field,
componentProps: {
options: [] as LabelValueOptions,
},
};
formInstance?.updateSchema([newSchema]);
const options = await getProjectOptions(keyword).finally(() => (schema.loading = false));
newSchema.componentProps.options = options;
formInstance?.updateSchema([newSchema]);
}, 500),
}),
},
}, },
{ {
title: '所属公司', title: '所属公司',

View File

@ -237,7 +237,7 @@ export const formSchemas = (isEdit?: boolean): FormSchema<API.MaterialsInOutEnti
}, },
]; ];
const getProjectOptions = async (keyword?: string): Promise<LabelValueOptions> => { export const getProjectOptions = async (keyword?: string): Promise<LabelValueOptions> => {
const { items: result } = await Api.project.projectList({ pageSize: 100, name: keyword }); const { items: result } = await Api.project.projectList({ pageSize: 100, name: keyword });
return ( return (
result?.map((item) => ({ result?.map((item) => ({

View File

@ -145,6 +145,8 @@
return ( return (
<AttachmentUpload <AttachmentUpload
onClose={handleUploadClose} onClose={handleUploadClose}
bussinessModule="materialsInOut"
bussinessRecordId={record.id}
afterUploadCallback={(files) => { afterUploadCallback={(files) => {
afterUploadCallback(files, record.id); afterUploadCallback(files, record.id);
}} }}

View File

@ -101,6 +101,8 @@
content: () => { content: () => {
return ( return (
<AttachmentUpload <AttachmentUpload
bussinessModule="product"
bussinessRecordId={record.id}
onClose={handleUploadClose} onClose={handleUploadClose}
afterUploadCallback={(files) => { afterUploadCallback={(files) => {
afterUploadCallback(files, record.id); afterUploadCallback(files, record.id);

View File

@ -100,6 +100,8 @@
content: () => { content: () => {
return ( return (
<AttachmentUpload <AttachmentUpload
bussinessModule="project"
bussinessRecordId={record.id}
onClose={handleUploadClose} onClose={handleUploadClose}
afterUploadCallback={(files) => { afterUploadCallback={(files) => {
afterUploadCallback(files, record.id); afterUploadCallback(files, record.id);

View File

@ -3,6 +3,7 @@ import type { TableColumn } from '@/components/core/dynamic-table';
import type { FormSchema } from '@/components/core/schema-form'; import type { FormSchema } from '@/components/core/schema-form';
import { formatToDateTime } from '@/utils/dateUtil'; import { formatToDateTime } from '@/utils/dateUtil';
import { baseApiUrl } from '@/utils/request'; import { baseApiUrl } from '@/utils/request';
import { StorageBussinessModuleEnum } from '@/enums/storageBussinessModuleEnum';
export type TableListItem = API.StorageInfo; export type TableListItem = API.StorageInfo;
export type TableColumnItem = TableColumn<TableListItem>; export type TableColumnItem = TableColumn<TableListItem>;
@ -75,12 +76,26 @@ export const baseColumns: TableColumnItem[] = [
dataIndex: 'username', dataIndex: 'username',
width: 120, width: 120,
}, },
{ {
title: '创建时间', title: '创建时间',
dataIndex: 'createdAt', dataIndex: 'createdAt',
width: 160, width: 160,
customRender: ({ record }) => formatToDateTime(record.createdAt), customRender: ({ record }) => formatToDateTime(record.createdAt),
}, },
{
title: '关联业务模块',
dataIndex: 'bussinessModule',
width: 120,
customRender: ({ record }) => {
return formatBussinessModules(record.bussinessModule) || '';
},
},
{
title: '关联业务ID',
dataIndex: 'bussinessRecordId',
width: 80,
},
]; ];
export const fileListColumns: TableColumn<FileItem>[] = [ export const fileListColumns: TableColumn<FileItem>[] = [
@ -151,3 +166,19 @@ export const searchFormSchema: FormSchema[] = [
colProps: { span: 8 }, colProps: { span: 8 },
}, },
]; ];
const formatBussinessModules = (moduleName: string) => {
switch (moduleName) {
case StorageBussinessModuleEnum.Contract:
return '合同审核';
case StorageBussinessModuleEnum.Company:
return '乙方公司管理';
case StorageBussinessModuleEnum.MaterialsInOut:
return '原材料出入库记录';
case StorageBussinessModuleEnum.Product:
return '产品管理';
case StorageBussinessModuleEnum.Project:
return '项目管理';
default:
}
};

View File

@ -103,6 +103,8 @@
content: () => { content: () => {
return ( return (
<AttachmentUpload <AttachmentUpload
bussinessModule="vehicleUsage"
bussinessRecordId={record.id}
onClose={handleUploadClose} onClose={handleUploadClose}
afterUploadCallback={(files) => { afterUploadCallback={(files) => {
afterUploadCallback(files, record.id); afterUploadCallback(files, record.id);