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*/
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', {
method: 'GET',
params,
method: 'POST',
data: body,
...(options || {}),
});
}

View File

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

View File

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

View File

@ -1,97 +1,96 @@
import type { TableColumn } from '@/components/core/dynamic-table';
import { ContractStatusEnum } from '@/enums/contractEnum';
import { DictEnum } from '@/enums/dictEnum';
import { useDictStore } from '@/store/modules/dict';
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 TableColumnItem = TableColumn<TableListItem>;
export const baseColumns = (ctx: {
contractTypes: API.DictItemEntity[];
dynamicTableInstance;
}): TableColumnItem[] => {
const { contractTypes } = ctx;
return [
{
title: '编号',
width: 100,
maxWidth: 100,
fixed: 'left',
dataIndex: 'contractNumber',
},
{
title: '标题',
width: 180,
dataIndex: 'title',
},
{
title: '类型',
width: 80,
formItemProps: {
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 || ''
: '';
const dictStore = useDictStore();
export const baseColumns: TableColumnItem[] = [
{
title: '编号',
width: 100,
maxWidth: 100,
fixed: 'left',
dataIndex: 'contractNumber',
},
{
title: '标题',
width: 180,
dataIndex: 'title',
},
{
title: '类型',
width: 80,
formItemProps: {
component: 'Select',
componentProps: {
options: dictStore
.getDictItemsByCode(DictEnum.ContractType)
.map(({ label, id }) => ({ value: id, label })),
},
},
{
title: '甲方',
width: 120,
dataIndex: 'partyA',
dataIndex: 'type',
customRender: ({ record }) => {
return dictStore.getDictItemsByCode(DictEnum.ContractType)?.length
? dictStore
.getDictItemsByCode(DictEnum.ContractType)
.find((item) => item.id === record.type)?.label || ''
: '';
},
{
title: '乙方',
width: 120,
dataIndex: 'partyB',
},
{
title: '甲方',
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,
maxWidth: 60,
hideInSearch: true,
dataIndex: 'signingDate',
customRender: ({ record }) => {
return formatToDate(record.signingDate);
},
{
title: '交付期限',
width: 60,
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)),
},
},
{
title: '交付期限',
width: 60,
maxWidth: 60,
hideInSearch: true,
dataIndex: 'deliveryDeadline',
customRender: ({ record }) => {
return formatToDate(record.deliveryDeadline);
},
customRender: ({ record }) => {
const { color, label } = formatStatus(record.status);
return <Tag color={color}>{label}</Tag>;
},
{
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): {
color: string;

View File

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