Browse Source

Merge pull request 'Zyq' (#44) from Zyq into master

Reviewed-on: http://120.26.116.243:3000/root/alert-front/pulls/44
YKS
dreamglade 2 months ago
parent
commit
9e1170bbc8
  1. 42
      src/api/system/config/SystemConfig.ts
  2. 47
      src/views/system/config/SystemConfig/SystemConfig.ts
  3. 66
      src/views/system/config/SystemConfig/SystemConfigModal.vue
  4. 85
      src/views/system/config/SystemConfig/index.vue

42
src/api/system/config/SystemConfig.ts

@ -0,0 +1,42 @@
import { defHttp } from '@/utils/http/axios'
/**
* @description: VO
*/
export interface SystemConfigVO {
id?: number
name: string
abbreviation?: string
}
/**
* @description:
*/
export interface SystemConfigPageReqVO {
name?: string
}
// 查询系统配置分页列表
export function getSystemConfigPage(params: SystemConfigPageReqV) {
return defHttp.get({ url: '/system/system-config/page', params })
}
// 获取系统配置详情
export function getSystemConfig(id: number) {
return defHttp.get({ url: `/system/system-config/get?id=${id}` })
}
// 新增系统配置
export function createSystemConfig(data: SystemConfigVO) {
return defHttp.post({ url: '/system/system-config/create', data })
}
// 修改系统配置
export function updateSystemConfig(data: SystemConfigVO) {
return defHttp.put({ url: '/system/system-config/update', data })
}
// 删除系统配置
export function deleteSystemConfig(id: number) {
return defHttp.delete({ url: `/system/system-config/delete?id=${id}` })
}

47
src/views/system/config/SystemConfig/SystemConfig.ts

@ -0,0 +1,47 @@
import { h } from 'vue'
import { Tag } from 'ant-design-vue'
import type { BasicColumn, FormSchema } from '@/components/Table'
// 表格列定义
export const columns: BasicColumn[] = [
{
title: '系统名称',
dataIndex: 'name',
width: 180,
},
{
title: '系统简称',
dataIndex: 'abbreviation',
width: 180,
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 180,
// 使用 Vben 框架的方式格式化时间
customRender: ({ text }) => {
return h(Tag, { color: 'blue' }, () => text)
},
},
]
// 弹窗表单定义
export const formSchema: FormSchema[] = [
{
label: '编号',
field: 'id',
show: false, // 隐藏,仅用于表单绑定
component: 'Input',
},
{
label: '系统名称',
field: 'name',
required: true,
component: 'Input',
},
{
label: '系统简称',
field: 'abbreviation',
component: 'Input',
},
]

66
src/views/system/config/SystemConfig/SystemConfigModal.vue

@ -0,0 +1,66 @@
<script lang="ts" setup>
import { ref, unref } from 'vue'
import { formSchema } from './SystemConfig'
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 { createSystemConfig, getSystemConfig, updateSystemConfig } from '@/api/system/config/SystemConfig'
import type { SystemConfigVO } from '@/api/system/config/SystemConfig'
defineOptions({ name: 'SystemConfigModal' })
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 getSystemConfig(data.record.id)
setFieldsValue({ ...res })
}
})
async function handleSubmit() {
try {
const values = await validate()
setModalProps({ confirmLoading: true })
if (unref(isUpdate))
await updateSystemConfig(values as SystemConfigVO)
else
await createSystemConfig(values as SystemConfigVO)
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>

85
src/views/system/config/SystemConfig/index.vue

@ -0,0 +1,85 @@
<script lang="ts" setup>
import SystemConfigModal from './SystemConfigModal.vue'
import { columns } from './SystemConfig'
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 { deleteSystemConfig, getSystemConfigPage } from '@/api/system/config/SystemConfig'
defineOptions({ name: 'SystemConfig' })
const { t } = useI18n()
const { createMessage } = useMessage()
const [registerModal, { openModal }] = useModal()
const [registerTable, { reload }] = useTable({
title: '系统列表',
api: getSystemConfigPage, // API
columns,
rowKey: 'id',
pagination: true,
useSearchForm: false, // 使 true
bordered: true,
showIndexColumn: true,
actionColumn: {
width: 140,
title: t('common.action'),
dataIndex: 'action',
fixed: 'right',
},
})
function handleCreate() {
openModal(true, { isUpdate: false })
}
function handleEdit(record: Recordable) {
openModal(true, { record, isUpdate: true })
}
async function handleDelete(record: Recordable) {
await deleteSystemConfig(record.id)
createMessage.success(t('common.delSuccessText'))
reload() //
}
</script>
<template>
<div>
<BasicTable @register="registerTable">
<template #toolbar>
<a-button v-auth="'system:system-config: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:system-config:update', //
onClick: handleEdit.bind(null, record),
},
{
icon: IconEnum.DELETE,
danger: true,
label: t('action.delete'),
auth: 'system:system-config:delete', //
popConfirm: {
title: t('common.delMessage'),
placement: 'left',
confirm: handleDelete.bind(null, record),
},
},
]"
/>
</template>
</template>
</BasicTable>
<SystemConfigModal @register="registerModal" @success="reload()" />
</div>
</template>
Loading…
Cancel
Save