From 6a68e724df7cc5512de1302194e2e60fbc619f86 Mon Sep 17 00:00:00 2001 From: louis <869322496@qq.com> Date: Mon, 4 Mar 2024 13:33:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=93=E5=AD=98=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/backend/api/systemDictType.ts | 6 +- src/api/backend/api/typings.d.ts | 2 + src/store/modules/dict.ts | 15 +-- src/views/contract/columns.tsx | 161 +++++++++++++------------- src/views/contract/index.vue | 106 ++++++++--------- 5 files changed, 136 insertions(+), 154 deletions(-) diff --git a/src/api/backend/api/systemDictType.ts b/src/api/backend/api/systemDictType.ts index b641303..997dfe0 100644 --- a/src/api/backend/api/systemDictType.ts +++ b/src/api/backend/api/systemDictType.ts @@ -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/system/dict-type/all', { - method: 'GET', - params, + method: 'POST', + data: body, ...(options || {}), }); } diff --git a/src/api/backend/api/typings.d.ts b/src/api/backend/api/typings.d.ts index b063b53..c99ec9a 100644 --- a/src/api/backend/api/typings.d.ts +++ b/src/api/backend/api/typings.d.ts @@ -231,6 +231,8 @@ declare namespace API { status?: number; /** 备注 */ remark?: string; + /** 关联的字典项 */ + dictItems?: DictItemEntity[]; id?: number; createdAt?: string; updatedAt?: string; diff --git a/src/store/modules/dict.ts b/src/store/modules/dict.ts index 459e310..f176545 100644 --- a/src/store/modules/dict.ts +++ b/src/store/modules/dict.ts @@ -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 => { - 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 }; diff --git a/src/views/contract/columns.tsx b/src/views/contract/columns.tsx index b1113d3..a65ee3b 100644 --- a/src/views/contract/columns.tsx +++ b/src/views/contract/columns.tsx @@ -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; - -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 {label}; }, - { - 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 {label}; - }, - }, - - ]; -}; + }, +]; export function formatStatus(status: ContractStatusEnum): { color: string; diff --git a/src/views/contract/index.vue b/src/views/contract/index.vue index 5ec2674..bbd4f3c 100644 --- a/src/views/contract/index.vue +++ b/src/views/contract/index.vue @@ -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([]); - - const getContractTypes = async () => { - contractTypes.value = await getDictItemsByCode(DictEnum.ContractType); - }; const isUploadPopupVisiable = ref(false); // contractList; let columns = ref(); onMounted(() => { - getContractTypes().then((res) => { - columns.value = [ - ...baseColumns({ - dynamicTableInstance, - contractTypes: contractTypes.value, - }), - { - title: '附件', - width: 50, - maxWidth: 50, - hideInSearch: true, - fixed: 'right', - dataIndex: 'files', - customRender: ({ 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 }) => , + }, + { + 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) => {