ipms-sjy-ui/src/views/system/menu/index.vue

216 lines
6.0 KiB
Vue
Raw Normal View History

<template>
<doc-alert title="功能权限" url="https://doc.iocoder.cn/resource-permission" />
<doc-alert title="菜单路由" url="https://doc.iocoder.cn/vue2/route/" />
2023-03-26 22:15:45 +08:00
<!-- 搜索工作栏 -->
<ContentWrap>
2023-03-26 22:15:45 +08:00
<el-form
ref="queryFormRef"
:inline="true"
:model="queryParams"
class="-mb-15px"
2023-03-26 22:15:45 +08:00
label-width="68px"
>
2023-03-25 16:47:20 +08:00
<el-form-item label="菜单名称" prop="name">
<el-input
v-model="queryParams.name"
class="!w-240px"
2023-03-25 16:47:20 +08:00
clearable
placeholder="请输入菜单名称"
2023-03-25 16:47:20 +08:00
@keyup.enter="handleQuery"
/>
</el-form-item>
2023-03-25 16:47:20 +08:00
<el-form-item label="状态" prop="status">
2023-03-26 22:15:45 +08:00
<el-select
v-model="queryParams.status"
class="!w-240px"
clearable
placeholder="请选择菜单状态"
2023-03-26 22:15:45 +08:00
>
2023-03-25 16:47:20 +08:00
<el-option
2023-03-26 22:15:45 +08:00
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
2023-03-25 16:47:20 +08:00
:label="dict.label"
2023-03-26 22:15:45 +08:00
:value="dict.value"
2023-03-25 16:47:20 +08:00
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery">
<Icon class="mr-5px" icon="ep:search" />
搜索
</el-button>
<el-button @click="resetQuery">
<Icon class="mr-5px" icon="ep:refresh" />
重置
</el-button>
2023-03-26 22:15:45 +08:00
<el-button
v-hasPermi="['system:menu:create']"
2023-03-26 22:15:45 +08:00
plain
type="primary"
2023-03-26 22:15:45 +08:00
@click="openForm('create')"
>
<Icon class="mr-5px" icon="ep:plus" />
新增
</el-button>
<el-button plain type="danger" @click="toggleExpandAll">
<Icon class="mr-5px" icon="ep:sort" />
展开/折叠
2023-03-25 16:47:20 +08:00
</el-button>
<el-button plain @click="refreshMenu">
<Icon class="mr-5px" icon="ep:refresh" />
刷新菜单缓存
2023-03-26 22:15:45 +08:00
</el-button>
</el-form-item>
</el-form>
2023-03-26 22:15:45 +08:00
</ContentWrap>
2023-03-25 16:47:20 +08:00
2023-03-26 22:15:45 +08:00
<!-- 列表 -->
<ContentWrap>
2023-03-25 16:47:20 +08:00
<el-table
v-if="refreshTable"
2023-03-25 16:47:20 +08:00
v-loading="loading"
:data="list"
:default-expand-all="isExpandAll"
row-key="id"
2023-03-25 16:47:20 +08:00
>
<el-table-column :show-overflow-tooltip="true" label="菜单名称" prop="name" width="250" />
<el-table-column align="center" label="图标" prop="icon" width="100">
2023-03-25 16:47:20 +08:00
<template #default="scope">
<Icon :icon="scope.row.icon" />
</template>
</el-table-column>
<el-table-column label="排序" prop="sort" width="60" />
<el-table-column :show-overflow-tooltip="true" label="权限标识" prop="permission" />
<el-table-column :show-overflow-tooltip="true" label="组件路径" prop="component" />
<el-table-column :show-overflow-tooltip="true" label="组件名称" prop="componentName" />
<el-table-column label="状态" prop="status" width="80">
2023-03-25 16:47:20 +08:00
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column align="center" label="操作">
2023-03-25 16:47:20 +08:00
<template #default="scope">
<el-button
v-hasPermi="['system:menu:update']"
2023-03-25 16:47:20 +08:00
link
type="primary"
2023-03-26 22:15:45 +08:00
@click="openForm('update', scope.row.id)"
2023-03-25 16:47:20 +08:00
>
2023-03-26 22:15:45 +08:00
修改
</el-button>
2023-03-25 16:47:20 +08:00
<el-button
v-hasPermi="['system:menu:create']"
2023-03-25 16:47:20 +08:00
link
type="primary"
2023-03-26 22:15:45 +08:00
@click="openForm('create', undefined, scope.row.id)"
2023-03-25 16:47:20 +08:00
>
2023-03-26 22:15:45 +08:00
新增
</el-button>
2023-03-25 16:47:20 +08:00
<el-button
v-hasPermi="['system:menu:delete']"
2023-03-25 16:47:20 +08:00
link
2023-03-26 22:15:45 +08:00
type="danger"
2023-03-25 16:47:20 +08:00
@click="handleDelete(scope.row.id)"
>
2023-03-26 22:15:45 +08:00
删除
</el-button>
2023-03-25 16:47:20 +08:00
</template>
</el-table-column>
</el-table>
</ContentWrap>
2023-03-26 22:15:45 +08:00
2023-03-25 16:47:20 +08:00
<!-- 表单弹窗添加/修改 -->
2023-03-26 22:15:45 +08:00
<MenuForm ref="formRef" @success="getList" />
</template>
2023-06-21 19:14:34 +08:00
<script lang="ts" setup>
2023-03-26 22:15:45 +08:00
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
2023-03-25 16:47:20 +08:00
import { handleTree } from '@/utils/tree'
import * as MenuApi from '@/api/system/menu'
2023-03-26 22:15:45 +08:00
import MenuForm from './MenuForm.vue'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
2023-06-21 19:14:34 +08:00
defineOptions({ name: 'SystemMenu' })
const { wsCache } = useCache()
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
2023-03-25 16:47:20 +08:00
const loading = ref(true) // 列表的加载中
const list = ref<any>([]) // 列表的数据
const queryParams = reactive({
name: undefined,
status: undefined
})
2023-03-25 16:47:20 +08:00
const queryFormRef = ref() // 搜索的表单
2023-03-26 22:15:45 +08:00
const isExpandAll = ref(false) // 是否展开,默认全部折叠
const refreshTable = ref(true) // 重新渲染表格状态
2023-03-28 23:18:10 +08:00
/** 查询列表 */
2023-03-25 16:47:20 +08:00
const getList = async () => {
loading.value = true
try {
2023-03-26 22:15:45 +08:00
const data = await MenuApi.getMenuList(queryParams)
2023-03-25 16:47:20 +08:00
list.value = handleTree(data)
} finally {
loading.value = false
}
}
2023-03-25 16:47:20 +08:00
/** 搜索按钮操作 */
const handleQuery = () => {
getList()
}
2023-03-25 16:47:20 +08:00
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
2023-03-25 16:47:20 +08:00
/** 添加/修改操作 */
2023-03-26 22:15:45 +08:00
const formRef = ref()
const openForm = (type: string, id?: number, parentId?: number) => {
formRef.value.open(type, id, parentId)
}
2023-03-25 16:47:20 +08:00
/** 展开/折叠操作 */
const toggleExpandAll = () => {
refreshTable.value = false
isExpandAll.value = !isExpandAll.value
nextTick(() => {
refreshTable.value = true
})
}
/** 刷新菜单缓存按钮操作 */
const refreshMenu = async () => {
try {
await message.confirm('即将更新缓存刷新浏览器!', '刷新菜单缓存')
// 清空,从而触发刷新
wsCache.delete(CACHE_KEY.USER)
wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
// 刷新浏览器
location.reload()
} catch {}
}
2023-03-25 16:47:20 +08:00
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
2023-03-25 16:47:20 +08:00
// 删除的二次确认
await message.delConfirm()
// 发起删除
2023-03-26 22:15:45 +08:00
await MenuApi.deleteMenu(id)
2023-03-25 16:47:20 +08:00
message.success(t('common.delSuccess'))
// 刷新列表
await getList()
} catch {}
}
2023-03-25 16:47:20 +08:00
/** 初始化 **/
onMounted(() => {
getList()
})
</script>