diff --git a/packages/runtime/CHANGELOG.md b/packages/runtime/CHANGELOG.md index 135647f309d243339f29d17ddbad2594c0d6dcdc..4e6fe86484ca9008ceb422dee08473ca952cf6da 100644 --- a/packages/runtime/CHANGELOG.md +++ b/packages/runtime/CHANGELOG.md @@ -14,6 +14,12 @@ - 新增移动端mobWeChatDebug全局参数,控制是否开启微信js-sdk的debug模式 - 新增微信工具类,包含获取签名getSign、配置微信授权config方法 - 新增表单全局参数validateMode与表单部件参数validatemode,为notification时表单项错误信息以通知方式显示 +- 新增部件状态属性isCounterDisabled(是否禁用计数器,值为true时禁用),新增部件能力disableCounter(禁用部件计数器方法) +- 新增表单项计数器,并将表单项计数器逻辑统一迁移至控制器处理 + +### Changed + +- 菜单、表单、搜索栏、工具栏、树、分页导航面板、面板等部件,在初始化计数器时识别部件状态属性isCounterDisabled(是否禁用计数器) ### Fixed diff --git a/packages/runtime/src/controller/common/control/control.controller.ts b/packages/runtime/src/controller/common/control/control.controller.ts index 584e07e7e0639b3e4e01e42e5e7f3ab1416a7165..01917e99b8433377248c7c8a292a77927c5623d8 100644 --- a/packages/runtime/src/controller/common/control/control.controller.ts +++ b/packages/runtime/src/controller/common/control/control.controller.ts @@ -221,6 +221,7 @@ export class ControlController< this.state.disabled = false; this.state.maskOption = { mode: 'BLANK' }; this.state.zIndex = undefined; + this.state.isCounterDisabled = false; } protected async onCreated(): Promise { @@ -681,4 +682,12 @@ export class ControlController< } this.state.maskOption = options; } + + /** + * @description 禁用部件计数器 + * @memberof ControlController + */ + disableCounter(): void { + this.state.isCounterDisabled = true; + } } diff --git a/packages/runtime/src/controller/control/app-menu/app-menu.controller.ts b/packages/runtime/src/controller/control/app-menu/app-menu.controller.ts index 27976dfc825aa72563147a17531a7ac6f4ad62ca..ec1f5642638cb9cf42684740dd74dd1c827b2be6 100644 --- a/packages/runtime/src/controller/control/app-menu/app-menu.controller.ts +++ b/packages/runtime/src/controller/control/app-menu/app-menu.controller.ts @@ -309,6 +309,7 @@ export class AppMenuController * @Date: 2023-07-10 15:14:21 */ getCounter(id: string): AppCounter | null { + if (this.state.isCounterDisabled) return null; const { counters } = this.ctx.view; if (counters[id]) { return counters[id]; diff --git a/packages/runtime/src/controller/control/form/form-detail/form-detail/form-detail.controller.ts b/packages/runtime/src/controller/control/form/form-detail/form-detail/form-detail.controller.ts index d1035c6923b8f9b05a9af3eb6d7cb2481712900b..b5fde585e7d658e5ec4ee82e001140a4a9c9edb0 100644 --- a/packages/runtime/src/controller/control/form/form-detail/form-detail/form-detail.controller.ts +++ b/packages/runtime/src/controller/control/form/form-detail/form-detail/form-detail.controller.ts @@ -10,6 +10,7 @@ import { ScriptFactory, verifyFormGroupLogic } from '../../../../../utils'; import { FormNotifyState } from '../../../../constant'; import { FormDetailState } from './form-detail.state'; import { FormController } from '../../form'; +import { AppCounter } from '../../../../../service'; export class FormDetailController implements IFormDetailController @@ -122,6 +123,13 @@ export class FormDetailController required: undefined, }; + /** + * @description 计数器对象 + * @type {AppCounter} + * @memberof FormDetailController + */ + counter?: AppCounter; + /** * Creates an instance of FormDetailController. * @author lxm @@ -189,6 +197,45 @@ export class FormDetailController this.model.caption, ); } + this.handleCounterChange = this.handleCounterChange.bind(this); + this.initCounter(); + } + + /** + * @description 初始化计数器 + * @protected + * @returns {*} {void} + * @memberof FormDetailController + */ + protected initCounter(): void { + const { counters } = this.form; + const { appCounterRefId } = this.model; + if (appCounterRefId) { + this.counter = counters[appCounterRefId]; + this.counter?.onChange(this.handleCounterChange); + } + } + + /** + * @description 处理计数器改变,并根据计数器模式计算显示状态 + * @protected + * @param {IData} data + * @returns {*} {void} + * @memberof FormDetailController + */ + protected handleCounterChange(data: IData): void { + this.state.counterData = data; + let state: boolean = true; + const { counterId, counterMode } = this.model; + if (counterId) { + const count = this.counter?.getCounter(counterId); + if (counterMode === 1 && count === 0) state = false; + this.state.visible = state; + } + } + + destroy(): void { + this.counter?.offChange(this.handleCounterChange); } /** diff --git a/packages/runtime/src/controller/control/form/form-detail/form-detail/form-detail.state.ts b/packages/runtime/src/controller/control/form/form-detail/form-detail/form-detail.state.ts index 8d4eee57d1e5987d34925dd0d69ed7bf4173b4bd..c11feb7e452320a1dfd667f4428c45f69e68547c 100644 --- a/packages/runtime/src/controller/control/form/form-detail/form-detail/form-detail.state.ts +++ b/packages/runtime/src/controller/control/form/form-detail/form-detail/form-detail.state.ts @@ -81,6 +81,13 @@ export class FormDetailState implements IFormDetailState { */ enableReadonly: boolean = true; + /** + * @description 计数器数据 + * @type {IData} + * @memberof FormDetailState + */ + counterData: IData = {}; + constructor(protected parent?: IFormDetailContainerState) { // 定义是否显示,set方法需要返回true,否则vue proxy报错 let $visible: boolean = true; diff --git a/packages/runtime/src/controller/control/form/form-detail/form-tab-panel/form-tab-panel.controller.ts b/packages/runtime/src/controller/control/form/form-detail/form-tab-panel/form-tab-panel.controller.ts index 0e15acfb4e54a9a276bbb7e35e149b53f3d6566b..08c53b7bc704626be9d0c6543a8e1906a31e4d9c 100644 --- a/packages/runtime/src/controller/control/form/form-detail/form-tab-panel/form-tab-panel.controller.ts +++ b/packages/runtime/src/controller/control/form/form-detail/form-tab-panel/form-tab-panel.controller.ts @@ -28,6 +28,25 @@ export class FormTabPanelController this.state.activeTab = this.model.deformTabPages?.[0].id || ''; } + /** + * @description 初始化计数器 + * @protected + * @returns {*} {void} + * @memberof FormTabPanelController + */ + protected initCounter(): void { + const tabPage = this.model.deformTabPages?.find( + _item => !!_item.appCounterRefId, + ); + if (!tabPage) return; + const { counters } = this.form; + const { appCounterRefId } = tabPage; + if (appCounterRefId) { + this.counter = counters[appCounterRefId]; + this.counter?.onChange(this.handleCounterChange); + } + } + /** * 分页点击切换处理 * @author lxm diff --git a/packages/runtime/src/controller/control/form/form/form.controller.ts b/packages/runtime/src/controller/control/form/form/form.controller.ts index 3624368f5bcee1972bf64d1a2695688ace8aeaba..9590187f337e916b7fca9c83ec5dd8f3ae5c36c3 100644 --- a/packages/runtime/src/controller/control/form/form/form.controller.ts +++ b/packages/runtime/src/controller/control/form/form/form.controller.ts @@ -261,9 +261,9 @@ export abstract class FormController< */ protected async onCreated(): Promise { await super.onCreated(); - await this.initDetailControllers(); // 初始化计数器 await this.initCounter(); + await this.initDetailControllers(); // 数据变更通知防抖,且合并参数 this.dataChangeNotify = debounceAndAsyncMerge( @@ -585,6 +585,9 @@ export abstract class FormController< await super.onDestroyed(); // 销毁视图计数器 Object.values(this.counters).forEach(counter => counter.destroy()); + Object.values(this.formItems).forEach(item => { + item.destroy(); + }); } /** @@ -595,6 +598,7 @@ export abstract class FormController< * @return {*} {Promise} */ protected async initCounter(): Promise { + if (this.state.isCounterDisabled) return; this.counters = {}; const { appCounterRefs } = this.model; if (appCounterRefs && appCounterRefs.length > 0) { diff --git a/packages/runtime/src/controller/control/panel/panel/panel-item.controller.ts b/packages/runtime/src/controller/control/panel/panel/panel-item.controller.ts index 47546f70d1acef6f943231ef8329bc0ce6e32d17..55f445ea1809ee49f14d9a4455bd41f80ecf6624 100644 --- a/packages/runtime/src/controller/control/panel/panel/panel-item.controller.ts +++ b/packages/runtime/src/controller/control/panel/panel/panel-item.controller.ts @@ -133,6 +133,7 @@ export class PanelItemController if (labelSysCss?.cssName) { this.state.class.label.push(labelSysCss.cssName); } + this.handleCounterChange = this.handleCounterChange.bind(this); this.initCounter(); } @@ -145,7 +146,6 @@ export class PanelItemController protected initCounter(): void { const { counters } = this.panel; const { appCounterRefId } = this.model; - this.handleCounterChange = this.handleCounterChange.bind(this); if (appCounterRefId) { this.counter = counters[appCounterRefId]; this.counter?.onChange(this.handleCounterChange); diff --git a/packages/runtime/src/controller/control/panel/panel/panel.controller.ts b/packages/runtime/src/controller/control/panel/panel/panel.controller.ts index c86f044fbf82eee4792a1f988e21c4eda716c822..5f6bd8921153ec6a530d6037f97387ab3b2170fb 100644 --- a/packages/runtime/src/controller/control/panel/panel/panel.controller.ts +++ b/packages/runtime/src/controller/control/panel/panel/panel.controller.ts @@ -166,6 +166,7 @@ export class PanelController< * @memberof PanelController */ protected async initCounter(): Promise { + if (this.state.isCounterDisabled) return; this.counters = {}; const { appCounterRefs } = this.model; if (appCounterRefs && appCounterRefs.length > 0) { diff --git a/packages/runtime/src/controller/control/search-bar/search-bar.controller.ts b/packages/runtime/src/controller/control/search-bar/search-bar.controller.ts index 76aa63bcdaa54e22d15813f77ac1adb3fa3fa0e6..cb90774caa1f056222d3a5bb4a430c0ed5a489f8 100644 --- a/packages/runtime/src/controller/control/search-bar/search-bar.controller.ts +++ b/packages/runtime/src/controller/control/search-bar/search-bar.controller.ts @@ -1069,6 +1069,7 @@ export class SearchBarController * @memberof SearchBarController */ protected async initCounter(): Promise { + if (this.state.isCounterDisabled) return; const { appCounterRefs } = this.model as IData; const appCounterRef = appCounterRefs?.[0]; if (appCounterRef) { diff --git a/packages/runtime/src/controller/control/tab-exp-panel/tab-exp-panel.controller.ts b/packages/runtime/src/controller/control/tab-exp-panel/tab-exp-panel.controller.ts index 9c9e3ad4fdb8572e1ebf938cfc0ba013e9f42815..d7dcbe187b176041ca845525ed03a2624105271e 100644 --- a/packages/runtime/src/controller/control/tab-exp-panel/tab-exp-panel.controller.ts +++ b/packages/runtime/src/controller/control/tab-exp-panel/tab-exp-panel.controller.ts @@ -308,6 +308,7 @@ export class TabExpPanelController * @memberof TabExpPanelController */ protected async initCounter(): Promise { + if (this.state.isCounterDisabled) return; const { appCounterRefs } = this.model as IData; const appCounterRef = appCounterRefs?.[0]; if (appCounterRef) { diff --git a/packages/runtime/src/controller/control/toolbar/toolbar.controller.ts b/packages/runtime/src/controller/control/toolbar/toolbar.controller.ts index f687cf2866b98771a88b8ae24c3f9ed357d5cd0a..76313d70fc7b757825a1a0c3dc5820345cc18e9f 100644 --- a/packages/runtime/src/controller/control/toolbar/toolbar.controller.ts +++ b/packages/runtime/src/controller/control/toolbar/toolbar.controller.ts @@ -213,6 +213,7 @@ export class ToolbarController< * @return {*} */ initCounter(): void { + if (this.state.isCounterDisabled) return; const { counters } = this.ctx.view; const { appCounterRefs } = this.ctx.view.model.viewLayoutPanel!; if (appCounterRefs && appCounterRefs.length > 0) { diff --git a/packages/runtime/src/controller/control/tree/tree.controller.ts b/packages/runtime/src/controller/control/tree/tree.controller.ts index da6d0024bf824aa70677fd46091e6bea22a791b1..def94072b905dd9807f4405b54406e0e681fa01f 100644 --- a/packages/runtime/src/controller/control/tree/tree.controller.ts +++ b/packages/runtime/src/controller/control/tree/tree.controller.ts @@ -280,6 +280,7 @@ export class TreeController< * @return {*} {Promise} */ protected async initCounter(): Promise { + if (this.state.isCounterDisabled) return; const { appCounterRefs } = this.model; const appCounterRef = appCounterRefs?.[0]; if (appCounterRef) { diff --git a/packages/runtime/src/interface/api/controller/control/i-api-control.controller.ts b/packages/runtime/src/interface/api/controller/control/i-api-control.controller.ts index 21973151bbdb9ce78d6834c2d59e12ad492002dd..ddbbbae510b6e6fa39fd42df06b521916199590d 100644 --- a/packages/runtime/src/interface/api/controller/control/i-api-control.controller.ts +++ b/packages/runtime/src/interface/api/controller/control/i-api-control.controller.ts @@ -88,6 +88,12 @@ export interface IApiControlController< */ disabled(options?: IApiMaskOption): void; + /** + * @description 禁用部件计数器 + * @memberof IApiControlController + */ + disableCounter(): void; + /** * @description 触发实体数据变更的通知 * @param {('create' | 'update' | 'remove')} type diff --git a/packages/runtime/src/interface/api/state/control/form-detail/i-api-form-detail.state.ts b/packages/runtime/src/interface/api/state/control/form-detail/i-api-form-detail.state.ts index 9028f2dacc71a048ead40b8774d62584f11a2a08..54b3ac7e9ee765a7317071e0edddeb0b5dcfcad8 100644 --- a/packages/runtime/src/interface/api/state/control/form-detail/i-api-form-detail.state.ts +++ b/packages/runtime/src/interface/api/state/control/form-detail/i-api-form-detail.state.ts @@ -1,3 +1,4 @@ +import { IApiData } from '@ibiz-template/core'; import { IApiColState } from '../../common'; /** @@ -69,4 +70,11 @@ export interface IApiFormDetailState extends IApiColState { * @memberof IApiFormDetailState */ required: boolean; + + /** + * @description 计数器数据 + * @type {IApiData} + * @memberof IApiFormDetailState + */ + counterData: IApiData; } diff --git a/packages/runtime/src/interface/api/state/control/i-api-control.state.ts b/packages/runtime/src/interface/api/state/control/i-api-control.state.ts index a82f45d251cbf0f5aefcb4e4915172065467c401..ec5df78d622178d2b810d9b3a8c81dafbad9ae8a 100644 --- a/packages/runtime/src/interface/api/state/control/i-api-control.state.ts +++ b/packages/runtime/src/interface/api/state/control/i-api-control.state.ts @@ -62,4 +62,11 @@ export interface IApiControlState extends IApiControllerState { * @memberof IApiControlState */ maskOption: IApiMaskOption; + + /** + * @description 是否禁用计数器 + * @type {boolean} + * @memberof IApiControllerState + */ + isCounterDisabled: boolean; } diff --git a/packages/runtime/src/interface/controller/controller/control/form-detail/i-form-detail.controller.ts b/packages/runtime/src/interface/controller/controller/control/form-detail/i-form-detail.controller.ts index 1897c44769219ca2ff7a4e21cc040d8decb474e7..7150a126937d6e0e5ef9c0db08527fc2e290044a 100644 --- a/packages/runtime/src/interface/controller/controller/control/form-detail/i-form-detail.controller.ts +++ b/packages/runtime/src/interface/controller/controller/control/form-detail/i-form-detail.controller.ts @@ -27,4 +27,10 @@ export interface IFormDetailController * @memberof IFormDetailController */ formStateNotify(state: FormNotifyState): Promise; + + /** + * @description 销毁方法 + * @memberof IApiFormDetailController + */ + destroy(): void; }