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 type { MenuVO } from './types'
// 查询菜单(精简)列表
// 查询菜单(精简列表
export const listSimpleMenusApi = () => {
return request.get({ url: '/system/menu/list-all-simple' })
}
// 查询菜单列表
export const getMenuListApi = (params) => {
return request.get({ url: '/system/menu/list', params })

View File

@ -1,5 +1,6 @@
<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" :inline="true">
<el-form-item label="菜单名称" prop="name">
<el-input v-model="queryParams.name" placeholder="请输入菜单名称" />
@ -15,17 +16,20 @@
</el-select>
</el-form-item>
<el-form-item>
<!-- 操作搜索 -->
<XButton
type="primary"
preIcon="ep:search"
:title="t('common.query')"
@click="handleQuery()"
/>
<!-- 操作重置 -->
<XButton preIcon="ep:refresh-right" :title="t('common.reset')" @click="resetQuery()" />
</el-form-item>
</el-form>
<vxe-toolbar>
<template #buttons>
<!-- 操作新增 -->
<XButton
type="primary"
preIcon="ep:zoom-in"
@ -37,6 +41,8 @@
<XButton title="关闭所有" @click="xTable?.clearTreeExpand()" />
</template>
</vxe-toolbar>
<!-- 列表 -->
<!-- TODO 星语是不是也搞成 grid 会好点后续代码就统一走 grid 风格 -->
<vxe-table
show-overflow
keep-source
@ -73,12 +79,14 @@
<vxe-column title="创建时间" field="createTime" formatter="formatDate" />
<vxe-column title="操作" width="200">
<template #default="{ row }">
<!-- 操作修改 -->
<XTextButton
preIcon="ep:edit"
:title="t('action.edit')"
v-hasPermi="['system:menu:update']"
@click="handleUpdate(row)"
/>
<!-- 操作删除 -->
<XTextButton
preIcon="ep:delete"
:title="t('action.del')"
@ -89,6 +97,7 @@
</vxe-column>
</vxe-table>
</ContentWrap>
<!-- 添加或修改菜单对话框 -->
<XModal v-model="dialogVisible" id="menuModel" :title="dialogTitle">
<template #default>
<!-- 对话框(添加 / 修改) -->
@ -227,7 +236,7 @@
</el-form>
</template>
<template #footer>
<!-- 操作按钮 -->
<!-- 按钮保存 -->
<XButton
v-if="['create', 'update'].includes(actionType)"
type="primary"
@ -235,22 +244,17 @@
@click="submitForm"
:title="t('action.save')"
/>
<!-- 按钮关闭 -->
<XButton :loading="actionLoading" @click="dialogVisible = false" :title="t('dialog.close')" />
</template>
</XModal>
</template>
<script setup lang="ts">
import * as MenuApi from '@/api/system/menu'
import { MenuVO } from '@/api/system/menu/types'
// import
import { onMounted, reactive, ref } from 'vue'
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'
// TODO @ 'element-plus' '@/components/Tooltip' '@/components/Icon'
import {
ElRow,
ElCol,
@ -264,17 +268,29 @@ import {
ElRadioGroup,
ElRadioButton
} 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'
const { t } = useI18n() //
const message = useMessage()
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 actionType = ref('') //
const actionLoading = ref(false) //
//
const menuForm = ref<MenuVO>({
id: 0,
name: '',
@ -290,12 +306,24 @@ const menuForm = ref<MenuVO>({
keepAlive: true,
createTime: ''
})
//
const rules = reactive({
name: [required],
sort: [required],
path: [required],
status: [required]
})
// ========== [] ==========
// []
// TODO @menuProps
const menuProps = {
checkStrictly: true,
children: 'children',
label: 'name',
value: 'id'
}
// TODO @Tree
interface Tree {
id: number
name: string
@ -309,6 +337,7 @@ const getTree = async () => {
menu.children = handleTree(res)
menuOptions.value.push(menu)
}
// ========== ==========
const queryParams = reactive({
name: null,
@ -316,58 +345,47 @@ const queryParams = reactive({
})
const getList = async () => {
tableLoading.value = true
statusOption.value = getIntDictOptions(DICT_TYPE.COMMON_STATUS)
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 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 () => {
actionLoading.value = true
//
@ -400,8 +418,26 @@ const submitForm = async () => {
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 () => {
await getList()
// TODO @
getTree()
})
</script>