feat: menu init
parent
bcf8353fdc
commit
8ba4ef9b9a
|
@ -0,0 +1,58 @@
|
|||
<template>
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
<script lang="ts" setup name="MenuModel">
|
||||
import { ref, computed, unref } from 'vue'
|
||||
import { BasicModal, useModalInner } from '@/components/Modal'
|
||||
import { BasicForm, useForm } from '@/components/Form'
|
||||
import { formSchema } from './menu.data'
|
||||
import { createDeptApi, getDeptApi, updateDeptApi } from '@/api/system/dept'
|
||||
|
||||
const emit = defineEmits(['success', 'register'])
|
||||
const isUpdate = ref(true)
|
||||
const rowId = ref()
|
||||
|
||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||
labelWidth: 100,
|
||||
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 getDeptApi(data.record.id)
|
||||
rowId.value = res.id
|
||||
setFieldsValue({
|
||||
...res
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const getTitle = computed(() => (!unref(isUpdate) ? '新增部门' : '编辑部门'))
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
const values = await validate()
|
||||
setModalProps({ confirmLoading: true })
|
||||
if (unref(isUpdate)) {
|
||||
await updateDeptApi(values)
|
||||
} else {
|
||||
await createDeptApi(values)
|
||||
}
|
||||
closeModal()
|
||||
emit('success')
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false })
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -2,19 +2,51 @@
|
|||
<div>
|
||||
<BasicTable @register="register">
|
||||
<template #toolbar>
|
||||
<a-button type="primary" @click="expandAll">展开全部</a-button>
|
||||
<a-button type="primary" @click="collapseAll">折叠全部</a-button>
|
||||
<a-button type="primary" @click="handleCreate"> 新增 </a-button>
|
||||
<a-button type="info" @click="expandAll">展开全部</a-button>
|
||||
<a-button type="info" @click="collapseAll">折叠全部</a-button>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'action'">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
icon: 'clarity:note-edit-line',
|
||||
onClick: handleEdit.bind(null, record)
|
||||
},
|
||||
{
|
||||
icon: 'ant-design:delete-outlined',
|
||||
color: 'error',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
placement: 'left',
|
||||
confirm: handleDelete.bind(null, record)
|
||||
}
|
||||
}
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<DeptModel @register="registerModal" @success="reload()" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="Menu">
|
||||
import { BasicTable, useTable } from '@/components/Table'
|
||||
import { BasicTable, useTable, TableAction } from '@/components/Table'
|
||||
import { getMenuListApi } from '@/api/system/menu'
|
||||
import { columns, searchFormSchema } from './menu.data'
|
||||
const [register, { expandAll, collapseAll }] = useTable({
|
||||
import { useModal } from '@/components/Modal'
|
||||
import DeptModel from './MenuModel.vue'
|
||||
import { useMessage } from '@/hooks/web/useMessage'
|
||||
import { handleTree } from '@/utils/tree'
|
||||
import { deleteDeptApi } from '@/api/system/dept'
|
||||
|
||||
const { createMessage } = useMessage()
|
||||
const [registerModal, { openModal }] = useModal()
|
||||
|
||||
const [register, { expandAll, collapseAll, getForm, reload }] = useTable({
|
||||
title: '菜单列表',
|
||||
api: getMenuListApi,
|
||||
api: getList,
|
||||
columns,
|
||||
rowKey: 'id',
|
||||
formConfig: {
|
||||
|
@ -22,9 +54,13 @@ const [register, { expandAll, collapseAll }] = useTable({
|
|||
schemas: searchFormSchema
|
||||
},
|
||||
isTreeTable: true,
|
||||
useSearchForm: true,
|
||||
pagination: false,
|
||||
striped: false,
|
||||
useSearchForm: true,
|
||||
showTableSetting: true,
|
||||
bordered: true,
|
||||
showIndexColumn: false,
|
||||
canResize: false,
|
||||
actionColumn: {
|
||||
width: 120,
|
||||
title: '操作',
|
||||
|
@ -32,4 +68,30 @@ const [register, { expandAll, collapseAll }] = useTable({
|
|||
fixed: 'right'
|
||||
}
|
||||
})
|
||||
async function getList() {
|
||||
const res = await getMenuListApi(getForm().getFieldsValue() as any)
|
||||
return handleTree(res, 'id')
|
||||
}
|
||||
|
||||
function handleCreate() {
|
||||
openModal(true, {
|
||||
isUpdate: false
|
||||
})
|
||||
}
|
||||
|
||||
function handleEdit(record: Recordable) {
|
||||
openModal(true, {
|
||||
record,
|
||||
isUpdate: true
|
||||
})
|
||||
}
|
||||
|
||||
async function handleDelete(record: Recordable) {
|
||||
console.log(record)
|
||||
const res = await deleteDeptApi(record.id)
|
||||
if (res) {
|
||||
createMessage.success('删除成功')
|
||||
reload()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import Icon from '@/components/Icon'
|
||||
import { listSimpleMenusApi } from '@/api/system/menu'
|
||||
import { BasicColumn, FormSchema, useRender } from '@/components/Table'
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import { h } from 'vue'
|
||||
|
@ -69,35 +70,118 @@ export const formSchema: FormSchema[] = [
|
|||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '岗位名称',
|
||||
label: '上级菜单',
|
||||
field: 'parentId',
|
||||
required: true,
|
||||
component: 'ApiTreeSelect',
|
||||
componentProps: {
|
||||
api: () => listSimpleMenusApi(),
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
key: 'id',
|
||||
value: 'id'
|
||||
},
|
||||
handleTree: 'id'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '菜单类型',
|
||||
field: 'type',
|
||||
required: true,
|
||||
defaultValue: '0',
|
||||
component: 'RadioButtonGroup',
|
||||
componentProps: {
|
||||
options: getIntDictOptions(DICT_TYPE.SYSTEM_MENU_TYPE)
|
||||
},
|
||||
colProps: { lg: 24, md: 24 }
|
||||
},
|
||||
{
|
||||
label: '菜单名称',
|
||||
field: 'name',
|
||||
required: true,
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '岗位编码',
|
||||
field: 'code',
|
||||
label: '菜单图标',
|
||||
field: 'icon',
|
||||
component: 'IconPicker',
|
||||
ifShow: ({ values }) => values.type !== 3
|
||||
},
|
||||
{
|
||||
label: '显示排序',
|
||||
field: 'sort',
|
||||
required: true,
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '岗位顺序',
|
||||
field: 'sort',
|
||||
label: '路由地址',
|
||||
field: 'path',
|
||||
required: true,
|
||||
component: 'InputNumber'
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => values.type !== 3
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
label: '权限标识',
|
||||
field: 'permission',
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => values.type !== 1
|
||||
},
|
||||
{
|
||||
label: '组件路径',
|
||||
field: 'component',
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => values.type === 2
|
||||
},
|
||||
{
|
||||
label: '组件名称',
|
||||
field: 'componentName',
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => values.type === 2
|
||||
},
|
||||
{
|
||||
label: '菜单状态',
|
||||
field: 'status',
|
||||
component: 'Select',
|
||||
required: true,
|
||||
component: 'RadioButtonGroup',
|
||||
defaultValue: 0,
|
||||
componentProps: {
|
||||
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '备注',
|
||||
field: 'remark',
|
||||
component: 'InputTextArea'
|
||||
label: '显示状态',
|
||||
field: 'visible',
|
||||
component: 'RadioButtonGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: true, key: true, value: '显示' },
|
||||
{ label: false, key: false, value: '隐藏' }
|
||||
]
|
||||
},
|
||||
ifShow: ({ values }) => values.type !== 3
|
||||
},
|
||||
{
|
||||
label: '总是显示',
|
||||
field: 'alwaysShow',
|
||||
component: 'RadioButtonGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: true, key: true, value: '显示' },
|
||||
{ label: false, key: false, value: '隐藏' }
|
||||
]
|
||||
},
|
||||
ifShow: ({ values }) => values.type !== 3
|
||||
},
|
||||
{
|
||||
label: '是否缓存',
|
||||
field: 'keepAlive',
|
||||
component: 'RadioButtonGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: true, key: true, value: '缓存' },
|
||||
{ label: false, key: false, value: '不缓存' }
|
||||
]
|
||||
},
|
||||
ifShow: ({ values }) => values.type === 2
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue