feat: 缓存业务字典模块
This commit is contained in:
parent
7d34d4ac83
commit
6a68e724df
|
@ -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 || {}),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -231,6 +231,8 @@ declare namespace API {
|
|||
status?: number;
|
||||
/** 备注 */
|
||||
remark?: string;
|
||||
/** 关联的字典项 */
|
||||
dictItems?: DictItemEntity[];
|
||||
id?: number;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
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 [
|
||||
const dictStore = useDictStore();
|
||||
export const baseColumns: TableColumnItem[] = [
|
||||
{
|
||||
title: '编号',
|
||||
width: 100,
|
||||
|
@ -30,13 +27,17 @@ export const baseColumns = (ctx: {
|
|||
formItemProps: {
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: contractTypes.map(({ label, id }) => ({ value: id, label })),
|
||||
options: dictStore
|
||||
.getDictItemsByCode(DictEnum.ContractType)
|
||||
.map(({ label, id }) => ({ value: id, label })),
|
||||
},
|
||||
},
|
||||
dataIndex: 'type',
|
||||
customRender: ({ record }) => {
|
||||
return contractTypes?.length
|
||||
? contractTypes.find((item) => item.id === record.type)?.label || ''
|
||||
return dictStore.getDictItemsByCode(DictEnum.ContractType)?.length
|
||||
? dictStore
|
||||
.getDictItemsByCode(DictEnum.ContractType)
|
||||
.find((item) => item.id === record.type)?.label || ''
|
||||
: '';
|
||||
},
|
||||
},
|
||||
|
@ -75,7 +76,7 @@ export const baseColumns = (ctx: {
|
|||
dataIndex: 'status',
|
||||
maxWidth: 60,
|
||||
width: 60,
|
||||
fixed:'right',
|
||||
fixed: 'right',
|
||||
formItemProps: {
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
|
@ -89,9 +90,7 @@ export const baseColumns = (ctx: {
|
|||
return <Tag color={color}>{label}</Tag>;
|
||||
},
|
||||
},
|
||||
|
||||
];
|
||||
};
|
||||
];
|
||||
|
||||
export function formatStatus(status: ContractStatusEnum): {
|
||||
color: string;
|
||||
|
|
|
@ -27,38 +27,27 @@
|
|||
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,
|
||||
}),
|
||||
...baseColumns,
|
||||
{
|
||||
title: '附件',
|
||||
width: 50,
|
||||
|
@ -106,7 +95,6 @@
|
|||
},
|
||||
];
|
||||
});
|
||||
});
|
||||
|
||||
const openAttachmentUploadModal = async (record: API.ContractEntity) => {
|
||||
isUploadPopupVisiable.value = true;
|
||||
|
|
Loading…
Reference in New Issue