5 changed files with 270 additions and 4 deletions
@ -0,0 +1,39 @@ |
|||||
|
import { defHttp } from '@/utils/http/axios' |
||||
|
|
||||
|
export interface CompanyVO { |
||||
|
id?: number |
||||
|
name: string // 集团名称
|
||||
|
short: string // 集团简称
|
||||
|
status: number // 状态
|
||||
|
createTime: Date // 创建时间
|
||||
|
} |
||||
|
|
||||
|
export interface CompanyPageReqVO { |
||||
|
name?: string |
||||
|
status?: number |
||||
|
} |
||||
|
|
||||
|
// 查询集团列表
|
||||
|
export function getCompanyPage(params: CompanyPageReqVO) { |
||||
|
return defHttp.get({ url: '/system/Company/page', params }) |
||||
|
} |
||||
|
|
||||
|
// 查询集团详情
|
||||
|
export function getCompany(id: number) { |
||||
|
return defHttp.get({ url: `/system/Company/get?id=${id}` }) |
||||
|
} |
||||
|
|
||||
|
// 新增集团
|
||||
|
export function createCompany(data: CompanyVO) { |
||||
|
return defHttp.post({ url: '/system/Company/create', data }) |
||||
|
} |
||||
|
|
||||
|
// 修改集团
|
||||
|
export function updateCompany(params: CompanyVO) { |
||||
|
return defHttp.put({ url: '/system/Company/update', data: params }) |
||||
|
} |
||||
|
|
||||
|
// 删除集团
|
||||
|
export function deleteCompany(id: number) { |
||||
|
return defHttp.delete({ url: `/system/Company/delete?id=${id}` }) |
||||
|
} |
@ -0,0 +1,79 @@ |
|||||
|
import type { BasicColumn, FormSchema } from '@/components/Table' |
||||
|
import { useRender } from '@/components/Table' |
||||
|
import { DICT_TYPE, getDictOptions } from '@/utils/dict' |
||||
|
|
||||
|
export const columns: BasicColumn[] = [ |
||||
|
{ |
||||
|
title: '集团名称', |
||||
|
dataIndex: 'name', |
||||
|
width: 260, |
||||
|
}, |
||||
|
{ |
||||
|
title: '集团简称', |
||||
|
dataIndex: 'shortName', // 注意:后端是 shortName,不是 short!
|
||||
|
width: 60, |
||||
|
}, |
||||
|
{ |
||||
|
title: '状态', |
||||
|
dataIndex: 'status', |
||||
|
width: 180, |
||||
|
customRender: ({ text }) => { |
||||
|
return useRender.renderDict(text, DICT_TYPE.COMMON_STATUS) |
||||
|
}, |
||||
|
}, |
||||
|
{ |
||||
|
title: '创建时间', |
||||
|
dataIndex: 'createTime', |
||||
|
width: 180, |
||||
|
customRender: ({ text }) => { |
||||
|
return useRender.renderDate(text) |
||||
|
}, |
||||
|
}, |
||||
|
] |
||||
|
|
||||
|
export const searchFormSchema: FormSchema[] = [ |
||||
|
{ |
||||
|
label: '集团名称', |
||||
|
field: 'name', |
||||
|
component: 'Input', |
||||
|
colProps: { span: 8 }, |
||||
|
}, |
||||
|
{ |
||||
|
label: '状态', |
||||
|
field: 'status', |
||||
|
component: 'Select', |
||||
|
componentProps: { |
||||
|
options: getDictOptions(DICT_TYPE.COMMON_STATUS), |
||||
|
}, |
||||
|
colProps: { span: 8 }, |
||||
|
}, |
||||
|
] |
||||
|
|
||||
|
export const formSchema: FormSchema[] = [ |
||||
|
{ |
||||
|
label: '编号', |
||||
|
field: 'id', |
||||
|
show: false, |
||||
|
component: 'Input', |
||||
|
}, |
||||
|
{ |
||||
|
label: '集团名称', |
||||
|
field: 'name', |
||||
|
required: true, |
||||
|
component: 'Input', |
||||
|
}, |
||||
|
{ |
||||
|
label: '集团简称', |
||||
|
field: 'shortName', // 注意:后端是 shortName,不是 short!
|
||||
|
required: true, |
||||
|
component: 'Input', |
||||
|
}, |
||||
|
{ |
||||
|
label: '集团状态', |
||||
|
field: 'status', |
||||
|
component: 'Select', |
||||
|
componentProps: { |
||||
|
options: getDictOptions(DICT_TYPE.COMMON_STATUS), |
||||
|
}, |
||||
|
}, |
||||
|
] |
@ -0,0 +1,63 @@ |
|||||
|
<script lang="ts" setup> |
||||
|
import { ref, unref } from 'vue' |
||||
|
import { formSchema } from './Company' |
||||
|
import { useI18n } from '@/hooks/web/useI18n' |
||||
|
import { useMessage } from '@/hooks/web/useMessage' |
||||
|
import { BasicForm, useForm } from '@/components/Form' |
||||
|
import { BasicModal, useModalInner } from '@/components/Modal' |
||||
|
import { createCompany, getCompany, updateCompany } from '@/api/system/unit/Company' |
||||
|
|
||||
|
defineOptions({ name: 'CompanyModal' }) |
||||
|
|
||||
|
const emit = defineEmits(['success', 'register']) |
||||
|
const { t } = useI18n() |
||||
|
const { createMessage } = useMessage() |
||||
|
const isUpdate = ref(true) |
||||
|
|
||||
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ |
||||
|
labelWidth: 120, |
||||
|
baseColProps: { span: 24 }, |
||||
|
schemas: formSchema, |
||||
|
showActionButtonGroup: false, |
||||
|
actionColOptions: { span: 23 }, |
||||
|
}) |
||||
|
|
||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
||||
|
resetFields() |
||||
|
setModalProps({ confirmLoading: false }) |
||||
|
isUpdate.value = !!data?.isUpdate |
||||
|
if (unref(isUpdate)) { |
||||
|
const res = await getCompany(data.record.id) |
||||
|
setFieldsValue({ ...res }) |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
async function handleSubmit() { |
||||
|
try { |
||||
|
const values = await validate() |
||||
|
setModalProps({ confirmLoading: true }) |
||||
|
if (unref(isUpdate)) |
||||
|
await updateCompany(values) |
||||
|
else |
||||
|
await createCompany(values) |
||||
|
|
||||
|
closeModal() |
||||
|
emit('success') |
||||
|
createMessage.success(t('common.saveSuccessText')) |
||||
|
} |
||||
|
finally { |
||||
|
setModalProps({ confirmLoading: false }) |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<template> |
||||
|
<BasicModal |
||||
|
v-bind="$attrs" :title="isUpdate ? t('action.edit') : t('action.create')" @register="registerModal" |
||||
|
@ok="handleSubmit" |
||||
|
> |
||||
|
<BasicForm @register="registerForm" /> |
||||
|
</BasicModal> |
||||
|
</template> |
||||
|
./Company |
||||
|
@/api/system/unit/Company |
@ -0,0 +1,89 @@ |
|||||
|
<script lang="ts" setup> |
||||
|
import CompanyModal from './CompanyModal.vue' |
||||
|
import { columns, searchFormSchema } from './Company' |
||||
|
import { useI18n } from '@/hooks/web/useI18n' |
||||
|
import { useMessage } from '@/hooks/web/useMessage' |
||||
|
import { useModal } from '@/components/Modal' |
||||
|
import { IconEnum } from '@/enums/appEnum' |
||||
|
import { BasicTable, TableAction, useTable } from '@/components/Table' |
||||
|
import { deleteCompany, getCompanyPage } from '@/api/system/unit/Company' |
||||
|
|
||||
|
defineOptions({ name: 'UnitCompany' }) |
||||
|
|
||||
|
const { t } = useI18n() |
||||
|
const { createMessage } = useMessage() |
||||
|
const [registerModal, { openModal }] = useModal() |
||||
|
|
||||
|
// 移除了 expandAll, collapseAll 相关的功能 |
||||
|
const [register, { getForm, reload }] = useTable({ |
||||
|
title: '集团列表', |
||||
|
api: getList, |
||||
|
columns, |
||||
|
rowKey: 'id', |
||||
|
formConfig: { labelWidth: 120, schemas: searchFormSchema }, |
||||
|
pagination: true, |
||||
|
useSearchForm: true, |
||||
|
showTableSetting: true, |
||||
|
showIndexColumn: false, |
||||
|
actionColumn: { |
||||
|
width: 140, |
||||
|
title: t('common.action'), |
||||
|
dataIndex: 'action', |
||||
|
fixed: 'right', |
||||
|
}, |
||||
|
}) |
||||
|
|
||||
|
async function getList() { |
||||
|
const res = await getCompanyPage(getForm().getFieldsValue() as any) |
||||
|
return res |
||||
|
} |
||||
|
|
||||
|
function handleCreate() { |
||||
|
openModal(true, { isUpdate: false }) |
||||
|
} |
||||
|
|
||||
|
function handleEdit(record: Recordable) { |
||||
|
openModal(true, { record, isUpdate: true }) |
||||
|
} |
||||
|
|
||||
|
async function handleDelete(record: Recordable) { |
||||
|
await deleteCompany(record.id) |
||||
|
createMessage.success(t('common.delSuccessText')) |
||||
|
reload() |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<template> |
||||
|
<div> |
||||
|
<BasicTable @register="register"> |
||||
|
<template #toolbar> |
||||
|
<a-button v-auth="['system:unit:create']" type="primary" :pre-icon="IconEnum.ADD" @click="handleCreate"> |
||||
|
{{ t('action.create') }} |
||||
|
</a-button> |
||||
|
</template> |
||||
|
<template #bodyCell="{ column, record }"> |
||||
|
<template v-if="column.key === 'action'"> |
||||
|
<TableAction |
||||
|
:actions="[ |
||||
|
{ icon: IconEnum.EDIT, label: t('action.edit'), auth: 'system:unit:update', onClick: handleEdit.bind(null, record) }, |
||||
|
{ |
||||
|
icon: IconEnum.DELETE, |
||||
|
danger: true, |
||||
|
label: t('action.delete'), |
||||
|
auth: 'system:unit:delete', |
||||
|
popConfirm: { |
||||
|
title: t('common.delMessage'), |
||||
|
placement: 'left', |
||||
|
confirm: handleDelete.bind(null, record), |
||||
|
}, |
||||
|
}, |
||||
|
]" |
||||
|
/> |
||||
|
</template> |
||||
|
</template> |
||||
|
</BasicTable> |
||||
|
<CompanyModal @register="registerModal" @success="reload()" /> |
||||
|
</div> |
||||
|
</template> |
||||
|
./Company |
||||
|
@/api/system/unit/Company |
Loading…
Reference in new issue