@complex-suite/plugin
Advanced tools
+4
-0
@@ -10,2 +10,6 @@ <!-- | ||
| ### 5.0.18 | ||
| - feat(layout): `PluginLayoutData.visible` 改为 `{ user, system }` 双维度对象,新增 `getVisible`/`getVisibleWidth`/`getVisibleHeight` 方法;移除 `show`/`hide`/`toggle` | ||
| - feat(layout): `PluginLayout` 新增 `setVisible(prop, type, val)` 程序化可见性控制;`triggerChange` 与 `setVisible` 统一触发 `mainChange` 生命周期(source 区分 `change`/`visible`) | ||
| ### 5.0.17 | ||
@@ -12,0 +16,0 @@ - fix(tsconfig): 移除 `extends` 外部引用,改为自包含配置,消除 npm 发布后 extends 解析失败导致 TypeScript 降级到默认 target 的问题 |
+2
-2
| { | ||
| "name": "@complex-suite/plugin", | ||
| "version": "5.0.17", | ||
| "version": "5.0.18", | ||
| "description": "a complex plugin", | ||
@@ -15,3 +15,3 @@ "type": "module", | ||
| "dependencies": { | ||
| "@complex-suite/utils": "3.0.17" | ||
| "@complex-suite/utils": "3.0.18" | ||
| }, | ||
@@ -18,0 +18,0 @@ "devDependencies": { |
+45
-27
@@ -63,3 +63,3 @@ import { _Data, Life, throttle } from "@complex-suite/utils" | ||
| export interface PluginLayoutDataInitOption { | ||
| visible?: boolean | ||
| visible?: { user?: boolean; system?: boolean } | ||
| width?: number | ||
@@ -74,3 +74,3 @@ height?: number | ||
| static $formatConfig = { name: 'PluginLayoutData', level: 80, recommend: true } | ||
| visible: boolean | ||
| visible: { user: boolean; system: boolean } | ||
| width: number | ||
@@ -82,3 +82,6 @@ height: number | ||
| super() | ||
| this.visible = initOption.visible === undefined ? true : initOption.visible | ||
| this.visible = { | ||
| user: initOption.visible?.user ?? true, | ||
| system: initOption.visible?.system ?? true | ||
| } | ||
| this.width = initOption.width || 0 | ||
@@ -96,11 +99,2 @@ this.height = initOption.height || 0 | ||
| } | ||
| show() { | ||
| this.visible = true | ||
| } | ||
| hide() { | ||
| this.visible = false | ||
| } | ||
| toggle() { | ||
| this.visible = !this.visible | ||
| } | ||
| change(width: number, height: number) { | ||
@@ -115,11 +109,23 @@ if (this.width !== width || this.height !== height) { | ||
| } | ||
| /** | ||
| * 当前布局是否真正可见:用户维度(visible.user)与系统维度(visible.system)同时为真 | ||
| */ | ||
| getVisible(): boolean { | ||
| return this.visible.user && this.visible.system | ||
| } | ||
| /** | ||
| * 获取可见状态下的宽度,不可见时返回 0(供样式读取,不影响内部 width 存储) | ||
| */ | ||
| getVisibleWidth(): number { | ||
| return this.getVisible() ? this.width : 0 | ||
| } | ||
| /** | ||
| * 获取可见状态下的高度,不可见时返回 0(供样式读取,不影响内部 height 存储) | ||
| */ | ||
| getVisibleHeight(): number { | ||
| return this.getVisible() ? this.height : 0 | ||
| } | ||
| count(extraLayout: PluginLayoutData) { | ||
| if (this.visible) { | ||
| if (this.width) { | ||
| extraLayout.width += this.width | ||
| } | ||
| if (this.height) { | ||
| extraLayout.height += this.height | ||
| } | ||
| } | ||
| extraLayout.width += this.getVisibleWidth() | ||
| extraLayout.height += this.getVisibleHeight() | ||
| } | ||
@@ -131,8 +137,5 @@ } | ||
| * 当前布局类型标识,用于页面快速判断当前布局形态以决定渲染逻辑 | ||
| * 默认值 'default' 表示无额外布局面板(仅展示页面主体) | ||
| * 可选值由业务层自行约定,例如: | ||
| * - 'default':无侧边栏/顶部栏,仅展示页面 | ||
| * - 'left-menu':左侧菜单 + 页面主体 | ||
| * - 'top-header':顶部 header + 页面主体 | ||
| * - 'left-menu-top-header':左侧菜单 + 顶部 header + 页面主体 | ||
| * 默认值 'default',具体含义由业务层自行约定(不做硬性要求),例如: | ||
| * - 'default':标准布局(含侧边栏/顶部栏) | ||
| * - 'pure':纯净布局(仅页面主体,无侧边栏/顶部栏) | ||
| */ | ||
@@ -203,3 +206,3 @@ type: string | ||
| this.$countMain(true) | ||
| this.triggerLife('change', prop, ...args) | ||
| this.triggerLife('mainChange', 'change', prop, ...args) | ||
| } else { | ||
@@ -209,2 +212,17 @@ this.$exportMsg(pluginLocale.t('layout.moduleNotFound', { prop }), 'error') | ||
| } | ||
| /** | ||
| * 程序化设置布局可见性(不触发 onChange,区别于用户交互的 triggerChange) | ||
| * @param prop 面板名(sider/header/...) | ||
| * @param type 维度:'user' 用户手动 | 'system' 系统自动 | ||
| * @param val 是否可见 | ||
| * prop 未安装时静默返回不报错(系统自动调用场景下不应中断流程) | ||
| * 触发 'mainChange' 生命周期(source='visible'),供业务层监听 | ||
| */ | ||
| setVisible(prop: string, type: 'user' | 'system', val: boolean) { | ||
| const layoutData = this.data[prop] | ||
| if (!layoutData || layoutData.visible[type] === val) return | ||
| layoutData.visible[type] = val | ||
| this.$countMain(true) | ||
| this.triggerLife('mainChange', 'visible', prop, type, val) | ||
| } | ||
| destroy() { | ||
@@ -211,0 +229,0 @@ window.removeEventListener('resize', this.func) |
27371
5.97%567
3.28%+ Added
- Removed
Updated