refactor(editor): ui-slect事件名使用常量

This commit is contained in:
roymondchen 2023-10-23 19:54:26 +08:00
parent 6cfcbdb76e
commit 5a345575c4
4 changed files with 30 additions and 8 deletions

View File

@ -49,7 +49,7 @@ import { TMagicButton, TMagicTooltip } from '@tmagic/design';
import type { FieldProps, FormState } from '@tmagic/form'; import type { FieldProps, FormState } from '@tmagic/form';
import type { Id } from '@tmagic/schema'; import type { Id } from '@tmagic/schema';
import type { Services } from '@editor/type'; import { Services, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
defineOptions({ defineOptions({
name: 'MEditorUISelect', name: 'MEditorUISelect',
@ -68,7 +68,7 @@ const cancelHandler = () => {
if (!services?.uiService) return; if (!services?.uiService) return;
services.uiService.set('uiSelectMode', false); services.uiService.set('uiSelectMode', false);
uiSelectMode.value = false; uiSelectMode.value = false;
globalThis.document.removeEventListener('ui-select', clickHandler as EventListener); globalThis.document.removeEventListener(UI_SELECT_MODE_EVENT_NAME, clickHandler as EventListener);
}; };
const clickHandler = ({ detail }: Event & { detail: any }) => { const clickHandler = ({ detail }: Event & { detail: any }) => {
@ -92,7 +92,7 @@ const startSelect = () => {
if (!services?.uiService) return; if (!services?.uiService) return;
services.uiService.set('uiSelectMode', true); services.uiService.set('uiSelectMode', true);
uiSelectMode.value = true; uiSelectMode.value = true;
globalThis.document.addEventListener('ui-select', clickHandler as EventListener); globalThis.document.addEventListener(UI_SELECT_MODE_EVENT_NAME, clickHandler as EventListener);
}; };
const deleteHandler = () => { const deleteHandler = () => {

View File

@ -5,7 +5,12 @@ import StageCore, { GuidesType, RemoveEventData, SortEventData, UpdateEventData
import editorService from '@editor/services/editor'; import editorService from '@editor/services/editor';
import uiService from '@editor/services/ui'; import uiService from '@editor/services/ui';
import { H_GUIDE_LINE_STORAGE_KEY, StageOptions, V_GUIDE_LINE_STORAGE_KEY } from '@editor/type'; import {
H_GUIDE_LINE_STORAGE_KEY,
StageOptions,
UI_SELECT_MODE_EVENT_NAME,
V_GUIDE_LINE_STORAGE_KEY,
} from '@editor/type';
import { getGuideLineFromCache } from '@editor/utils/editor'; import { getGuideLineFromCache } from '@editor/utils/editor';
const root = computed(() => editorService.get('root')); const root = computed(() => editorService.get('root'));
@ -30,7 +35,7 @@ export const useStage = (stageOptions: StageOptions) => {
const elCanSelect = stageOptions.canSelect(el); const elCanSelect = stageOptions.canSelect(el);
// 在组件联动过程中不能再往下选择,返回并触发 ui-select // 在组件联动过程中不能再往下选择,返回并触发 ui-select
if (uiSelectMode.value && elCanSelect && event.type === 'mousedown') { if (uiSelectMode.value && elCanSelect && event.type === 'mousedown') {
document.dispatchEvent(new CustomEvent('ui-select', { detail: el })); document.dispatchEvent(new CustomEvent(UI_SELECT_MODE_EVENT_NAME, { detail: el }));
return stop(); return stop();
} }

View File

@ -62,7 +62,7 @@ import type { Id, MContainer, MNode } from '@tmagic/schema';
import { isPage } from '@tmagic/utils'; import { isPage } from '@tmagic/utils';
import MIcon from '@editor/components/Icon.vue'; import MIcon from '@editor/components/Icon.vue';
import type { LayerNodeSlots, LayerNodeStatus, Services } from '@editor/type'; import { LayerNodeSlots, LayerNodeStatus, Services, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
import LayerNodeTool from './LayerNodeTool.vue'; import LayerNodeTool from './LayerNodeTool.vue';
import { useDrag } from './use-drag'; import { useDrag } from './use-drag';
@ -128,7 +128,7 @@ const nodeClickHandler = () => {
if (!nodeStatusMap?.value) return; if (!nodeStatusMap?.value) return;
if (uiService?.get('uiSelectMode')) { if (uiService?.get('uiSelectMode')) {
document.dispatchEvent(new CustomEvent('ui-select', { detail: props.data })); document.dispatchEvent(new CustomEvent(UI_SELECT_MODE_EVENT_NAME, { detail: props.data }));
return; return;
} }
@ -155,7 +155,7 @@ const nodeContentmenuHandler = (event: MouseEvent, node: MNode) => {
emit('node-contextmenu', event, node); emit('node-contextmenu', event, node);
}; };
// //
const select = async (data: MNode) => { const select = async (data: MNode) => {
if (!data.id) { if (!data.id) {
throw new Error('没有id'); throw new Error('没有id');

View File

@ -467,6 +467,7 @@ export interface EventSelectConfig {
name: string; name: string;
type: 'event-select'; type: 'event-select';
src: 'datasource' | 'component'; src: 'datasource' | 'component';
labelWidth?: string;
/** 事件名称表单配置 */ /** 事件名称表单配置 */
eventNameConfig?: FormItem; eventNameConfig?: FormItem;
/** 动作类型配置 */ /** 动作类型配置 */
@ -539,6 +540,7 @@ export interface KeyBindingCacheItem {
export interface CodeSelectColConfig { export interface CodeSelectColConfig {
type: 'code-select-col'; type: 'code-select-col';
name: string; name: string;
text: string;
labelWidth?: number | string; labelWidth?: number | string;
disabled?: boolean | FilterFunction; disabled?: boolean | FilterFunction;
display?: boolean | FilterFunction; display?: boolean | FilterFunction;
@ -547,6 +549,7 @@ export interface CodeSelectColConfig {
export interface DataSourceMethodSelectConfig { export interface DataSourceMethodSelectConfig {
type: 'data-source-method-select'; type: 'data-source-method-select';
name: string; name: string;
text: string;
labelWidth?: number | string; labelWidth?: number | string;
disabled?: boolean | FilterFunction; disabled?: boolean | FilterFunction;
display?: boolean | FilterFunction; display?: boolean | FilterFunction;
@ -561,6 +564,7 @@ export interface DataSourceFieldSelectConfig {
display?: boolean | FilterFunction; display?: boolean | FilterFunction;
} }
/** 依赖收集的目标类型 */
export enum DepTargetType { export enum DepTargetType {
DEFAULT = 'default', DEFAULT = 'default',
/** 代码块 */ /** 代码块 */
@ -573,18 +577,31 @@ export enum DepTargetType {
DATA_SOURCE_COND = 'data-source-cond', DATA_SOURCE_COND = 'data-source-cond',
} }
/** 可新增的数据源类型选项 */
export interface DatasourceTypeOption { export interface DatasourceTypeOption {
/** 数据源类型 */
type: string; type: string;
/** 数据源名称 */
text: string; text: string;
} }
/** 组件树节点状态 */
export interface LayerNodeStatus { export interface LayerNodeStatus {
/** 显隐 */
visible: boolean; visible: boolean;
/** 展开子节点 */
expand: boolean; expand: boolean;
/** 选中 */
selected: boolean; selected: boolean;
} }
/** 拖拽类型 */
export enum DragType { export enum DragType {
/** 从组件列表拖到画布 */
COMPONENT_LIST = 'component-list', COMPONENT_LIST = 'component-list',
/** 拖动组件树节点 */
LAYER_TREE = 'layer-tree', LAYER_TREE = 'layer-tree',
} }
/** 当uiService.get('uiSelectMode')为true,点击组件(包括任何形式,组件树/画布)时触发的事件名 */
export const UI_SELECT_MODE_EVENT_NAME = 'ui-select';