mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
vue3:【menu】
1. 添加 TODO 修改建议 2. 增加注释 3. 调整一些 import、const 的顺序
This commit is contained in:
parent
424520490d
commit
7cbd6cfb68
@ -1,10 +1,11 @@
|
|||||||
import request from '@/config/axios'
|
import request from '@/config/axios'
|
||||||
import type { MenuVO } from './types'
|
import type { MenuVO } from './types'
|
||||||
|
|
||||||
// 查询菜单(精简)列表
|
// 查询菜单(精简)列表
|
||||||
export const listSimpleMenusApi = () => {
|
export const listSimpleMenusApi = () => {
|
||||||
return request.get({ url: '/system/menu/list-all-simple' })
|
return request.get({ url: '/system/menu/list-all-simple' })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询菜单列表
|
// 查询菜单列表
|
||||||
export const getMenuListApi = (params) => {
|
export const getMenuListApi = (params) => {
|
||||||
return request.get({ url: '/system/menu/list', params })
|
return request.get({ url: '/system/menu/list', params })
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<ContentWrap>
|
<ContentWrap>
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
<el-form :model="queryParams" ref="queryForm" :inline="true">
|
<el-form :model="queryParams" ref="queryForm" :inline="true">
|
||||||
<el-form-item label="菜单名称" prop="name">
|
<el-form-item label="菜单名称" prop="name">
|
||||||
<el-input v-model="queryParams.name" placeholder="请输入菜单名称" />
|
<el-input v-model="queryParams.name" placeholder="请输入菜单名称" />
|
||||||
@ -15,17 +16,20 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
|
<!-- 操作:搜索 -->
|
||||||
<XButton
|
<XButton
|
||||||
type="primary"
|
type="primary"
|
||||||
preIcon="ep:search"
|
preIcon="ep:search"
|
||||||
:title="t('common.query')"
|
:title="t('common.query')"
|
||||||
@click="handleQuery()"
|
@click="handleQuery()"
|
||||||
/>
|
/>
|
||||||
|
<!-- 操作:重置 -->
|
||||||
<XButton preIcon="ep:refresh-right" :title="t('common.reset')" @click="resetQuery()" />
|
<XButton preIcon="ep:refresh-right" :title="t('common.reset')" @click="resetQuery()" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<vxe-toolbar>
|
<vxe-toolbar>
|
||||||
<template #buttons>
|
<template #buttons>
|
||||||
|
<!-- 操作:新增 -->
|
||||||
<XButton
|
<XButton
|
||||||
type="primary"
|
type="primary"
|
||||||
preIcon="ep:zoom-in"
|
preIcon="ep:zoom-in"
|
||||||
@ -37,6 +41,8 @@
|
|||||||
<XButton title="关闭所有" @click="xTable?.clearTreeExpand()" />
|
<XButton title="关闭所有" @click="xTable?.clearTreeExpand()" />
|
||||||
</template>
|
</template>
|
||||||
</vxe-toolbar>
|
</vxe-toolbar>
|
||||||
|
<!-- 列表 -->
|
||||||
|
<!-- TODO 星语:是不是也搞成 grid 会好点,后续代码就统一走 grid 风格? -->
|
||||||
<vxe-table
|
<vxe-table
|
||||||
show-overflow
|
show-overflow
|
||||||
keep-source
|
keep-source
|
||||||
@ -73,12 +79,14 @@
|
|||||||
<vxe-column title="创建时间" field="createTime" formatter="formatDate" />
|
<vxe-column title="创建时间" field="createTime" formatter="formatDate" />
|
||||||
<vxe-column title="操作" width="200">
|
<vxe-column title="操作" width="200">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
|
<!-- 操作:修改 -->
|
||||||
<XTextButton
|
<XTextButton
|
||||||
preIcon="ep:edit"
|
preIcon="ep:edit"
|
||||||
:title="t('action.edit')"
|
:title="t('action.edit')"
|
||||||
v-hasPermi="['system:menu:update']"
|
v-hasPermi="['system:menu:update']"
|
||||||
@click="handleUpdate(row)"
|
@click="handleUpdate(row)"
|
||||||
/>
|
/>
|
||||||
|
<!-- 操作:删除 -->
|
||||||
<XTextButton
|
<XTextButton
|
||||||
preIcon="ep:delete"
|
preIcon="ep:delete"
|
||||||
:title="t('action.del')"
|
:title="t('action.del')"
|
||||||
@ -89,6 +97,7 @@
|
|||||||
</vxe-column>
|
</vxe-column>
|
||||||
</vxe-table>
|
</vxe-table>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
|
<!-- 添加或修改菜单对话框 -->
|
||||||
<XModal v-model="dialogVisible" id="menuModel" :title="dialogTitle">
|
<XModal v-model="dialogVisible" id="menuModel" :title="dialogTitle">
|
||||||
<template #default>
|
<template #default>
|
||||||
<!-- 对话框(添加 / 修改) -->
|
<!-- 对话框(添加 / 修改) -->
|
||||||
@ -227,7 +236,7 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
</template>
|
</template>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<!-- 操作按钮 -->
|
<!-- 按钮:保存 -->
|
||||||
<XButton
|
<XButton
|
||||||
v-if="['create', 'update'].includes(actionType)"
|
v-if="['create', 'update'].includes(actionType)"
|
||||||
type="primary"
|
type="primary"
|
||||||
@ -235,22 +244,17 @@
|
|||||||
@click="submitForm"
|
@click="submitForm"
|
||||||
:title="t('action.save')"
|
:title="t('action.save')"
|
||||||
/>
|
/>
|
||||||
|
<!-- 按钮:关闭 -->
|
||||||
<XButton :loading="actionLoading" @click="dialogVisible = false" :title="t('dialog.close')" />
|
<XButton :loading="actionLoading" @click="dialogVisible = false" :title="t('dialog.close')" />
|
||||||
</template>
|
</template>
|
||||||
</XModal>
|
</XModal>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import * as MenuApi from '@/api/system/menu'
|
// 全局相关的 import
|
||||||
import { MenuVO } from '@/api/system/menu/types'
|
import { onMounted, reactive, ref } from 'vue'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useMessage } from '@/hooks/web/useMessage'
|
import { useMessage } from '@/hooks/web/useMessage'
|
||||||
import { IconSelect } from '@/components/Icon'
|
// TODO @星语:是不是 'element-plus' 和 '@/components/Tooltip' 和 '@/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 {
|
import {
|
||||||
ElRow,
|
ElRow,
|
||||||
ElCol,
|
ElCol,
|
||||||
@ -264,17 +268,29 @@ import {
|
|||||||
ElRadioGroup,
|
ElRadioGroup,
|
||||||
ElRadioButton
|
ElRadioButton
|
||||||
} from 'element-plus'
|
} from 'element-plus'
|
||||||
|
import { Tooltip } from '@/components/Tooltip'
|
||||||
|
import { IconSelect } from '@/components/Icon'
|
||||||
|
import { VxeTableInstance } from 'vxe-table'
|
||||||
|
// 业务相关的 import
|
||||||
|
import * as MenuApi from '@/api/system/menu'
|
||||||
|
import { MenuVO } from '@/api/system/menu/types'
|
||||||
|
import { required } from '@/utils/formRules.js'
|
||||||
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||||
|
import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree } from '@/utils/tree'
|
||||||
|
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
const message = useMessage()
|
const message = useMessage() // 消息弹窗
|
||||||
|
// 列表相关的变量
|
||||||
const xTable = ref<VxeTableInstance>()
|
const xTable = ref<VxeTableInstance>()
|
||||||
const tableLoading = ref(false)
|
const tableLoading = ref(false)
|
||||||
const tableData = ref()
|
const tableData = ref()
|
||||||
const actionLoading = ref(false) // 遮罩层
|
// 弹窗相关的变量
|
||||||
const actionType = ref('') // 操作按钮的类型
|
|
||||||
const dialogVisible = ref(false) // 是否显示弹出层
|
const dialogVisible = ref(false) // 是否显示弹出层
|
||||||
const dialogTitle = ref('edit') // 弹出层标题
|
const dialogTitle = ref('edit') // 弹出层标题
|
||||||
const statusOption = ref() // 状态选项
|
const actionType = ref('') // 操作按钮的类型
|
||||||
|
const actionLoading = ref(false) // 遮罩层
|
||||||
|
// 新增和修改的表单值
|
||||||
const menuForm = ref<MenuVO>({
|
const menuForm = ref<MenuVO>({
|
||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
@ -290,12 +306,24 @@ const menuForm = ref<MenuVO>({
|
|||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
createTime: ''
|
createTime: ''
|
||||||
})
|
})
|
||||||
|
// 新增和修改的表单校验
|
||||||
|
const rules = reactive({
|
||||||
|
name: [required],
|
||||||
|
sort: [required],
|
||||||
|
path: [required],
|
||||||
|
status: [required]
|
||||||
|
})
|
||||||
|
|
||||||
|
// ========== 下拉框[上级菜单] ==========
|
||||||
|
// 下拉框[上级菜单]的配置项目
|
||||||
|
// TODO @星语:menuProps 貌似也可以抽到全局?
|
||||||
const menuProps = {
|
const menuProps = {
|
||||||
checkStrictly: true,
|
checkStrictly: true,
|
||||||
children: 'children',
|
children: 'children',
|
||||||
label: 'name',
|
label: 'name',
|
||||||
value: 'id'
|
value: 'id'
|
||||||
}
|
}
|
||||||
|
// TODO @星语:Tree 可以是全局的
|
||||||
interface Tree {
|
interface Tree {
|
||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
@ -309,6 +337,7 @@ const getTree = async () => {
|
|||||||
menu.children = handleTree(res)
|
menu.children = handleTree(res)
|
||||||
menuOptions.value.push(menu)
|
menuOptions.value.push(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 查询 ==========
|
// ========== 查询 ==========
|
||||||
const queryParams = reactive({
|
const queryParams = reactive({
|
||||||
name: null,
|
name: null,
|
||||||
@ -316,58 +345,47 @@ const queryParams = reactive({
|
|||||||
})
|
})
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
tableLoading.value = true
|
tableLoading.value = true
|
||||||
statusOption.value = getIntDictOptions(DICT_TYPE.COMMON_STATUS)
|
|
||||||
const res = await MenuApi.getMenuListApi(queryParams)
|
const res = await MenuApi.getMenuListApi(queryParams)
|
||||||
tableData.value = res
|
tableData.value = res
|
||||||
tableLoading.value = false
|
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 () => {
|
const handleQuery = async () => {
|
||||||
await getList()
|
await getList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置操作
|
// 重置操作
|
||||||
const resetQuery = async () => {
|
const resetQuery = async () => {
|
||||||
queryParams.name = null
|
queryParams.name = null
|
||||||
queryParams.status = null
|
queryParams.status = null
|
||||||
await getList()
|
await getList()
|
||||||
}
|
}
|
||||||
// 保存操作
|
|
||||||
const isExternal = (path: string) => {
|
// ========== 新增/修改 ==========
|
||||||
return /^(https?:|mailto:|tel:)/.test(path)
|
|
||||||
|
// 设置标题
|
||||||
|
const setDialogTile = (type: string) => {
|
||||||
|
dialogTitle.value = t('action.' + type)
|
||||||
|
actionType.value = type
|
||||||
|
dialogVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新建操作
|
||||||
|
const handleCreate = () => {
|
||||||
|
setDialogTile('create')
|
||||||
|
// TODO @星语:重置表单
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改操作
|
||||||
|
const handleUpdate = async (row: MenuVO) => {
|
||||||
|
setDialogTile('update')
|
||||||
|
// 设置数据
|
||||||
|
const res = await MenuApi.getMenuApi(row.id)
|
||||||
|
menuForm.value = res
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交新增/修改的表单
|
||||||
const submitForm = async () => {
|
const submitForm = async () => {
|
||||||
actionLoading.value = true
|
actionLoading.value = true
|
||||||
// 提交请求
|
// 提交请求
|
||||||
@ -400,8 +418,26 @@ const submitForm = async () => {
|
|||||||
actionLoading.value = false
|
actionLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断 path 是不是外部的 HTTP 等链接
|
||||||
|
const isExternal = (path: string) => {
|
||||||
|
return /^(https?:|mailto:|tel:)/.test(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 删除 ==========
|
||||||
|
// 删除操作
|
||||||
|
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()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 初始化 ==========
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await getList()
|
await getList()
|
||||||
|
// TODO @星语:这个告警解决下;是不是改成新增和修改点击的时候,去加载下好一点哈?
|
||||||
getTree()
|
getTree()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user