diff --git a/Api/Ewide.Core/Entity/SysMenu.cs b/Api/Ewide.Core/Entity/SysMenu.cs index fd1f95a..6297da5 100644 --- a/Api/Ewide.Core/Entity/SysMenu.cs +++ b/Api/Ewide.Core/Entity/SysMenu.cs @@ -115,11 +115,11 @@ namespace Ewide.Core [Comment("备注")] public string Remark { get; set; } /// - /// 不关联上级菜单显示 0标识关联 1表示不需要关联菜单 仅按钮有效 + /// 关联上级菜单显示 0表示不需要关联菜单 1表示关联 仅按钮有效 /// - [Comment("不关联菜单显示")] - [Column("UnbindParent", TypeName = "bit")] - public bool UnbindParent { get; set; } + [Comment("关联菜单显示")] + [Column("VisibleParent", TypeName = "bit")] + public bool VisibleParent { get; set; } /// /// 状态(字典 0正常 1停用 2删除) diff --git a/Api/Ewide.Core/Service/Menu/Dto/MenuInput.cs b/Api/Ewide.Core/Service/Menu/Dto/MenuInput.cs index affd554..38176ae 100644 --- a/Api/Ewide.Core/Service/Menu/Dto/MenuInput.cs +++ b/Api/Ewide.Core/Service/Menu/Dto/MenuInput.cs @@ -88,9 +88,9 @@ namespace Ewide.Core.Service public string Remark { get; set; } /// - /// 不绑定上级菜单 + /// 绑定上级菜单显示 /// - public int UnbindParent { get; set; } + public bool VisibleParent { get; set; } } public class AddMenuInput : MenuInput diff --git a/Api/Ewide.Core/Service/Menu/Dto/MenuTreeOutput.cs b/Api/Ewide.Core/Service/Menu/Dto/MenuTreeOutput.cs index 40782ed..11fe065 100644 --- a/Api/Ewide.Core/Service/Menu/Dto/MenuTreeOutput.cs +++ b/Api/Ewide.Core/Service/Menu/Dto/MenuTreeOutput.cs @@ -28,10 +28,20 @@ namespace Ewide.Core.Service /// public string Value { get; set; } + /// + /// 菜单类型 + /// + public int Type { get; set; } + + /// + /// 关联显示父级 + /// + public bool VisibleParent { get; set; } + /// /// 排序,越小优先级越高 /// - public int Weight { get; set; } + public int Sort { get; set; } /// /// 子节点 diff --git a/Api/Ewide.Core/Service/Menu/SysMenuService.cs b/Api/Ewide.Core/Service/Menu/SysMenuService.cs index c1b2921..5272e4a 100644 --- a/Api/Ewide.Core/Service/Menu/SysMenuService.cs +++ b/Api/Ewide.Core/Service/Menu/SysMenuService.cs @@ -182,7 +182,7 @@ namespace Ewide.Core.Service var router = input.Router; var permission = input.Permission; var openType = input.OpenType; - var isUnbindParent = input.UnbindParent==1; + var isVisibleParent = input.VisibleParent; if (type.Equals((int)MenuType.DIR)) { @@ -208,8 +208,8 @@ namespace Ewide.Core.Service //if (!urlSet.Contains(permission.Replace(":","/"))) // throw Oops.Oh(ErrorCode.meu1005); } - //按钮可以设置未不绑定菜单 - if(isUnbindParent && type.Equals((int)MenuType.BTN)) + //按钮可以设置绑定菜单 + if(!isVisibleParent && type.Equals((int)MenuType.BTN)) { throw Oops.Oh(ErrorCode.D4004); } @@ -382,7 +382,9 @@ namespace Ewide.Core.Service ParentId = u.Pid, Value = u.Id.ToString(), Title = u.Name, - Weight = u.Sort + Type = u.Type, + VisibleParent = u.VisibleParent, + Sort = u.Sort }).ToListAsync(); return new TreeBuildUtil().DoTreeBuild(menus); } @@ -413,7 +415,9 @@ namespace Ewide.Core.Service ParentId = u.Pid, Value = u.Id.ToString(), Title = u.Name, - Weight = u.Sort + Type = u.Type, + VisibleParent = u.VisibleParent, + Sort = u.Sort }).ToListAsync(); return new TreeBuildUtil().DoTreeBuild(menus); } diff --git a/Web/src/common/login/index.js b/Web/src/common/login/index.js index f2f3473..1ba96ca 100644 --- a/Web/src/common/login/index.js +++ b/Web/src/common/login/index.js @@ -1,6 +1,6 @@ import { api } from '@/common/api' import { token } from '@/common/token' -import { GLOBAL_INFO_KEY, APP_MENU_KEY } from '@/common/storage' +import { GLOBAL_INFO_KEY, ACTIVE_APP_KEY } from '@/common/storage' import { encryptByDES, decryptByDES } from '@/util/des' import app from '@/main' @@ -50,7 +50,7 @@ const doLogout = () => { if (success) { removeGlobal() token.value = '' - window.localStorage.removeItem(APP_MENU_KEY) + window.localStorage.removeItem(ACTIVE_APP_KEY) if (app.$route.path === '/') { app.$router.replace('/login') } else { diff --git a/Web/src/common/storage/index.js b/Web/src/common/storage/index.js index f901c21..8f2cc8a 100644 --- a/Web/src/common/storage/index.js +++ b/Web/src/common/storage/index.js @@ -1,11 +1,11 @@ const SESSION_KEY = '__SESSION' const SETTING_KEY = '__SETTINGS' const GLOBAL_INFO_KEY = '__GLOBAL_INFO' -const APP_MENU_KEY = '__APP_MENU' +const ACTIVE_APP_KEY = '__ACTIVE_APP' export { SESSION_KEY, SETTING_KEY, GLOBAL_INFO_KEY, - APP_MENU_KEY + ACTIVE_APP_KEY } \ No newline at end of file diff --git a/Web/src/components/yoAuthorityView/index.js b/Web/src/components/yoAuthorityView/index.js index 3c8f394..759281a 100644 --- a/Web/src/components/yoAuthorityView/index.js +++ b/Web/src/components/yoAuthorityView/index.js @@ -59,11 +59,18 @@ export default { renderCheckbox(data) { return (
+ {data.visibleParent && data.type == 2 && + + + + } this.onChange(e, data)} - >{data.title} + > + {data.title} +
) }, @@ -100,7 +107,16 @@ export default { this.onSelect(e.target.checked, item) - this.$emit('select', this.list.filter(p => p.checked).map(p => p.id), this.list.filter(p => p.checked || p.indeterminate).map(p => p.id)) + const visible = this.getVisible() + + this.$emit('select', + // 返回所有选中 + this.list.filter(p => p.checked).map(p => p.id), + // 返回所有选中和半选 + this.list.filter(p => p.checked || p.indeterminate).map(p => p.id), + // 返回所有选中和半选,但是不返回没有子级选中visibleParent的半选 + visible + ) }, onSelect(check, item) { @@ -167,6 +183,42 @@ export default { }) }, + getVisible() { + const checked = this.list.filter(p => p.checked) + const caseChildren = checked.filter(p => p.visibleParent || p.type != 2) + const visibleParents = [] + // 递归寻找父级 + const findVisibleParents = (children) => { + const parents = [] + children.forEach(item => { + if (item.parentId) { + const parent = this.list.find(p => p.id === item.parentId) + if (parent) { + parents.push(parent) + visibleParents.push(parent) + } + } + }) + if (parents.length) { + findVisibleParents(parents) + } + } + + findVisibleParents(caseChildren) + + const checkedIds = checked.map(p => p.id) + const visibleParentsIds = visibleParents.map(p => p.id) + + const result = checkedIds + visibleParentsIds.forEach(p => { + if (result.indexOf(p) === -1) { + result.push(p) + } + }) + + return result + }, + }, render() { diff --git a/Web/src/pages/system/menu/form.vue b/Web/src/pages/system/menu/form.vue index dbe65fa..7ce629a 100644 --- a/Web/src/pages/system/menu/form.vue +++ b/Web/src/pages/system/menu/form.vue @@ -94,8 +94,11 @@ + + + - + @@ -132,6 +135,7 @@ const defaultValue = { type: '1', openType: '1', weight: '1', + visibleParent: false, visible: true, sort: 100, }; diff --git a/Web/src/pages/system/role/menuForm.vue b/Web/src/pages/system/role/menuForm.vue index a9114df..4a4523c 100644 --- a/Web/src/pages/system/role/menuForm.vue +++ b/Web/src/pages/system/role/menuForm.vue @@ -69,8 +69,8 @@ export default { }); }, - onSelect(a1, a2) { - this.selectedKeys = a2; + onSelect(a1, a2, a3) { + this.selectedKeys = a3; }, onOk() { diff --git a/Web/src/views/main/_layout/sider/app.vue b/Web/src/views/main/_layout/sider/app.vue index 6bc298d..f97d621 100644 --- a/Web/src/views/main/_layout/sider/app.vue +++ b/Web/src/views/main/_layout/sider/app.vue @@ -37,10 +37,6 @@ export default { }, }, - created() { - console.log(this.apps); - }, - methods: { onChangeApp(app) { this.$emit('change-app', app); diff --git a/Web/src/views/main/_layout/sider/index.vue b/Web/src/views/main/_layout/sider/index.vue index ed8b9d9..0acaa6c 100644 --- a/Web/src/views/main/_layout/sider/index.vue +++ b/Web/src/views/main/_layout/sider/index.vue @@ -82,6 +82,9 @@ export default { mounted() { // swiper不能使用vue版本的组件.效果相当差 swiper = new Swiper('#layout--swiper-container', siderSwiperOptions); + this.$nextTick(() => { + this.onUpdateSwiper(); + }); window.addEventListener('resize', () => { if (this.$root.global.settings.layout === 'left-menu' || this.$root.global.settings.layout === 'right-menu') { diff --git a/Web/src/views/main/index.vue b/Web/src/views/main/index.vue index fad068b..7183d42 100644 --- a/Web/src/views/main/index.vue +++ b/Web/src/views/main/index.vue @@ -40,7 +40,7 @@ import Content from './_layout/content'; import Setting from './setting'; import { setGlobal } from '@/common/login'; -import { APP_MENU_KEY } from '@/common/storage'; +import { ACTIVE_APP_KEY } from '@/common/storage'; import { EMPTY_ID } from '@/util/global'; @@ -210,13 +210,7 @@ export default { this.nav.loading = true; this.$api.sysMenuChange({ application: app.code }).then(({ data }) => { this.nav.apps.map((p) => (p.active = p.code === app.code)); - window.localStorage.setItem( - APP_MENU_KEY, - JSON.stringify({ - ...this.nav.apps.find((p) => p.active), - menus: data, - }) - ); + window.localStorage.removeItem(ACTIVE_APP_KEY); this.onSetNav({ apps: this.nav.apps, menus: data, @@ -229,20 +223,19 @@ export default { onSetNav(nav) { // 从本地存储获取当前选中的应用及菜单 this.nav.apps = nav.apps; - const storage = JSON.parse(window.localStorage.getItem(APP_MENU_KEY)); - if (storage) { - this.nav.apps.map((p) => (p.active = p.code === storage.code)); - this.serializeMenu(storage.menus); + const code = window.localStorage.getItem(ACTIVE_APP_KEY); + if (code) { + this.nav.apps.map((p) => (p.active = p.code === code.code)); + this.onChangeApp({ + code, + }); } else { // 将默认选中菜单存储 - window.localStorage.setItem( - APP_MENU_KEY, - JSON.stringify({ - ...nav.apps.find((p) => p.active), - menus: nav.menus, - }) - ); - this.serializeMenu(nav.menus); + const app = nav.apps.find((p) => p.active); + if (app) { + window.localStorage.setItem(ACTIVE_APP_KEY, app.code); + this.serializeMenu(nav.menus); + } } },