feat: 缓存业务字典模块

This commit is contained in:
louis 2024-03-04 13:33:45 +08:00
parent 7d34d4ac83
commit 6a68e724df
5 changed files with 136 additions and 154 deletions

View File

@ -91,10 +91,10 @@ export async function dictTypeDelete(
} }
/** 一次性获取所有的字典类型(不分页) GET /api/system/dict-type/all*/ /** 一次性获取所有的字典类型(不分页) GET /api/system/dict-type/all*/
export async function dictTypeGetAll(params: API.DictTypeListParams, options?: RequestOptions) { export async function dictTypeGetAll(body: API.DictTypeListParams, options?: RequestOptions) {
return request<API.DictTypeEntity[]>('/api/system/dict-type/all', { return request<API.DictTypeEntity[]>('/api/system/dict-type/all', {
method: 'GET', method: 'POST',
params, data: body,
...(options || {}), ...(options || {}),
}); });
} }

View File

@ -231,6 +231,8 @@ declare namespace API {
status?: number; status?: number;
/** 备注 */ /** 备注 */
remark?: string; remark?: string;
/** 关联的字典项 */
dictItems?: DictItemEntity[];
id?: number; id?: number;
createdAt?: string; createdAt?: string;
updatedAt?: string; updatedAt?: string;

View File

@ -2,8 +2,9 @@ import { ref } from 'vue';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import Api from '@/api'; import Api from '@/api';
import { store } from '@/store'; import { store } from '@/store';
import { DictEnum } from '@/enums/dictEnum';
const needCachedKey = [ const needCachedKey = [
'contract_type', // 合同类型 DictEnum.ContractType, // 合同类型
]; ];
export const useDictStore = defineStore('dict', () => { export const useDictStore = defineStore('dict', () => {
@ -15,16 +16,8 @@ export const useDictStore = defineStore('dict', () => {
}); });
}; };
getDictTypes(); getDictTypes();
const getDictItemsByCode = async (code: string): Promise<API.DictItemEntity[]> => { const getDictItemsByCode = (code: string): API.DictItemEntity[] => {
try { return dictTypes.value.find((item) => item.code === code)?.dictItems || [];
const dictType = dictTypes.value.find((item) => item.code === code);
if (dictType) {
return await Api.systemDictItem.dictItemGetAllByTypeId(dictType.id!);
}
return Promise.resolve([]);
} catch (error) {
return Promise.reject(error);
}
}; };
return { dictTypes, getDictTypes, getDictItemsByCode }; return { dictTypes, getDictTypes, getDictItemsByCode };

View File

@ -1,97 +1,96 @@
import type { TableColumn } from '@/components/core/dynamic-table'; import type { TableColumn } from '@/components/core/dynamic-table';
import { ContractStatusEnum } from '@/enums/contractEnum'; import { ContractStatusEnum } from '@/enums/contractEnum';
import { DictEnum } from '@/enums/dictEnum';
import { useDictStore } from '@/store/modules/dict';
import { formatToDate } from '@/utils/dateUtil'; import { formatToDate } from '@/utils/dateUtil';
import { Tag, Button } from 'ant-design-vue'; import { Tag } from 'ant-design-vue';
export type TableListItem = API.ContractEntity; export type TableListItem = API.ContractEntity;
export type TableColumnItem = TableColumn<TableListItem>; export type TableColumnItem = TableColumn<TableListItem>;
const dictStore = useDictStore();
export const baseColumns = (ctx: { export const baseColumns: TableColumnItem[] = [
contractTypes: API.DictItemEntity[]; {
dynamicTableInstance; title: '编号',
}): TableColumnItem[] => { width: 100,
const { contractTypes } = ctx; maxWidth: 100,
return [ fixed: 'left',
{ dataIndex: 'contractNumber',
title: '编号', },
width: 100, {
maxWidth: 100, title: '标题',
fixed: 'left', width: 180,
dataIndex: 'contractNumber', dataIndex: 'title',
}, },
{ {
title: '标题', title: '类型',
width: 180, width: 80,
dataIndex: 'title', formItemProps: {
}, component: 'Select',
{ componentProps: {
title: '类型', options: dictStore
width: 80, .getDictItemsByCode(DictEnum.ContractType)
formItemProps: { .map(({ label, id }) => ({ value: id, label })),
component: 'Select',
componentProps: {
options: contractTypes.map(({ label, id }) => ({ value: id, label })),
},
},
dataIndex: 'type',
customRender: ({ record }) => {
return contractTypes?.length
? contractTypes.find((item) => item.id === record.type)?.label || ''
: '';
}, },
}, },
{ dataIndex: 'type',
title: '甲方', customRender: ({ record }) => {
width: 120, return dictStore.getDictItemsByCode(DictEnum.ContractType)?.length
dataIndex: 'partyA', ? dictStore
.getDictItemsByCode(DictEnum.ContractType)
.find((item) => item.id === record.type)?.label || ''
: '';
}, },
{ },
title: '乙方', {
width: 120, title: '甲方',
dataIndex: 'partyB', width: 120,
dataIndex: 'partyA',
},
{
title: '乙方',
width: 120,
dataIndex: 'partyB',
},
{
title: '签订时间',
width: 60,
maxWidth: 60,
hideInSearch: true,
dataIndex: 'signingDate',
customRender: ({ record }) => {
return formatToDate(record.signingDate);
}, },
{ },
title: '签订时间', {
width: 60, title: '交付期限',
maxWidth: 60, width: 60,
hideInSearch: true, maxWidth: 60,
dataIndex: 'signingDate', hideInSearch: true,
customRender: ({ record }) => { dataIndex: 'deliveryDeadline',
return formatToDate(record.signingDate); customRender: ({ record }) => {
return formatToDate(record.deliveryDeadline);
},
},
{
title: '审核结果',
dataIndex: 'status',
maxWidth: 60,
width: 60,
fixed: 'right',
formItemProps: {
component: 'Select',
componentProps: {
options: Object.values(ContractStatusEnum)
.filter((value) => typeof value === 'number')
.map((item) => formatStatus(item as ContractStatusEnum)),
}, },
}, },
{ customRender: ({ record }) => {
title: '交付期限', const { color, label } = formatStatus(record.status);
width: 60, return <Tag color={color}>{label}</Tag>;
maxWidth: 60,
hideInSearch: true,
dataIndex: 'deliveryDeadline',
customRender: ({ record }) => {
return formatToDate(record.deliveryDeadline);
},
}, },
{ },
title: '审核结果', ];
dataIndex: 'status',
maxWidth: 60,
width: 60,
fixed:'right',
formItemProps: {
component: 'Select',
componentProps: {
options: Object.values(ContractStatusEnum)
.filter((value) => typeof value === 'number')
.map((item) => formatStatus(item as ContractStatusEnum)),
},
},
customRender: ({ record }) => {
const { color, label } = formatStatus(record.status);
return <Tag color={color}>{label}</Tag>;
},
},
];
};
export function formatStatus(status: ContractStatusEnum): { export function formatStatus(status: ContractStatusEnum): {
color: string; color: string;

View File

@ -27,85 +27,73 @@
import { useTable } from '@/components/core/dynamic-table'; import { useTable } from '@/components/core/dynamic-table';
import { baseColumns, type TableColumnItem, type TableListItem } from './columns'; import { baseColumns, type TableColumnItem, type TableListItem } from './columns';
import Api from '@/api/'; import Api from '@/api/';
import { useDictStore } from '@/store/modules/dict';
import { onMounted, ref, type FunctionalComponent } from 'vue';
import { DictEnum } from '@/enums/dictEnum';
import { useFormModal, useModal } from '@/hooks/useModal'; import { useFormModal, useModal } from '@/hooks/useModal';
import { contractSchemas } from './formSchemas'; import { contractSchemas } from './formSchemas';
import { formatToDate } from '@/utils/dateUtil'; import { formatToDate } from '@/utils/dateUtil';
import { Button } from 'ant-design-vue'; import { Button } from 'ant-design-vue';
import AttachmentManage from '@/components/business/attachment-manage/index.vue'; import AttachmentManage from '@/components/business/attachment-manage/index.vue';
import AttachmentUpload from '@/components/business/attachment-upload/index.vue'; import AttachmentUpload from '@/components/business/attachment-upload/index.vue';
import { ref, onMounted, type FunctionalComponent } from 'vue';
defineOptions({ defineOptions({
name: 'Contract', name: 'Contract',
}); });
const [DynamicTable, dynamicTableInstance] = useTable(); const [DynamicTable, dynamicTableInstance] = useTable();
const [showModal] = useFormModal(); const [showModal] = useFormModal();
const [fnModal] = useModal(); const [fnModal] = useModal();
const { getDictItemsByCode } = useDictStore();
const contractTypes = ref<API.DictItemEntity[]>([]); const contractTypes = ref<API.DictItemEntity[]>([]);
const getContractTypes = async () => {
contractTypes.value = await getDictItemsByCode(DictEnum.ContractType);
};
const isUploadPopupVisiable = ref(false); const isUploadPopupVisiable = ref(false);
// contractList; // contractList;
let columns = ref<TableColumnItem[]>(); let columns = ref<TableColumnItem[]>();
onMounted(() => { onMounted(() => {
getContractTypes().then((res) => { columns.value = [
columns.value = [ ...baseColumns,
...baseColumns({ {
dynamicTableInstance, title: '附件',
contractTypes: contractTypes.value, width: 50,
}), maxWidth: 50,
{ hideInSearch: true,
title: '附件', fixed: 'right',
width: 50, dataIndex: 'files',
maxWidth: 50, customRender: ({ record }) => <FilesRender {...record} />,
hideInSearch: true, },
fixed: 'right', {
dataIndex: 'files', title: '操作',
customRender: ({ record }) => <FilesRender {...record} />, maxWidth: 80,
}, width: 80,
{ minWidth: 80,
title: '操作', dataIndex: 'ACTION',
maxWidth: 80, hideInSearch: true,
width: 80, fixed: 'right',
minWidth: 80, actions: ({ record }) => [
dataIndex: 'ACTION', {
hideInSearch: true, icon: 'ant-design:edit-outlined',
fixed: 'right', tooltip: '编辑',
actions: ({ record }) => [ auth: {
{ perm: 'app:contract:update',
icon: 'ant-design:edit-outlined', effect: 'disable',
tooltip: '编辑',
auth: {
perm: 'app:contract:update',
effect: 'disable',
},
onClick: () => openEditModal(record),
}, },
{ onClick: () => openEditModal(record),
icon: 'ant-design:delete-outlined', },
color: 'red', {
tooltip: '删除此合同', icon: 'ant-design:delete-outlined',
auth: 'app:contract:delete', color: 'red',
popConfirm: { tooltip: '删除此合同',
title: '你确定要删除吗?', auth: 'app:contract:delete',
placement: 'left', popConfirm: {
onConfirm: () => delRowConfirm(record.id), title: '你确定要删除吗?',
}, placement: 'left',
onConfirm: () => delRowConfirm(record.id),
}, },
{ },
icon: 'ant-design:cloud-upload-outlined', {
tooltip: '上传附件', icon: 'ant-design:cloud-upload-outlined',
onClick: () => openAttachmentUploadModal(record), tooltip: '上传附件',
}, onClick: () => openAttachmentUploadModal(record),
], },
}, ],
]; },
}); ];
}); });
const openAttachmentUploadModal = async (record: API.ContractEntity) => { const openAttachmentUploadModal = async (record: API.ContractEntity) => {