diff --git a/src/control/app-menu/app-menu.tsx b/src/control/app-menu/app-menu.tsx index d29f7e4d71a4f2f848b6418906691087d21c4c73..e79f4d36a7c1b15dc53fb03b0ac2811ef89a2200 100644 --- a/src/control/app-menu/app-menu.tsx +++ b/src/control/app-menu/app-menu.tsx @@ -276,6 +276,10 @@ export const AppMenuControl = defineComponent({ }, ); + const fn = (data: IData) => { + counterData.value = data; + }; + c.evt.on('onMounted', async () => { const allItems = c.getAllItems(); // 默认激活的菜单项 @@ -307,15 +311,13 @@ export const AppMenuControl = defineComponent({ if (counterRefId) { counter = c.getCounter(counterRefId); if (counter) { - counter.onChange((data: IData) => { - counterData.value = data; - }); + counter.onChange(fn); } } }); onUnmounted(() => { - counter?.destroy(); + counter?.offChange(fn); }); const menuMode = computed(() => { diff --git a/src/control/drbar/drbar.tsx b/src/control/drbar/drbar.tsx index 5f6180b2b4775b0f66dd608df70fa4cf30d31aa7..a8178da9a287cd8e62fafe98b28d5073a06b8897 100644 --- a/src/control/drbar/drbar.tsx +++ b/src/control/drbar/drbar.tsx @@ -4,7 +4,14 @@ import { useControlController, useNamespace, } from '@ibiz-template/vue3-util'; -import { defineComponent, PropType, reactive, VNode, watch } from 'vue'; +import { + defineComponent, + onUnmounted, + PropType, + reactive, + VNode, + watch, +} from 'vue'; import { IDEDRBar } from '@ibiz/model-core'; import { useRoute, useRouter } from 'vue-router'; import { IControlProvider, IDRBarItemsState } from '@ibiz-template/runtime'; @@ -28,14 +35,19 @@ export const DRBarControl = defineComponent({ const router = useRouter(); const counterData = reactive({}); + const fn = (counter: IData) => { + Object.assign(counterData, counter); + }; c.evt.on('onCreated', () => { if (c.counter) { - c.counter.onChange((counter: IData) => { - Object.assign(counterData, counter); - }, true); + c.counter.onChange(fn, true); } }); + onUnmounted(() => { + c.counter?.offChange(fn); + }); + c.setRouter(router); const handleSelect = (key: string): void => { diff --git a/src/control/drtab/drtab.tsx b/src/control/drtab/drtab.tsx index 0389189bb27ad4d0b77870990a01deca5fcb53f5..036718ec77acd81b9f1d95e76fd43adc2605ad43 100644 --- a/src/control/drtab/drtab.tsx +++ b/src/control/drtab/drtab.tsx @@ -4,7 +4,7 @@ import { useControlController, useNamespace, } from '@ibiz-template/vue3-util'; -import { defineComponent, PropType, reactive, watch } from 'vue'; +import { defineComponent, onUnmounted, PropType, reactive, watch } from 'vue'; import { IDEDRTab } from '@ibiz/model-core'; import { useRoute, useRouter } from 'vue-router'; import { IControlProvider, hasSubRoute } from '@ibiz-template/runtime'; @@ -26,14 +26,19 @@ export const DRTabControl = defineComponent({ const router = useRouter(); const counterData = reactive({}); + const fn = (counter: IData) => { + Object.assign(counterData, counter); + }; c.evt.on('onCreated', () => { if (c.counter) { - c.counter.onChange((counter: IData) => { - Object.assign(counterData, counter); - }, true); + c.counter.onChange(fn, true); } }); + onUnmounted(() => { + c.counter?.offChange(fn); + }); + c.setRouter(router); const handleTabChange = (): void => { diff --git a/src/control/form/form-detail/form-tab-panel/form-tab-panel.tsx b/src/control/form/form-detail/form-tab-panel/form-tab-panel.tsx index 8b42e8d548a0401b0d1dd8ec7027fe5adae8bca8..0bbabf4ce1325b4185aa5d64881bf9341d4a98d7 100644 --- a/src/control/form/form-detail/form-tab-panel/form-tab-panel.tsx +++ b/src/control/form/form-detail/form-tab-panel/form-tab-panel.tsx @@ -53,6 +53,10 @@ export const FormTabPanel = defineComponent({ } }; + const fn = (data: IData) => { + counterData.value = data; + }; + onMounted(() => { // 计数器相关 const defaultSlots: VNode[] = slots.default?.() || []; @@ -73,15 +77,13 @@ export const FormTabPanel = defineComponent({ if (counterRefId.value) { counter = props.controller.getCounter(counterRefId.value); if (counter) { - counter.onChange((data: IData) => { - counterData.value = data; - }); + counter.onChange(fn); } } }); onUnmounted(() => { - counter?.destroy(); + counter?.offChange(fn); }); return { diff --git a/src/control/grid/grid-column/grid-field-column/grid-field-column.tsx b/src/control/grid/grid-column/grid-field-column/grid-field-column.tsx index 7da5261452bcc322d5d2928276f1245fcb78eb29..5b9d5b4c3ea1f43f19a94fd257d664e53f768f48 100644 --- a/src/control/grid/grid-column/grid-field-column/grid-field-column.tsx +++ b/src/control/grid/grid-column/grid-field-column/grid-field-column.tsx @@ -1,8 +1,10 @@ import { IUIActionGroupDetail } from '@ibiz/model-core'; -import { computed, defineComponent, ref } from 'vue'; +import { computed, defineComponent, onMounted, onUnmounted, ref } from 'vue'; import { useNamespace } from '@ibiz-template/vue3-util'; import './grid-field-column.scss'; import { + CodeListItem, + DynamicCodeListCache, GridFieldColumnController, GridRowState, } from '@ibiz-template/runtime'; @@ -100,6 +102,38 @@ export const GridFieldColumn = defineComponent({ ): Promise => { await props.controller.onActionClick(detail, props.row, event); }; + + const items = ref([]); + if (props.controller.codeList) { + items.value = props.controller.codeListItems!; + } + + const fn = (data: CodeListItem[] | undefined) => { + if (data) { + items.value = data; + } + }; + + let codeListInstance: DynamicCodeListCache | undefined; + + onMounted(async () => { + if (props.controller.model.appCodeListId) { + const app = await ibiz.hub.getApp(props.controller.context.srfappid); + codeListInstance = await app.codeList.getCodeListInstance( + props.controller.model.appCodeListId, + ); + if (codeListInstance) { + codeListInstance.onChange(fn); + } + } + }); + + onUnmounted(() => { + if (codeListInstance) { + codeListInstance.offChange(fn); + } + }); + return { ns, onCellClick, @@ -111,6 +145,7 @@ export const GridFieldColumn = defineComponent({ formatValue, tooltip, zIndex, + items, }; }, render() { @@ -138,7 +173,7 @@ export const GridFieldColumn = defineComponent({ content = ( ({}); + const fn = (counter: IData) => { + Object.assign(counterData, counter); + }; c.evt.on('onCreated', () => { if (c.counter) { - c.counter.onChange((counter: IData) => { - Object.assign(counterData, counter); - }, true); + c.counter.onChange(fn, true); } if (c.controlParams.cascadeselect) { cascadeSelect.value = true; } }); + onUnmounted(() => { + c.counter?.offChange(fn); + }); + const ns = useNamespace(`control-${c.model.controlType!.toLowerCase()}`); const treeRef = ref | null>(null); const treeviewRef = ref(null); diff --git a/src/editor/check-box-list/ibiz-checkbox-list/ibiz-checkbox-list.tsx b/src/editor/check-box-list/ibiz-checkbox-list/ibiz-checkbox-list.tsx index 8e696befe4976c82c5509e9e75449333745403cb..40d1933bb8baf260ee7fb7e75b2b7e474da3a846 100644 --- a/src/editor/check-box-list/ibiz-checkbox-list/ibiz-checkbox-list.tsx +++ b/src/editor/check-box-list/ibiz-checkbox-list/ibiz-checkbox-list.tsx @@ -1,4 +1,11 @@ -import { computed, defineComponent, ref, watch } from 'vue'; +import { + computed, + defineComponent, + ref, + watch, + onMounted, + onUnmounted, +} from 'vue'; import { getCheckboxListProps, getEditorEmits, @@ -7,6 +14,7 @@ import { } from '@ibiz-template/vue3-util'; import { isNil } from 'ramda'; import './ibiz-checkbox-list.scss'; +import { CodeListItem, DynamicCodeListCache } from '@ibiz-template/runtime'; import { CheckBoxListEditorController } from '../checkbox-list-editor.controller'; export const IBizCheckboxList = defineComponent({ @@ -55,6 +63,32 @@ export const IBizCheckboxList = defineComponent({ return 'str'; }); + const fn = (data: CodeListItem[] | undefined) => { + if (data) { + items.value = data; + } + }; + + let codeListInstance: DynamicCodeListCache | undefined; + + onMounted(async () => { + if (c.model.appCodeListId) { + const app = await ibiz.hub.getApp(c.context.srfappid); + codeListInstance = await app.codeList.getCodeListInstance( + c.model.appCodeListId, + ); + if (codeListInstance) { + codeListInstance.onChange(fn); + } + } + }); + + onUnmounted(() => { + if (codeListInstance) { + codeListInstance.offChange(fn); + } + }); + // 值分隔符 let valueSeparator = ','; if (codeList && codeList.valueSeparator) { diff --git a/src/editor/dropdown-list/ibiz-dropdown/ibiz-dropdown.tsx b/src/editor/dropdown-list/ibiz-dropdown/ibiz-dropdown.tsx index dbad31fe9ebc0fc80747dae8750edae2ed435e5f..d97df72cba11ec6fc3c210ed57ca7cf0fae242ab 100644 --- a/src/editor/dropdown-list/ibiz-dropdown/ibiz-dropdown.tsx +++ b/src/editor/dropdown-list/ibiz-dropdown/ibiz-dropdown.tsx @@ -16,6 +16,7 @@ import { } from '@ibiz-template/vue3-util'; import './ibiz-dropdown.scss'; import { OnClickOutsideResult } from '@ibiz-template/core'; +import { CodeListItem, DynamicCodeListCache } from '@ibiz-template/runtime'; import { DropDownListEditorController } from '../dropdown-list-editor.controller'; export const IBizDropdown = defineComponent({ @@ -283,7 +284,24 @@ export const IBizDropdown = defineComponent({ } }; - onMounted(() => { + const fn = (data: CodeListItem[] | undefined) => { + if (data) { + items.value = data; + } + }; + + let codeListInstance: DynamicCodeListCache | undefined; + + onMounted(async () => { + if (c.model.appCodeListId) { + const app = await ibiz.hub.getApp(c.context.srfappid); + codeListInstance = await app.codeList.getCodeListInstance( + c.model.appCodeListId, + ); + if (codeListInstance) { + codeListInstance.onChange(fn); + } + } if (editorRef.value) { funcs = useClickOutside(editorRef, async _evt => { editorState = 'outside'; @@ -295,6 +313,9 @@ export const IBizDropdown = defineComponent({ if (funcs && funcs.stop) { funcs.stop(); } + if (codeListInstance) { + codeListInstance.offChange(fn); + } }); return { diff --git a/src/editor/list-box/ibiz-list-box/ibiz-list-box.tsx b/src/editor/list-box/ibiz-list-box/ibiz-list-box.tsx index b1713144ba8012e12484d2b698952be7495f1bee..79ff4e0037e05d01c22f1435793ec801380fe54d 100644 --- a/src/editor/list-box/ibiz-list-box/ibiz-list-box.tsx +++ b/src/editor/list-box/ibiz-list-box/ibiz-list-box.tsx @@ -1,4 +1,12 @@ -import { computed, defineComponent, Ref, ref, watch } from 'vue'; +import { + computed, + defineComponent, + onMounted, + onUnmounted, + Ref, + ref, + watch, +} from 'vue'; import { getListBoxProps, getEditorEmits, @@ -7,6 +15,7 @@ import { } from '@ibiz-template/vue3-util'; import { isNil } from 'ramda'; import './ibiz-list-box.scss'; +import { CodeListItem, DynamicCodeListCache } from '@ibiz-template/runtime'; import { ListBoxEditorController } from '../list-box-editor.controller'; import { ListBoxPickerEditorController } from '../list-box-picker-editor.controller'; @@ -72,6 +81,32 @@ export const IBizListBox = defineComponent({ loadListBoxItems(); + const fn = (data: CodeListItem[] | undefined) => { + if (data) { + items.value = data; + } + }; + + let codeListInstance: DynamicCodeListCache | undefined; + + onMounted(async () => { + if ((c as ListBoxEditorController).model.appCodeListId) { + const app = await ibiz.hub.getApp(c.context.srfappid); + codeListInstance = await app.codeList.getCodeListInstance( + (c as ListBoxEditorController).model.appCodeListId!, + ); + if (codeListInstance) { + codeListInstance.onChange(fn); + } + } + }); + + onUnmounted(() => { + if (codeListInstance) { + codeListInstance.offChange(fn); + } + }); + // 当前模式 const currentMode = computed(() => { if (codeList && codeList.orMode) { diff --git a/src/editor/radio-button-list/ibiz-radio/ibiz-radio.tsx b/src/editor/radio-button-list/ibiz-radio/ibiz-radio.tsx index d940c1a279c0fe022d5b9531b799fbb52833701b..ca4239485541401b67d659592ef7d9354975c3f1 100644 --- a/src/editor/radio-button-list/ibiz-radio/ibiz-radio.tsx +++ b/src/editor/radio-button-list/ibiz-radio/ibiz-radio.tsx @@ -1,4 +1,11 @@ -import { computed, defineComponent, ref, watch } from 'vue'; +import { + computed, + defineComponent, + onMounted, + onUnmounted, + ref, + watch, +} from 'vue'; import { getEditorEmits, getRadioProps, @@ -7,6 +14,7 @@ import { } from '@ibiz-template/vue3-util'; import './ibiz-radio.scss'; import { notNilEmpty } from 'qx-util'; +import { CodeListItem, DynamicCodeListCache } from '@ibiz-template/runtime'; import { RadioButtonListEditorController } from '../radio-button-list.controller'; export const IBizRadio = defineComponent({ @@ -54,6 +62,32 @@ export const IBizRadio = defineComponent({ }, ); + const fn = (data: CodeListItem[] | undefined) => { + if (data) { + items.value = data; + } + }; + + let codeListInstance: DynamicCodeListCache | undefined; + + onMounted(async () => { + if (c.model.appCodeListId) { + const app = await ibiz.hub.getApp(c.context.srfappid); + codeListInstance = await app.codeList.getCodeListInstance( + c.model.appCodeListId, + ); + if (codeListInstance) { + codeListInstance.onChange(fn); + } + } + }); + + onUnmounted(() => { + if (codeListInstance) { + codeListInstance.offChange(fn); + } + }); + const valueText = computed(() => { // eslint-disable-next-line eqeqeq return items.value.find(item => item.value == props.value)?.text || ''; diff --git a/src/editor/span/span/span.tsx b/src/editor/span/span/span.tsx index bedc8af58d39c94ba430a8b6f766cfa21fde44c0..872247475a929d18e9fe81572cc4b9ed748f511e 100644 --- a/src/editor/span/span/span.tsx +++ b/src/editor/span/span/span.tsx @@ -1,11 +1,19 @@ -import { ref, defineComponent, Ref, watch, computed } from 'vue'; +import { + ref, + defineComponent, + Ref, + watch, + computed, + onUnmounted, + onMounted, +} from 'vue'; import { getSpanProps, useFocusAndBlur, useNamespace, } from '@ibiz-template/vue3-util'; import './span.scss'; -import { CodeListItem } from '@ibiz-template/runtime'; +import { CodeListItem, DynamicCodeListCache } from '@ibiz-template/runtime'; import { isNil } from 'ramda'; import { DataTypes } from '@ibiz-template/core'; import dayjs from 'dayjs'; @@ -129,6 +137,32 @@ export const IBizSpan = defineComponent({ ); } + const fn = (data: CodeListItem[] | undefined) => { + if (data) { + items.value = data; + } + }; + + let codeListInstance: DynamicCodeListCache | undefined; + + onMounted(async () => { + if (c.model.appCodeListId) { + const app = await ibiz.hub.getApp(c.context.srfappid); + codeListInstance = await app.codeList.getCodeListInstance( + c.model.appCodeListId, + ); + if (codeListInstance) { + codeListInstance.onChange(fn); + } + } + }); + + onUnmounted(() => { + if (codeListInstance) { + codeListInstance.offChange(fn); + } + }); + // 聚焦失焦事件 const { componentRef: editorRef } = useFocusAndBlur( () => emit('focus'),