5 changed files with 239 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||||
|
import type { GetParamListParams, Param } from './types' |
||||||
|
import { defHttp } from '@/utils/http/axios' |
||||||
|
|
||||||
|
export function getParamList(params: GetParamListParams) { |
||||||
|
return defHttp.get({ |
||||||
|
url: '/param/page', |
||||||
|
params, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
export function createParam(data: Partial<Param>) { |
||||||
|
return defHttp.post({ |
||||||
|
url: '/param/save', |
||||||
|
data, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
export function updateParam(data: Partial<Param>) { |
||||||
|
return defHttp.post({ |
||||||
|
url: '/param/update', |
||||||
|
data, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
export function deleteParam(id: string) { |
||||||
|
return defHttp.post({ |
||||||
|
url: `/param/remove?id=${id}`, |
||||||
|
}) |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
export interface GetParamListParams extends PageParam { |
||||||
|
paramName?: string |
||||||
|
paramKey?: string |
||||||
|
} |
||||||
|
|
||||||
|
export interface Param { |
||||||
|
id: string |
||||||
|
paramName: string |
||||||
|
paramKey: string |
||||||
|
paramValue: string |
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
<script lang="ts" setup> |
||||||
|
import { ref } from 'vue' |
||||||
|
import { formSchema } from './data' |
||||||
|
import { useMessage } from '@/hooks/web/useMessage' |
||||||
|
import { BasicForm, useForm } from '@/components/Form' |
||||||
|
import { BasicModal, useModalInner } from '@/components/Modal' |
||||||
|
import { createParam, updateParam } from '@/api/system/param' |
||||||
|
import type { Param } from '@/api/system/param/types' |
||||||
|
|
||||||
|
defineOptions({ name: 'ParamFormModal' }) |
||||||
|
|
||||||
|
const emit = defineEmits(['success', 'register']) |
||||||
|
|
||||||
|
const [registerForm, { setFieldsValue, validate }] = useForm({ |
||||||
|
labelWidth: 120, |
||||||
|
baseColProps: { span: 24 }, |
||||||
|
schemas: formSchema, |
||||||
|
showActionButtonGroup: false, |
||||||
|
}) |
||||||
|
|
||||||
|
const isUpdate = ref(false) |
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
||||||
|
isUpdate.value = true |
||||||
|
setFieldsValue(data) |
||||||
|
}) |
||||||
|
|
||||||
|
async function handleSubmit() { |
||||||
|
try { |
||||||
|
const values = await validate<Param>() |
||||||
|
setModalProps({ confirmLoading: true }) |
||||||
|
await (isUpdate.value ? updateParam(values) : createParam(values)) |
||||||
|
closeModal() |
||||||
|
emit('success') |
||||||
|
useMessage().createMessage.success('保存成功') |
||||||
|
} |
||||||
|
catch {} |
||||||
|
finally { |
||||||
|
setModalProps({ confirmLoading: false }) |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
||||||
|
|
||||||
|
<template> |
||||||
|
<BasicModal |
||||||
|
:title="isUpdate ? '编辑' : '新增'" |
||||||
|
:after-close="() => isUpdate = false" |
||||||
|
@register="registerModal" |
||||||
|
@ok="handleSubmit" |
||||||
|
> |
||||||
|
<BasicForm @register="registerForm" /> |
||||||
|
</BasicModal> |
||||||
|
</template> |
@ -0,0 +1,60 @@ |
|||||||
|
import type { BasicColumn, FormSchema } from '@/components/Table' |
||||||
|
|
||||||
|
export const columns: BasicColumn[] = [ |
||||||
|
{ |
||||||
|
title: '参数名称', |
||||||
|
dataIndex: 'paramName', |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '参数键名', |
||||||
|
dataIndex: 'paramKey', |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '参数键值', |
||||||
|
dataIndex: 'paramValue', |
||||||
|
}, |
||||||
|
] |
||||||
|
|
||||||
|
export const searchFormSchema: FormSchema[] = [ |
||||||
|
{ |
||||||
|
label: '参数名称', |
||||||
|
field: 'paramName', |
||||||
|
component: 'Input', |
||||||
|
colProps: { |
||||||
|
span: 6, |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '参数键名', |
||||||
|
field: 'paramKey', |
||||||
|
component: 'Input', |
||||||
|
colProps: { |
||||||
|
span: 6, |
||||||
|
}, |
||||||
|
}, |
||||||
|
] |
||||||
|
|
||||||
|
export const formSchema: FormSchema[] = [ |
||||||
|
{ |
||||||
|
label: '参数名称', |
||||||
|
field: 'paramName', |
||||||
|
fields: ['id'], |
||||||
|
required: true, |
||||||
|
component: 'Input', |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '参数键名', |
||||||
|
field: 'paramKey', |
||||||
|
required: true, |
||||||
|
component: 'Input', |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '参数键值', |
||||||
|
field: 'paramValue', |
||||||
|
required: true, |
||||||
|
component: 'InputTextArea', |
||||||
|
componentProps: { |
||||||
|
rows: 8, |
||||||
|
}, |
||||||
|
}, |
||||||
|
] |
@ -0,0 +1,87 @@ |
|||||||
|
<script lang="ts" setup> |
||||||
|
import { PlusOutlined } from '@ant-design/icons-vue' |
||||||
|
import ParamFormModal from './ParamFormModal.vue' |
||||||
|
import { columns, searchFormSchema } from './data' |
||||||
|
import { BasicTable, TableAction, useTable } from '@/components/Table' |
||||||
|
import { deleteParam, getParamList } from '@/api/system/param' |
||||||
|
import type { Param } from '@/api/system/param/types' |
||||||
|
import { useModal } from '@/components/Modal' |
||||||
|
import { useMessage } from '@/hooks/web/useMessage' |
||||||
|
import { usePermission } from '@/hooks/web/usePermission' |
||||||
|
|
||||||
|
defineOptions({ name: 'SystemParams' }) |
||||||
|
|
||||||
|
const [registerModal, { openModal }] = useModal<Param>() |
||||||
|
|
||||||
|
const [registerTable, { reload }] = useTable({ |
||||||
|
api: getParamList, |
||||||
|
columns, |
||||||
|
formConfig: { |
||||||
|
labelWidth: 100, |
||||||
|
schemas: searchFormSchema, |
||||||
|
actionColOptions: { span: 4 }, |
||||||
|
}, |
||||||
|
bordered: true, |
||||||
|
canResize: false, |
||||||
|
useSearchForm: true, |
||||||
|
actionColumn: { |
||||||
|
width: 160, |
||||||
|
title: '操作', |
||||||
|
dataIndex: 'action', |
||||||
|
fixed: 'right', |
||||||
|
auth: ['param_delete', 'param_edit'], |
||||||
|
}, |
||||||
|
}) |
||||||
|
|
||||||
|
async function handleDelete(id: string) { |
||||||
|
try { |
||||||
|
await deleteParam(id) |
||||||
|
useMessage().createMessage.success('删除成功!') |
||||||
|
reload() |
||||||
|
} |
||||||
|
catch {} |
||||||
|
} |
||||||
|
|
||||||
|
const { hasPermission } = usePermission() |
||||||
|
</script> |
||||||
|
|
||||||
|
<template> |
||||||
|
<div> |
||||||
|
<BasicTable :api="async () => ([] as Param[])" @register="registerTable"> |
||||||
|
<template v-if="hasPermission('param_add')" #tableTitle> |
||||||
|
<a-button type="primary" @click="openModal"> |
||||||
|
<PlusOutlined /> |
||||||
|
新建 |
||||||
|
</a-button> |
||||||
|
</template> |
||||||
|
|
||||||
|
<template #bodyCell="{ column, record }"> |
||||||
|
<template v-if="column.key === 'action'"> |
||||||
|
<TableAction |
||||||
|
:actions="[ |
||||||
|
{ |
||||||
|
icon: 'i-ant-design:edit-outlined', |
||||||
|
label: '编辑', |
||||||
|
auth: 'param_edit', |
||||||
|
onClick: () => openModal(true, record), |
||||||
|
}, |
||||||
|
{ |
||||||
|
icon: 'i-ant-design:delete-outlined', |
||||||
|
label: '删除', |
||||||
|
danger: true, |
||||||
|
auth: 'param_delete', |
||||||
|
popConfirm: { |
||||||
|
title: '确定要删除数据吗?', |
||||||
|
placement: 'left', |
||||||
|
confirm: () => handleDelete(record.id), |
||||||
|
}, |
||||||
|
}, |
||||||
|
]" |
||||||
|
/> |
||||||
|
</template> |
||||||
|
</template> |
||||||
|
</BasicTable> |
||||||
|
|
||||||
|
<ParamFormModal @register="registerModal" @success="reload()" /> |
||||||
|
</div> |
||||||
|
</template> |
Loading…
Reference in new issue