|
|
|
|
@ -1,169 +1,3 @@
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import * as MenuApi from '@/api/system/menu'
|
|
|
|
|
import { MenuVO } from '@/api/system/menu/types'
|
|
|
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
|
|
|
import { useMessage } from '@/hooks/web/useMessage'
|
|
|
|
|
import { IconSelect } from '@/components/Icon'
|
|
|
|
|
import { Tooltip } from '@/components/Tooltip'
|
|
|
|
|
import { required } from '@/utils/formRules.js'
|
|
|
|
|
import { onMounted, reactive, ref } from 'vue'
|
|
|
|
|
import { VxeTableInstance } from 'vxe-table'
|
|
|
|
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
|
|
|
|
import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants'
|
|
|
|
|
import {
|
|
|
|
|
ElRow,
|
|
|
|
|
ElCol,
|
|
|
|
|
ElForm,
|
|
|
|
|
ElFormItem,
|
|
|
|
|
ElInput,
|
|
|
|
|
ElInputNumber,
|
|
|
|
|
ElSelect,
|
|
|
|
|
ElTreeSelect,
|
|
|
|
|
ElOption,
|
|
|
|
|
ElRadioGroup,
|
|
|
|
|
ElRadioButton
|
|
|
|
|
} from 'element-plus'
|
|
|
|
|
import { handleTree } from '@/utils/tree'
|
|
|
|
|
const { t } = useI18n() // 国际化
|
|
|
|
|
const message = useMessage()
|
|
|
|
|
const xTable = ref<VxeTableInstance>()
|
|
|
|
|
const tableLoading = ref(false)
|
|
|
|
|
const tableData = ref()
|
|
|
|
|
const actionLoading = ref(false) // 遮罩层
|
|
|
|
|
const actionType = ref('') // 操作按钮的类型
|
|
|
|
|
const dialogVisible = ref(false) // 是否显示弹出层
|
|
|
|
|
const dialogTitle = ref('edit') // 弹出层标题
|
|
|
|
|
const statusOption = ref() // 状态选项
|
|
|
|
|
const menuForm = ref<MenuVO>({
|
|
|
|
|
id: 0,
|
|
|
|
|
name: '',
|
|
|
|
|
permission: '',
|
|
|
|
|
type: SystemMenuTypeEnum.DIR,
|
|
|
|
|
sort: 1,
|
|
|
|
|
parentId: 0,
|
|
|
|
|
path: '',
|
|
|
|
|
icon: '',
|
|
|
|
|
component: '',
|
|
|
|
|
status: CommonStatusEnum.ENABLE,
|
|
|
|
|
visible: true,
|
|
|
|
|
keepAlive: true,
|
|
|
|
|
createTime: ''
|
|
|
|
|
})
|
|
|
|
|
const menuProps = {
|
|
|
|
|
checkStrictly: true,
|
|
|
|
|
children: 'children',
|
|
|
|
|
label: 'name',
|
|
|
|
|
value: 'id'
|
|
|
|
|
}
|
|
|
|
|
interface Tree {
|
|
|
|
|
id: number
|
|
|
|
|
name: string
|
|
|
|
|
children?: Tree[] | any[]
|
|
|
|
|
}
|
|
|
|
|
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 queryParams = reactive({
|
|
|
|
|
name: null,
|
|
|
|
|
status: null
|
|
|
|
|
})
|
|
|
|
|
const getList = async () => {
|
|
|
|
|
statusOption.value = getIntDictOptions(DICT_TYPE.COMMON_STATUS)
|
|
|
|
|
tableLoading.value = true
|
|
|
|
|
const res = await MenuApi.getMenuListApi(queryParams)
|
|
|
|
|
tableData.value = res
|
|
|
|
|
tableLoading.value = false
|
|
|
|
|
}
|
|
|
|
|
// 设置标题
|
|
|
|
|
const setDialogTile = (type: string) => {
|
|
|
|
|
dialogTitle.value = t('action.' + type)
|
|
|
|
|
actionType.value = type
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
}
|
|
|
|
|
// 新建操作
|
|
|
|
|
const handleCreate = () => {
|
|
|
|
|
setDialogTile('create')
|
|
|
|
|
}
|
|
|
|
|
// 修改操作
|
|
|
|
|
const handleUpdate = async (row: MenuVO) => {
|
|
|
|
|
// 设置数据
|
|
|
|
|
const res = await MenuApi.getMenuApi(row.id)
|
|
|
|
|
console.log(res)
|
|
|
|
|
menuForm.value = res
|
|
|
|
|
setDialogTile('update')
|
|
|
|
|
}
|
|
|
|
|
// 删除操作
|
|
|
|
|
const handleDelete = async (row: MenuVO) => {
|
|
|
|
|
message.confirm(t('common.delDataMessage'), t('common.confirmTitle')).then(async () => {
|
|
|
|
|
await MenuApi.deleteMenuApi(row.id)
|
|
|
|
|
message.success(t('common.delSuccess'))
|
|
|
|
|
await getList()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// 表单校验
|
|
|
|
|
const rules = reactive({
|
|
|
|
|
name: [required],
|
|
|
|
|
sort: [required],
|
|
|
|
|
path: [required],
|
|
|
|
|
status: [required]
|
|
|
|
|
})
|
|
|
|
|
// 查询操作
|
|
|
|
|
const handleQuery = async () => {
|
|
|
|
|
await getList()
|
|
|
|
|
}
|
|
|
|
|
// 重置操作
|
|
|
|
|
const resetQuery = async () => {
|
|
|
|
|
queryParams.name = null
|
|
|
|
|
queryParams.status = null
|
|
|
|
|
await getList()
|
|
|
|
|
}
|
|
|
|
|
// 保存操作
|
|
|
|
|
const isExternal = (path: string) => {
|
|
|
|
|
return /^(https?:|mailto:|tel:)/.test(path)
|
|
|
|
|
}
|
|
|
|
|
const submitForm = async () => {
|
|
|
|
|
actionLoading.value = true
|
|
|
|
|
// 提交请求
|
|
|
|
|
try {
|
|
|
|
|
if (
|
|
|
|
|
menuForm.value.type === SystemMenuTypeEnum.DIR ||
|
|
|
|
|
menuForm.value.type === SystemMenuTypeEnum.MENU
|
|
|
|
|
) {
|
|
|
|
|
if (!isExternal(menuForm.value.path)) {
|
|
|
|
|
if (menuForm.value.parentId === 0 && menuForm.value.path.charAt(0) !== '/') {
|
|
|
|
|
message.error('路径必须以 / 开头')
|
|
|
|
|
return
|
|
|
|
|
} else if (menuForm.value.parentId !== 0 && menuForm.value.path.charAt(0) === '/') {
|
|
|
|
|
message.error('路径不能以 / 开头')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (actionType.value === 'create') {
|
|
|
|
|
await MenuApi.createMenuApi(menuForm.value)
|
|
|
|
|
message.success(t('common.createSuccess'))
|
|
|
|
|
} else {
|
|
|
|
|
await MenuApi.updateMenuApi(menuForm.value)
|
|
|
|
|
message.success(t('common.updateSuccess'))
|
|
|
|
|
}
|
|
|
|
|
// 操作成功,重新加载列表
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
await getList()
|
|
|
|
|
} finally {
|
|
|
|
|
actionLoading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await getList()
|
|
|
|
|
getTree()
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
<template>
|
|
|
|
|
<ContentWrap>
|
|
|
|
|
<el-form :model="queryParams" ref="queryForm" :inline="true">
|
|
|
|
|
@ -211,6 +45,7 @@ onMounted(async () => {
|
|
|
|
|
:print-config="{}"
|
|
|
|
|
:export-config="{}"
|
|
|
|
|
:data="tableData"
|
|
|
|
|
class="xtable"
|
|
|
|
|
>
|
|
|
|
|
<vxe-column title="菜单名称" field="name" width="200" tree-node>
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
@ -255,19 +90,7 @@ onMounted(async () => {
|
|
|
|
|
</vxe-column>
|
|
|
|
|
</vxe-table>
|
|
|
|
|
</ContentWrap>
|
|
|
|
|
<vxe-modal
|
|
|
|
|
v-model="dialogVisible"
|
|
|
|
|
id="menuModel"
|
|
|
|
|
:title="dialogTitle"
|
|
|
|
|
width="800"
|
|
|
|
|
height="6f00"
|
|
|
|
|
min-width="460"
|
|
|
|
|
min-height="320"
|
|
|
|
|
show-zoom
|
|
|
|
|
resize
|
|
|
|
|
transfer
|
|
|
|
|
show-footer
|
|
|
|
|
>
|
|
|
|
|
<XModal v-model="dialogVisible" id="menuModel" :title="dialogTitle">
|
|
|
|
|
<template #default>
|
|
|
|
|
<!-- 对话框(添加 / 修改) -->
|
|
|
|
|
<el-form
|
|
|
|
|
@ -410,10 +233,175 @@ onMounted(async () => {
|
|
|
|
|
type="primary"
|
|
|
|
|
:loading="actionLoading"
|
|
|
|
|
@click="submitForm"
|
|
|
|
|
>
|
|
|
|
|
{{ t('action.save') }}
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
|
|
|
|
|
:content="t('action.save')"
|
|
|
|
|
/>
|
|
|
|
|
<el-button @click="dialogVisible = false" :content="t('dialog.close')" />
|
|
|
|
|
</template>
|
|
|
|
|
</vxe-modal>
|
|
|
|
|
</XModal>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import * as MenuApi from '@/api/system/menu'
|
|
|
|
|
import { MenuVO } from '@/api/system/menu/types'
|
|
|
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
|
|
|
import { useMessage } from '@/hooks/web/useMessage'
|
|
|
|
|
import { IconSelect } from '@/components/Icon'
|
|
|
|
|
import { Tooltip } from '@/components/Tooltip'
|
|
|
|
|
import { required } from '@/utils/formRules.js'
|
|
|
|
|
import { onMounted, reactive, ref } from 'vue'
|
|
|
|
|
import { VxeTableInstance } from 'vxe-table'
|
|
|
|
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
|
|
|
|
import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants'
|
|
|
|
|
import {
|
|
|
|
|
ElRow,
|
|
|
|
|
ElCol,
|
|
|
|
|
ElForm,
|
|
|
|
|
ElFormItem,
|
|
|
|
|
ElInput,
|
|
|
|
|
ElInputNumber,
|
|
|
|
|
ElSelect,
|
|
|
|
|
ElTreeSelect,
|
|
|
|
|
ElOption,
|
|
|
|
|
ElRadioGroup,
|
|
|
|
|
ElRadioButton
|
|
|
|
|
} from 'element-plus'
|
|
|
|
|
import { handleTree } from '@/utils/tree'
|
|
|
|
|
const { t } = useI18n() // 国际化
|
|
|
|
|
const message = useMessage()
|
|
|
|
|
const xTable = ref<VxeTableInstance>()
|
|
|
|
|
const tableLoading = ref(false)
|
|
|
|
|
const tableData = ref()
|
|
|
|
|
const actionLoading = ref(false) // 遮罩层
|
|
|
|
|
const actionType = ref('') // 操作按钮的类型
|
|
|
|
|
const dialogVisible = ref(false) // 是否显示弹出层
|
|
|
|
|
const dialogTitle = ref('edit') // 弹出层标题
|
|
|
|
|
const statusOption = ref() // 状态选项
|
|
|
|
|
const menuForm = ref<MenuVO>({
|
|
|
|
|
id: 0,
|
|
|
|
|
name: '',
|
|
|
|
|
permission: '',
|
|
|
|
|
type: SystemMenuTypeEnum.DIR,
|
|
|
|
|
sort: 1,
|
|
|
|
|
parentId: 0,
|
|
|
|
|
path: '',
|
|
|
|
|
icon: '',
|
|
|
|
|
component: '',
|
|
|
|
|
status: CommonStatusEnum.ENABLE,
|
|
|
|
|
visible: true,
|
|
|
|
|
keepAlive: true,
|
|
|
|
|
createTime: ''
|
|
|
|
|
})
|
|
|
|
|
const menuProps = {
|
|
|
|
|
checkStrictly: true,
|
|
|
|
|
children: 'children',
|
|
|
|
|
label: 'name',
|
|
|
|
|
value: 'id'
|
|
|
|
|
}
|
|
|
|
|
interface Tree {
|
|
|
|
|
id: number
|
|
|
|
|
name: string
|
|
|
|
|
children?: Tree[] | any[]
|
|
|
|
|
}
|
|
|
|
|
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 queryParams = reactive({
|
|
|
|
|
name: null,
|
|
|
|
|
status: null
|
|
|
|
|
})
|
|
|
|
|
const getList = async () => {
|
|
|
|
|
statusOption.value = getIntDictOptions(DICT_TYPE.COMMON_STATUS)
|
|
|
|
|
tableLoading.value = true
|
|
|
|
|
const res = await MenuApi.getMenuListApi(queryParams)
|
|
|
|
|
tableData.value = res
|
|
|
|
|
tableLoading.value = false
|
|
|
|
|
}
|
|
|
|
|
// 设置标题
|
|
|
|
|
const setDialogTile = (type: string) => {
|
|
|
|
|
dialogTitle.value = t('action.' + type)
|
|
|
|
|
actionType.value = type
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
}
|
|
|
|
|
// 新建操作
|
|
|
|
|
const handleCreate = () => {
|
|
|
|
|
setDialogTile('create')
|
|
|
|
|
}
|
|
|
|
|
// 修改操作
|
|
|
|
|
const handleUpdate = async (row: MenuVO) => {
|
|
|
|
|
// 设置数据
|
|
|
|
|
const res = await MenuApi.getMenuApi(row.id)
|
|
|
|
|
console.log(res)
|
|
|
|
|
menuForm.value = res
|
|
|
|
|
setDialogTile('update')
|
|
|
|
|
}
|
|
|
|
|
// 删除操作
|
|
|
|
|
const handleDelete = async (row: MenuVO) => {
|
|
|
|
|
message.confirm(t('common.delDataMessage'), t('common.confirmTitle')).then(async () => {
|
|
|
|
|
await MenuApi.deleteMenuApi(row.id)
|
|
|
|
|
message.success(t('common.delSuccess'))
|
|
|
|
|
await getList()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// 表单校验
|
|
|
|
|
const rules = reactive({
|
|
|
|
|
name: [required],
|
|
|
|
|
sort: [required],
|
|
|
|
|
path: [required],
|
|
|
|
|
status: [required]
|
|
|
|
|
})
|
|
|
|
|
// 查询操作
|
|
|
|
|
const handleQuery = async () => {
|
|
|
|
|
await getList()
|
|
|
|
|
}
|
|
|
|
|
// 重置操作
|
|
|
|
|
const resetQuery = async () => {
|
|
|
|
|
queryParams.name = null
|
|
|
|
|
queryParams.status = null
|
|
|
|
|
await getList()
|
|
|
|
|
}
|
|
|
|
|
// 保存操作
|
|
|
|
|
const isExternal = (path: string) => {
|
|
|
|
|
return /^(https?:|mailto:|tel:)/.test(path)
|
|
|
|
|
}
|
|
|
|
|
const submitForm = async () => {
|
|
|
|
|
actionLoading.value = true
|
|
|
|
|
// 提交请求
|
|
|
|
|
try {
|
|
|
|
|
if (
|
|
|
|
|
menuForm.value.type === SystemMenuTypeEnum.DIR ||
|
|
|
|
|
menuForm.value.type === SystemMenuTypeEnum.MENU
|
|
|
|
|
) {
|
|
|
|
|
if (!isExternal(menuForm.value.path)) {
|
|
|
|
|
if (menuForm.value.parentId === 0 && menuForm.value.path.charAt(0) !== '/') {
|
|
|
|
|
message.error('路径必须以 / 开头')
|
|
|
|
|
return
|
|
|
|
|
} else if (menuForm.value.parentId !== 0 && menuForm.value.path.charAt(0) === '/') {
|
|
|
|
|
message.error('路径不能以 / 开头')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (actionType.value === 'create') {
|
|
|
|
|
await MenuApi.createMenuApi(menuForm.value)
|
|
|
|
|
message.success(t('common.createSuccess'))
|
|
|
|
|
} else {
|
|
|
|
|
await MenuApi.updateMenuApi(menuForm.value)
|
|
|
|
|
message.success(t('common.updateSuccess'))
|
|
|
|
|
}
|
|
|
|
|
// 操作成功,重新加载列表
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
await getList()
|
|
|
|
|
} finally {
|
|
|
|
|
actionLoading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await getList()
|
|
|
|
|
getTree()
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|