diff --git a/src/core/system/index.ts b/src/core/system/index.ts new file mode 100644 index 0000000..5ecdd1f --- /dev/null +++ b/src/core/system/index.ts @@ -0,0 +1 @@ +export * from './ui'; diff --git a/src/core/system/ui/controller.ts b/src/core/system/ui/controller.ts new file mode 100644 index 0000000..3b690ea --- /dev/null +++ b/src/core/system/ui/controller.ts @@ -0,0 +1,55 @@ +import { Component, VNodeProps } from 'vue'; + +export interface IUIControllerConfig { + /** + * 将一个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 { + constructor(config: IUIControllerConfig) {} + + /** + * 设置当ui改变时控制器的行为 + * @param open 打开时的行为 + * @param close 关闭时的行为 + */ + setChangeMode(open: OpenOption, close: CloseOption) {} + + /** + * 将这个UI控制器挂载至容器上 + * @param container 要挂载至的容器 + */ + mount(container: Element) {} +} diff --git a/src/core/system/ui/index.ts b/src/core/system/ui/index.ts new file mode 100644 index 0000000..0471403 --- /dev/null +++ b/src/core/system/ui/index.ts @@ -0,0 +1 @@ +export * from './controller'; diff --git a/src/plugin/utils.ts b/src/plugin/utils.ts index 7b1b38a..65a60dc 100644 --- a/src/plugin/utils.ts +++ b/src/plugin/utils.ts @@ -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; +}