vue3:【menu】

1. 添加 TODO 修改建议
2. 增加注释
3. 调整一些 import、const 的顺序
This commit is contained in:
YunaiV 2022-11-13 02:35:34 +08:00
parent 424520490d
commit 7cbd6cfb68
2 changed files with 89 additions and 52 deletions

View File

@ -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 })

View File

@ -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>