diff --git a/packages/editor/src/layouts/sidebar/code-block/CodeBlockList.vue b/packages/editor/src/layouts/sidebar/code-block/CodeBlockList.vue index 4f20f613..79fdefde 100644 --- a/packages/editor/src/layouts/sidebar/code-block/CodeBlockList.vue +++ b/packages/editor/src/layouts/sidebar/code-block/CodeBlockList.vue @@ -158,6 +158,9 @@ watch( services?.codeBlockService.refreshAllRelations(); refreshCodeList(); }, + { + immediate: true, + }, ); watch( diff --git a/packages/editor/src/theme/nav-menu.scss b/packages/editor/src/theme/nav-menu.scss index 8ed833fc..d57cb396 100644 --- a/packages/editor/src/theme/nav-menu.scss +++ b/packages/editor/src/theme/nav-menu.scss @@ -53,8 +53,7 @@ padding: 5px; } - .is-text, - i { + .is-text > i { color: $--font-color; } diff --git a/packages/form/src/Form.vue b/packages/form/src/Form.vue index a2fbc3e2..37f9ff04 100644 --- a/packages/form/src/Form.vue +++ b/packages/form/src/Form.vue @@ -15,6 +15,8 @@ :key="item[keyProp] ?? index" :config="item" :model="values" + :last-values="lastValuesProcessed" + :is-compare="isCompare" :label-width="item.labelWidth || labelWidth" :step-active="stepActive" :size="size" @@ -26,8 +28,8 @@ diff --git a/packages/form/src/containers/Container.vue b/packages/form/src/containers/Container.vue index d1240140..63b7f03b 100644 --- a/packages/form/src/containers/Container.vue +++ b/packages/form/src/containers/Container.vue @@ -20,6 +20,8 @@ :size="size" :is="tagName" :model="model" + :last-values="lastValues" + :is-compare="isCompare" :config="config" :disabled="disabled" :name="name" @@ -28,15 +30,120 @@ :expand-more="expand" :label-width="itemLabelWidth" @change="onChangeHandler" + @addDiffCount="onAddDiffCount" > - @@ -107,8 +217,9 @@ diff --git a/packages/form/src/containers/GroupList.vue b/packages/form/src/containers/GroupList.vue index f5d94837..e46a2df1 100644 --- a/packages/form/src/containers/GroupList.vue +++ b/packages/form/src/containers/GroupList.vue @@ -10,6 +10,8 @@ v-for="(item, index) in model[name]" :key="index" :model="item" + :lastValues="getLastValues(lastValues[name], index)" + :is-compare="isCompare" :config="config" :prop="prop" :index="index" @@ -20,6 +22,7 @@ @remove-item="removeHandler" @swap-item="swapHandler" @change="changeHandler" + @addDiffCount="onAddDiffCount()" > 添加组 @@ -41,6 +44,8 @@ import MFieldsGroupListItem from './GroupListItem.vue'; const props = defineProps<{ model: any; + lastValues?: any; + isCompare?: boolean; config: GroupListConfig; name: string; labelWidth?: string; @@ -49,7 +54,7 @@ const props = defineProps<{ disabled?: boolean; }>(); -const emit = defineEmits(['change']); +const emit = defineEmits(['change', 'addDiffCount']); const mForm = inject('mForm'); @@ -123,4 +128,7 @@ const toggleMode = () => { text: null, }))) as any; }; +const onAddDiffCount = () => emit('addDiffCount'); + +const getLastValues = (item: any, index: number) => item?.[index] || {}; diff --git a/packages/form/src/containers/GroupListItem.vue b/packages/form/src/containers/GroupListItem.vue index 9a2f3815..4d474d63 100644 --- a/packages/form/src/containers/GroupListItem.vue +++ b/packages/form/src/containers/GroupListItem.vue @@ -32,11 +32,14 @@ v-if="expand" :config="rowConfig" :model="model" + :lastValues="lastValues" + :is-compare="isCompare" :labelWidth="labelWidth" :prop="`${prop}${prop ? '.' : ''}${String(index)}`" :size="size" :disabled="disabled" @change="changeHandler" + @addDiffCount="onAddDiffCount()" > @@ -54,6 +57,8 @@ import Container from './Container.vue'; const props = defineProps<{ model: any; + lastValues: any; + isCompare?: boolean; groupModel: any[]; config: GroupListConfig; labelWidth?: string; @@ -63,7 +68,7 @@ const props = defineProps<{ disabled?: boolean; }>(); -const emit = defineEmits(['swap-item', 'remove-item', 'change']); +const emit = defineEmits(['swap-item', 'remove-item', 'change', 'addDiffCount']); const mForm = inject('mForm'); const expand = ref(false); @@ -122,4 +127,5 @@ const movable = () => { } return movable; }; +const onAddDiffCount = () => emit('addDiffCount'); diff --git a/packages/form/src/containers/Panel.vue b/packages/form/src/containers/Panel.vue index 9782e247..2128fe6f 100644 --- a/packages/form/src/containers/Panel.vue +++ b/packages/form/src/containers/Panel.vue @@ -23,11 +23,14 @@ :key="item[mForm?.keyProp || '__key'] ?? index" :config="item" :model="name ? model[name] : model" + :lastValues="name ? lastValues[name] : lastValues" + :is-compare="isCompare" :prop="prop" :size="size" :disabled="disabled" :label-width="config.labelWidth || labelWidth" @change="changeHandler" + @addDiffCount="onAddDiffCount()" > @@ -40,11 +43,14 @@ :key="item[mForm?.keyProp || '__key'] ?? index" :config="item" :model="name ? model[name] : model" + :lastValues="name ? lastValues[name] : lastValues" + :is-compare="isCompare" :prop="prop" :size="size" :disabled="disabled" :label-width="config.labelWidth || labelWidth" @change="changeHandler" + @addDiffCount="onAddDiffCount()" > @@ -64,6 +70,8 @@ import Container from './Container.vue'; const props = defineProps<{ model: any; + lastValues?: any; + isCompare?: boolean; config: PanelConfig; name: string; labelWidth?: string; @@ -72,7 +80,7 @@ const props = defineProps<{ disabled?: boolean; }>(); -const emit = defineEmits(['change']); +const emit = defineEmits(['change', 'addDiffCount']); const mForm = inject('mForm'); @@ -83,4 +91,5 @@ const items = computed(() => props.config.items); const filter = (config: any) => filterFunction(mForm, config, props); const changeHandler = () => emit('change', props.model); +const onAddDiffCount = () => emit('addDiffCount'); diff --git a/packages/form/src/containers/Row.vue b/packages/form/src/containers/Row.vue index 0473449b..b009601b 100644 --- a/packages/form/src/containers/Row.vue +++ b/packages/form/src/containers/Row.vue @@ -8,10 +8,13 @@ :labelWidth="config.labelWidth || labelWidth" :expandMore="expandMore" :model="name ? model[name] : model" + :lastValues="name ? lastValues[name] : lastValues" + :is-compare="isCompare" :prop="prop" :size="size" :disabled="disabled" @change="changeHandler" + @add-diff-count="onAddDiffCount" /> @@ -27,6 +30,8 @@ import Col from './Col.vue'; const props = defineProps<{ model: any; + lastValues?: any; + isCompare?: boolean; config: RowConfig; name: string; labelWidth?: string; @@ -36,9 +41,10 @@ const props = defineProps<{ disabled?: boolean; }>(); -const emit = defineEmits(['change']); +const emit = defineEmits(['change', 'addDiffCount']); const mForm = inject('mForm'); const changeHandler = () => emit('change', props.name ? props.model[props.name] : props.model); +const onAddDiffCount = () => emit('addDiffCount'); diff --git a/packages/form/src/containers/Step.vue b/packages/form/src/containers/Step.vue index 40f6e16e..21722eac 100644 --- a/packages/form/src/containers/Step.vue +++ b/packages/form/src/containers/Step.vue @@ -18,11 +18,14 @@ :key="item[mForm?.keyProp || '__key']" :config="item" :model="step.name ? model[step.name] : model" + :lastValues="step.name ? lastValues[step.name] : lastValues" + :is-compare="isCompare" :prop="`${step.name}`" :size="size" :disabled="disabled" :label-width="config.labelWidth || labelWidth" @change="changeHandler" + @addDiffCount="onAddDiffCount()" > @@ -41,6 +44,8 @@ import Container from './Container.vue'; const props = withDefaults( defineProps<{ model: any; + lastValues?: any; + isCompare?: boolean; config: StepConfig; stepActive?: number; labelWidth?: string; @@ -52,7 +57,7 @@ const props = withDefaults( }, ); -const emit = defineEmits(['change']); +const emit = defineEmits(['change', 'addDiffCount']); const mForm = inject('mForm'); const active = ref(1); @@ -69,4 +74,5 @@ const stepClick = (index: number) => { const changeHandler = () => { emit('change', props.model); }; +const onAddDiffCount = () => emit('addDiffCount'); diff --git a/packages/form/src/containers/Table.vue b/packages/form/src/containers/Table.vue index 08238c0b..6926faeb 100644 --- a/packages/form/src/containers/Table.vue +++ b/packages/form/src/containers/Table.vue @@ -9,6 +9,7 @@ style="width: 100%" :row-key="config.rowKey || 'id'" :data="data" + :lastData="lastData" :border="config.border" :max-height="config.maxHeight" :default-expand-all="true" @@ -108,8 +109,11 @@ :rules="column.rules" :config="makeConfig(column, scope.row)" :model="scope.row" + :lastValues="lastData[scope.$index]" + :is-compare="isCompare" :size="size" @change="$emit('change', model[modelName])" + @addDiffCount="onAddDiffCount()" > @@ -196,6 +200,8 @@ import Container from './Container.vue'; const props = withDefaults( defineProps<{ model: any; + lastValues?: any; + isCompare?: boolean; config: TableConfig; name: string; prop?: string; @@ -213,10 +219,12 @@ const props = withDefaults( sortKey: '', enableToggleMode: true, showIndex: true, + lastValues: () => ({}), + isCompare: false, }, ); -const emit = defineEmits(['change', 'select']); +const emit = defineEmits(['change', 'select', 'addDiffCount']); let timer: any | null = null; const mForm = inject('mForm'); @@ -241,6 +249,15 @@ const data = computed(() => : props.model[modelName.value], ); +const lastData = computed(() => + props.config.pagination + ? props.lastValues[modelName.value].filter( + (item: any, index: number) => + index >= pagecontext.value * pagesize.value && index + 1 <= (pagecontext.value + 1) * pagesize.value, + ) + : props.lastValues[modelName.value] || {}, +); + const sortChange = ({ prop, order }: SortProp) => { if (order === 'ascending') { props.model[modelName.value] = props.model[modelName.value].sort((a: any, b: any) => a[prop] - b[prop]); @@ -593,6 +610,8 @@ const getProp = (index: number) => { return `${prop.value}${prop.value ? '.' : ''}${index + 1 + pagecontext.value * pagesize.value - 1}`; }; +const onAddDiffCount = () => emit('addDiffCount'); + defineExpose({ toggleRowSelection, }); diff --git a/packages/form/src/containers/Tabs.vue b/packages/form/src/containers/Tabs.vue index 0119fffa..914cc329 100644 --- a/packages/form/src/containers/Tabs.vue +++ b/packages/form/src/containers/Tabs.vue @@ -18,25 +18,26 @@ :label="filter(tab.title)" :lazy="tab.lazy || false" > + @@ -54,6 +55,10 @@ import { display as displayFunc, filterFunction } from '../utils/form'; import Container from './Container.vue'; +type DiffCount = { + [tabIndex: number]: number; +}; + const uiComponent = getConfig('components').tabPane; const getActive = (mForm: FormState | undefined, props: any, activeTabName: string) => { @@ -83,21 +88,30 @@ const tabClick = (mForm: FormState | undefined, tab: any, props: any) => { } }; -const props = defineProps<{ - model: any; - config: TabConfig; - name: string; - size?: string; - labelWidth?: string; - prop?: string; - expandMore?: boolean; - disabled?: boolean; -}>(); +const props = withDefaults( + defineProps<{ + model: any; + lastValues?: any; + isCompare?: boolean; + config: TabConfig; + name: string; + size?: string; + labelWidth?: string; + prop?: string; + expandMore?: boolean; + disabled?: boolean; + }>(), + { + lastValues: () => ({}), + isCompare: false, + }, +); -const emit = defineEmits(['change']); +const emit = defineEmits(['change', 'addDiffCount']); const mForm = inject('mForm'); const activeTabName = ref(getActive(mForm, props, '')); +const diffCount = ref({}); const tabs = computed(() => { if (props.config.dynamic) { @@ -170,4 +184,27 @@ const changeHandler = () => { props.config.onChange(mForm, { model: props.model, prop: props.prop, config: props.config }); } }; + +const getValues = (model: any, tabIndex: number, tab: any) => { + const tabName = props.config.dynamic ? (model[props?.name] || model)[tabIndex] : tab.name; + let propName = props.name; + if (tabName) { + propName = (model[props?.name] || model)[tab.name]; + } + if (propName) { + return model[props.name]; + } + return model; +}; + +// 在tabs组件中收集事件触发次数,即该tab下的差异数 +const onAddDiffCount = (tabIndex: number) => { + if (!diffCount.value[tabIndex]) { + diffCount.value[tabIndex] = 1; + } else { + diffCount.value[tabIndex] += 1; + } + // 继续抛出给更高层级的组件 + emit('addDiffCount'); +}; diff --git a/packages/form/src/schema.ts b/packages/form/src/schema.ts index 65cd9aaf..db055fbd 100644 --- a/packages/form/src/schema.ts +++ b/packages/form/src/schema.ts @@ -28,6 +28,8 @@ export type FormState = { config: FormConfig; popperClass?: string; initValues: FormValue; + lastValues: FormValue; + isCompare: boolean; values: FormValue; $emit: (event: string, ...args: any[]) => void; keyProp?: string; diff --git a/packages/form/src/theme/index.scss b/packages/form/src/theme/index.scss index 51e9cf9d..ea8c0062 100644 --- a/packages/form/src/theme/index.scss +++ b/packages/form/src/theme/index.scss @@ -7,3 +7,4 @@ @use "./panel.scss"; @use "./table.scss"; @use "./select.scss"; +@use "./tabs.scss"; diff --git a/packages/form/src/theme/tabs.scss b/packages/form/src/theme/tabs.scss index 6f93eae5..ca385430 100644 --- a/packages/form/src/theme/tabs.scss +++ b/packages/form/src/theme/tabs.scss @@ -23,3 +23,7 @@ .magic-form-tab { margin-bottom: 10px; } + +.diff-count-badge { + top: -10px; +} diff --git a/playground/src/pages/Form.vue b/playground/src/pages/Form.vue index 79df619b..35af4895 100644 --- a/playground/src/pages/Form.vue +++ b/playground/src/pages/Form.vue @@ -1,9 +1,21 @@