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