Vue3 重构:REVIEW 菜单

This commit is contained in:
YunaiV 2023-03-26 22:15:45 +08:00
parent d72101b194
commit 56e2f21d1a
7 changed files with 316 additions and 350 deletions

View File

@ -18,18 +18,13 @@ export interface MenuVO {
createTime: Date createTime: Date
} }
export interface MenuPageReqVO {
name?: string
status?: number
}
// 查询菜单(精简)列表 // 查询菜单(精简)列表
export const listSimpleMenusApi = () => { export const getSimpleMenusList = () => {
return request.get({ url: '/system/menu/list-all-simple' }) return request.get({ url: '/system/menu/list-all-simple' })
} }
// 查询菜单列表 // 查询菜单列表
export const getMenuListApi = (params: MenuPageReqVO) => { export const getMenuList = (params) => {
return request.get({ url: '/system/menu/list', params }) return request.get({ url: '/system/menu/list', params })
} }
@ -39,16 +34,16 @@ export const getMenuApi = (id: number) => {
} }
// 新增菜单 // 新增菜单
export const createMenuApi = (data: MenuVO) => { export const createMenu = (data: MenuVO) => {
return request.post({ url: '/system/menu/create', data }) return request.post({ url: '/system/menu/create', data })
} }
// 修改菜单 // 修改菜单
export const updateMenuApi = (data: MenuVO) => { export const updateMenu = (data: MenuVO) => {
return request.put({ url: '/system/menu/update', data }) return request.put({ url: '/system/menu/update', data })
} }
// 删除菜单 // 删除菜单
export const deleteMenuApi = (id: number) => { export const deleteMenu = (id: number) => {
return request.delete({ url: '/system/menu/delete?id=' + id }) return request.delete({ url: '/system/menu/delete?id=' + id })
} }

View File

@ -6,7 +6,7 @@ import { useForm } from '@/hooks/web/useForm'
import { FormSchema } from '@/types/form' import { FormSchema } from '@/types/form'
import { CodegenTableVO } from '@/api/infra/codegen/types' import { CodegenTableVO } from '@/api/infra/codegen/types'
import { getIntDictOptions } from '@/utils/dict' import { getIntDictOptions } from '@/utils/dict'
import { listSimpleMenusApi } from '@/api/system/menu' import { getSimpleMenusList } from '@/api/system/menu'
import { handleTree, defaultProps } from '@/utils/tree' import { handleTree, defaultProps } from '@/utils/tree'
import { PropType } from 'vue' import { PropType } from 'vue'
@ -21,7 +21,7 @@ const templateTypeOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_T
const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE) const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
const menuOptions = ref<any>([]) // const menuOptions = ref<any>([]) //
const getTree = async () => { const getTree = async () => {
const res = await listSimpleMenusApi() const res = await getSimpleMenusList()
menuOptions.value = handleTree(res) menuOptions.value = handleTree(res)
} }

View File

