refactor(web-antd): 重构 Tinyflow 组件并优化类型定义
- 将 Item 类型和 Tinyflow 相关类型移动到 ui/typing 文件夹 - 删除 ui/index.d.ts 文件,减少冗余类型定义 - 优化 Tinyflow 组件代码,简化 imports - 移除 formatTime.ts 中的冗余代码,使用 @vben/utils 中的 formatDate 函数pull/145/head
parent
33b7a11a4e
commit
f285aa8a27
|
@ -1,9 +1,9 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Item } from './ui';
|
import type { Item } from './ui/typing';
|
||||||
|
|
||||||
import { onMounted, onUnmounted, ref } from 'vue';
|
import { onMounted, onUnmounted, ref } from 'vue';
|
||||||
|
|
||||||
import { Tinyflow as TinyflowNative } from './ui';
|
import { Tinyflow as TinyflowNative } from './ui/typing';
|
||||||
|
|
||||||
import './ui/index.css';
|
import './ui/index.css';
|
||||||
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
import { Edge } from '@xyflow/svelte';
|
|
||||||
import { Node as Node_2 } from '@xyflow/svelte';
|
|
||||||
import { useSvelteFlow } from '@xyflow/svelte';
|
|
||||||
import { Viewport } from '@xyflow/svelte';
|
|
||||||
|
|
||||||
export declare type Item = {
|
|
||||||
value: number | string;
|
|
||||||
label: string;
|
|
||||||
children?: Item[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export declare class Tinyflow {
|
|
||||||
private options;
|
|
||||||
private rootEl;
|
|
||||||
private svelteFlowInstance;
|
|
||||||
constructor(options: TinyflowOptions);
|
|
||||||
private _init;
|
|
||||||
private _setOptions;
|
|
||||||
getOptions(): TinyflowOptions;
|
|
||||||
getData(): {
|
|
||||||
nodes: Node_2[];
|
|
||||||
edges: Edge[];
|
|
||||||
viewport: Viewport;
|
|
||||||
};
|
|
||||||
setData(data: TinyflowData): void;
|
|
||||||
destroy(): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare type TinyflowData = Partial<ReturnType<ReturnType<typeof useSvelteFlow>['toObject']>>;
|
|
||||||
|
|
||||||
export declare type TinyflowOptions = {
|
|
||||||
element: string | Element;
|
|
||||||
data?: TinyflowData;
|
|
||||||
provider?: {
|
|
||||||
llm?: () => Item[] | Promise<Item[]>;
|
|
||||||
knowledge?: () => Item[] | Promise<Item[]>;
|
|
||||||
internal?: () => Item[] | Promise<Item[]>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export { }
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { Edge, Node as Node_2, useSvelteFlow, Viewport } from '@xyflow/svelte';
|
||||||
|
|
||||||
|
export declare type Item = {
|
||||||
|
children?: Item[];
|
||||||
|
label: string;
|
||||||
|
value: number | string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export declare class Tinyflow {
|
||||||
|
private _init;
|
||||||
|
private _setOptions;
|
||||||
|
private options;
|
||||||
|
private rootEl;
|
||||||
|
private svelteFlowInstance;
|
||||||
|
constructor(options: TinyflowOptions);
|
||||||
|
destroy(): void;
|
||||||
|
getData(): {
|
||||||
|
edges: Edge[];
|
||||||
|
nodes: Node_2[];
|
||||||
|
viewport: Viewport;
|
||||||
|
};
|
||||||
|
getOptions(): TinyflowOptions;
|
||||||
|
setData(data: TinyflowData): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare type TinyflowData = Partial<
|
||||||
|
ReturnType<ReturnType<typeof useSvelteFlow>['toObject']>
|
||||||
|
>;
|
||||||
|
|
||||||
|
export declare type TinyflowOptions = {
|
||||||
|
data?: TinyflowData;
|
||||||
|
element: Element | string;
|
||||||
|
provider?: {
|
||||||
|
internal?: () => Item[] | Promise<Item[]>;
|
||||||
|
knowledge?: () => Item[] | Promise<Item[]>;
|
||||||
|
llm?: () => Item[] | Promise<Item[]>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export {};
|
|
@ -1,24 +1,4 @@
|
||||||
import dayjs from 'dayjs';
|
import { formatDate } from '@vben/utils';
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间日期转换
|
|
||||||
* @param date 当前时间,new Date() 格式
|
|
||||||
* @param format 需要转换的时间格式字符串
|
|
||||||
* @description format 字符串随意,如 `YYYY-MM、YYYY-MM-DD`
|
|
||||||
* @description format 季度:"YYYY-MM-DD HH:mm:ss QQQQ"
|
|
||||||
* @description format 星期:"YYYY-MM-DD HH:mm:ss WWW"
|
|
||||||
* @description format 几周:"YYYY-MM-DD HH:mm:ss ZZZ"
|
|
||||||
* @description format 季度 + 星期 + 几周:"YYYY-MM-DD HH:mm:ss WWW QQQQ ZZZ"
|
|
||||||
* @returns 返回拼接后的时间字符串
|
|
||||||
*/
|
|
||||||
export function formatDate(date: Date, format?: string): string {
|
|
||||||
// 日期不存在,则返回空
|
|
||||||
if (!date) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
// 日期存在,则进行格式化
|
|
||||||
return date ? dayjs(date).format(format ?? 'YYYY-MM-DD HH:mm:ss') : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将时间转换为 `几秒前`、`几分钟前`、`几小时前`、`几天前`
|
* 将时间转换为 `几秒前`、`几分钟前`、`几小时前`、`几天前`
|
||||||
|
|
Loading…
Reference in New Issue