@zhangqingcq/vgce 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -1
- package/dist/vgce.js +5 -12
- package/dist/vgce.umd.cjs +2 -2
- package/package.json +3 -2
- package/src/App.vue +11 -0
- package/src/assets/base.less +49 -0
- package/src/assets/icons/add.svg +1 -0
- package/src/assets/icons/delete.svg +12 -0
- package/src/assets/icons/export.svg +1 -0
- package/src/assets/icons/group.svg +13 -0
- package/src/assets/icons/import.svg +1 -0
- package/src/assets/icons/lock.svg +7 -0
- package/src/assets/icons/menu-fold.svg +9 -0
- package/src/assets/icons/menu-unfold.svg +9 -0
- package/src/assets/icons/preview.svg +6 -0
- package/src/assets/icons/redo.svg +8 -0
- package/src/assets/icons/return.svg +8 -0
- package/src/assets/icons/rotate.svg +1 -0
- package/src/assets/icons/save.svg +9 -0
- package/src/assets/icons/setting.svg +6 -0
- package/src/assets/icons/undo.svg +7 -0
- package/src/assets/icons/ungroup.svg +16 -0
- package/src/assets/icons/unlock.svg +7 -0
- package/src/assets/main.less +6 -0
- package/src/assets/svgs/alternator.svg +8 -0
- package/src/assets/svgs/bot-12.svg +1 -0
- package/src/assets/svgs/bot-2.svg +1 -0
- package/src/assets/svgs/bot-3.svg +1 -0
- package/src/assets/svgs/bot-7.svg +1 -0
- package/src/assets/svgs/bot-9.svg +94 -0
- package/src/assets/svgs/car.svg +1 -0
- package/src/assets/svgs/circuit-breaker.svg +11 -0
- package/src/assets/svgs/clock-a.svg +23 -0
- package/src/assets/svgs/common-table.svg +7 -0
- package/src/assets/svgs/el-button.svg +10 -0
- package/src/assets/svgs/el-tag.svg +13 -0
- package/src/assets/svgs/hospital.svg +1 -0
- package/src/assets/svgs/house.svg +1 -0
- package/src/assets/svgs/light.svg +24 -0
- package/src/assets/svgs/now-time.svg +9 -0
- package/src/assets/svgs/package.svg +1 -0
- package/src/assets/svgs/pie-charts.svg +10 -0
- package/src/assets/svgs/progress-a.svg +1 -0
- package/src/assets/svgs/reservoir.svg +10 -0
- package/src/assets/svgs/svg-text.svg +5 -0
- package/src/assets/svgs/switch-a.svg +5 -0
- package/src/assets/svgs/traction-transformer.svg +11 -0
- package/src/components/ace-edit/index.ts +27 -0
- package/src/components/config/index.ts +450 -0
- package/src/components/config/types.ts +25 -0
- package/src/components/svg-analysis/index.vue +11 -0
- package/src/components/svg-editor/center-panel/index.vue +867 -0
- package/src/components/svg-editor/center-panel/types.ts +11 -0
- package/src/components/svg-editor/component-tree/index.vue +33 -0
- package/src/components/svg-editor/connection-line/index.vue +125 -0
- package/src/components/svg-editor/connection-panel/index.vue +198 -0
- package/src/components/svg-editor/export-json/index.vue +37 -0
- package/src/components/svg-editor/handle-panel/index.vue +342 -0
- package/src/components/svg-editor/import-json/index.vue +37 -0
- package/src/components/svg-editor/index.vue +280 -0
- package/src/components/svg-editor/left-panel/index.vue +83 -0
- package/src/components/svg-editor/right-panel/code-edit-modal.vue +50 -0
- package/src/components/svg-editor/right-panel/common-animate.vue +96 -0
- package/src/components/svg-editor/right-panel/condition.vue +101 -0
- package/src/components/svg-editor/right-panel/dynamic-el-form-item.vue +97 -0
- package/src/components/svg-editor/right-panel/index.vue +304 -0
- package/src/components/svg-editor/right-panel/list.vue +86 -0
- package/src/components/svg-editor/top-panel/index.vue +139 -0
- package/src/components/svg-editor/types.ts +22 -0
- package/src/components/svg-viewer/index.vue +340 -0
- package/src/components/vue3-ruler-tool/index.vue +506 -0
- package/src/config/files/clock-a.vue +66 -0
- package/src/config/files/common-table.vue +49 -0
- package/src/config/files/light-a.vue +72 -0
- package/src/config/files/now-time.vue +53 -0
- package/src/config/files/pie-charts.vue +72 -0
- package/src/config/files/progress.vue +40 -0
- package/src/config/files/svg-text.vue +39 -0
- package/src/config/files/switch-a.vue +45 -0
- package/src/config/index.ts +28 -0
- package/src/config/svg/animation/index.ts +8 -0
- package/src/config/svg/animation/reservoir.ts +32 -0
- package/src/config/svg/custom/clock-a.ts +23 -0
- package/src/config/svg/custom/index.ts +11 -0
- package/src/config/svg/custom/light.ts +29 -0
- package/src/config/svg/custom/svg-text.ts +54 -0
- package/src/config/svg/custom/switch-a.ts +29 -0
- package/src/config/svg/index.ts +12 -0
- package/src/config/svg/stateful/circuit-breaker.ts +38 -0
- package/src/config/svg/stateful/index.ts +8 -0
- package/src/config/svg/stateless/alternator.ts +28 -0
- package/src/config/svg/stateless/bot-12.ts +22 -0
- package/src/config/svg/stateless/bot-2.ts +22 -0
- package/src/config/svg/stateless/bot-3.ts +22 -0
- package/src/config/svg/stateless/bot-7.ts +22 -0
- package/src/config/svg/stateless/bot-9.ts +22 -0
- package/src/config/svg/stateless/car.ts +22 -0
- package/src/config/svg/stateless/hospital.ts +22 -0
- package/src/config/svg/stateless/house.ts +22 -0
- package/src/config/svg/stateless/index.ts +30 -0
- package/src/config/svg/stateless/package.ts +22 -0
- package/src/config/svg/stateless/traction-transformer.ts +28 -0
- package/src/config/types.ts +126 -0
- package/src/config/vue/component/button.ts +57 -0
- package/src/config/vue/component/common-table.ts +124 -0
- package/src/config/vue/component/index.ts +13 -0
- package/src/config/vue/component/now-time.ts +29 -0
- package/src/config/vue/component/progress.ts +29 -0
- package/src/config/vue/component/tag.ts +46 -0
- package/src/config/vue/echarts/index.ts +8 -0
- package/src/config/vue/echarts/pie-charts.ts +60 -0
- package/src/config/vue/index.ts +5 -0
- package/src/hooks.ts +47 -0
- package/src/index.ts +14 -0
- package/src/main.ts +15 -0
- package/src/router.ts +24 -0
- package/src/stores/config/index.ts +44 -0
- package/src/stores/config/types.ts +27 -0
- package/src/stores/global/index.ts +109 -0
- package/src/stores/global/types.ts +115 -0
- package/src/stores/main.ts +10 -0
- package/src/stores/svg-edit-layout/index.ts +17 -0
- package/src/stores/svg-edit-layout/types.ts +8 -0
- package/src/stores/system/index.ts +174 -0
- package/src/stores/system/types.ts +43 -0
- package/src/utils/fetch.ts +351 -0
- package/src/utils/file-read-write.ts +26 -0
- package/src/utils/index.ts +397 -0
- package/src/utils/mqtt-net.ts +48 -0
- package/src/utils/proxy.ts +7 -0
- package/src/utils/scale-core.ts +214 -0
- package/src/utils/types.ts +13 -0
- package/src/views/EditorS.vue +18 -0
- package/src/views/Preview.vue +12 -0
package/src/hooks.ts
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
import type { IDataModel } from '@/components/svg-editor/types'
|
2
|
+
import { createPinia } from 'pinia'
|
3
|
+
import { useConfigStore } from '@/stores/config'
|
4
|
+
import { useGlobalStore } from '@/stores/global'
|
5
|
+
import type { IDoneJson } from '@/stores/global/types'
|
6
|
+
import { useSvgEditLayoutStore } from '@/stores/svg-edit-layout'
|
7
|
+
import { useEditPrivateStore } from '@/stores/system'
|
8
|
+
|
9
|
+
import { ElMessage } from 'element-plus'
|
10
|
+
|
11
|
+
export const pinia = createPinia()
|
12
|
+
|
13
|
+
export const useHistoryRecord = (done_json: IDoneJson[]) => {
|
14
|
+
const edit_private_store = useEditPrivateStore()
|
15
|
+
if (edit_private_store.is_record_history) {
|
16
|
+
if (edit_private_store.history_now_index + 1 < edit_private_store.history_doneComponent.length) {
|
17
|
+
edit_private_store.history_doneComponent.splice(edit_private_store.history_now_index + 1)
|
18
|
+
}
|
19
|
+
edit_private_store.history_doneComponent.push(done_json)
|
20
|
+
edit_private_store.history_now_index = edit_private_store.history_doneComponent.length - 1
|
21
|
+
if (edit_private_store.history_doneComponent.length > edit_private_store.max_record_times) {
|
22
|
+
edit_private_store.history_doneComponent.shift()
|
23
|
+
edit_private_store.history_now_index = edit_private_store.history_doneComponent.length - 1
|
24
|
+
}
|
25
|
+
}
|
26
|
+
edit_private_store.is_record_history = true
|
27
|
+
}
|
28
|
+
export const useImportDataModel = (model_str: string) => {
|
29
|
+
try {
|
30
|
+
const json: IDataModel = JSON.parse(model_str)
|
31
|
+
if (!json.config || !json.layout_center || !json.done_json) {
|
32
|
+
ElMessage.error('请导入正确的数据模型!')
|
33
|
+
return false
|
34
|
+
}
|
35
|
+
const globalStore = useGlobalStore(pinia)
|
36
|
+
const svgEditLayoutStore = useSvgEditLayoutStore(pinia)
|
37
|
+
const configStore = useConfigStore(pinia)
|
38
|
+
configStore.$state = json.config
|
39
|
+
svgEditLayoutStore.center_offset = json.layout_center
|
40
|
+
globalStore.setDoneJson(json.done_json)
|
41
|
+
return true
|
42
|
+
} catch (error) {
|
43
|
+
ElMessage.error('请导入正确的数据模型!')
|
44
|
+
console.error(error)
|
45
|
+
return false
|
46
|
+
}
|
47
|
+
}
|
package/src/index.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* @description 库vgce入口
|
3
|
+
* @author Ricky email:zhangqingcq@foxmail.com
|
4
|
+
* @created 2023.07.10
|
5
|
+
*/
|
6
|
+
|
7
|
+
import 'virtual:windi.css'
|
8
|
+
import 'virtual:svg-icons-register'
|
9
|
+
import './assets/main.less'
|
10
|
+
|
11
|
+
import SvgEditor from '@/components/svg-editor/index.vue'
|
12
|
+
import SvgViewer from '@/components/svg-viewer/index.vue'
|
13
|
+
|
14
|
+
export { SvgEditor, SvgViewer }
|
package/src/main.ts
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import { createApp } from 'vue'
|
2
|
+
import { pinia } from '@/hooks'
|
3
|
+
|
4
|
+
import App from './App.vue'
|
5
|
+
import router from './router'
|
6
|
+
import 'virtual:windi.css'
|
7
|
+
import 'virtual:svg-icons-register'
|
8
|
+
import './assets/main.less'
|
9
|
+
|
10
|
+
const app = createApp(App)
|
11
|
+
|
12
|
+
app.use(router)
|
13
|
+
app.use(pinia)
|
14
|
+
|
15
|
+
app.mount('#app')
|
package/src/router.ts
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
import { createRouter, createWebHistory } from 'vue-router'
|
2
|
+
import EditorS from '@/views/EditorS.vue'
|
3
|
+
|
4
|
+
const router = createRouter({
|
5
|
+
history: createWebHistory(import.meta.env.BASE_URL),
|
6
|
+
routes: [
|
7
|
+
{
|
8
|
+
path: '/',
|
9
|
+
redirect: '/EditorS'
|
10
|
+
},
|
11
|
+
{
|
12
|
+
path: '/EditorS',
|
13
|
+
name: 'EditorS',
|
14
|
+
component: EditorS
|
15
|
+
},
|
16
|
+
{
|
17
|
+
path: '/Preview',
|
18
|
+
name: 'Preview',
|
19
|
+
component: () => import('@/views/Preview.vue')
|
20
|
+
}
|
21
|
+
]
|
22
|
+
})
|
23
|
+
|
24
|
+
export default router
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { defineStore } from 'pinia'
|
2
|
+
import { objectDeepClone } from '@/utils'
|
3
|
+
import { connection_line_system } from '@/components/config'
|
4
|
+
|
5
|
+
let l = localStorage.getItem('svg-editor-config')
|
6
|
+
let s: any
|
7
|
+
let t: any
|
8
|
+
|
9
|
+
if (l) {
|
10
|
+
let b = JSON.parse(l)
|
11
|
+
t = b.connection_line
|
12
|
+
s = b.svg
|
13
|
+
} else {
|
14
|
+
t = objectDeepClone(connection_line_system)
|
15
|
+
s = {
|
16
|
+
background_color: '#fff',
|
17
|
+
scale: 1,
|
18
|
+
position_center: {
|
19
|
+
x: -333,
|
20
|
+
y: -113
|
21
|
+
},
|
22
|
+
svg_position_center: {
|
23
|
+
x: 50,
|
24
|
+
y: 50
|
25
|
+
},
|
26
|
+
grid: true,
|
27
|
+
ruler: true
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* 配置文件
|
33
|
+
*/
|
34
|
+
export const useConfigStore = defineStore('config-store', {
|
35
|
+
state: () => {
|
36
|
+
return {
|
37
|
+
svg: s,
|
38
|
+
connection_line: t,
|
39
|
+
net: { mqtt: { url: '', user: '', pwd: '', topics: '' } }
|
40
|
+
}
|
41
|
+
},
|
42
|
+
getters: {},
|
43
|
+
actions: {}
|
44
|
+
})
|
@@ -0,0 +1,27 @@
|
|
1
|
+
export interface IPositionCenter {
|
2
|
+
svg: IPositionCenterSvg
|
3
|
+
}
|
4
|
+
|
5
|
+
export interface IPositionCenterSvg {
|
6
|
+
background_color: string
|
7
|
+
scale: number
|
8
|
+
position_center: {
|
9
|
+
x: number
|
10
|
+
y: number
|
11
|
+
}
|
12
|
+
svg_position_center: {
|
13
|
+
x: number
|
14
|
+
y: number
|
15
|
+
}
|
16
|
+
grid: boolean
|
17
|
+
ruler: boolean
|
18
|
+
}
|
19
|
+
|
20
|
+
export interface INet {
|
21
|
+
mqtt: {
|
22
|
+
url: string
|
23
|
+
user: string
|
24
|
+
pwd: string
|
25
|
+
topics: string
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import { defineStore } from 'pinia'
|
2
|
+
import { nextTick } from 'vue'
|
3
|
+
import { config } from '@/config'
|
4
|
+
import type { IConfigItem } from '@/config/types'
|
5
|
+
import { isOfType, objectDeepClone, setSvgActualInfo } from '@/utils'
|
6
|
+
import { EGlobalStoreIntention, EMouseInfoState, EScaleInfoType } from './types'
|
7
|
+
import type { IDoneJson, IGlobalStore, IMouseInfo, IScaleInfo } from './types'
|
8
|
+
import { useHistoryRecord } from '@/hooks'
|
9
|
+
|
10
|
+
/**
|
11
|
+
* 全局共享状态
|
12
|
+
*/
|
13
|
+
export const useGlobalStore = defineStore('global-store', {
|
14
|
+
state: (): IGlobalStore => {
|
15
|
+
return {
|
16
|
+
config_center: config,
|
17
|
+
intention: EGlobalStoreIntention.None,
|
18
|
+
create_svg_info: null,
|
19
|
+
done_json: [],
|
20
|
+
mouse_info: {
|
21
|
+
state: EMouseInfoState.Up,
|
22
|
+
position_x: 0,
|
23
|
+
position_y: 0,
|
24
|
+
now_position_x: 0,
|
25
|
+
now_position_y: 0,
|
26
|
+
new_position_x: 0,
|
27
|
+
new_position_y: 0
|
28
|
+
},
|
29
|
+
handle_svg_info: null,
|
30
|
+
scale_info: {
|
31
|
+
type: EScaleInfoType.None,
|
32
|
+
scale_times: {
|
33
|
+
x: 1,
|
34
|
+
y: 1
|
35
|
+
},
|
36
|
+
scale_item_info: {
|
37
|
+
x: 0,
|
38
|
+
y: 0
|
39
|
+
},
|
40
|
+
symmetric_point: {
|
41
|
+
x: 0,
|
42
|
+
y: 0
|
43
|
+
}
|
44
|
+
},
|
45
|
+
rotate_info: {
|
46
|
+
angle: 0
|
47
|
+
},
|
48
|
+
connection_line_node_info: {
|
49
|
+
init_pos: {
|
50
|
+
x: 0,
|
51
|
+
y: 0
|
52
|
+
},
|
53
|
+
point_index: 0
|
54
|
+
}
|
55
|
+
}
|
56
|
+
},
|
57
|
+
getters: {},
|
58
|
+
actions: {
|
59
|
+
setCreateInfo(create_svg_info: IConfigItem | null) {
|
60
|
+
this.intention = EGlobalStoreIntention.Create
|
61
|
+
this.create_svg_info = create_svg_info
|
62
|
+
},
|
63
|
+
setDoneJson(done_json: IDoneJson[] | IDoneJson) {
|
64
|
+
// 有id的组件
|
65
|
+
if (isOfType(done_json, 'id')) {
|
66
|
+
this.done_json.push(done_json)
|
67
|
+
nextTick(() => {
|
68
|
+
// 设置组件在画布中的属性(位置和宽高)
|
69
|
+
setSvgActualInfo(done_json)
|
70
|
+
})
|
71
|
+
} else {
|
72
|
+
this.done_json = objectDeepClone<IDoneJson[]>(done_json)
|
73
|
+
}
|
74
|
+
nextTick(() => {
|
75
|
+
//压入历史操作记录
|
76
|
+
useHistoryRecord(objectDeepClone<IDoneJson[]>(this.done_json))
|
77
|
+
})
|
78
|
+
},
|
79
|
+
setMouseInfo(mouse_info: IMouseInfo) {
|
80
|
+
this.mouse_info = mouse_info
|
81
|
+
},
|
82
|
+
setHandleSvgInfo(info: IDoneJson | null, index?: number) {
|
83
|
+
let current_index = index
|
84
|
+
if (info) {
|
85
|
+
if (!current_index && current_index != 0) {
|
86
|
+
//如果索引没传 在这根据id查出索引
|
87
|
+
current_index = this.done_json.findIndex((f) => f.id === info.id) ?? -1
|
88
|
+
}
|
89
|
+
this.handle_svg_info = {
|
90
|
+
info: info,
|
91
|
+
index: current_index
|
92
|
+
}
|
93
|
+
} else {
|
94
|
+
this.handle_svg_info = info
|
95
|
+
}
|
96
|
+
},
|
97
|
+
setScaleInfo(info: IScaleInfo) {
|
98
|
+
this.scale_info = info
|
99
|
+
},
|
100
|
+
spliceDoneJson(index: number) {
|
101
|
+
const globalStore = useGlobalStore()
|
102
|
+
globalStore.done_json.splice(index, 1)
|
103
|
+
useHistoryRecord(globalStore.done_json)
|
104
|
+
}
|
105
|
+
}
|
106
|
+
})
|
107
|
+
// useGlobalStore().$subscribe((mutation, state) => {
|
108
|
+
// console.log(mutation, state, 102);
|
109
|
+
// });
|
@@ -0,0 +1,115 @@
|
|
1
|
+
import type { IConfig, IConfigItem } from '@/config/types'
|
2
|
+
|
3
|
+
export interface IGlobalStore {
|
4
|
+
config_center: IConfig
|
5
|
+
intention: EGlobalStoreIntention
|
6
|
+
create_svg_info: IConfigItem | null
|
7
|
+
done_json: IDoneJson[]
|
8
|
+
mouse_info: IMouseInfo
|
9
|
+
handle_svg_info: IHandleSvgInfo | null
|
10
|
+
scale_info: IScaleInfo
|
11
|
+
rotate_info: IRotateInfo
|
12
|
+
connection_line_node_info: IConnectionLineNodeInfo
|
13
|
+
}
|
14
|
+
export interface IDoneJson extends IConfigItem {
|
15
|
+
id: string
|
16
|
+
x: number
|
17
|
+
y: number
|
18
|
+
client: ICoordinate
|
19
|
+
scale_x: number
|
20
|
+
scale_y: number
|
21
|
+
rotate: number
|
22
|
+
actual_bound: {
|
23
|
+
x: number
|
24
|
+
y: number
|
25
|
+
width: number
|
26
|
+
height: number
|
27
|
+
}
|
28
|
+
point_coordinate: {
|
29
|
+
tl: ICoordinate
|
30
|
+
tc: ICoordinate
|
31
|
+
tr: ICoordinate
|
32
|
+
l: ICoordinate
|
33
|
+
r: ICoordinate
|
34
|
+
bl: ICoordinate
|
35
|
+
bc: ICoordinate
|
36
|
+
br: ICoordinate
|
37
|
+
}
|
38
|
+
}
|
39
|
+
export enum EGlobalStoreIntention {
|
40
|
+
None = 'None',
|
41
|
+
Create = 'Create',
|
42
|
+
Move = 'Move',
|
43
|
+
MoveCanvas = 'MoveCanvas',
|
44
|
+
Select = 'Select',
|
45
|
+
Zoom = 'Zoom',
|
46
|
+
Rotate = 'Rotate',
|
47
|
+
Connection = 'Connection',
|
48
|
+
SetConnectionLineNode = 'SetConnectionLineNode',
|
49
|
+
ContextMenu = 'ContextMenu'
|
50
|
+
}
|
51
|
+
export interface IMouseInfo {
|
52
|
+
state: EMouseInfoState
|
53
|
+
position_x: number //鼠标指针坐标
|
54
|
+
position_y: number
|
55
|
+
now_position_x: number //当前目标的坐标
|
56
|
+
now_position_y: number
|
57
|
+
new_position_x: number //移动之后目标的坐标
|
58
|
+
new_position_y: number
|
59
|
+
}
|
60
|
+
export enum EMouseInfoState {
|
61
|
+
Down = 'Down',
|
62
|
+
Up = 'Up'
|
63
|
+
}
|
64
|
+
export interface IHandleSvgInfo {
|
65
|
+
info: IDoneJson
|
66
|
+
index: number
|
67
|
+
}
|
68
|
+
/**
|
69
|
+
* 缩放信息
|
70
|
+
*/
|
71
|
+
export interface IScaleInfo {
|
72
|
+
type: EScaleInfoType
|
73
|
+
scale_times: {
|
74
|
+
//点击缩放时当前组件的缩放倍数
|
75
|
+
x: number
|
76
|
+
y: number
|
77
|
+
}
|
78
|
+
scale_item_info: {
|
79
|
+
x: number
|
80
|
+
y: number
|
81
|
+
}
|
82
|
+
symmetric_point: {
|
83
|
+
//缩放前缩放手柄对应组件中心坐标的对称点坐标
|
84
|
+
x: number
|
85
|
+
y: number
|
86
|
+
}
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* 旋转信息
|
90
|
+
*/
|
91
|
+
export interface IRotateInfo {
|
92
|
+
angle: number
|
93
|
+
}
|
94
|
+
export enum EScaleInfoType {
|
95
|
+
None = '',
|
96
|
+
TopLeft = 'TopLeft',
|
97
|
+
TopCenter = 'TopCenter',
|
98
|
+
TopRight = 'TopRight',
|
99
|
+
Left = 'Left',
|
100
|
+
Right = 'Right',
|
101
|
+
BottomLeft = 'BottomLeft',
|
102
|
+
BottomCenter = 'BottomCenter',
|
103
|
+
BottomRight = 'BottomRight'
|
104
|
+
}
|
105
|
+
export interface ICoordinate {
|
106
|
+
x: number
|
107
|
+
y: number
|
108
|
+
}
|
109
|
+
export interface IConnectionLineNodeInfo {
|
110
|
+
init_pos: {
|
111
|
+
x: number
|
112
|
+
y: number
|
113
|
+
}
|
114
|
+
point_index: number
|
115
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { defineStore } from 'pinia'
|
2
|
+
import type { ISvgEditLayoutStore } from './types'
|
3
|
+
/**
|
4
|
+
* 编辑器布局状态
|
5
|
+
*/
|
6
|
+
export const useSvgEditLayoutStore = defineStore('svg-edit-layout-store', {
|
7
|
+
state: (): ISvgEditLayoutStore => {
|
8
|
+
return {
|
9
|
+
left_nav: true,
|
10
|
+
right_nav: true,
|
11
|
+
center_offset: {
|
12
|
+
x: 0,
|
13
|
+
y: 0
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
})
|
@@ -0,0 +1,174 @@
|
|
1
|
+
import { objectDeepClone, randomString } from '@/utils'
|
2
|
+
import { defineStore } from 'pinia'
|
3
|
+
import { useGlobalStore } from '../global'
|
4
|
+
import type { IDoneJson } from '../global/types'
|
5
|
+
import { EGlobalStoreIntention } from '../global/types'
|
6
|
+
import type { ContextMenuStoreState, EditPrivateStoreState } from './types'
|
7
|
+
import { EContextMenuInfoType } from './types'
|
8
|
+
import { useHistoryRecord } from '@/hooks'
|
9
|
+
|
10
|
+
/**
|
11
|
+
* 编辑器私有状态
|
12
|
+
*/
|
13
|
+
export const useEditPrivateStore = defineStore('edit-private-store', {
|
14
|
+
state: (): EditPrivateStoreState => {
|
15
|
+
return {
|
16
|
+
old_done_components: [], //记录预览之前的组件数据
|
17
|
+
history_doneComponent: [],
|
18
|
+
history_now_index: 0,
|
19
|
+
is_record_history: true, //是否需要记录当前状态,如果是操作的历史记录,则不需要记录
|
20
|
+
max_record_times: 10
|
21
|
+
}
|
22
|
+
},
|
23
|
+
getters: {
|
24
|
+
getTopBtnUndoStatus(state) {
|
25
|
+
return state.history_now_index >= 1
|
26
|
+
},
|
27
|
+
getTopBtnRedoStatus(state) {
|
28
|
+
return state.history_now_index + 1 != state.history_doneComponent.length
|
29
|
+
}
|
30
|
+
},
|
31
|
+
actions: {
|
32
|
+
topUndoBtnClick() {
|
33
|
+
console.log('撤销')
|
34
|
+
if (this.history_now_index < 1) {
|
35
|
+
return
|
36
|
+
}
|
37
|
+
const global_store = useGlobalStore()
|
38
|
+
// select_component_info.value = {};
|
39
|
+
this.is_record_history = false
|
40
|
+
this.history_now_index -= 1
|
41
|
+
global_store.setDoneJson(this.history_doneComponent[this.history_now_index])
|
42
|
+
},
|
43
|
+
topRedoBtnClick() {
|
44
|
+
console.log('重做')
|
45
|
+
if (this.history_now_index + 1 == this.history_doneComponent.length) {
|
46
|
+
return
|
47
|
+
}
|
48
|
+
const global_store = useGlobalStore()
|
49
|
+
this.is_record_history = false
|
50
|
+
this.history_now_index += 1
|
51
|
+
global_store.setDoneJson(this.history_doneComponent[this.history_now_index])
|
52
|
+
}
|
53
|
+
}
|
54
|
+
})
|
55
|
+
export const useContextMenuStore = defineStore('context-menu-store', {
|
56
|
+
state: (): ContextMenuStoreState => {
|
57
|
+
return {
|
58
|
+
display: false,
|
59
|
+
info: {
|
60
|
+
[EContextMenuInfoType.Copy]: {
|
61
|
+
title: '复制',
|
62
|
+
hot_key: 'Ctrl+C',
|
63
|
+
enable: true
|
64
|
+
},
|
65
|
+
[EContextMenuInfoType.Delete]: {
|
66
|
+
title: '删除',
|
67
|
+
hot_key: 'Delete',
|
68
|
+
enable: true
|
69
|
+
},
|
70
|
+
[EContextMenuInfoType.MoveUpTopLevel]: {
|
71
|
+
title: '置于顶层',
|
72
|
+
hot_key: 'Ctrl+→',
|
73
|
+
enable: true
|
74
|
+
},
|
75
|
+
[EContextMenuInfoType.MoveDownTopLevel]: {
|
76
|
+
title: '置于底层',
|
77
|
+
hot_key: 'Ctrl+←',
|
78
|
+
enable: true
|
79
|
+
},
|
80
|
+
[EContextMenuInfoType.MoveUpOneLevel]: {
|
81
|
+
title: '置于上一层',
|
82
|
+
hot_key: 'Ctrl+↑',
|
83
|
+
enable: true
|
84
|
+
},
|
85
|
+
[EContextMenuInfoType.MoveDownOneLevel]: {
|
86
|
+
title: '置于下一层',
|
87
|
+
hot_key: 'Ctrl+↓',
|
88
|
+
enable: true
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
},
|
93
|
+
actions: {
|
94
|
+
onContextMenuClick(type: keyof typeof EContextMenuInfoType) {
|
95
|
+
const globalStore = useGlobalStore()
|
96
|
+
if (!globalStore.handle_svg_info) {
|
97
|
+
return
|
98
|
+
}
|
99
|
+
globalStore.intention = EGlobalStoreIntention.Select
|
100
|
+
switch (type) {
|
101
|
+
case EContextMenuInfoType.Copy:
|
102
|
+
const temp_item = objectDeepClone<IDoneJson>(globalStore.handle_svg_info.info)
|
103
|
+
temp_item.id = temp_item.name + randomString()
|
104
|
+
temp_item.title += '-copy'
|
105
|
+
temp_item.x += 10
|
106
|
+
temp_item.y += 10
|
107
|
+
globalStore.setDoneJson(temp_item)
|
108
|
+
this.display = false
|
109
|
+
globalStore.setHandleSvgInfo(temp_item, globalStore.done_json.length)
|
110
|
+
break
|
111
|
+
case EContextMenuInfoType.Delete:
|
112
|
+
globalStore.spliceDoneJson(globalStore.handle_svg_info.index)
|
113
|
+
this.display = false
|
114
|
+
globalStore.setHandleSvgInfo(null)
|
115
|
+
globalStore.intention = EGlobalStoreIntention.None
|
116
|
+
break
|
117
|
+
case EContextMenuInfoType.MoveUpOneLevel:
|
118
|
+
if (
|
119
|
+
globalStore.done_json.length === 1 ||
|
120
|
+
globalStore.handle_svg_info.index === globalStore.done_json.length - 1
|
121
|
+
) {
|
122
|
+
return
|
123
|
+
}
|
124
|
+
const temp_up_one = globalStore.handle_svg_info.info
|
125
|
+
globalStore.done_json[globalStore.handle_svg_info.index] =
|
126
|
+
globalStore.done_json[globalStore.handle_svg_info.index + 1]
|
127
|
+
globalStore.done_json[globalStore.handle_svg_info.index + 1] = temp_up_one
|
128
|
+
useHistoryRecord(globalStore.done_json)
|
129
|
+
this.display = false
|
130
|
+
globalStore.setHandleSvgInfo(temp_up_one, globalStore.handle_svg_info.index + 1)
|
131
|
+
break
|
132
|
+
case EContextMenuInfoType.MoveDownOneLevel:
|
133
|
+
if (globalStore.done_json.length === 1 || globalStore.handle_svg_info.index === 0) {
|
134
|
+
return
|
135
|
+
}
|
136
|
+
const temp_down_one = globalStore.handle_svg_info.info
|
137
|
+
globalStore.done_json[globalStore.handle_svg_info.index] =
|
138
|
+
globalStore.done_json[globalStore.handle_svg_info.index - 1]
|
139
|
+
globalStore.done_json[globalStore.handle_svg_info.index - 1] = temp_down_one
|
140
|
+
useHistoryRecord(globalStore.done_json)
|
141
|
+
this.display = false
|
142
|
+
globalStore.setHandleSvgInfo(temp_down_one, globalStore.handle_svg_info.index - 1)
|
143
|
+
break
|
144
|
+
case EContextMenuInfoType.MoveDownTopLevel:
|
145
|
+
if (globalStore.done_json.length === 1 || globalStore.handle_svg_info.index === 0) {
|
146
|
+
return
|
147
|
+
}
|
148
|
+
const temp_down_top = globalStore.handle_svg_info.info
|
149
|
+
globalStore.done_json.splice(globalStore.handle_svg_info.index, 1)
|
150
|
+
globalStore.done_json.unshift(temp_down_top)
|
151
|
+
useHistoryRecord(globalStore.done_json)
|
152
|
+
this.display = false
|
153
|
+
globalStore.setHandleSvgInfo(temp_down_top, 0)
|
154
|
+
break
|
155
|
+
case EContextMenuInfoType.MoveUpTopLevel:
|
156
|
+
if (
|
157
|
+
globalStore.done_json.length === 1 ||
|
158
|
+
globalStore.handle_svg_info.index === globalStore.done_json.length
|
159
|
+
) {
|
160
|
+
return
|
161
|
+
}
|
162
|
+
const temp_up_top = globalStore.handle_svg_info.info
|
163
|
+
globalStore.done_json.splice(globalStore.handle_svg_info.index, 1)
|
164
|
+
globalStore.done_json.push(temp_up_top)
|
165
|
+
useHistoryRecord(globalStore.done_json)
|
166
|
+
this.display = false
|
167
|
+
globalStore.setHandleSvgInfo(temp_up_top, globalStore.done_json.length - 1)
|
168
|
+
break
|
169
|
+
default:
|
170
|
+
break
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
})
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import type { IDoneJson } from '../global/types'
|
2
|
+
|
3
|
+
export interface EditPrivateStoreState {
|
4
|
+
old_done_components: IDoneJson[]
|
5
|
+
history_doneComponent: IDoneJson[][]
|
6
|
+
history_now_index: number
|
7
|
+
is_record_history: boolean
|
8
|
+
max_record_times: number
|
9
|
+
}
|
10
|
+
export interface ContextMenuStoreState {
|
11
|
+
display: boolean
|
12
|
+
info: {
|
13
|
+
[key in EContextMenuInfoType]: IContextMenuInfo
|
14
|
+
}
|
15
|
+
}
|
16
|
+
export interface IContextMenuInfo {
|
17
|
+
title: string
|
18
|
+
hot_key: string
|
19
|
+
enable: boolean
|
20
|
+
}
|
21
|
+
export enum EContextMenuInfoType {
|
22
|
+
Copy = 'Copy',
|
23
|
+
Delete = 'Delete',
|
24
|
+
MoveUpOneLevel = 'MoveUpOneLevel',
|
25
|
+
MoveDownOneLevel = 'MoveDownOneLevel',
|
26
|
+
MoveUpTopLevel = 'MoveUpTopLevel',
|
27
|
+
MoveDownTopLevel = 'MoveDownTopLevel'
|
28
|
+
}
|
29
|
+
|
30
|
+
export enum EShortcutKeyType {
|
31
|
+
Copy = 'Copy',
|
32
|
+
Delete = 'Delete',
|
33
|
+
MoveUpOneLevel = 'MoveUpOneLevel',
|
34
|
+
MoveDownOneLevel = 'MoveDownOneLevel',
|
35
|
+
MoveUpTopLevel = 'MoveUpTopLevel',
|
36
|
+
MoveDownTopLevel = 'MoveDownTopLevel',
|
37
|
+
Redo = 'Redo',
|
38
|
+
Undo = 'Undo',
|
39
|
+
MoveUp = 'MoveUp',
|
40
|
+
MoveDown = 'MoveDown',
|
41
|
+
MoveLeft = 'MoveLeft',
|
42
|
+
MoveRight = 'MoveRight'
|
43
|
+
}
|