@ -0,0 +1,253 @@
<template>
<Dialog :title="modelTitle" v-model="modelVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="上级菜单">
<el-tree-select
node-key="id"
v-model="formData.parentId"
:props="defaultProps"
:data="menuTree"
:default-expanded-keys="[0]"
check-strictly
/>
</el-form-item>
<el-form-item label="菜单名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入菜单名称" clearable />
</el-form-item>
<el-form-item label="菜单类型" prop="type">
<el-radio-group v-model="formData.type">
<el-radio-button
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_MENU_TYPE)"
:key="dict.label"
:label="dict.value"
>
{{ dict.label }}
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="菜单图标" v-if="formData.type !== 3">
<IconSelect v-model="formData.icon" clearable />
</el-form-item>
<el-form-item label="路由地址" prop="path" v-if="formData.type !== 3">
<template #label>
<Tooltip
titel="路由地址"
message="访问的路由地址,如:`user`。如需外网地址时,则以 `http(s)://` 开头"
/>
</template>
<el-input v-model="formData.path" placeholder="请输入路由地址" clearable />
</el-form-item>
<el-form-item label="组件地址" prop="component" v-if="formData.type === 2">
<el-input v-model="formData.component" placeholder="例如说system/user/index" clearable />
</el-form-item>
<el-form-item label="组件名字" prop="componentName" v-if="formData.type === 2">
<el-input v-model="formData.componentName" placeholder="例如说SystemUser" clearable />
</el-form-item>
<el-form-item label="权限标识" prop="permission" v-if="formData.type !== 1">
<template #label>
<Tooltip
titel="权限标识"
message="Controller 方法上的权限字符,如:@PreAuthorize(`@ss.hasPermission('system:user:list')`)"
/>
</template>
<el-input v-model="formData.permission" placeholder="请输入权限标识" clearable />
</el-form-item>
<el-form-item label="显示排序" prop="sort">
<el-input-number v-model="formData.sort" controls-position="right" :min="0" clearable />
</el-form-item>
<el-form-item label="菜单状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.label"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="显示状态" prop="visible" v-if="formData.type !== 3">
<template #label>
<Tooltip titel="显示状态" message="选择隐藏时,路由将不会出现在侧边栏,但仍然可以访问" />
</template>
<el-radio-group v-model="formData.visible">
<el-radio border key="true" :label="true">显示</el-radio>
<el-radio border key="false" :label="false">隐藏</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="总是显示" prop="alwaysShow" v-if="formData.type !== 3">
<template #label>
<Tooltip
titel="总是显示"
message="选择不是时,当该菜单只有一个子菜单时,不展示自己,直接展示子菜单"
/>
</template>
<el-radio-group v-model="formData.alwaysShow">
<el-radio border key="true" :label="true">总是</el-radio>
<el-radio border key="false" :label="false">不是</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="缓存状态" prop="keepAlive" v-if="formData.type === 2">
<template #label>
<Tooltip
titel="缓存状态"
message="选择缓存时,则会被 `keep-alive` 缓存,必须填写「组件名称」字段"
/>
</template>
<el-radio-group v-model="formData.keepAlive">
<el-radio border key="true" :label="true">缓存</el-radio>
<el-radio border key="false" :label="false">不缓存</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="modelVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as MenuApi from '@/api/system/menu'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants'
import { handleTree, defaultProps } from '@/utils/tree'
const { wsCache } = useCache()
const { t } = useI18n() //
const message = useMessage() //
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: 0,
name: '',
permission: '',
type: SystemMenuTypeEnum.DIR,
sort: Number(undefined),
parentId: 0,
path: '',
icon: '',
component: '',
componentName: '',
status: CommonStatusEnum.ENABLE,
visible: true,
keepAlive: true,
alwaysShow: true
})
const formRules = reactive({
name: [{ required: true, message: '菜单名称不能为空', trigger: 'blur' }],
sort: [{ required: true, message: '菜单顺序不能为空', trigger: 'blur' }],
path: [{ required: true, message: '路由地址不能为空', trigger: 'blur' }],
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
/** 打开弹窗 */
const open = async (type: string, id?: number, parentId?: number) => {
modelVisible.value = true
modelTitle.value = t('action.' + type)
formType.value = type
resetForm()
if (parentId) {
formData.value.parentId = parentId
}
//
if (id) {
formLoading.value = true
try {
formData.value = await MenuApi.getMenuApi(id)
} finally {
formLoading.value = false
}
}
//
await getTree()
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
if (
formData.value.type === SystemMenuTypeEnum.DIR ||
formData.value.type === SystemMenuTypeEnum.MENU
) {
if (!isExternal(formData.value.path)) {
if (formData.value.parentId === 0 && formData.value.path.charAt(0) !== '/') {
message.error('路径必须以 / 开头')
return
} else if (formData.value.parentId !== 0 && formData.value.path.charAt(0) === '/') {
message.error('路径不能以 / 开头')
return
}
}
}
const data = formData.value as unknown as MenuApi.MenuVO
if (formType.value === 'create') {
await MenuApi.createMenu(data)
message.success(t('common.createSuccess'))
} else {
await MenuApi.updateMenu(data)
message.success(t('common.updateSuccess'))
}
modelVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
//
wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
}
}
/** 获取下拉框[上级菜单]的数据 */
const menuTree = ref<Tree[]>([]) //
const getTree = async () => {
menuTree.value = []
const res = await MenuApi.getSimpleMenusList()
let menu: Tree = { id: 0, name: '主类目', children: [] }
menu.children = handleTree(res)
menuTree.value.push(menu)
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: 0,
name: '',
permission: '',
type: SystemMenuTypeEnum.DIR,
sort: Number(undefined),
parentId: 0,
path: '',
icon: '',
component: '',
componentName: '',
status: CommonStatusEnum.ENABLE,
visible: true,
keepAlive: true,
alwaysShow: true
}
formRef.value?.resetFields()
}
/** 判断 path 是不是外部的 HTTP 等链接 */
const isExternal = (path: string) => {
return /^(https?:|mailto:|tel:)/.test(path)
}
</script>

View File

