fix: 🐛 新增菜单顶级菜单显示不正确问题修复

This commit is contained in:
ray
2024-11-26 23:39:35 +08:00
parent 038bfd7a79
commit 5758b80190
2 changed files with 16 additions and 13 deletions

View File

@@ -49,7 +49,7 @@ const MenuAPI = {
* *
* @param id 菜单ID * @param id 菜单ID
*/ */
getFormData(id: number) { getFormData(id: string) {
return request<any, MenuForm>({ return request<any, MenuForm>({
url: `${MENU_BASE_URL}/${id}/form`, url: `${MENU_BASE_URL}/${id}/form`,
method: "get", method: "get",
@@ -118,11 +118,11 @@ export interface MenuVO {
/** ICON */ /** ICON */
icon?: string; icon?: string;
/** 菜单ID */ /** 菜单ID */
id?: number; id?: string;
/** 菜单名称 */ /** 菜单名称 */
name?: string; name?: string;
/** 父菜单ID */ /** 父菜单ID */
parentId?: number; parentId?: string;
/** 按钮权限标识 */ /** 按钮权限标识 */
perm?: string; perm?: string;
/** 跳转路径 */ /** 跳转路径 */
@@ -144,7 +144,7 @@ export interface MenuForm {
/** 菜单ID */ /** 菜单ID */
id?: string; id?: string;
/** 父菜单ID */ /** 父菜单ID */
parentId?: number; parentId?: string;
/** 菜单名称 */ /** 菜单名称 */
name?: string; name?: string;
/** 菜单是否可见(1-是 0-否) */ /** 菜单是否可见(1-是 0-否) */

View File

@@ -23,7 +23,7 @@
v-hasPerm="['sys:menu:add']" v-hasPerm="['sys:menu:add']"
type="success" type="success"
icon="plus" icon="plus"
@click="handleOpenDialog(0)" @click="handleOpenDialog('0')"
> >
新增 新增
</el-button> </el-button>
@@ -357,7 +357,7 @@ const menuOptions = ref<OptionType[]>([]);
// 初始菜单表单数据 // 初始菜单表单数据
const initialMenuFormData = ref<MenuForm>({ const initialMenuFormData = ref<MenuForm>({
id: undefined, id: undefined,
parentId: 0, parentId: "0",
visible: 1, visible: 1,
sort: 1, sort: 1,
type: MenuTypeEnum.MENU, // 默认菜单 type: MenuTypeEnum.MENU, // 默认菜单
@@ -379,7 +379,7 @@ const rules = reactive({
}); });
// 选择表格的行菜单ID // 选择表格的行菜单ID
const selectedMenuId = ref<number | undefined>(); const selectedMenuId = ref<string | undefined>();
// 查询菜单 // 查询菜单
function handleQuery() { function handleQuery() {
@@ -401,7 +401,6 @@ function handleResetQuery() {
// 行点击事件 // 行点击事件
function handleRowClick(row: MenuVO) { function handleRowClick(row: MenuVO) {
// 记录表格选择的菜单ID新增子菜单作为父菜单ID
selectedMenuId.value = row.id; selectedMenuId.value = row.id;
} }
@@ -411,10 +410,10 @@ function handleRowClick(row: MenuVO) {
* @param parentId 父菜单ID * @param parentId 父菜单ID
* @param menuId 菜单ID * @param menuId 菜单ID
*/ */
function handleOpenDialog(parentId?: number, menuId?: number) { function handleOpenDialog(parentId?: string, menuId?: string) {
MenuAPI.getOptions(true) MenuAPI.getOptions(true)
.then((data) => { .then((data) => {
menuOptions.value = [{ value: 0, label: "顶级菜单", children: data }]; menuOptions.value = [{ value: "0", label: "顶级菜单", children: data }];
}) })
.then(() => { .then(() => {
dialog.visible = true; dialog.visible = true;
@@ -501,12 +500,16 @@ function handleDelete(menuId: number) {
); );
} }
function resetRorm() {
menuFormRef.value.resetFields();
menuFormRef.value.clearValidate();
formData.value = { ...initialMenuFormData.value };
}
// 关闭弹窗 // 关闭弹窗
function handleCloseDialog() { function handleCloseDialog() {
dialog.visible = false; dialog.visible = false;
menuFormRef.value.resetFields(); resetRorm();
menuFormRef.value.clearValidate();
formData.value.id = undefined;
} }
onMounted(() => { onMounted(() => {