From e7288043a475a3b7df4681b92143576ad2c7043f Mon Sep 17 00:00:00 2001 From: Sagi Date: Sat, 1 Oct 2022 22:12:39 +0800 Subject: [PATCH] refactor(section): refector section render function --- .../section/src/section.component.tsx | 154 ++++++++++++------ .../components/section/src/section.props.ts | 7 +- packages/ui-vue/src/App.vue | 2 + packages/ui-vue/src/components/section.vue | 13 ++ 4 files changed, 124 insertions(+), 52 deletions(-) create mode 100644 packages/ui-vue/src/components/section.vue diff --git a/packages/ui-vue/components/section/src/section.component.tsx b/packages/ui-vue/components/section/src/section.component.tsx index d292c9a..b06fda6 100644 --- a/packages/ui-vue/components/section/src/section.component.tsx +++ b/packages/ui-vue/components/section/src/section.component.tsx @@ -10,6 +10,14 @@ export default defineComponent({ return true; }); + const shouldShowHeaderTitle = computed(() => { + return true; + }); + + const shouldShowSubHeaderTitle = computed(() => { + return true; + }); + const shouldShowToolbarInHeader = computed(() => { return false; }); @@ -28,65 +36,109 @@ export default defineComponent({ const toolbarButtons = ref([]); - const headerClass = computed(() => ({})); + const headerClass = computed(() => { + const customClassArray = props.headerClass.split(' '); + const headClassObject = { + 'f-section-header': true + }; + customClassArray.reduce>((classObject, classString) => { + classObject[classString] = true; + return classObject; + }, headClassObject); + return headClassObject; + }); - const extendAreaClass = computed(() => ({})); - - const contentClass = computed(() => ({ - 'f-section-content': true, + const extendAreaClass = computed(() => ({ + 'f-section-extend': true })); - function getToolbarState() { + const contentClass = computed(() => { + const customClassArray = props.contentClass.split(' '); + const contentClassObject = { + 'f-section-content': true + }; + customClassArray.reduce((classObject, classString) => { + classObject[classString] = true; + return classObject; + }, contentClassObject); + return contentClassObject; + }); + + function getToolbarState(buttonId: string, visiableMap: any, defaultValue: boolean) { return true; } + const mainTitle = ref(props.mainTitle); + + const subTitle = ref(props.subTitle); + + function renderSectionHeader() { + return ( + shouldShowHeader.value && ( +
+ {shouldShowHeaderTitle.value && ( +
+

{mainTitle.value}

+ {shouldShowSubHeaderTitle.value && {subTitle}} +
+ )} +
+ ) + ); + } + + function renderSectionContent() { + return
{context.slots.default && context.slots.default()}
; + } + return () => { return ( - <> - {shouldShowHeader.value && ( -
- {shouldShowToolbarInHeader.value && ( -
- {toolbarButtons.value - .filter((toolButton: ButtonConfig) => getToolbarState(toolButton.id, btnVisible, true)) - .forEach((toolButton: ButtonConfig) => { - return ; - })} -
- )} -
- )} - {shouldShowToolbarInContent.value && ( -
- {toolbarButtons.value - .filter((toolButton: ButtonConfig) => getToolbarState(toolButton.id, btnVisible, true)) - .forEach((toolButton: ButtonConfig) => { - return ; - })} -
- )} - {shouldShowExtendArea.value && ( -
- {context.slots.extend && context.slots.extend()} -
- )} - -
- {shouldShowToolbarTemplateInContent.value && ( -
- {context.slots.toolbarButtons && - context.slots.toolbarButtons({ - datas: toolbarBtns, - dpHidden: toolbarDpHidden, - dpDatas: inMoreButtonContents, - })} -
- )} - - {context.slots.default && context.slots.default()} -
- +
+ {renderSectionHeader()} + {renderSectionContent()} +
); }; - }, + + // return () => { + // return ( + // <> + // {shouldShowHeader.value && ( + //
+ // {shouldShowToolbarInHeader.value && ( + //
+ // {toolbarButtons.value + // .filter((toolButton: ButtonConfig) => getToolbarState(toolButton.id, {}, true)) + // .forEach((toolButton: ButtonConfig) => { + // return ; + // })} + //
+ // )} + //
+ // )} + // {shouldShowToolbarInContent.value && ( + //
+ // {toolbarButtons.value + // .filter((toolButton: ButtonConfig) => getToolbarState(toolButton.id, {}, true)) + // .forEach((toolButton: ButtonConfig) => { + // return ; + // })} + //
+ // )} + // {shouldShowExtendArea.value && ( + //
{context.slots.extend && context.slots.extend()}
+ // )} + + //
+ // {shouldShowToolbarTemplateInContent.value && ( + //
+ // {context.slots.toolbarButtons && context.slots.toolbarButtons({})} + //
+ // )} + // {context.slots.default && context.slots.default()} + //
+ // + // ); + // }; + } }); diff --git a/packages/ui-vue/components/section/src/section.props.ts b/packages/ui-vue/components/section/src/section.props.ts index c51fef2..e990884 100644 --- a/packages/ui-vue/components/section/src/section.props.ts +++ b/packages/ui-vue/components/section/src/section.props.ts @@ -1,11 +1,15 @@ import { ExtractPropTypes, PropType } from 'vue'; +export interface ButtonAppearance { + class: string; +} + export interface ButtonConfig { id: string; disable: boolean; title: string; click: any; - appearance: object; + appearance: ButtonAppearance; visible?: boolean; } @@ -32,5 +36,6 @@ export const sectionProps = { toolbar: { type: Object as PropType, default: {} }, showToolbarMoreButton: { type: Boolean, default: true }, clickThrottleTime: { type: Number, default: 350 }, + headerClass: { type: String, default: '' } }; export type SectionProps = ExtractPropTypes; diff --git a/packages/ui-vue/src/App.vue b/packages/ui-vue/src/App.vue index 99e7703..d879dbd 100644 --- a/packages/ui-vue/src/App.vue +++ b/packages/ui-vue/src/App.vue @@ -7,6 +7,7 @@ import Avatar from './components/avatar.vue'; import ButtonEdit from './components/button-edit.vue'; import FButton from '../components/button/src/button.component'; import Switch from './components/switch.vue'; +import Section from './components/section.vue'; const canEdit = ref(true); const disable = ref(false); @@ -34,6 +35,7 @@ const canAutoComplete = ref(false); +