Commit cea2999c authored by baiyinhao's avatar baiyinhao

修改菜单-新增菜单类型标记

parent b361c818
...@@ -15,9 +15,8 @@ ...@@ -15,9 +15,8 @@
import { BasicForm, useForm } from '@/components/Form'; import { BasicForm, useForm } from '@/components/Form';
import { formSchema } from './menu.data'; import { formSchema } from './menu.data';
import { BasicDrawer, useDrawerInner } from '@/components/Drawer'; import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
import { menuDetailApi,menuUpdataApi,getMenuList,addMenuApi } from "@/api/system/menu/menu"; import { menuDetailApi, menuUpdataApi, getMenuList, addMenuApi } from '@/api/system/menu/menu';
import {useMessage} from "@/hooks/web/useMessage"; import { useMessage } from '@/hooks/web/useMessage';
defineOptions({ name: 'MenuDrawer' }); defineOptions({ name: 'MenuDrawer' });
const emit = defineEmits(['success', 'register']); const emit = defineEmits(['success', 'register']);
...@@ -41,30 +40,30 @@ ...@@ -41,30 +40,30 @@
// 获取行数据的菜单id // 获取行数据的菜单id
menuId.value = data.record.businessId; menuId.value = data.record.businessId;
// 通过id获取菜单详情信息 // 通过id获取菜单详情信息
menuDetailApi(menuId.value).then(res => { menuDetailApi(menuId.value).then((res) => {
const form = res.data const form = res.data;
// 塞值 // 塞值
setFieldsValue({ setFieldsValue({
...form, ...form,
}); });
}) });
} }
if (unref(isAdd)){ if (unref(isAdd)) {
// 通过id获取菜单详情信息 // 通过id获取菜单详情信息
const id = data.record.businessId const id = data.record.businessId;
const params = { const params = {
parentId: id, parentId: id,
} };
// 塞值 // 塞值
setFieldsValue({ setFieldsValue({
...params, ...params,
}); });
} }
var treeData = [] var treeData = [];
const res = await getMenuList(); const res = await getMenuList();
const menu = { businessId: 0,parentId: 0 ,menuName: '主类目', children: [] } const menu = { businessId: 0, parentId: 0, menuName: '主类目', children: [] };
menu.children = handleTree(res.data, 'businessId',undefined,undefined,undefined) menu.children = handleTree(res.data, 'businessId', undefined, undefined, undefined);
treeData.push(menu) treeData.push(menu);
updateSchema({ updateSchema({
field: 'parentId', field: 'parentId',
componentProps: { treeData }, componentProps: { treeData },
...@@ -77,15 +76,18 @@ ...@@ -77,15 +76,18 @@
const formData = await validate(); const formData = await validate();
setDrawerProps({ confirmLoading: true }); setDrawerProps({ confirmLoading: true });
// 编辑 // 编辑
if(unref(isUpdate)) { if (unref(isUpdate)) {
formData.businessId = menuId.value formData.businessId = menuId.value;
menuUpdataApi(formData).then(res => { menuUpdataApi(formData).then((res) => {
if(res.code === 200){ if (res.code === 200) {
createMessage.success('编辑成功'); createMessage.success('编辑成功');
closeDrawer(); closeDrawer();
emit('success', { isUpdate: unref(isUpdate), values: { ...formData, businessId: menuId.value } }); emit('success', {
isUpdate: unref(isUpdate),
values: { ...formData, businessId: menuId.value },
});
} }
}) });
} else { } else {
//新增 //新增
const paramsAdd = { const paramsAdd = {
...@@ -102,14 +104,18 @@ ...@@ -102,14 +104,18 @@
path: formData.path, path: formData.path,
perms: formData.perms, perms: formData.perms,
component: formData.component, component: formData.component,
} remarks: formData.remarks,
addMenuApi(paramsAdd).then(res => { };
if(res.code === 200){ addMenuApi(paramsAdd).then((res) => {
if (res.code === 200) {
createMessage.success('新增成功'); createMessage.success('新增成功');
closeDrawer(); closeDrawer();
emit('success', { isUpdate: unref(isUpdate), values: { ...formData, businessId: menuId.value } }); emit('success', {
isUpdate: unref(isUpdate),
values: { ...formData, businessId: menuId.value },
});
} }
}) });
} }
} finally { } finally {
setDrawerProps({ confirmLoading: false }); setDrawerProps({ confirmLoading: false });
...@@ -118,22 +124,30 @@ ...@@ -118,22 +124,30 @@
/**结构转换方法*/ /**结构转换方法*/
function handleTree(data, id, parentId, children, rootId) { function handleTree(data, id, parentId, children, rootId) {
id = id || 'id' id = id || 'id';
parentId = parentId || 'parentId' parentId = parentId || 'parentId';
children = children || 'children' children = children || 'children';
rootId = rootId || Math.min.apply(Math, data.map(item => { return item[parentId] })) || 0 rootId =
rootId ||
Math.min.apply(
Math,
data.map((item) => {
return item[parentId];
}),
) ||
0;
// 对源数据深度克隆 // 对源数据深度克隆
const cloneData = JSON.parse(JSON.stringify(data)) const cloneData = JSON.parse(JSON.stringify(data));
// 循环所有项 // 循环所有项
const treeData = cloneData.filter(father => { const treeData = cloneData.filter((father) => {
const branchArr = cloneData.filter(child => { const branchArr = cloneData.filter((child) => {
// 返回每一项的子级数组 // 返回每一项的子级数组
return father[id] === child[parentId] return father[id] === child[parentId];
}) });
branchArr.length > 0 ? father.children = branchArr : '' branchArr.length > 0 ? (father.children = branchArr) : '';
// 返回第一层 // 返回第一层
return father[parentId] === rootId return father[parentId] === rootId;
}) });
return treeData !== '' ? treeData : data return treeData !== '' ? treeData : data;
} }
</script> </script>
...@@ -9,17 +9,17 @@ ...@@ -9,17 +9,17 @@
<TableAction <TableAction
:actions="[ :actions="[
{ {
label:'新增', label: '新增',
onClick: handleAdd.bind(null, record), onClick: handleAdd.bind(null, record),
}, },
{ {
// icon: 'clarity:note-edit-line', // icon: 'clarity:note-edit-line',
label:'修改', label: '修改',
onClick: handleEdit.bind(null, record), onClick: handleEdit.bind(null, record),
}, },
{ {
// icon: 'ant-design:delete-outlined', // icon: 'ant-design:delete-outlined',
label:'删除', label: '删除',
color: 'error', color: 'error',
popConfirm: { popConfirm: {
title: '是否确认删除', title: '是否确认删除',
...@@ -40,12 +40,12 @@ ...@@ -40,12 +40,12 @@
import { useDrawer } from '@/components/Drawer'; import { useDrawer } from '@/components/Drawer';
import MenuDrawer from './MenuDrawer.vue'; import MenuDrawer from './MenuDrawer.vue';
import { columns, searchFormSchema } from './menu.data'; import { columns, searchFormSchema } from './menu.data';
import { deleteById,getMenuListByPage } from "@/api/system/menu/menu"; import { deleteById, getMenuListByPage } from '@/api/system/menu/menu';
import { useMessage } from "@/hooks/web/useMessage"; import { useMessage } from '@/hooks/web/useMessage';
import { ref,reactive,unref,onDeactivated,onMounted,nextTick } from 'vue'; import { ref, reactive, unref, onDeactivated, onMounted, nextTick } from 'vue';
import { useRoute,onBeforeRouteLeave } from 'vue-router'; import { useRoute, onBeforeRouteLeave } from 'vue-router';
import { useFilterStore } from '@/store/modules/filterData'; import { useFilterStore } from '@/store/modules/filterData';
import { useUserStore } from "@/store/modules/user"; import { useUserStore } from '@/store/modules/user';
defineOptions({ name: 'MenuManagement' }); defineOptions({ name: 'MenuManagement' });
const filterStore = useFilterStore(); const filterStore = useFilterStore();
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
const { createMessage } = useMessage(); const { createMessage } = useMessage();
const [registerDrawer, { openDrawer }] = useDrawer(); const [registerDrawer, { openDrawer }] = useDrawer();
const treeData = ref(); const treeData = ref();
const [registerTable, { reload, expandAll,getForm }] = useTable({ const [registerTable, { reload, expandAll, getForm }] = useTable({
title: '菜单列表', title: '菜单列表',
api: async (params) => { api: async (params) => {
const response = await getMenuListByPage(params); const response = await getMenuListByPage(params);
...@@ -85,29 +85,37 @@ ...@@ -85,29 +85,37 @@
/**改变列表结构 列表->树*/ /**改变列表结构 列表->树*/
function transformData(data) { function transformData(data) {
treeData.value = handleTree(data, 'businessId',undefined,undefined,undefined) treeData.value = handleTree(data, 'businessId', undefined, undefined, undefined);
return treeData.value return treeData.value;
} }
/**结构转换方法*/ /**结构转换方法*/
function handleTree(data, id, parentId, children, rootId) { function handleTree(data, id, parentId, children, rootId) {
id = id || 'id' id = id || 'id';
parentId = parentId || 'parentId' parentId = parentId || 'parentId';
children = children || 'children' children = children || 'children';
rootId = rootId || Math.min.apply(Math, data.map(item => { return item[parentId] })) || 0 rootId =
rootId ||
Math.min.apply(
Math,
data.map((item) => {
return item[parentId];
}),
) ||
0;
// 对源数据深度克隆 // 对源数据深度克隆
const cloneData = JSON.parse(JSON.stringify(data)) const cloneData = JSON.parse(JSON.stringify(data));
// 循环所有项 // 循环所有项
const treeData = cloneData.filter(father => { const treeData = cloneData.filter((father) => {
const branchArr = cloneData.filter(child => { const branchArr = cloneData.filter((child) => {
// 返回每一项的子级数组 // 返回每一项的子级数组
return father[id] === child[parentId] return father[id] === child[parentId];
}) });
branchArr.length > 0 ? father.children = branchArr : '' branchArr.length > 0 ? (father.children = branchArr) : '';
// 返回第一层 // 返回第一层
return father[parentId] === rootId return father[parentId] === rootId;
}) });
return treeData !== '' ? treeData : data return treeData !== '' ? treeData : data;
} }
/**新增*/ /**新增*/
...@@ -152,31 +160,29 @@ ...@@ -152,31 +160,29 @@
/**进入页面的初始化方法*/ /**进入页面的初始化方法*/
onMounted(() => { onMounted(() => {
const path = route.path const path = route.path;
if(filterStore.getSearchParams[path]) { if (filterStore.getSearchParams[path]) {
if(JSON.parse(filterStore.getSearchParams[path] !== {})){ if (JSON.parse(filterStore.getSearchParams[path] !== {})) {
const params = JSON.parse(filterStore.getSearchParams[path]) const params = JSON.parse(filterStore.getSearchParams[path]);
getForm().setFieldsValue({ getForm().setFieldsValue({
page: params.page, page: params.page,
pageSize: params.pageSize, pageSize: params.pageSize,
menuName: params.menuName, menuName: params.menuName,
flag: params.flag, flag: params.flag,
}) });
} }
} }
}); });
/**离开路由前调用的钩子函数*/ /**离开路由前调用的钩子函数*/
onBeforeRouteLeave((to, from, next) => { onBeforeRouteLeave((to, from, next) => {
const params = Object.assign({},getForm().getFieldsValue()); const params = Object.assign({}, getForm().getFieldsValue());
filterStore.setSearchParams( filterStore.setSearchParams({
{ path: from.path,
path: from.path, param: {
param: { ...params,
...params },
} });
}
)
next(); // 允许导航 next(); // 允许导航
}); });
</script> </script>
import { BasicColumn, FormSchema } from '@/components/Table'; import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue'; import { h } from 'vue';
import {Switch, Tag} from 'ant-design-vue'; import { Switch, Tag } from 'ant-design-vue';
import Icon from '@/components/Icon/Icon.vue'; import Icon from '@/components/Icon/Icon.vue';
import {useMessage} from "@/hooks/web/useMessage"; import { useMessage } from '@/hooks/web/useMessage';
import {setMenuStatus} from "@/api/system/menu/menu"; import { setMenuStatus } from '@/api/system/menu/menu';
export const columns: BasicColumn[] = [ export const columns: BasicColumn[] = [
{ {
...@@ -65,12 +65,12 @@ export const columns: BasicColumn[] = [ ...@@ -65,12 +65,12 @@ export const columns: BasicColumn[] = [
path: record.path, path: record.path,
perms: record.perms, perms: record.perms,
component: record.component, component: record.component,
} };
setMenuStatus(params) setMenuStatus(params)
.then(() => { .then(() => {
record.flag = newStatus; record.flag = newStatus;
const text = record.flag === '1' ? '启用' : '停用' const text = record.flag === '1' ? '启用' : '停用';
createMessage.success( text + `成功`); createMessage.success(text + `成功`);
}) })
.catch(() => { .catch(() => {
// createMessage.error('操作失败'); // createMessage.error('操作失败');
...@@ -260,4 +260,18 @@ export const formSchema: FormSchema[] = [ ...@@ -260,4 +260,18 @@ export const formSchema: FormSchema[] = [
], ],
ifShow: ({ values }) => !isButton(values.menuType), ifShow: ({ values }) => !isButton(values.menuType),
}, },
{
field: 'remarks',
label: '菜单类型标记',
component: 'Select',
componentProps: {
placeholder: '请选择菜单类型',
options: [
{ label: '第一模块', value: '1' },
{ label: '第二模块', value: '2' },
{ label: '第三模块', value: '3' },
{ label: '第四模块', value: '4' },
],
},
},
]; ];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment