mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
feat(editor): 支持配置页面过滤函数
This commit is contained in:
parent
12ce5c568e
commit
13abe898a9
@ -1,5 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<Framework :disabled-page-fragment="disabledPageFragment" :page-bar-sort-options="pageBarSortOptions">
|
<Framework
|
||||||
|
:disabled-page-fragment="disabledPageFragment"
|
||||||
|
:page-bar-sort-options="pageBarSortOptions"
|
||||||
|
:page-filter-function="pageFilterFunction"
|
||||||
|
>
|
||||||
<template #header>
|
<template #header>
|
||||||
<slot name="header"></slot>
|
<slot name="header"></slot>
|
||||||
</template>
|
</template>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import type { DataSourceSchema, EventOption, Id, MApp, MNode } from '@tmagic/core';
|
import type { DataSourceSchema, EventOption, Id, MApp, MNode, MPage, MPageFragment } from '@tmagic/core';
|
||||||
import type { FormConfig, FormState } from '@tmagic/form';
|
import type { FormConfig, FormState } from '@tmagic/form';
|
||||||
import StageCore, {
|
import StageCore, {
|
||||||
CONTAINER_HIGHLIGHT_CLASS_NAME,
|
CONTAINER_HIGHLIGHT_CLASS_NAME,
|
||||||
@ -97,6 +97,8 @@ export interface EditorProps {
|
|||||||
extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
||||||
/** 页面顺序拖拽配置参数 */
|
/** 页面顺序拖拽配置参数 */
|
||||||
pageBarSortOptions?: PageBarSortOptions;
|
pageBarSortOptions?: PageBarSortOptions;
|
||||||
|
/** 页面搜索函数 */
|
||||||
|
pageFilterFunction?: (page: MPage | MPageFragment, keyword: string) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultEditorProps = {
|
export const defaultEditorProps = {
|
||||||
|
@ -38,7 +38,11 @@
|
|||||||
</slot>
|
</slot>
|
||||||
|
|
||||||
<slot name="page-bar">
|
<slot name="page-bar">
|
||||||
<PageBar :disabled-page-fragment="disabledPageFragment" :page-bar-sort-options="pageBarSortOptions">
|
<PageBar
|
||||||
|
:disabled-page-fragment="disabledPageFragment"
|
||||||
|
:page-bar-sort-options="pageBarSortOptions"
|
||||||
|
:filter-function="pageFilterFunction"
|
||||||
|
>
|
||||||
<template #page-bar-add-button><slot name="page-bar-add-button"></slot></template>
|
<template #page-bar-add-button><slot name="page-bar-add-button"></slot></template>
|
||||||
<template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
|
<template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
|
||||||
<template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
|
<template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
|
||||||
@ -62,6 +66,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, inject, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
import { computed, inject, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import type { MPage, MPageFragment } from '@tmagic/core';
|
||||||
import { TMagicScrollbar } from '@tmagic/design';
|
import { TMagicScrollbar } from '@tmagic/design';
|
||||||
|
|
||||||
import SplitView from '@editor/components/SplitView.vue';
|
import SplitView from '@editor/components/SplitView.vue';
|
||||||
@ -81,6 +86,7 @@ defineOptions({
|
|||||||
defineProps<{
|
defineProps<{
|
||||||
disabledPageFragment: boolean;
|
disabledPageFragment: boolean;
|
||||||
pageBarSortOptions?: PageBarSortOptions;
|
pageBarSortOptions?: PageBarSortOptions;
|
||||||
|
pageFilterFunction?: (page: MPage | MPageFragment, keyword: string) => boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const DEFAULT_LEFT_COLUMN_WIDTH = 310;
|
const DEFAULT_LEFT_COLUMN_WIDTH = 310;
|
||||||
|
@ -81,10 +81,16 @@ defineOptions({
|
|||||||
name: 'MEditorPageBar',
|
name: 'MEditorPageBar',
|
||||||
});
|
});
|
||||||
|
|
||||||
defineProps<{
|
const props = withDefaults(
|
||||||
disabledPageFragment: boolean;
|
defineProps<{
|
||||||
pageBarSortOptions?: PageBarSortOptions;
|
disabledPageFragment: boolean;
|
||||||
}>();
|
pageBarSortOptions?: PageBarSortOptions;
|
||||||
|
filterFunction?: (page: MPage | MPageFragment, keyword: string) => boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
filterFunction: (page, keyword) => page.name?.includes(keyword) || `${page.id}`.includes(keyword),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
const editorService = services?.editorService;
|
const editorService = services?.editorService;
|
||||||
@ -109,7 +115,7 @@ const list = computed(() => {
|
|||||||
return (root.value?.items || []).filter((item) => {
|
return (root.value?.items || []).filter((item) => {
|
||||||
if (pageType.includes(item.type)) {
|
if (pageType.includes(item.type)) {
|
||||||
if (keyword) {
|
if (keyword) {
|
||||||
return item.name?.includes(keyword);
|
return props.filterFunction(item, keyword);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
:inline="true"
|
:inline="true"
|
||||||
:config="formConfig"
|
:config="formConfig"
|
||||||
:init-values="query"
|
:init-values="query"
|
||||||
|
:prevent-submit-default="true"
|
||||||
@change="onFormChange"
|
@change="onFormChange"
|
||||||
></MForm>
|
></MForm>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
@ -51,7 +52,9 @@ const formConfig = createForm([
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'keyword',
|
name: 'keyword',
|
||||||
|
type: 'text',
|
||||||
placeholder: '请输入关键字',
|
placeholder: '请输入关键字',
|
||||||
|
clearable: true,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user