From d7632b7963608ebb977702d6502522ce95c5918d Mon Sep 17 00:00:00 2001 From: ShineKOT <1917095344@qq.com> Date: Thu, 4 Jul 2024 19:22:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=20=E6=96=B0=E5=A2=9E=E6=89=93=E5=BC=80?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/index.ts | 2 + src/common/quick-edit/quick-edit.scss | 8 ++ src/common/quick-edit/quick-edit.tsx | 141 ++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 src/common/quick-edit/quick-edit.scss create mode 100644 src/common/quick-edit/quick-edit.tsx diff --git a/src/common/index.ts b/src/common/index.ts index 9ebf66f74..11cbd0662 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -30,6 +30,7 @@ import { IBizCoopAlert } from './coop-alert/coop-alert'; import { CustomTheme } from './custom-theme/custom-theme'; import { IBizCarouselCard } from './carousel-card/carousel-card'; import { IBizEmojiSelect } from './emoji-select/emoji-select'; +import { IBizQuickEdit } from './quick-edit/quick-edit'; export * from './col/col'; export * from './row/row'; @@ -44,6 +45,7 @@ export { DoingNotice } from './doing-notice/doing-notice'; export const IBizCommonComponents = { install: (v: App): void => { v.component(IBizControlBase.name, IBizControlBase); + v.component(IBizQuickEdit.name, IBizQuickEdit); v.component(IBizEmojiSelect.name, IBizEmojiSelect); v.component(IBizIcon.name, IBizIcon); v.component(DoingNotice.name, DoingNotice); diff --git a/src/common/quick-edit/quick-edit.scss b/src/common/quick-edit/quick-edit.scss new file mode 100644 index 000000000..f63e0cd75 --- /dev/null +++ b/src/common/quick-edit/quick-edit.scss @@ -0,0 +1,8 @@ +@include b('quick-edit') { + + @include e('footer') { + display: flex; + justify-content: end; + padding: getCssVar('spacing', 'tight'); + } +} \ No newline at end of file diff --git a/src/common/quick-edit/quick-edit.tsx b/src/common/quick-edit/quick-edit.tsx new file mode 100644 index 000000000..c8806f172 --- /dev/null +++ b/src/common/quick-edit/quick-edit.tsx @@ -0,0 +1,141 @@ +import { defineComponent, PropType, Ref, ref } from 'vue'; +import { + IDEEditForm, + IDEEditFormItem, + IDEFormDetail, + IDEFormItem, +} from '@ibiz/model-core'; +import { useNamespace } from '@ibiz-template/vue3-util'; +import { + EventBase, + IModalData, + EditFormController, + findChildFormDetails, +} from '@ibiz-template/runtime'; +import './quick-edit.scss'; + +export const IBizQuickEdit = defineComponent({ + name: 'IBizQuickEdit', + props: { + context: { + type: Object as PropType, + required: true, + }, + params: { + type: Object as PropType, + required: true, + }, + modelData: { + type: Object as PropType, + }, + }, + emits: { + close: (_modalData: IModalData) => true, + }, + setup(props, { emit }) { + const ns = useNamespace('quick-edit'); + const controller: Ref = ref(undefined); + const editItemModel: IDEFormItem[] = []; + + /** + * 递归查找编辑项 + * + * @param {IDEFormDetail} detail + */ + const findEditItem = (detail: IDEFormDetail): void => { + const childern = findChildFormDetails(detail); + childern.forEach(child => { + if (child.detailType === 'FORMITEM' && !(child as IDEFormItem).hidden) { + editItemModel.push(child); + } + findEditItem(child); + }); + }; + + /** + * 初始化 + * + */ + const init = (): void => { + if (props.modelData) { + props.modelData.deformPages?.forEach(child => { + findEditItem(child); + }); + } + }; + + init(); + + /** + * 控制器创建完成 + * + * @param {EventBase} event + */ + const onCreated = (event: EventBase): void => { + controller.value = event.ctrl as EditFormController; + }; + + /** + * 获取编辑项数据 + * + */ + const getEditItemData = (): IData => { + const data: IData = {}; + const item = (controller.value as IData).getDiffData(); + editItemModel.forEach(formItem => { + const uiKey = formItem.id!.toLowerCase(); + const deKey = + formItem.fieldName || (formItem as IDEEditFormItem).appDEFieldId!; + if (item[uiKey]) { + data[deKey] = item[uiKey]; + } + }); + return data; + }; + + /** + * 确认 + * + */ + const onConfirm = (): void => { + let data: IData[] | undefined; + if (controller.value) { + const item = getEditItemData(); + if (Object.keys(item).length > 0) { + data = [item]; + } + } + emit('close', { ok: true, data }); + }; + + /** + * 取消 + * + */ + const onCancel = (): void => { + emit('close', { ok: false }); + }; + + return { ns, onCreated, onConfirm, onCancel }; + }, + render() { + return ( +
+ +
+ + {ibiz.i18n.t('app.cancel')} + + + {ibiz.i18n.t('app.confirm')} + +
+
+ ); + }, +}); -- Gitee