feat: ui控制器接口设计

This commit is contained in:
unanmed 2024-12-24 18:10:49 +08:00
parent e99320c52d
commit 44276183bb
4 changed files with 65 additions and 0 deletions

1
src/core/system/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './ui';

View File

@ -0,0 +1,55 @@
import { Component, VNodeProps } from 'vue';
export interface IUIControllerConfig<Element, UI> {
/**
* ui挂载至目标元素时的操作
* @param element
* @param ui ui对象
*/
insert(element: Element, ui: UI): void;
/**
* ui从目标元素上移除时的操作
* @param element ui的父元素
* @param ui ui元素
*/
remove(element: Element, ui: UI): void;
/**
* UI
* @param component UI组件
* @param props UI传递的props
*/
createUI(
component: Component,
props?: (VNodeProps & { [key: string]: any }) | null
): UI;
}
export const enum OpenOption {
Push,
Unshift
}
export const enum CloseOption {
Splice,
Pop,
Shift
}
export class UIController<Element, UI> {
constructor(config: IUIControllerConfig<Element, UI>) {}
/**
* ui改变时控制器的行为
* @param open
* @param close
*/
setChangeMode(open: OpenOption, close: CloseOption) {}
/**
* UI控制器挂载至容器上
* @param container
*/
mount(container: Element) {}
}

View File

@ -0,0 +1 @@
export * from './controller';

View File

@ -517,3 +517,11 @@ export function calStringSize(str: string) {
return size;
}
export function clamp(num: number, start: number, end: number) {
const s = Math.min(start, end);
const e = Math.max(start, end);
if (num < s) return s;
else if (num > e) return e;
return num;
}