@ -1,297 +0,0 @@
<template>
<Dialog :title="modelTitle" v-model="modelVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="80px"
v-loading="formLoading"
>
<el-form-item label="上级菜单">
<el-tree-select
node-key="id"
v-model="formData.parentId"
:props="defaultProps"
:data="menuOptions"
:default-expanded-keys="[0]"
check-strictly
/>
</el-form-item>
<el-col :span="16">
<el-form-item label="菜单名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入菜单名称" clearable />
</el-form-item>
</el-col>
<el-form-item label="菜单类型" prop="type">
<el-radio-group v-model="formData.type">
<el-radio-button
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_MENU_TYPE)"
:key="dict.label"
:label="dict.value"
>
{{ dict.label }}
</el-radio-button>
</el-radio-group>
</el-form-item>
<template v-if="formData.type !== 3">
<el-form-item label="菜单图标">
<IconSelect v-model="formData.icon" clearable />
</el-form-item>
<el-col :span="16">
<el-form-item label="路由地址" prop="path">
<template #label>
<Tooltip
titel="路由地址"
message="访问的路由地址,如:`user`。如需外网地址时,则以 `http(s)://` 开头"
/>
</template>
<el-input v-model="formData.path" placeholder="请输入路由地址" clearable />
</el-form-item>
</el-col>
</template>
<template v-if="formData.type === 2">
<el-col :span="16">
<el-form-item label="组件地址" prop="component">
<el-input
v-model="formData.component"
placeholder="例如说system/user/index"
clearable
/>
</el-form-item>
</el-col>
<el-col :span="16">
<el-form-item label="组件名字" prop="componentName">
<el-input v-model="formData.componentName" placeholder="例如说SystemUser" clearable />
</el-form-item>
</el-col>
</template>
<template v-if="formData.type !== 1">
<el-col :span="16">
<el-form-item label="权限标识" prop="permission">
<template #label>
<Tooltip
titel="权限标识"
message="Controller 方法上的权限字符,如:@PreAuthorize(`@ss.hasPermission('system:user:list')`)"
/>
</template>
<el-input v-model="formData.permission" placeholder="请输入权限标识" clearable />
</el-form-item>
</el-col>
</template>
<el-col :span="16">
<el-form-item label="显示排序" prop="sort">
<el-input-number v-model="formData.sort" controls-position="right" :min="0" clearable />
</el-form-item>
</el-col>
<el-col :span="16">
<el-form-item label="菜单状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio
border
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.label"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<template v-if="formData.type !== 3">
<el-col :span="16">
<el-form-item label="显示状态" prop="visible">
<template #label>
<Tooltip
titel="显示状态"
message="选择隐藏时,路由将不会出现在侧边栏,但仍然可以访问"
/>
</template>
<el-radio-group v-model="formData.visible">
<el-radio border key="true" :label="true">显示</el-radio>
<el-radio border key="false" :label="false">隐藏</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
</template>
<template v-if="formData.type !== 3">
<el-col :span="16">
<el-form-item label="总是显示" prop="alwaysShow">
<template #label>
<Tooltip
titel="总是显示"
message="选择不是时,当该菜单只有一个子菜单时,不展示自己,直接展示子菜单"
/>
</template>
<el-radio-group v-model="formData.alwaysShow">
<el-radio border key="true" :label="true">总是</el-radio>
<el-radio border key="false" :label="false">不是</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
</template>
<template v-if="formData.type === 2">
<el-col :span="16">
<el-form-item label="缓存状态" prop="keepAlive">
<template #label>
<Tooltip
titel="缓存状态"
message="选择缓存时,则会被 `keep-alive` 缓存,必须填写「组件名称」字段"
/>
</template>
<el-radio-group v-model="formData.keepAlive">
<el-radio border key="true" :label="true">缓存</el-radio>
<el-radio border key="false" :label="false">不缓存</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
</template>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="modelVisible = false"> </el-button>
</div>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as MenuApi from '@/api/system/menu'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants'
import { handleTree, defaultProps } from '@/utils/tree'
const { wsCache } = useCache()
const { t } = useI18n() //
const message = useMessage() //
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: 0,
name: '',
permission: '',
type: SystemMenuTypeEnum.DIR,
sort: 1,
parentId: 0,
path: '',
icon: '',
component: '',
componentName: '',
status: CommonStatusEnum.ENABLE,
visible: true,
keepAlive: true,
alwaysShow: true,
createTime: new Date()
})
const formRules = reactive({
name: [{ required: true, message: '菜单名称不能为空', trigger: 'blur' }],
sort: [{ required: true, message: '菜单顺序不能为空', trigger: 'blur' }],
path: [{ required: true, message: '路由地址不能为空', trigger: 'blur' }],
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
/** 打开弹窗 */
const openModal = async (type: string, id?: number) => {
modelVisible.value = true
modelTitle.value = t('action.' + type)
formType.value = type
resetForm()
await getTree()
//
if (id) {
formLoading.value = true
try {
formData.value = await MenuApi.getMenuApi(id)
// TODO
// formData.value.componentName = res.componentName || ''
// formData.value.alwaysShow = res.alwaysShow !== undefined ? res.alwaysShow : true
} finally {
formLoading.value = false
}
}
}
defineExpose({ openModal }) // openModal
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
if (
formData.value.type === SystemMenuTypeEnum.DIR ||
formData.value.type === SystemMenuTypeEnum.MENU
) {
if (!isExternal(formData.value.path)) {
if (formData.value.parentId === 0 && formData.value.path.charAt(0) !== '/') {
message.error('路径必须以 / 开头')
return
} else if (formData.value.parentId !== 0 && formData.value.path.charAt(0) === '/') {
message.error('路径不能以 / 开头')
return
}
}
}
const data = formData.value
if (formType.value === 'create') {
await MenuApi.createMenuApi(data)
message.success(t('common.createSuccess'))
} else {
await MenuApi.updateMenuApi(data)
message.success(t('common.updateSuccess'))
}
modelVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
}
}
// ========== [] ==========
const menuOptions = ref<any[]>([]) //
// []
const getTree = async () => {
menuOptions.value = []
const res = await MenuApi.listSimpleMenusApi()
let menu: Tree = { id: 0, name: '主类目', children: [] }
menu.children = handleTree(res)
menuOptions.value.push(menu)
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: 0,
name: '',
permission: '',
type: SystemMenuTypeEnum.DIR,
sort: 1,
parentId: 0,
path: '',
icon: '',
component: '',
componentName: '',
status: CommonStatusEnum.ENABLE,
visible: true,
keepAlive: true,
alwaysShow: true,
createTime: new Date()
}
formRef.value?.resetFields()
}
// path HTTP
const isExternal = (path: string) => {
return /^(https?:|mailto:|tel:)/.test(path)
}
</script>

View File

@ -1,49 +1,63 @@
<template> <template>
<!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<!-- 搜索工作栏 --> <el-form
<el-form :model="queryParams" ref="queryFormRef" :inline="true"> class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="菜单名称" prop="name"> <el-form-item label="菜单名称" prop="name">
<el-input <el-input
v-model="queryParams.name" v-model="queryParams.name"
placeholder="请输入菜单名称" placeholder="请输入菜单名称"
clearable clearable
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="菜单状态" clearable> <el-select
v-model="queryParams.status"
placeholder="请选择菜单状态"
clearable
class="!w-240px"
>
<el-option <el-option
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)" v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="parseInt(dict.value)" :key="dict.value"
:label="dict.label" :label="dict.label"
:value="parseInt(dict.value)" :value="dict.value"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button type="primary" @click="openModal('create')" v-hasPermi="['system:menu:create']"> <el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['system:menu:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增 <Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button> </el-button>
<el-button type="danger" plain @click="toggleExpandAll">
<Icon icon="ep:sort" class="mr-5px" /> 展开/折叠
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</ContentWrap>
<el-row :gutter="10" class="mb8"> <!-- 列表 -->
<el-col :span="1.5"> <ContentWrap>
<el-button type="info" plain icon="el-icon-sort" @click="toggleExpandAll"
>展开/折叠</el-button
>
</el-col>
</el-row>
<el-table <el-table
v-loading="loading" v-loading="loading"
:data="list" :data="list"
v-if="refreshTable"
row-key="id" row-key="id"
v-if="refreshTable"
:default-expand-all="isExpandAll" :default-expand-all="isExpandAll"
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
> >
<el-table-column prop="name" label="菜单名称" :show-overflow-tooltip="true" width="250" /> <el-table-column prop="name" label="菜单名称" :show-overflow-tooltip="true" width="250" />
<el-table-column prop="icon" label="图标" align="center" width="100"> <el-table-column prop="icon" label="图标" align="center" width="100">
@ -60,62 +74,63 @@
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" /> <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center">
<template #default="scope"> <template #default="scope">
<el-button <el-button
link link
type="primary" type="primary"
@click="openModal('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['system:menu:update']" v-hasPermi="['system:menu:update']"
>修改</el-button
> >
修改
</el-button>
<el-button <el-button
link link
type="primary" type="primary"
@click="openModal('create', scope.row.id)" @click="openForm('create', undefined, scope.row.id)"
v-hasPermi="['system:menu:create']" v-hasPermi="['system:menu:create']"
>新增</el-button
> >
新增
</el-button>
<el-button <el-button
link link
type="primary" type="danger"
@click="handleDelete(scope.row.id)" @click="handleDelete(scope.row.id)"
v-hasPermi="['system:menu:delete']" v-hasPermi="['system:menu:delete']"
>删除</el-button
> >
删除
</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</ContentWrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<menu-form ref="modalRef" @success="getList" /> <MenuForm ref="formRef" @success="getList" />
</template> </template>
<script setup lang="ts" name="Menu"> <script setup lang="ts" name="Menu">
// import import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { handleTree } from '@/utils/tree' import { handleTree } from '@/utils/tree'
import * as MenuApi from '@/api/system/menu' import * as MenuApi from '@/api/system/menu'
import MenuForm from './form.vue' import MenuForm from './MenuForm.vue'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const loading = ref(true) // const loading = ref(true) //
const list = ref<any>([]) // const list = ref<any>([]) //
const isExpandAll = ref(false) //
const refreshTable = ref(true) //
const queryParams = reactive({ const queryParams = reactive({
name: undefined, name: undefined,
status: undefined status: undefined
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const isExpandAll = ref(false) //
const refreshTable = ref(true) //
/** 查询参数列表 */ /** 查询参数列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await MenuApi.getMenuListApi(queryParams) const data = await MenuApi.getMenuList(queryParams)
list.value = handleTree(data) list.value = handleTree(data)
} finally { } finally {
loading.value = false loading.value = false
@ -134,9 +149,9 @@ const resetQuery = () => {
} }
/** 添加/修改操作 */ /** 添加/修改操作 */
const modalRef = ref() const formRef = ref()
const openModal = async (type: string, id?: number) => { const openForm = (type: string, id?: number, parentId?: number) => {
modalRef.value.openModal(type, id) formRef.value.open(type, id, parentId)
} }
/** 展开/折叠操作 */ /** 展开/折叠操作 */
@ -154,7 +169,7 @@ const handleDelete = async (id: number) => {
// //
await message.delConfirm() await message.delConfirm()
// //
await MenuApi.deleteMenuApi(id) await MenuApi.deleteMenu(id)
message.success(t('common.delSuccess')) message.success(t('common.delSuccess'))
// //
await getList() await getList()

View File

@ -164,7 +164,7 @@ import { SystemDataScopeEnum } from '@/utils/constants'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { rules, allSchemas } from './role.data' import { rules, allSchemas } from './role.data'
import * as RoleApi from '@/api/system/role' import * as RoleApi from '@/api/system/role'
import { listSimpleMenusApi } from '@/api/system/menu' import { getSimpleMenusList } from '@/api/system/menu'
import { getSimpleDeptList } from '@/api/system/dept' import { getSimpleDeptList } from '@/api/system/dept'
import * as PermissionApi from '@/api/system/permission' import * as PermissionApi from '@/api/system/permission'
@ -269,7 +269,7 @@ const handleScope = async (type: string, row: RoleApi.RoleVO) => {
actionScopeType.value = type actionScopeType.value = type
dialogScopeVisible.value = true dialogScopeVisible.value = true
if (type === 'menu') { if (type === 'menu') {
const menuRes = await listSimpleMenusApi() const menuRes = await getSimpleMenusList()
treeOptions.value = handleTree(menuRes) treeOptions.value = handleTree(menuRes)
const role = await PermissionApi.listRoleMenusApi(row.id) const role = await PermissionApi.listRoleMenusApi(row.id)
if (role) { if (role) {

View File

@ -71,7 +71,7 @@ import type { ElTree } from 'element-plus'
// import // import
import { rules, allSchemas } from './tenantPackage.data' import { rules, allSchemas } from './tenantPackage.data'
import * as TenantPackageApi from '@/api/system/tenantPackage' import * as TenantPackageApi from '@/api/system/tenantPackage'
import { listSimpleMenusApi } from '@/api/system/menu' import { getSimpleMenusList } from '@/api/system/menu'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
@ -102,7 +102,7 @@ const validateCategory = (rule: any, value: any, callback: any) => {
rules.menuIds = [{ required: true, validator: validateCategory, trigger: 'blur' }] rules.menuIds = [{ required: true, validator: validateCategory, trigger: 'blur' }]
const getTree = async () => { const getTree = async () => {
const res = await listSimpleMenusApi() const res = await getSimpleMenusList()
menuOptions.value = handleTree(res) menuOptions.value = handleTree(res)
} }