Skip to content

Commit

Permalink
fix: table internal search collspaed configuration does not take effect
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Oct 7, 2024
1 parent f0edad8 commit f9c3a8d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ watch(
</script>
<template>
<div
:class="cn('col-span-full w-full text-right', rootProps.actionWrapperClass)"
:class="
cn('col-span-full w-full pb-6 text-right', rootProps.actionWrapperClass)
"
:style="queryFormStyle"
>
<component
Expand Down
5 changes: 3 additions & 2 deletions packages/@core/ui-kit/form-ui/src/use-vben-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function useVbenForm<
onBeforeUnmount(() => {
api.unmount();
});
api.setState({ ...props, ...attrs });
return () =>
h(VbenUseForm, { ...props, ...attrs, formApi: extendedApi }, slots);
},
Expand All @@ -37,9 +38,9 @@ export function useVbenForm<
// Add reactivity support
if (IS_REACTIVE) {
watch(
() => options.schema,
() => options,
() => {
api.setState({ schema: options.schema });
api.setState(options);
},
{ immediate: true },
);
Expand Down
13 changes: 1 addition & 12 deletions packages/@core/ui-kit/form-ui/src/vben-use-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,12 @@ props.formApi?.mount?.(form);
const handleUpdateCollapsed = (value: boolean) => {
props.formApi?.setState({ collapsed: !!value });
};
// if (isFunction(forward.value.handleValuesChange)) {
// watch(
// () => form.values,
// (val) => {
// forward.value.handleValuesChange?.(toRaw(val));
// },
// {
// deep: true,
// immediate: true,
// },
// );
// }
</script>

<template>
<Form
v-bind="forward"
:collapsed="state.collapsed"
:component-bind-event-map="COMPONENT_BIND_EVENT_MAP"
:component-map="COMPONENT_MAP"
:form="form"
Expand Down
23 changes: 12 additions & 11 deletions packages/effects/plugins/src/vxe-table/use-vxe-grid.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { ExtendedVxeGridApi, VxeGridProps } from './types';

import { defineComponent, h, onBeforeUnmount } from 'vue';
import { defineComponent, h, isReactive, onBeforeUnmount, watch } from 'vue';

import { useStore } from '@vben-core/shared/store';

import { VxeGridApi } from './api';
import VxeGrid from './use-vxe-grid.vue';

export function useVbenVxeGrid(options: VxeGridProps) {
// const IS_REACTIVE = isReactive(options);
const IS_REACTIVE = isReactive(options);
const api = new VxeGridApi(options);
const extendedApi: ExtendedVxeGridApi = api as ExtendedVxeGridApi;
extendedApi.useStore = (selector) => {
Expand All @@ -20,6 +20,7 @@ export function useVbenVxeGrid(options: VxeGridProps) {
onBeforeUnmount(() => {
api.unmount();
});
api.setState({ ...props, ...attrs });
return () => h(VxeGrid, { ...props, ...attrs, api: extendedApi }, slots);
},
{
Expand All @@ -28,15 +29,15 @@ export function useVbenVxeGrid(options: VxeGridProps) {
},
);
// Add reactivity support
// if (IS_REACTIVE) {
// watch(
// () => options,
// () => {
// api.setState(options);
// },
// { immediate: true },
// );
// }
if (IS_REACTIVE) {
watch(
() => options,
() => {
api.setState(options);
},
{ immediate: true },
);
}

return [Grid, extendedApi] as const;
}
3 changes: 1 addition & 2 deletions packages/effects/plugins/src/vxe-table/use-vxe-grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ async function init() {
);
}
}
onMounted(() => {
props.api?.mount?.(gridRef.value, formApi);
init();
Expand Down Expand Up @@ -246,7 +245,7 @@ onMounted(() => {
<slot :name="slotName" v-bind="slotProps"></slot>
</template>
<template #form>
<div v-if="formOptions" class="relative rounded py-3 pb-6">
<div v-if="formOptions" class="relative rounded py-3 pb-4">
<slot name="form">
<Form v-bind="vbenFormOptions">
<template
Expand Down
23 changes: 20 additions & 3 deletions playground/src/views/examples/vxe-table/form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { VbenFormProps, VxeGridProps } from '#/adapter';
import { Page } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter';
import { getExampleTableApi } from '#/api';
Expand Down Expand Up @@ -92,11 +92,28 @@ const gridOptions: VxeGridProps<RowType> = {
},
};
const [Grid] = useVbenVxeGrid({ formOptions, gridOptions });
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
function toggleFormCollspae() {
gridApi.formApi.resetForm();
gridApi.setState({
formOptions: {
showCollapseButton: !(
gridApi.state?.formOptions?.showCollapseButton ?? true
),
},
});
}
</script>

<template>
<Page auto-content-height>
<Grid />
<Grid>
<template #toolbar-tools>
<Button type="primary" @click="toggleFormCollspae">
切换表单折叠按钮
</Button>
</template>
</Grid>
</Page>
</template>

0 comments on commit f9c3a8d

Please sign in to comment.