form-designer-xinyi 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +10 -0
- package/.vscode/extensions.json +3 -0
- package/.vscode/settings.json +6 -0
- package/LICENSE +21 -0
- package/README.md +236 -0
- package/docs/.vitepress/config.ts +158 -0
- package/docs/.vitepress/theme/custom.css +38 -0
- package/docs/.vitepress/theme/index.ts +7 -0
- package/docs/.vitepress/theme/style.css +36 -0
- package/docs/guide/about/about.md +25 -0
- package/docs/guide/action/customFunctions.md +560 -0
- package/docs/guide/action/publicMethods.md +25 -0
- package/docs/guide/components/EBuilder.md +544 -0
- package/docs/guide/components/EDesigner.md +117 -0
- package/docs/guide/extensions/actionBar.md +55 -0
- package/docs/guide/extensions/component.md +113 -0
- package/docs/guide/extensions/icon.md +41 -0
- package/docs/guide/extensions/rightSidebar.md +57 -0
- package/docs/guide/start/dark-mode.md +149 -0
- package/docs/guide/start/i18n-cn.md +39 -0
- package/docs/guide/start/index.md +59 -0
- package/docs/guide/start/layoutGuide.md +0 -0
- package/docs/guide/start/quick-start.md +179 -0
- package/docs/guide/start/theme.md +122 -0
- package/docs/guide/utils/pageManager.md +97 -0
- package/docs/guide/utils/pluginManager.md +227 -0
- package/docs/index.md +41 -0
- package/docs/package.json +14 -0
- package/docs/public/dark.png +0 -0
- package/docs/public/favicon.ico +0 -0
- package/docs/public/icons/demo.css +539 -0
- package/docs/public/icons/demo_index.html +589 -0
- package/docs/public/icons/iconfont.css +379 -0
- package/docs/public/icons/iconfont.js +1 -0
- package/docs/public/icons/iconfont.json +646 -0
- package/docs/public/icons/iconfont.ttf +0 -0
- package/docs/public/icons/iconfont.woff +0 -0
- package/docs/public/icons/iconfont.woff2 +0 -0
- package/docs/public/layout.jpg +0 -0
- package/docs/public/logo.png +0 -0
- package/docs/public/theme.jpg +0 -0
- package/docs/updateLog.md +364 -0
- package/docs/vite.config.ts +18 -0
- package/docs//345/210/235/345/247/213/345/214/226/345/270/203/345/261/200.jpg +0 -0
- package/docs//350/256/276/350/256/241/345/231/250/344/273/213/347/273/215.md +21 -0
- package/docs//350/256/276/350/256/241/345/231/250/345/270/203/345/261/200.jpg +0 -0
- package/examples/README.md +18 -0
- package/examples/index.html +13 -0
- package/examples/package.json +27 -0
- package/examples/public/favicon.ico +0 -0
- package/examples/src/App.vue +5 -0
- package/examples/src/assets/logo.png +0 -0
- package/examples/src/layout/baseLayout.vue +3 -0
- package/examples/src/layout/components/Header/index.vue +102 -0
- package/examples/src/layout/components/Main/Maximize.vue +77 -0
- package/examples/src/layout/components/Main/index.vue +16 -0
- package/examples/src/layout/components/Menu/index.vue +49 -0
- package/examples/src/layout/index.vue +26 -0
- package/examples/src/main.ts +6 -0
- package/examples/src/router/index.ts +98 -0
- package/examples/src/style/reset.css +253 -0
- package/examples/src/style.less +44 -0
- package/examples/src/views/builder/basic/index.vue +182 -0
- package/examples/src/views/builder/disableDisplay/index.vue +153 -0
- package/examples/src/views/builder/disableDisplay copy/index.vue +111 -0
- package/examples/src/views/builder/loadData/index.vue +195 -0
- package/examples/src/views/builder/sum/index.vue +127 -0
- package/examples/src/views/designer/basic/index.vue +22 -0
- package/examples/src/views/designer/loadData/index.vue +186 -0
- package/examples/src/vite-env.d.ts +1 -0
- package/examples/tsconfig.json +27 -0
- package/examples/tsconfig.node.json +10 -0
- package/examples/vite.config.ts +28 -0
- package/package.json +44 -0
- package/packages/core/LICENSE +21 -0
- package/packages/core/components/asyncLoader/index.less +92 -0
- package/packages/core/components/asyncLoader/index.vue +7 -0
- package/packages/core/components/builder/index.ts +3 -0
- package/packages/core/components/builder/src/builder.vue +217 -0
- package/packages/core/components/builder/src/types.ts +4 -0
- package/packages/core/components/designer/index.ts +3 -0
- package/packages/core/components/designer/src/designer.vue +258 -0
- package/packages/core/components/designer/src/index.less +81 -0
- package/packages/core/components/designer/src/modules/actionBar/index.less +79 -0
- package/packages/core/components/designer/src/modules/actionBar/index.vue +44 -0
- package/packages/core/components/designer/src/modules/attributeView/attributeView.vue +104 -0
- package/packages/core/components/designer/src/modules/attributeView/eventView.vue +76 -0
- package/packages/core/components/designer/src/modules/attributeView/index.less +36 -0
- package/packages/core/components/designer/src/modules/attributeView/styleView.vue +103 -0
- package/packages/core/components/designer/src/modules/componentView/index.less +52 -0
- package/packages/core/components/designer/src/modules/componentView/index.vue +118 -0
- package/packages/core/components/designer/src/modules/editContainer/editNodeItem.vue +74 -0
- package/packages/core/components/designer/src/modules/editContainer/editScreenContainer.vue +142 -0
- package/packages/core/components/designer/src/modules/editContainer/index.less +129 -0
- package/packages/core/components/designer/src/modules/editContainer/index.vue +37 -0
- package/packages/core/components/designer/src/modules/editContainer/nodeItem.vue +91 -0
- package/packages/core/components/designer/src/modules/editContainer/previewJson.vue +61 -0
- package/packages/core/components/designer/src/modules/editContainer/previewWidgets.vue +373 -0
- package/packages/core/components/designer/src/modules/editContainer/toolbar.vue +248 -0
- package/packages/core/components/designer/src/modules/header/index.less +16 -0
- package/packages/core/components/designer/src/modules/header/index.vue +60 -0
- package/packages/core/components/designer/src/modules/outline/index.less +7 -0
- package/packages/core/components/designer/src/modules/outline/outline.vue +39 -0
- package/packages/core/components/designer/src/modules/preview/index.less +0 -0
- package/packages/core/components/designer/src/modules/preview/index.vue +71 -0
- package/packages/core/components/designer/src/modules/rightSidebar/breadcrumb.vue +30 -0
- package/packages/core/components/designer/src/modules/rightSidebar/index.less +75 -0
- package/packages/core/components/designer/src/modules/rightSidebar/index.vue +58 -0
- package/packages/core/components/designer/src/modules/sourceCode/index.less +7 -0
- package/packages/core/components/designer/src/modules/sourceCode/index.vue +34 -0
- package/packages/core/components/designer/src/types.ts +9 -0
- package/packages/core/components/icon/index.ts +2 -0
- package/packages/core/components/icon/src/icon.vue +15 -0
- package/packages/core/components/node/index.ts +2 -0
- package/packages/core/components/node/src/node.vue +350 -0
- package/packages/core/components/tree/index.ts +2 -0
- package/packages/core/components/tree/src/index.less +106 -0
- package/packages/core/components/tree/src/tree.vue +113 -0
- package/packages/core/components/tree/src/treeNodeItem.vue +87 -0
- package/packages/core/components/tree/src/treeNodes.vue +68 -0
- package/packages/core/extensions/EActionEditor/index.less +172 -0
- package/packages/core/extensions/EActionEditor/index.vue +160 -0
- package/packages/core/extensions/EActionEditor/src/EActionEditorItem.vue +133 -0
- package/packages/core/extensions/EActionEditor/src/EActionModal.vue +258 -0
- package/packages/core/extensions/EActionEditor/src/EArgsEditor.vue +61 -0
- package/packages/core/extensions/EActionEditor/src/EScriptEdit.vue +26 -0
- package/packages/core/extensions/EColEditor/index.less +24 -0
- package/packages/core/extensions/EColEditor/index.vue +65 -0
- package/packages/core/extensions/EInputSize/index.vue +59 -0
- package/packages/core/extensions/EOptionsEditor/index.vue +52 -0
- package/packages/core/extensions/EOptionsEditor/optionItem.vue +72 -0
- package/packages/core/extensions/ERuleEditor/ERuleItem.vue +137 -0
- package/packages/core/extensions/ERuleEditor/data.ts +24 -0
- package/packages/core/extensions/ERuleEditor/index.less +17 -0
- package/packages/core/extensions/ERuleEditor/index.vue +154 -0
- package/packages/core/extensions/ERuleEditor/types.ts +17 -0
- package/packages/core/extensions/MonacoEditor/index.ts +31 -0
- package/packages/core/extensions/MonacoEditor/index.vue +147 -0
- package/packages/core/extensions/Page/index.ts +23 -0
- package/packages/core/extensions/Page/index.vue +27 -0
- package/packages/core/extensions/index.ts +73 -0
- package/packages/core/index.less +27 -0
- package/packages/core/index.ts +35 -0
- package/packages/core/package.json +59 -0
- package/packages/core/static/icons/demo.css +539 -0
- package/packages/core/static/icons/demo_index.html +2281 -0
- package/packages/core/static/icons/iconfont.css +372 -0
- package/packages/core/static/icons/iconfont.js +1 -0
- package/packages/core/static/icons/iconfont.json +646 -0
- package/packages/core/static/icons/iconfont.ttf +0 -0
- package/packages/core/static/icons/iconfont.woff +0 -0
- package/packages/core/static/icons/iconfont.woff2 +0 -0
- package/packages/core/static/logo.png +0 -0
- package/packages/core/theme/var.less +175 -0
- package/packages/core/tsconfig.json +19 -0
- package/packages/core/types/epic-designer.ts +75 -0
- package/packages/epic-designer/.babelrc +9 -0
- package/packages/epic-designer/.eslintrc.cjs +76 -0
- package/packages/epic-designer/LICENSE +21 -0
- package/packages/epic-designer/README.md +239 -0
- package/packages/epic-designer/index.ts +13 -0
- package/packages/epic-designer/package.json +75 -0
- package/packages/epic-designer/shims-vue.d.ts +4 -0
- package/packages/epic-designer/tsconfig.json +19 -0
- package/packages/epic-designer/uno.config.ts +79 -0
- package/packages/script/package.json +17 -0
- package/packages/script/src/check-compiled.ts +22 -0
- package/packages/script/tsconfig.json +10 -0
- package/packages/ui/LICENSE +21 -0
- package/packages/ui/antd/button/button.vue +16 -0
- package/packages/ui/antd/button/index.ts +202 -0
- package/packages/ui/antd/card/card.ts +31 -0
- package/packages/ui/antd/card/index.ts +63 -0
- package/packages/ui/antd/cascader/cascader.vue +23 -0
- package/packages/ui/antd/cascader/index.ts +197 -0
- package/packages/ui/antd/checkbox/index.ts +99 -0
- package/packages/ui/antd/col/col.ts +31 -0
- package/packages/ui/antd/col/index.ts +22 -0
- package/packages/ui/antd/color-picker/index.ts +107 -0
- package/packages/ui/antd/date-picker/datePicker.ts +47 -0
- package/packages/ui/antd/date-picker/index.ts +302 -0
- package/packages/ui/antd/form/form.vue +118 -0
- package/packages/ui/antd/form/index.ts +195 -0
- package/packages/ui/antd/form-item/formItem.vue +15 -0
- package/packages/ui/antd/form-item/index.ts +11 -0
- package/packages/ui/antd/formLogic/actionEdit.vue +72 -0
- package/packages/ui/antd/formLogic/actionItem.vue +46 -0
- package/packages/ui/antd/formLogic/conditionEdit.vue +111 -0
- package/packages/ui/antd/formLogic/conditionItem.vue +150 -0
- package/packages/ui/antd/formLogic/drawer.vue +124 -0
- package/packages/ui/antd/formLogic/formLogic.vue +33 -0
- package/packages/ui/antd/formLogic/index.ts +11 -0
- package/packages/ui/antd/formLogic/types.ts +25 -0
- package/packages/ui/antd/index.less +33 -0
- package/packages/ui/antd/index.ts +323 -0
- package/packages/ui/antd/input/index.ts +169 -0
- package/packages/ui/antd/input-number/index.ts +181 -0
- package/packages/ui/antd/input-password/index.ts +152 -0
- package/packages/ui/antd/modal/index.ts +19 -0
- package/packages/ui/antd/modal/modal.vue +82 -0
- package/packages/ui/antd/radio/index.ts +105 -0
- package/packages/ui/antd/row/index.ts +114 -0
- package/packages/ui/antd/row/row.ts +31 -0
- package/packages/ui/antd/select/index.ts +228 -0
- package/packages/ui/antd/slider/index.ts +142 -0
- package/packages/ui/antd/switch/index.ts +141 -0
- package/packages/ui/antd/textarea/index.ts +162 -0
- package/packages/ui/antd/time-picker/index.ts +189 -0
- package/packages/ui/antd/upload-file/index.ts +88 -0
- package/packages/ui/antd/upload-file/uploadFile.ts +117 -0
- package/packages/ui/antd/upload-image/index.ts +69 -0
- package/packages/ui/antd/upload-image/uploadImage.vue +148 -0
- package/packages/ui/elementPlus/button/button.ts +25 -0
- package/packages/ui/elementPlus/button/index.ts +128 -0
- package/packages/ui/elementPlus/card/card.ts +36 -0
- package/packages/ui/elementPlus/card/index.ts +50 -0
- package/packages/ui/elementPlus/cascader/index.ts +216 -0
- package/packages/ui/elementPlus/checkbox/checkbox.ts +31 -0
- package/packages/ui/elementPlus/checkbox/index.ts +140 -0
- package/packages/ui/elementPlus/col/col.ts +31 -0
- package/packages/ui/elementPlus/col/index.ts +21 -0
- package/packages/ui/elementPlus/collapse/collapse.ts +32 -0
- package/packages/ui/elementPlus/collapse/index.ts +41 -0
- package/packages/ui/elementPlus/collapse-item/collapseItem.ts +31 -0
- package/packages/ui/elementPlus/collapse-item/index.ts +12 -0
- package/packages/ui/elementPlus/color-picker/index.ts +110 -0
- package/packages/ui/elementPlus/date-picker/index.ts +218 -0
- package/packages/ui/elementPlus/form/form.vue +99 -0
- package/packages/ui/elementPlus/form/index.ts +147 -0
- package/packages/ui/elementPlus/formItem/formItem.vue +15 -0
- package/packages/ui/elementPlus/formItem/index.ts +11 -0
- package/packages/ui/elementPlus/index.less +79 -0
- package/packages/ui/elementPlus/index.ts +84 -0
- package/packages/ui/elementPlus/input/index.ts +179 -0
- package/packages/ui/elementPlus/input-number/index.ts +145 -0
- package/packages/ui/elementPlus/modal/index.ts +18 -0
- package/packages/ui/elementPlus/modal/modal.ts +68 -0
- package/packages/ui/elementPlus/radio/index.ts +121 -0
- package/packages/ui/elementPlus/radio/radio.ts +32 -0
- package/packages/ui/elementPlus/row/index.ts +105 -0
- package/packages/ui/elementPlus/row/row.ts +32 -0
- package/packages/ui/elementPlus/select/index.ts +283 -0
- package/packages/ui/elementPlus/select/select.ts +31 -0
- package/packages/ui/elementPlus/slider/index.ts +237 -0
- package/packages/ui/elementPlus/switch/index.ts +159 -0
- package/packages/ui/elementPlus/textarea/index.ts +154 -0
- package/packages/ui/elementPlus/upload-file/index.ts +86 -0
- package/packages/ui/elementPlus/upload-file/uploadFile.ts +114 -0
- package/packages/ui/elementPlus/upload-image/index.ts +86 -0
- package/packages/ui/elementPlus/upload-image/uploadImage.ts +151 -0
- package/packages/ui/hooks/index.ts +1 -0
- package/packages/ui/hooks/logic.ts +129 -0
- package/packages/ui/index.ts +22 -0
- package/packages/ui/naiveUi/button/button.ts +25 -0
- package/packages/ui/naiveUi/button/index.ts +146 -0
- package/packages/ui/naiveUi/card/card.ts +32 -0
- package/packages/ui/naiveUi/card/index.ts +25 -0
- package/packages/ui/naiveUi/cascader/index.ts +218 -0
- package/packages/ui/naiveUi/checkbox/checkbox.ts +27 -0
- package/packages/ui/naiveUi/checkbox/index.ts +114 -0
- package/packages/ui/naiveUi/col/col.ts +30 -0
- package/packages/ui/naiveUi/col/index.ts +21 -0
- package/packages/ui/naiveUi/collapse/collapse.ts +31 -0
- package/packages/ui/naiveUi/collapse/index.ts +40 -0
- package/packages/ui/naiveUi/collapse-item/collapseItem.ts +31 -0
- package/packages/ui/naiveUi/collapse-item/index.ts +12 -0
- package/packages/ui/naiveUi/color-picker/index.ts +179 -0
- package/packages/ui/naiveUi/date-picker/index.ts +210 -0
- package/packages/ui/naiveUi/form/form.vue +85 -0
- package/packages/ui/naiveUi/form/index.ts +141 -0
- package/packages/ui/naiveUi/form-item/formItem.vue +15 -0
- package/packages/ui/naiveUi/form-item/index.ts +10 -0
- package/packages/ui/naiveUi/index.less +33 -0
- package/packages/ui/naiveUi/index.ts +80 -0
- package/packages/ui/naiveUi/input/index.ts +215 -0
- package/packages/ui/naiveUi/input-number/index.ts +141 -0
- package/packages/ui/naiveUi/modal/index.ts +18 -0
- package/packages/ui/naiveUi/modal/modal.ts +83 -0
- package/packages/ui/naiveUi/radio/index.ts +94 -0
- package/packages/ui/naiveUi/radio/radio.ts +27 -0
- package/packages/ui/naiveUi/row/index.ts +105 -0
- package/packages/ui/naiveUi/row/row.ts +31 -0
- package/packages/ui/naiveUi/select/index.ts +193 -0
- package/packages/ui/naiveUi/slider/index.ts +181 -0
- package/packages/ui/naiveUi/switch/index.ts +133 -0
- package/packages/ui/naiveUi/upload-file/index.ts +82 -0
- package/packages/ui/naiveUi/upload-file/uploadFile.ts +78 -0
- package/packages/ui/naiveUi/upload-image/index.ts +82 -0
- package/packages/ui/naiveUi/upload-image/uploadImage.ts +152 -0
- package/packages/ui/package.json +18 -0
- package/packages/ui/tsconfig.json +19 -0
- package/packages/utils/LICENSE +21 -0
- package/packages/utils/common/common.ts +18 -0
- package/packages/utils/common/component.ts +22 -0
- package/packages/utils/common/data.ts +682 -0
- package/packages/utils/common/element.ts +166 -0
- package/packages/utils/common/index.ts +6 -0
- package/packages/utils/common/string.ts +18 -0
- package/packages/utils/common/theme.ts +84 -0
- package/packages/utils/index.ts +3 -0
- package/packages/utils/manager/index.ts +3 -0
- package/packages/utils/manager/pageManager.ts +157 -0
- package/packages/utils/manager/pluginManager.ts +586 -0
- package/packages/utils/manager/revoke.ts +128 -0
- package/packages/utils/package.json +7 -0
- package/packages/utils/shareStore/index.ts +30 -0
- package/packages/utils/tsconfig.json +19 -0
- package/packages/utils/vite.config.ts +39 -0
- package/pnpm-workspace.yaml +5 -0
- package/turbo.json +20 -0
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
import { type ComponentSchema } from "@epic-designer/core/types/epic-designer";
|
|
2
|
+
import { loadAsyncComponent } from "../common";
|
|
3
|
+
import { ref, shallowRef, type ShallowRef } from "vue";
|
|
4
|
+
export interface ActivitybarModel {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
icon: string;
|
|
8
|
+
component: any;
|
|
9
|
+
visible?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RightSidebarModel {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
component: any;
|
|
16
|
+
visible?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ViewsContainersModel {
|
|
20
|
+
activitybars: ShallowRef<ActivitybarModel[]>;
|
|
21
|
+
rightSidebars: ShallowRef<RightSidebarModel[]>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Components = Record<string, any>;
|
|
25
|
+
|
|
26
|
+
export interface EventModel {
|
|
27
|
+
type: string;
|
|
28
|
+
describe: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ActionModel extends EventModel {
|
|
32
|
+
argsConfigs?: ComponentSchema[];
|
|
33
|
+
args?: any[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface EditConstraintsModel {
|
|
37
|
+
// 当前组件是否固定不可拖动,可选
|
|
38
|
+
immovable?: boolean;
|
|
39
|
+
// 子节点是否固定不可拖动,只控制下一级,可选
|
|
40
|
+
childImmovable?: boolean;
|
|
41
|
+
// 表单字段是否固定 不添加随机UUID
|
|
42
|
+
fixedField?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ComponentConfigModel {
|
|
46
|
+
// 组件
|
|
47
|
+
component: any;
|
|
48
|
+
// 分组名称(组件分组),不设置分组时仅注册,但不会显示在组件列表中,可选
|
|
49
|
+
groupName?: string;
|
|
50
|
+
// 组件图标
|
|
51
|
+
icon?: string;
|
|
52
|
+
// 默认组件结构数据
|
|
53
|
+
defaultSchema: ComponentSchema;
|
|
54
|
+
// 设计编辑约束
|
|
55
|
+
editConstraints?: EditConstraintsModel;
|
|
56
|
+
// 配置
|
|
57
|
+
config: {
|
|
58
|
+
// 属性编辑列表
|
|
59
|
+
attribute?: ComponentSchema[];
|
|
60
|
+
// 样式编辑组件列表
|
|
61
|
+
style?: ComponentSchema[];
|
|
62
|
+
// 可触发事件
|
|
63
|
+
event?: EventModel[];
|
|
64
|
+
// 可执行函数
|
|
65
|
+
action?: ActionModel[];
|
|
66
|
+
};
|
|
67
|
+
// 输入表单组件v-model绑定变量名称 默认 modelValue
|
|
68
|
+
bindModel?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type ComponentConfigModelRecords = Record<string, ComponentConfigModel>;
|
|
72
|
+
|
|
73
|
+
export interface PublicMethodModel {
|
|
74
|
+
describe?: string;
|
|
75
|
+
methodName?: string;
|
|
76
|
+
name: string;
|
|
77
|
+
method?: (...args) => any;
|
|
78
|
+
handler: (...args) => any;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type PublicMethodsModel = Record<string, PublicMethodModel>;
|
|
82
|
+
|
|
83
|
+
export interface ComponentGroup {
|
|
84
|
+
list: ComponentSchema[];
|
|
85
|
+
title: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type ComponentSchemaGroups = ComponentGroup[];
|
|
89
|
+
|
|
90
|
+
// 插件管理器类
|
|
91
|
+
export class PluginManager {
|
|
92
|
+
// 已初始化基础UI
|
|
93
|
+
initialized = ref(false);
|
|
94
|
+
|
|
95
|
+
// 组件对象字典,key 为组件type,value 为组件
|
|
96
|
+
components: Components = {};
|
|
97
|
+
|
|
98
|
+
// 组件配置记录字典,key 为组件type,value 为组件配置
|
|
99
|
+
componentConfigs: ComponentConfigModelRecords = {};
|
|
100
|
+
|
|
101
|
+
// 基础组件type,切换ui时,可先移除该数组记录的type
|
|
102
|
+
baseComponentTypes: string[] = [];
|
|
103
|
+
|
|
104
|
+
// 组件模式分组,使用 Vue Composition API 的 ref 进行响应式处理
|
|
105
|
+
componentSchemaGroups = ref<ComponentSchemaGroups>([]);
|
|
106
|
+
|
|
107
|
+
// 隐藏的组件列表,存储需要隐藏的组件名称
|
|
108
|
+
hiddenComponents: string[] = [];
|
|
109
|
+
|
|
110
|
+
// 组件分组名称映射,key 为组件原名称,value 为组件分组映射名称
|
|
111
|
+
componentGroupNameMap: Record<string, string> = {};
|
|
112
|
+
|
|
113
|
+
// 组件分组排序列表(设置之后,按该数组下标排序)
|
|
114
|
+
sortedGroups: string[] = ["表单", "布局"];
|
|
115
|
+
|
|
116
|
+
// 视图容器模型,包含活动栏和右侧边栏的配置
|
|
117
|
+
viewsContainers: ViewsContainersModel = {
|
|
118
|
+
activitybars: shallowRef([]), // 活动栏配置列表
|
|
119
|
+
rightSidebars: shallowRef([]), // 右侧边栏配置列表
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// 公共方法模型,存储插件的公共方法
|
|
123
|
+
publicMethods: PublicMethodsModel = {
|
|
124
|
+
// 示例数据
|
|
125
|
+
// publicTest: {
|
|
126
|
+
// describe: "测试函数",
|
|
127
|
+
// name: "test",
|
|
128
|
+
// handler: (e) => {
|
|
129
|
+
// console.log(e)
|
|
130
|
+
// // alert("测试函数弹出");
|
|
131
|
+
// },
|
|
132
|
+
// },
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 添加组件到插件管理器中
|
|
137
|
+
* @param componentType 组件类型
|
|
138
|
+
* @param component 组件
|
|
139
|
+
*/
|
|
140
|
+
component(componentType: string, component: any): void {
|
|
141
|
+
if (typeof component === "function") {
|
|
142
|
+
component = loadAsyncComponent(component);
|
|
143
|
+
}
|
|
144
|
+
// 注册组件
|
|
145
|
+
this.components[componentType] = component;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 注册组件到插件管理器中
|
|
150
|
+
* @param componentConfig 组件配置
|
|
151
|
+
*/
|
|
152
|
+
registerComponent(componentConfig: ComponentConfigModel): void {
|
|
153
|
+
// 添加组件
|
|
154
|
+
this.component(
|
|
155
|
+
componentConfig.defaultSchema.type,
|
|
156
|
+
componentConfig.component
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// 输入组件增加动作配置
|
|
160
|
+
if (componentConfig.defaultSchema.input) {
|
|
161
|
+
if (!componentConfig.config.action) {
|
|
162
|
+
componentConfig.config.action = [];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 补充组件可用方法
|
|
166
|
+
componentConfig.config.action.unshift(
|
|
167
|
+
...[
|
|
168
|
+
{
|
|
169
|
+
type: "setValue",
|
|
170
|
+
describe: "设置值",
|
|
171
|
+
// 参数配置
|
|
172
|
+
argsConfigs: [
|
|
173
|
+
{
|
|
174
|
+
...componentConfig.defaultSchema,
|
|
175
|
+
label: "设置数据",
|
|
176
|
+
field: "0",
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
type: "getValue",
|
|
182
|
+
describe: "获取值",
|
|
183
|
+
},
|
|
184
|
+
]
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// 添加组件配置
|
|
189
|
+
this.componentConfigs[componentConfig.defaultSchema.type] = componentConfig;
|
|
190
|
+
|
|
191
|
+
this.computedComponentSchemaGroups();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 从已记录的基础组件类型中移除特定类型的组件
|
|
196
|
+
* @param componentType 要移除的组件类型
|
|
197
|
+
*/
|
|
198
|
+
removeComponent(componentType: string) {
|
|
199
|
+
// 在数组中查找要移除的组件类型的索引
|
|
200
|
+
delete this.componentConfigs[componentType];
|
|
201
|
+
delete this.components[componentType];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* 记录基础组件类型
|
|
206
|
+
* @returns baseComponentTypes string[]
|
|
207
|
+
*/
|
|
208
|
+
setBaseComponentTypes(baseComponentTypes: string[]) {
|
|
209
|
+
this.baseComponentTypes = baseComponentTypes;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* 添加基础组件类型
|
|
214
|
+
* @returns baseComponentType string
|
|
215
|
+
*/
|
|
216
|
+
addBaseComponentTypes(baseComponentType: string) {
|
|
217
|
+
this.baseComponentTypes.push(baseComponentType);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* 移除已记录的基础组件类型
|
|
222
|
+
*/
|
|
223
|
+
removeBaseComponents() {
|
|
224
|
+
this.baseComponentTypes.forEach((componentType) => {
|
|
225
|
+
this.removeComponent(componentType);
|
|
226
|
+
});
|
|
227
|
+
this.setBaseComponentTypes([]);
|
|
228
|
+
|
|
229
|
+
this.computedComponentSchemaGroups();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 获取所有插件管理中的所有组件
|
|
234
|
+
* @returns components
|
|
235
|
+
*/
|
|
236
|
+
getComponents(): Components {
|
|
237
|
+
return this.components;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 通过type 查询相应的组件
|
|
242
|
+
* @returns components
|
|
243
|
+
*/
|
|
244
|
+
getComponent(type: string): any {
|
|
245
|
+
return this.components[type];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* 注册或更新活动栏(Activitybar)模型。
|
|
250
|
+
* 如果模型中的组件是一个函数,则异步加载该组件。
|
|
251
|
+
* @param activitybar 要注册或更新的活动栏模型
|
|
252
|
+
*/
|
|
253
|
+
registerActivitybar(activitybar: ActivitybarModel): void {
|
|
254
|
+
// 如果组件是一个函数,则异步加载该组件
|
|
255
|
+
if (typeof activitybar.component === "function") {
|
|
256
|
+
activitybar.component = loadAsyncComponent(activitybar.component);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 默认visible为true
|
|
260
|
+
if (typeof activitybar.visible === "undefined") {
|
|
261
|
+
activitybar.visible = true;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 查找活动栏在列表中的索引
|
|
265
|
+
const index = this.viewsContainers.activitybars.value.findIndex(
|
|
266
|
+
(item) => item.id === activitybar.id
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// 如果找到相同 id 的活动栏,则更新该活动栏模型
|
|
270
|
+
if (index !== -1) {
|
|
271
|
+
this.viewsContainers.activitybars.value[index] = activitybar;
|
|
272
|
+
} else {
|
|
273
|
+
// 否则将新的活动栏模型添加到活动栏列表中
|
|
274
|
+
this.viewsContainers.activitybars.value.push(activitybar);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 获取所有activitybars
|
|
280
|
+
* @returns activitybars
|
|
281
|
+
*/
|
|
282
|
+
getActivitybars(): ActivitybarModel[] {
|
|
283
|
+
return this.viewsContainers.activitybars.value;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* 隐藏活动栏
|
|
288
|
+
* @param value 属性
|
|
289
|
+
* @param attr 查询字段 默认值 title
|
|
290
|
+
*/
|
|
291
|
+
hideActivitybar(value: string, attr = "title") {
|
|
292
|
+
// 查找具有指定属性和值的活动栏的索引
|
|
293
|
+
const index = this.viewsContainers.activitybars.value.findIndex(
|
|
294
|
+
(rightSidebar) => rightSidebar[attr] === value
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
// 如果找到匹配的活动栏
|
|
298
|
+
if (index !== -1) {
|
|
299
|
+
// 将匹配的活动栏的 'visible' 属性设置为 false
|
|
300
|
+
this.viewsContainers.activitybars.value[index].visible = false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* 显示活动栏
|
|
305
|
+
* @param value 属性
|
|
306
|
+
* @param attr 查询字段 默认值 title
|
|
307
|
+
*/
|
|
308
|
+
showActivitybar(value: string, attr = "title") {
|
|
309
|
+
// 查找具有指定属性和值的活动栏的索引
|
|
310
|
+
const index = this.viewsContainers.activitybars.value.findIndex(
|
|
311
|
+
(rightSidebar) => rightSidebar[attr] === value
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
// 如果找到匹配的活动栏
|
|
315
|
+
if (index !== -1) {
|
|
316
|
+
// 将匹配的活动栏的 'visible' 属性设置为 true
|
|
317
|
+
this.viewsContainers.activitybars.value[index].visible = true;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 注册右侧栏
|
|
323
|
+
*/
|
|
324
|
+
registerRightSidebar(rightSidebar: RightSidebarModel): void {
|
|
325
|
+
if (typeof rightSidebar.component === "function") {
|
|
326
|
+
rightSidebar.component = loadAsyncComponent(rightSidebar.component);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// 默认visible为true
|
|
330
|
+
if (typeof rightSidebar.visible === "undefined") {
|
|
331
|
+
rightSidebar.visible = true;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const index = this.viewsContainers.rightSidebars.value.findIndex(
|
|
335
|
+
(sidebar) => sidebar.id === rightSidebar.id
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
if (index !== -1) {
|
|
339
|
+
this.viewsContainers.rightSidebars.value[index] = rightSidebar;
|
|
340
|
+
} else {
|
|
341
|
+
this.viewsContainers.rightSidebars.value.push(rightSidebar);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* 获取所有rightSidebars
|
|
347
|
+
* @returns rightSidebars
|
|
348
|
+
*/
|
|
349
|
+
getRightSidebars(): RightSidebarModel[] {
|
|
350
|
+
return this.viewsContainers.rightSidebars.value;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* 隐藏右侧边栏
|
|
355
|
+
* @param value 属性
|
|
356
|
+
* @param attr 查询字段 默认值 title
|
|
357
|
+
*/
|
|
358
|
+
hideRightSidebar(value: string, attr = "title") {
|
|
359
|
+
// 查找具有指定属性和值的右侧边栏的索引
|
|
360
|
+
const index = this.viewsContainers.rightSidebars.value.findIndex(
|
|
361
|
+
(rightSidebar) => rightSidebar[attr] === value
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
// 如果找到匹配的右侧边栏
|
|
365
|
+
if (index !== -1) {
|
|
366
|
+
// 将匹配的右侧边栏的 'visible' 属性设置为 false
|
|
367
|
+
this.viewsContainers.rightSidebars.value[index].visible = false;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 显示右侧边栏
|
|
373
|
+
* @param value 属性
|
|
374
|
+
* @param attr 查询字段 默认值 title
|
|
375
|
+
*/
|
|
376
|
+
showRightSidebar(value: string, attr = "title") {
|
|
377
|
+
// 查找具有指定属性和值的右侧边栏的索引
|
|
378
|
+
const index = this.viewsContainers.rightSidebars.value.findIndex(
|
|
379
|
+
(rightSidebar) => rightSidebar[attr] === value
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
// 如果找到匹配的右侧边栏
|
|
383
|
+
if (index !== -1) {
|
|
384
|
+
// 将匹配的右侧边栏的 'visible' 属性设置为 true
|
|
385
|
+
this.viewsContainers.rightSidebars.value[index].visible = true;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* 获取所有插件管理中的所有组件配置
|
|
391
|
+
* @returns componentAttrs
|
|
392
|
+
*/
|
|
393
|
+
getComponentConfings(): ComponentConfigModelRecords {
|
|
394
|
+
return this.componentConfigs;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 通过type获取ComponentConfing
|
|
399
|
+
* @returns
|
|
400
|
+
*/
|
|
401
|
+
getComponentConfingByType(type: string): ComponentConfigModel {
|
|
402
|
+
const componentConfig = this.componentConfigs[type];
|
|
403
|
+
return componentConfig;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 计算componentSchemaGroups
|
|
408
|
+
*/
|
|
409
|
+
computedComponentSchemaGroups() {
|
|
410
|
+
const componentSchemaGroups: ComponentSchemaGroups = [];
|
|
411
|
+
|
|
412
|
+
// 遍历组件配置字典的值
|
|
413
|
+
Object.values(this.componentConfigs).forEach((componentConfig) => {
|
|
414
|
+
// 如果组件的默认模式的类型在隐藏组件列表中,则跳过
|
|
415
|
+
if (this.hiddenComponents.includes(componentConfig.defaultSchema.type)) {
|
|
416
|
+
// 跳过当前循环,继续下一个组件
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// 如果组件配置中有分组名
|
|
421
|
+
if (componentConfig.groupName) {
|
|
422
|
+
// 查找当前分组在列表中的索引
|
|
423
|
+
|
|
424
|
+
const groupName =
|
|
425
|
+
this.componentGroupNameMap[componentConfig.groupName] ??
|
|
426
|
+
componentConfig.groupName;
|
|
427
|
+
|
|
428
|
+
let groupIndex = componentSchemaGroups.findIndex(
|
|
429
|
+
(item) => item.title === groupName
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
// 如果找不到分组,表示该分组还未添加过,需要新建一个分组
|
|
433
|
+
if (groupIndex === -1) {
|
|
434
|
+
// 创建新的分组,并将其添加到分组列表中
|
|
435
|
+
componentSchemaGroups.push({
|
|
436
|
+
title: groupName,
|
|
437
|
+
list: [],
|
|
438
|
+
});
|
|
439
|
+
// 获取新添加的分组的索引
|
|
440
|
+
groupIndex = componentSchemaGroups.length - 1;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// 查找当前组件在分组的列表中的索引
|
|
444
|
+
let componentIndex = componentSchemaGroups[groupIndex].list.findIndex(
|
|
445
|
+
(item) => item.type === componentConfig.defaultSchema.type
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
// 如果找到相同类型的组件,则更新该组件结构数据
|
|
449
|
+
if (componentIndex !== -1) {
|
|
450
|
+
componentSchemaGroups[groupIndex].list[componentIndex] =
|
|
451
|
+
componentConfig.defaultSchema;
|
|
452
|
+
} else {
|
|
453
|
+
// 否则将新的组件结构数据添加到相应的分组中
|
|
454
|
+
componentSchemaGroups[groupIndex].list.push(
|
|
455
|
+
componentConfig.defaultSchema
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// 调整分组排序
|
|
462
|
+
componentSchemaGroups.sort((a: ComponentGroup, b: ComponentGroup) => {
|
|
463
|
+
const indexA = this.sortedGroups.indexOf(a.title);
|
|
464
|
+
const indexB = this.sortedGroups.indexOf(b.title);
|
|
465
|
+
if (indexA === -1) {
|
|
466
|
+
return 1; // a.title 不在 orderArray 中,排在后面
|
|
467
|
+
}
|
|
468
|
+
if (indexB === -1) {
|
|
469
|
+
return -1; // b.title 不在 orderArray 中,排在前面
|
|
470
|
+
}
|
|
471
|
+
return indexA - indexB; // 按照 orderArray 中的顺序排序
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
this.componentSchemaGroups.value = componentSchemaGroups;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* 按照分组获取componentSchemaGroups 暂时没啥用
|
|
479
|
+
* @returns componentSchemaGroups
|
|
480
|
+
*/
|
|
481
|
+
getComponentSchemaGroups() {
|
|
482
|
+
return this.componentSchemaGroups;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* 设置组件分组名称到映射名称的关系
|
|
487
|
+
* @param groupName 组件分组名称
|
|
488
|
+
* @param mapName 映射的名称
|
|
489
|
+
*/
|
|
490
|
+
setComponentGroupNameMap(groupName: string, mapName: string) {
|
|
491
|
+
this.componentGroupNameMap[groupName] = mapName;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* 清空组件分组名称到映射名称的关系
|
|
496
|
+
*/
|
|
497
|
+
clearComponentGroupNameMap() {
|
|
498
|
+
this.componentGroupNameMap = {};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* 设置组件分组的排序
|
|
503
|
+
* @param sortedGroups 包含组名和排序字段的对象数组
|
|
504
|
+
*/
|
|
505
|
+
setSortedGroups(sortedGroups: string[]) {
|
|
506
|
+
this.sortedGroups = sortedGroups;
|
|
507
|
+
this.computedComponentSchemaGroups();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* 清空组件分组的排序
|
|
512
|
+
*/
|
|
513
|
+
clearSortedGroups() {
|
|
514
|
+
this.sortedGroups = [];
|
|
515
|
+
this.computedComponentSchemaGroups();
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* 添加需要隐藏的组件类型
|
|
520
|
+
* @param {*} type
|
|
521
|
+
* @returns
|
|
522
|
+
*/
|
|
523
|
+
hideComponent(type: string) {
|
|
524
|
+
this.hiddenComponents.push(type);
|
|
525
|
+
this.computedComponentSchemaGroups();
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* 移除需要隐藏的组件类型
|
|
530
|
+
* @param {*} type
|
|
531
|
+
* @returns
|
|
532
|
+
*/
|
|
533
|
+
showComponent(type: string) {
|
|
534
|
+
this.hiddenComponents = this.hiddenComponents.filter(
|
|
535
|
+
(item) => item !== type
|
|
536
|
+
);
|
|
537
|
+
this.computedComponentSchemaGroups();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* 设置需要隐藏的组件类型数组
|
|
542
|
+
* @param {*} type[]
|
|
543
|
+
* @returns
|
|
544
|
+
*/
|
|
545
|
+
setHideComponents(types: string[]) {
|
|
546
|
+
this.hiddenComponents = types;
|
|
547
|
+
this.computedComponentSchemaGroups();
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* 设置initialized的状态。
|
|
552
|
+
*
|
|
553
|
+
* @param value 要设置的布尔值。
|
|
554
|
+
*/
|
|
555
|
+
setInitialized(value: boolean): void {
|
|
556
|
+
this.initialized.value = value;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* 添加公共方法
|
|
561
|
+
* @param publicMethod
|
|
562
|
+
*/
|
|
563
|
+
addPublicMethod(publicMethod: PublicMethodModel): void {
|
|
564
|
+
// 兼容旧公共函数注册,后期可能移除该判断
|
|
565
|
+
// methodName 变量改成 name
|
|
566
|
+
// method 变量改成 handler
|
|
567
|
+
const name = publicMethod.methodName ?? publicMethod.name;
|
|
568
|
+
const handler = publicMethod.method ?? publicMethod.handler;
|
|
569
|
+
|
|
570
|
+
this.publicMethods[name] = {
|
|
571
|
+
...publicMethod,
|
|
572
|
+
name,
|
|
573
|
+
handler,
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* 移除公共方法
|
|
579
|
+
* @param methodName
|
|
580
|
+
*/
|
|
581
|
+
removePublicMethod(methodName: string): void {
|
|
582
|
+
delete this.publicMethods[methodName];
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
export const pluginManager = new PluginManager();
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { type ComponentSchema } from '@epic-designer/core/types/epic-designer'
|
|
2
|
+
import { ref, type Ref } from 'vue'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
历史记录模型
|
|
6
|
+
*/
|
|
7
|
+
export interface RecordModel {
|
|
8
|
+
type: string
|
|
9
|
+
componentSchema: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
撤销重做功能
|
|
14
|
+
*/
|
|
15
|
+
export function useRevoke (): {
|
|
16
|
+
recordList: Ref<Array<{
|
|
17
|
+
type: string
|
|
18
|
+
componentSchema: string
|
|
19
|
+
}>>
|
|
20
|
+
undoList: Ref<Array<{
|
|
21
|
+
type: string
|
|
22
|
+
componentSchema: string
|
|
23
|
+
}>>
|
|
24
|
+
currentRecord: Ref<{
|
|
25
|
+
type: string
|
|
26
|
+
componentSchema: string
|
|
27
|
+
} | null>
|
|
28
|
+
push: (componentSchema: ComponentSchema[], type?: string) => void
|
|
29
|
+
undo: () => RecordModel | false
|
|
30
|
+
redo: () => RecordModel | false
|
|
31
|
+
} {
|
|
32
|
+
// 历史记录
|
|
33
|
+
const recordList = ref<RecordModel[]>([])
|
|
34
|
+
|
|
35
|
+
// 撤销记录,用于重做
|
|
36
|
+
const undoList = ref<RecordModel[]>([])
|
|
37
|
+
|
|
38
|
+
// 当前记录用currentRecord变量暂时存储,当用户修改时,再存放到recordList
|
|
39
|
+
const currentRecord = ref<RecordModel | null>(null)
|
|
40
|
+
|
|
41
|
+
// 最后记录时间
|
|
42
|
+
let lastPushTime = 0
|
|
43
|
+
/**
|
|
44
|
+
* @description: 插入历史记录
|
|
45
|
+
* @param {object}componentSchema
|
|
46
|
+
* @return {boolean}
|
|
47
|
+
*/
|
|
48
|
+
function push (componentSchema: ComponentSchema[], type = '插入组件'): void {
|
|
49
|
+
// 忽略低于150ms时间差的记录
|
|
50
|
+
const nowTime = Date.now()
|
|
51
|
+
if (lastPushTime + 150 > nowTime) {
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
lastPushTime = nowTime
|
|
55
|
+
|
|
56
|
+
// 判断之前是否已经存在currentRecord记录,有则存储到recordList
|
|
57
|
+
if (currentRecord.value != null) {
|
|
58
|
+
recordList.value.push(currentRecord.value)
|
|
59
|
+
// 增加记录后则应该清空重做记录
|
|
60
|
+
undoList.value.splice(0, undoList.value.length)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 将json转成字符串存储
|
|
64
|
+
currentRecord.value = {
|
|
65
|
+
type,
|
|
66
|
+
componentSchema: JSON.stringify(componentSchema)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 最多存储20条记录,超过20条记录则删除之前的记录
|
|
70
|
+
if (recordList.value.length > 20) {
|
|
71
|
+
recordList.value.unshift()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @description: 撤销操作
|
|
77
|
+
* @param {*}
|
|
78
|
+
* @return {object}
|
|
79
|
+
*/
|
|
80
|
+
function undo (): RecordModel | false {
|
|
81
|
+
// 没有记录时,返回false
|
|
82
|
+
if (recordList.value.length === 0) {
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
const recordObj = recordList.value.pop() as RecordModel
|
|
86
|
+
|
|
87
|
+
// 将当前记录添加到重做记录里面
|
|
88
|
+
if (currentRecord.value != null) {
|
|
89
|
+
undoList.value.push(currentRecord.value)
|
|
90
|
+
}
|
|
91
|
+
// 丢弃当前记录,防止重复添加
|
|
92
|
+
currentRecord.value = recordObj
|
|
93
|
+
|
|
94
|
+
return JSON.parse(recordObj.componentSchema)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @description: 重做操作
|
|
99
|
+
* @param {*}
|
|
100
|
+
* @return {*}
|
|
101
|
+
*/
|
|
102
|
+
function redo (): RecordModel | false {
|
|
103
|
+
// 没有重做记录时,返回false
|
|
104
|
+
if (undoList.value.length === 0) {
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const recordObj = undoList.value.pop() as RecordModel
|
|
109
|
+
// 添加到重做记录里面
|
|
110
|
+
if (currentRecord.value != null) {
|
|
111
|
+
recordList.value.push(currentRecord.value)
|
|
112
|
+
}
|
|
113
|
+
// 丢弃当前记录,防止重复添加
|
|
114
|
+
currentRecord.value = recordObj
|
|
115
|
+
return JSON.parse(recordObj.componentSchema)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
recordList,
|
|
120
|
+
undoList,
|
|
121
|
+
currentRecord,
|
|
122
|
+
push,
|
|
123
|
+
undo,
|
|
124
|
+
redo
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const revoke = useRevoke()
|