feat: 乙方公司管理
This commit is contained in:
parent
2af6a94072
commit
b5ccfe5e0e
|
@ -0,0 +1,104 @@
|
|||
import { request, type RequestOptions } from '@/utils/request';
|
||||
|
||||
/** 获取公司列表 GET /api/company */
|
||||
export async function companyList(params: API.CompanyParams, options?: RequestOptions) {
|
||||
return request<{
|
||||
items?: API.CompanyEntity[];
|
||||
meta?: {
|
||||
itemCount?: number;
|
||||
totalItems?: number;
|
||||
itemsPerPage?: number;
|
||||
totalPages?: number;
|
||||
currentPage?: number;
|
||||
};
|
||||
}>('/api/company', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
// page has a default value: 1
|
||||
page: '1',
|
||||
// pageSize has a default value: 10
|
||||
pageSize: '10',
|
||||
|
||||
...params,
|
||||
},
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** 新增公司 POST /api/company */
|
||||
export async function companyCreate(body: API.CompanyDto, options?: RequestOptions) {
|
||||
return request<any>('/api/company', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || { successMsg: '创建成功' }),
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取公司信息 GET /api/company/${param0} */
|
||||
export async function companyInfo(
|
||||
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
||||
params: API.CompanyInfoParams,
|
||||
options?: RequestOptions,
|
||||
) {
|
||||
const { id: param0, ...queryParams } = params;
|
||||
return request<API.CompanyEntity>(`/api/company/${param0}`, {
|
||||
method: 'GET',
|
||||
params: { ...queryParams },
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** 解除公司和附件关联 PUT /api/company/unlink-attachments/${param0} */
|
||||
export async function unlinkAttachments(
|
||||
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
||||
params: API.CompanyUpdateParams,
|
||||
body: API.CompanyUpdateDto,
|
||||
options?: RequestOptions,
|
||||
) {
|
||||
const { id: param0, ...queryParams } = params;
|
||||
return request<any>(`/api/company/unlink-attachments/${param0}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
params: { ...queryParams },
|
||||
data: body,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
/** 更新公司 PUT /api/company/${param0} */
|
||||
export async function companyUpdate(
|
||||
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
||||
params: API.CompanyUpdateParams,
|
||||
body: API.CompanyUpdateDto,
|
||||
options?: RequestOptions,
|
||||
) {
|
||||
const { id: param0, ...queryParams } = params;
|
||||
return request<any>(`/api/company/${param0}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
params: { ...queryParams },
|
||||
data: body,
|
||||
...(options || { successMsg: '更新成功' }),
|
||||
});
|
||||
}
|
||||
|
||||
/** 删除公司 DELETE /api/company/${param0} */
|
||||
export async function companyDelete(
|
||||
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
||||
params: API.CompanyDeleteParams,
|
||||
options?: RequestOptions,
|
||||
) {
|
||||
const { id: param0, ...queryParams } = params;
|
||||
return request<any>(`/api/company/${param0}`, {
|
||||
method: 'DELETE',
|
||||
params: { ...queryParams },
|
||||
...(options || { successMsg: '删除成功' }),
|
||||
});
|
||||
}
|
|
@ -27,6 +27,7 @@ import * as netDiskOverview from './netDiskOverview';
|
|||
import * as businessTodo from './businessTodo';
|
||||
import * as contract from './contract';
|
||||
import * as materialsInventory from './materialsInventory';
|
||||
import * as company from './company';
|
||||
|
||||
export default {
|
||||
auth,
|
||||
|
@ -53,5 +54,6 @@ export default {
|
|||
netDiskOverview,
|
||||
businessTodo,
|
||||
contract,
|
||||
materialsInventory
|
||||
materialsInventory,
|
||||
company,
|
||||
};
|
||||
|
|
|
@ -1417,7 +1417,7 @@ declare namespace API {
|
|||
/** 备注 */
|
||||
remark: string;
|
||||
/** 附件 */
|
||||
files: number[];
|
||||
files: StorageInfo[];
|
||||
id: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
|
@ -1464,7 +1464,7 @@ declare namespace API {
|
|||
/** 备注 */
|
||||
remark: string;
|
||||
/** 附件 */
|
||||
files: number[];
|
||||
files: StorageInfo[];
|
||||
};
|
||||
type MaterialsInventoryUpdateDto = {
|
||||
/** 公司名称 */
|
||||
|
@ -1508,9 +1508,48 @@ declare namespace API {
|
|||
/** 备注 */
|
||||
remark: string;
|
||||
/** 附件 */
|
||||
files: number[];
|
||||
fileIds: number[];
|
||||
};
|
||||
type MaterialsInventoryDeleteParams = {
|
||||
id: number;
|
||||
};
|
||||
type CompanyEntity = {
|
||||
/** 公司名称 */
|
||||
name: string;
|
||||
/** 是否删除 */
|
||||
isDelete: string;
|
||||
/** 附件 */
|
||||
files?: StorageInfo[];
|
||||
id: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
type CompanyDto = {
|
||||
/** 公司名称 */
|
||||
name: string;
|
||||
fileIds?: number[];
|
||||
};
|
||||
type CompanyUpdateParams = {
|
||||
id: number;
|
||||
};
|
||||
type CompanyParams = {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
field?: string;
|
||||
order?: 'ASC' | 'DESC';
|
||||
_t?: number;
|
||||
};
|
||||
type CompanyInfoParams = {
|
||||
id: number;
|
||||
};
|
||||
type CompanyUpdateDto = {
|
||||
/** 公司名称 */
|
||||
name?: string;
|
||||
/** 附件 */
|
||||
fileIds?: number[];
|
||||
};
|
||||
type CompanyDeleteParams = {
|
||||
id: number;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -72,10 +72,19 @@ const permissions = [
|
|||
"netdisk:manage:cut",
|
||||
"netdisk:overview:desc",
|
||||
"app:contract:list",
|
||||
"app:materials_inventory:list",
|
||||
"app:contract:update",
|
||||
"app:contract:delete",
|
||||
"app:contract:read",
|
||||
"app:contract:create"
|
||||
"app:contract:create",
|
||||
"app:materials_inventory:create",
|
||||
"app:materials_inventory:update",
|
||||
"app:materials_inventory:delete",
|
||||
"app:company:list",
|
||||
"app:company:read",
|
||||
"app:company:create",
|
||||
"app:company:update",
|
||||
"app:company:delete"
|
||||
] as const;
|
||||
|
||||
export type PermissionType = (typeof permissions)[number];
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import type { TableColumn } from '@/components/core/dynamic-table';
|
||||
|
||||
export type TableListItem = API.CompanyEntity;
|
||||
export type TableColumnItem = TableColumn<TableListItem>;
|
||||
export const baseColumns: TableColumnItem[] = [
|
||||
{
|
||||
title: '公司名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
];
|
|
@ -0,0 +1,12 @@
|
|||
import type { FormSchema } from '@/components/core/schema-form/';
|
||||
export const formSchemas: FormSchema<API.CompanyEntity>[] = [
|
||||
{
|
||||
field: 'name',
|
||||
component: 'Input',
|
||||
label: '公司名称',
|
||||
rules: [{ required: true, type: 'string' }],
|
||||
colProps: {
|
||||
span: 12,
|
||||
},
|
||||
},
|
||||
];
|
|
@ -0,0 +1,201 @@
|
|||
<template>
|
||||
<div v-if="columns?.length">
|
||||
<DynamicTable
|
||||
row-key="id"
|
||||
header-title="公司管理"
|
||||
title-tooltip=""
|
||||
:data-request="Api.company.companyList"
|
||||
:columns="columns"
|
||||
bordered
|
||||
size="small"
|
||||
>
|
||||
<template #toolbar>
|
||||
<a-button
|
||||
type="primary"
|
||||
:disabled="!$auth('system:role:create')"
|
||||
@click="openEditModal({})"
|
||||
>
|
||||
新增
|
||||
</a-button>
|
||||
</template>
|
||||
</DynamicTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="tsx">
|
||||
import { useTable } from '@/components/core/dynamic-table';
|
||||
import { baseColumns, type TableColumnItem, type TableListItem } from './columns';
|
||||
import Api from '@/api/';
|
||||
import { useFormModal, useModal } from '@/hooks/useModal';
|
||||
import { formSchemas } from './formSchemas';
|
||||
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';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
defineOptions({
|
||||
name: 'Company',
|
||||
});
|
||||
const [DynamicTable, dynamicTableInstance] = useTable();
|
||||
const [showModal] = useFormModal();
|
||||
const [fnModal] = useModal();
|
||||
const isUploadPopupVisiable = ref(false);
|
||||
const dictStore = useDictStore();
|
||||
// companyList;
|
||||
let columns = ref<TableColumnItem[]>();
|
||||
onMounted(() => {
|
||||
columns.value = [
|
||||
...baseColumns,
|
||||
{
|
||||
title: '附件',
|
||||
width: 50,
|
||||
maxWidth: 50,
|
||||
hideInSearch: true,
|
||||
dataIndex: 'files',
|
||||
customRender: ({ record }) => <FilesRender {...record} />,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
maxWidth: 150,
|
||||
width: 150,
|
||||
minWidth: 150,
|
||||
fixed:'right',
|
||||
dataIndex: 'ACTION',
|
||||
hideInSearch: true,
|
||||
actions: ({ record }) => [
|
||||
{
|
||||
icon: 'ant-design:edit-outlined',
|
||||
tooltip: '编辑',
|
||||
auth: {
|
||||
perm: 'app:company:update',
|
||||
effect: 'disable',
|
||||
},
|
||||
onClick: () => openEditModal(record),
|
||||
},
|
||||
{
|
||||
icon: 'ant-design:delete-outlined',
|
||||
color: 'red',
|
||||
tooltip: '删除此公司',
|
||||
auth: 'app:company:delete',
|
||||
popConfirm: {
|
||||
title: '你确定要删除吗?',
|
||||
placement: 'left',
|
||||
onConfirm: () => delRowConfirm(record.id),
|
||||
},
|
||||
},
|
||||
{
|
||||
icon: 'ant-design:cloud-upload-outlined',
|
||||
tooltip: '上传附件',
|
||||
onClick: () => openAttachmentUploadModal(record),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
const openAttachmentUploadModal = async (record: TableListItem) => {
|
||||
isUploadPopupVisiable.value = true;
|
||||
fnModal.show({
|
||||
width: 800,
|
||||
title: `公司: ${record.name}`,
|
||||
content: () => {
|
||||
return (
|
||||
<AttachmentUpload
|
||||
onClose={handleUploadClose}
|
||||
afterUploadCallback={(files) => {
|
||||
afterUploadCallback(files, record.id);
|
||||
}}
|
||||
></AttachmentUpload>
|
||||
);
|
||||
},
|
||||
destroyOnClose: true,
|
||||
open: isUploadPopupVisiable.value,
|
||||
footer: null,
|
||||
});
|
||||
};
|
||||
const handleUploadClose = (hasSuccess: boolean) => {
|
||||
fnModal.hide();
|
||||
isUploadPopupVisiable.value = false;
|
||||
};
|
||||
const afterUploadCallback = async (
|
||||
files: { filename: { path: string; id: number } }[],
|
||||
id: number,
|
||||
) => {
|
||||
await Api.company.companyUpdate({ id }, { fileIds: files.map((item) => item.filename.id) });
|
||||
dynamicTableInstance?.reload();
|
||||
};
|
||||
|
||||
/**
|
||||
* @description 打开新增/编辑弹窗
|
||||
*/
|
||||
const openEditModal = async (record: Partial<TableListItem>) => {
|
||||
const [formRef] = await showModal({
|
||||
modalProps: {
|
||||
title: `${record.id ? '编辑' : '新增'}公司`,
|
||||
width: '50%',
|
||||
onFinish: async (values) => {
|
||||
if (record.id) {
|
||||
await Api.company.companyUpdate({ id: record.id }, values);
|
||||
} else {
|
||||
await Api.company.companyCreate(values);
|
||||
}
|
||||
dynamicTableInstance?.reload();
|
||||
},
|
||||
},
|
||||
formProps: {
|
||||
labelWidth: 100,
|
||||
schemas: formSchemas,
|
||||
},
|
||||
});
|
||||
|
||||
// 如果是编辑的话,需要获取角色详情
|
||||
if (record.id) {
|
||||
const info = await Api.company.companyInfo({ id: record.id });
|
||||
formRef?.setFieldsValue({
|
||||
...info,
|
||||
});
|
||||
}
|
||||
};
|
||||
const delRowConfirm = async (record) => {
|
||||
await Api.company.companyDelete({ id: record });
|
||||
dynamicTableInstance?.reload();
|
||||
};
|
||||
|
||||
const FilesRender: FunctionalComponent<TableListItem> = (company: TableListItem) => {
|
||||
const [fnModal] = useModal();
|
||||
return (
|
||||
<Button
|
||||
type="link"
|
||||
onClick={() => {
|
||||
openFilesManageModal(fnModal, company);
|
||||
}}
|
||||
>
|
||||
{company.files?.length || 0}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
const openFilesManageModal = (fnModal, company: TableListItem) => {
|
||||
const fileIds = company.files?.map((item) => item.id) || [];
|
||||
fnModal.show({
|
||||
width: 1200,
|
||||
title: `附件管理`,
|
||||
content: () => {
|
||||
return (
|
||||
<AttachmentManage
|
||||
fileIds={fileIds}
|
||||
onDelete={(unlinkIds) => unlinkAttachments(company.id, unlinkIds)}
|
||||
></AttachmentManage>
|
||||
);
|
||||
},
|
||||
destroyOnClose: true,
|
||||
footer: null,
|
||||
});
|
||||
};
|
||||
const unlinkAttachments = async (id: number, unlinkIds: number[]) => {
|
||||
await Api.company.unlinkAttachments({ id }, { fileIds: unlinkIds });
|
||||
dynamicTableInstance?.reload();
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
Loading…
Reference in New Issue