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 fd145e334540f974139763af30b4d0d145789942..33b2ea86ad18df5fc571ad8d782713342724a87e 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 @@ -13,6 +13,7 @@ import { CodeListItem, useCalcOrMode, useCalcOrModeType, + useCodeListSelection, } from '@ibiz-template/runtime'; import { CheckBoxListEditorController } from '../checkbox-list-editor.controller'; @@ -45,7 +46,7 @@ export const IBizCheckboxList = defineComponent({ () => props.data, newVal => { c.loadCodeList(newVal).then(_codeList => { - items.value = _codeList; + items.value = c.handleCodeListAllItems(_codeList); }); }, { @@ -68,7 +69,7 @@ export const IBizCheckboxList = defineComponent({ const fn = (data: CodeListItem[] | undefined) => { if (data) { - items.value = data; + items.value = c.handleCodeListAllItems(data); } }; @@ -85,6 +86,10 @@ export const IBizCheckboxList = defineComponent({ emit, ); + const { getSelection, getSelectionValue } = useCodeListSelection( + c.allItemsValue, + ); + // 选中数组 const selectArray = computed({ get() { @@ -98,12 +103,24 @@ export const IBizCheckboxList = defineComponent({ codeList?.codeItemValueNumber, ); if (selectsArray) { + if (c.allItems) { + return getSelection([], selectsArray, items.value, items.value); + } return selectsArray; } } return []; }, set(val: Array) { + if (c.allItems) { + const selection = getSelection( + selectArray.value, + val, + items.value, + items.value, + ); + val = getSelectionValue(selection); + } let value: null | string | number | string[] | number[] = null; const { setSelectArray } = calcOrMode; value = setSelectArray(val, items.value, valueSeparator); diff --git a/src/editor/dropdown-list/ibiz-dropdown/ibiz-dropdown.tsx b/src/editor/dropdown-list/ibiz-dropdown/ibiz-dropdown.tsx index 3746e38a87cc500ee9bf635efaae8cd62cb102e6..9de30be0690e2702c392eeb56d8df6625bf303cd 100644 --- a/src/editor/dropdown-list/ibiz-dropdown/ibiz-dropdown.tsx +++ b/src/editor/dropdown-list/ibiz-dropdown/ibiz-dropdown.tsx @@ -16,7 +16,7 @@ import { useCodeListListen, } from '@ibiz-template/vue3-util'; import { OnClickOutsideResult, showTitle } from '@ibiz-template/core'; -import { CodeListItem } from '@ibiz-template/runtime'; +import { CodeListItem, useCodeListSelection } from '@ibiz-template/runtime'; import { DropDownListEditorController } from '../dropdown-list-editor.controller'; import './ibiz-dropdown.scss'; @@ -119,9 +119,12 @@ export const IBizDropdown = defineComponent({ } } isLoading.value = true; - const codeList = await c.loadCodeList(props.data!); + let codeList = await c.loadCodeList(props.data!); + if (c.multiple && !codeList.some(item => item.children)) { + codeList = c.handleCodeListAllItems(codeList); + } isLoadedCodeList.value = true; - if (c.blankItemName) { + if (c.blankItemName && !c.multiple) { items.value = [ { value: undefined, @@ -179,6 +182,10 @@ export const IBizDropdown = defineComponent({ return list.find(item => item.value === value); }; + const { getSelection, getSelectionValue } = useCodeListSelection( + c.allItemsValue, + ); + // 当前值 const curValue = computed({ get() { @@ -190,11 +197,27 @@ export const IBizDropdown = defineComponent({ return props.data[editorItems[0].id!]?.toString(); } if (props.value && typeof props.value === 'string') { + if (c.allItems && c.multiple && !hasChildren.value) { + return getSelection( + [], + props.value.split(','), + items.value as readonly CodeListItem[], + items.value as readonly CodeListItem[], + ).map(v => `${v}`); + } return c!.multiple ? props.value?.toString().split(',') : props.value.toString(); } if (props.value && Array.isArray(props.value)) { + if (c.allItems && c.multiple && !hasChildren.value) { + return getSelection( + [], + props.value, + items.value as readonly CodeListItem[], + items.value as readonly CodeListItem[], + ).map(v => `${v}`); + } return c!.multiple ? props.value : props.value.toString(); } return props.value?.toString(); @@ -206,6 +229,15 @@ export const IBizDropdown = defineComponent({ select = undefined; } if (Array.isArray(select)) { + if (c.allItems && c.multiple && !hasChildren.value) { + const selection = getSelection( + curValue.value as string[], + select, + items.value as readonly CodeListItem[], + items.value as readonly CodeListItem[], + ); + select = getSelectionValue(selection).map(v => `${v}`); + } let selectArr = null; if (select.length === 0) { selectArr = null; @@ -333,6 +365,10 @@ export const IBizDropdown = defineComponent({ const fn = (data: CodeListItem[] | undefined) => { if (data) { + if (c.multiple && !data.some(item => item.children)) { + items.value = c.handleCodeListAllItems(data); + return; + } items.value = data; } }; 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 638de9efbc7668e2fd2d35c1d483a984cb6c6704..2b96d68e3f14719d2035dbfea85243b586c71ff8 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 @@ -21,6 +21,7 @@ import { CodeListItem, useCalcOrMode, useCalcOrModeType, + useCodeListSelection, } from '@ibiz-template/runtime'; import { ListBoxEditorController } from '../list-box-editor.controller'; import { ListBoxPickerEditorController } from '../list-box-picker-editor.controller'; @@ -74,6 +75,10 @@ export const IBizListBox = defineComponent({ if (Object.is('LISTBOX', editorType)) { const controller = c as ListBoxEditorController; controller.loadCodeList(props.data).then(_codeList => { + if (multiple) { + items.value = controller.handleCodeListAllItems(_codeList); + return; + } items.value = _codeList; }); } else if (Object.is('LISTBOXPICKUP', editorType)) { @@ -94,6 +99,12 @@ export const IBizListBox = defineComponent({ const fn = (data: CodeListItem[] | undefined) => { if (data) { + if (Object.is('LISTBOX', editorType) && multiple) { + items.value = (c as ListBoxEditorController).handleCodeListAllItems( + data, + ); + return; + } items.value = data; } }; @@ -123,6 +134,12 @@ export const IBizListBox = defineComponent({ valueSeparator = codeList.valueSeparator; } + const { getSelection, getSelectionValue } = useCodeListSelection( + Object.is('LISTBOX', editorType) + ? (c as ListBoxEditorController).allItemsValue + : '', + ); + // 选中数组 const selectArray: Ref<(string | number)[]> = ref([]); @@ -144,6 +161,14 @@ export const IBizListBox = defineComponent({ ); if (arr) { selectsArray = arr; + if ((c as ListBoxEditorController).allItems) { + selectsArray = getSelection( + [], + selectsArray, + items.value as readonly CodeListItem[], + items.value as readonly CodeListItem[], + ); + } } } else if (editorType === 'LISTBOXPICKUP') { if (newVal !== '') { @@ -169,8 +194,17 @@ export const IBizListBox = defineComponent({ let _value; // 单多选 if (multiple) { - const values = [...value]; + let values = [...value]; if (Object.is('LISTBOX', editorType)) { + if ((c as ListBoxEditorController).allItems) { + const selection = getSelection( + selectArray.value, + values, + items.value as readonly CodeListItem[], + items.value as readonly CodeListItem[], + ); + values = getSelectionValue(selection); + } // 根据代码表模式对值进行计算 const { setSelectArray } = calcOrMode; _value = setSelectArray(