@zhangqingcq/vgce 0.1.7 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +135 -92
- package/dist/style.css +1 -1
- package/dist/vgce.js +11044 -10941
- package/dist/vgce.umd.cjs +33 -33
- package/package.json +1 -1
- package/src/assets/base.less +69 -68
- package/src/assets/svgs/text-box.svg +1 -0
- package/src/assets/variables.less +6 -6
- package/src/components/svg-editor/center-panel.vue +3 -2
- package/src/components/svg-editor/index.vue +7 -5
- package/src/components/svg-viewer.vue +7 -4
- package/src/config/files/text-box.vue +72 -0
- package/src/config/index.ts +5 -3
- package/src/config/svg/animation/index.ts +3 -2
- package/src/config/svg/animation/thermometer.ts +2 -1
- package/src/config/svg/custom/clock-a.ts +2 -1
- package/src/config/svg/custom/index.ts +6 -5
- package/src/config/svg/custom/light.ts +2 -1
- package/src/config/svg/custom/svg-text.ts +2 -1
- package/src/config/svg/custom/switch-r.ts +2 -1
- package/src/config/svg/index.ts +6 -10
- package/src/config/svg/stateful/alert-light.ts +2 -1
- package/src/config/svg/stateful/index.ts +3 -2
- package/src/config/svg/stateless/bot-2.ts +2 -1
- package/src/config/svg/stateless/bot-9.ts +2 -1
- package/src/config/svg/stateless/hamburger.ts +2 -1
- package/src/config/svg/stateless/hotpot.ts +2 -1
- package/src/config/svg/stateless/index.ts +6 -5
- package/src/config/vue/component/button.ts +2 -1
- package/src/config/vue/component/common-table.ts +2 -1
- package/src/config/vue/component/index.ts +9 -7
- package/src/config/vue/component/now-time.ts +2 -1
- package/src/config/vue/component/progress.ts +2 -1
- package/src/config/vue/component/tag.ts +2 -1
- package/src/config/vue/component/text-box.ts +66 -0
- package/src/config/vue/echarts/index.ts +3 -2
- package/src/config/vue/echarts/pie-charts.ts +2 -1
- package/src/config/vue/index.ts +4 -3
- package/src/utils/index.ts +3 -2
package/README.md
CHANGED
@@ -2,96 +2,139 @@
|
|
2
2
|
|
3
3
|
Vector graphics configure editor. 矢量图组态编辑器。
|
4
4
|
|
5
|
-
## Guide
|
6
|
-
|
7
|
-
1. install
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
2.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
5
|
+
## Guide 使用说明
|
6
|
+
|
7
|
+
### 1. install 安装依赖
|
8
|
+
|
9
|
+
```
|
10
|
+
npm i @zhangqingcq/vgce element-plus@^2.3.8 ace-builds@^1.14.0 lodash-es^4.17.21 vue-echarts@^6.5.1 animate.css@^4.1.1
|
11
|
+
```
|
12
|
+
|
13
|
+
or
|
14
|
+
|
15
|
+
```
|
16
|
+
pnpm add @zhangqingcq/vgce element-plus@^2.3.8 ace-builds@^1.14.0 lodash-es^4.17.21 vue-echarts@^6.5.1 animate.css@^4.1.1
|
17
|
+
```
|
18
|
+
|
19
|
+
### 2. change main.ts or main.js 修改项目主文件
|
20
|
+
|
21
|
+
```
|
22
|
+
//main.js or main.ts
|
23
|
+
|
24
|
+
import '@zhangqingcq/vgce/dist/style.css'
|
25
|
+
```
|
26
|
+
|
27
|
+
### 3. use editor 使用编辑器
|
28
|
+
```
|
29
|
+
<script setup lang="ts">
|
30
|
+
import {SvgEditor} from '@zhangqingcq/vgce'
|
31
|
+
|
32
|
+
function preview(d: any) {
|
33
|
+
//save d and send it to SvgViewer's data
|
34
|
+
}
|
35
|
+
</script>
|
36
|
+
<template>
|
37
|
+
<SvgEditor @onPreview="preview"/>
|
38
|
+
</template>
|
39
|
+
```
|
40
|
+
### 4. use viewer 使用查看器
|
41
|
+
```
|
42
|
+
<script setup lang="ts">
|
43
|
+
import {SvgViewer} from '@zhangqingcq/vgce'
|
44
|
+
</script>
|
45
|
+
<template>
|
46
|
+
<SvgViewer :data="xxx"/>
|
47
|
+
</template>
|
48
|
+
```
|
49
|
+
### 5. custom toolbar 自定义组件
|
50
|
+
|
51
|
+
- copy `src/config/` and change as you want (复制`src/config/`文件夹,然后更改里面的配置)
|
52
|
+
|
53
|
+
- put svg files into `src/asset/svgs` , then file name need to be same with config.name (将svg文件放到`src/asset/svgs`,文件名需要和配置文件里的`name`的值一致)
|
54
|
+
|
55
|
+
- put custom vue components file into `src/config/files`, then import in `src/config/index.ts` and export with `vueComp` (将自定义vue组件放到`src/config/files`,然后在`src/config/index.ts`引入并以`vueComp`具名导出,组件在vueComp下的key应和配置文件里`tag`的值一致)
|
56
|
+
|
57
|
+
- send the vue components to the editor and viewer with the props vueComp (在编辑器和查看器使用处把`src/config/index.ts`导出的vueComp引入并以`vueComp`作为props传递给编辑器和查看器组件)
|
58
|
+
|
59
|
+
```
|
60
|
+
// editor
|
61
|
+
|
62
|
+
<script setup lang="ts">
|
63
|
+
import {SvgEditor} from '@zhangqingcq/vgce'
|
64
|
+
import {config,vueComp} from '@/config'
|
65
|
+
</script>
|
66
|
+
<template>
|
67
|
+
<SvgEditor :customToolbar="config" :vueComp="vueComp"/>
|
68
|
+
</template>
|
69
|
+
```
|
70
|
+
|
71
|
+
```
|
72
|
+
//viewer
|
73
|
+
|
74
|
+
<script setup lang="ts">
|
75
|
+
import {SvgViewer} from '@zhangqingcq/vgce'
|
76
|
+
import {vueComp} from '@/config'
|
77
|
+
</script>
|
78
|
+
<template>
|
79
|
+
<SvgViewer :vueComp="vueComp" :data="xxx"/>
|
80
|
+
</template>
|
81
|
+
```
|
82
|
+
- PS: you have to install `vite-plugin-svg-icons` plugin to append your svg to html dom.(你需要在项目安装npm依赖`vite-plugin-svg-icons`,用以把svg文件添加到项目入口html文件中进行使用)
|
83
|
+
|
84
|
+
### 6. how to use `vite-plugin-svg-icons` 如何使用 vite-plugin-svg-icons
|
85
|
+
|
86
|
+
- `npm i vite-plugin-svg-icons -D` or `pnpm add vite-plugin-svg-icons -D` (安装依赖)
|
87
|
+
- change `vite.config.ts` (修改项目vite配置文件)
|
88
|
+
|
89
|
+
````
|
90
|
+
// vite.config.ts
|
91
|
+
|
92
|
+
import { fileURLToPath, URL } from 'node:url'
|
93
|
+
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
94
|
+
|
95
|
+
export default defineConfig({
|
96
|
+
plugins: [
|
97
|
+
xxx,
|
98
|
+
createSvgIconsPlugin({
|
99
|
+
iconDirs: [fileURLToPath(new URL('./src/assets/svgs', import.meta.url))],
|
100
|
+
symbolId: 'svg-[name]',
|
101
|
+
svgoOptions: false,
|
102
|
+
customDomId: '__svg__icons__dom__'//your id, do not use this id!(使用你自己定义的id,不能使用__svg__icons__dom__,这是内置svg文件使用的id)
|
103
|
+
})
|
104
|
+
],
|
105
|
+
xxx
|
106
|
+
})
|
89
107
|
```
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
108
|
+
````
|
109
|
+
|
110
|
+
- change `main.ts` (修改项目主文件)
|
111
|
+
|
112
|
+
```
|
113
|
+
// main.ts
|
114
|
+
|
115
|
+
import 'virtual:svg-icons-register'
|
116
|
+
```
|
117
|
+
|
118
|
+
- PS: if there is error: `Cannot find module ‘fast-glob’`,then run `npm i fast-glob -D` or `pnpm add fast-glob -D` (如果报前面的错,就安装`fast-glob`npm 依赖)
|
119
|
+
|
120
|
+
### 7.mqtt 通信
|
121
|
+
- 在编辑器右侧‘通信’菜单下配置好mqtt通信需要的url、username、password、topics
|
122
|
+
- 在使用查看器的地方监听查看器emit的`onMessage`事件,并处理事件返回的数据`{ topics, message }`
|
123
|
+
- message可以用JSON.parse解析成对象(后端推给前端的MQTT消息内容需要是JSON格式)
|
124
|
+
- 拿到消息后可以配合setNodeAttrByID方法更新界面
|
125
|
+
- setNodeAttrByID的参数id可以在传给本组件的props.data(用户传进来的,自然知道值是多少)里done_json找到
|
126
|
+
>如何找到指定组件的两种方案:
|
127
|
+
> 1. 用你的项目里前后端约定的svg组件唯一标识符替换掉编辑器生成的id(必须保证唯一),然后调用setNodeAttrByID改变组件属性。
|
128
|
+
> 2. 如果不想改动id(避免因不能保证手动改过的id唯一性导致编辑器功能异常),可以在config里给想要改变的组件的配置文件的props里增加一个字段,
|
129
|
+
如deviceCode(svg-text的配置文件里有被注释的例子),然后在编辑组态时,给对应组件填上对应的deviceCode(这样deviceCode就和组件id实现
|
130
|
+
了映射关系),并保存,后台给前台推MQTT消息时带上指定的deviceCode,前台预览时,在收到MQTT消息后,凭借消息里的deviceCode在done_json
|
131
|
+
找到组件的id(可以用vue的computed计算一份deviceCode和id的映射关系存到一个对象里,这样在需要id时可直接在计算出的对象凭借deviceCode
|
132
|
+
直接取到),即可用setNodeAttrByID改变组件属性
|
133
|
+
|
134
|
+
### 8. example 查看示例
|
135
|
+
|
136
|
+
- download [VGCE](https://github.com/RickyHeaven/VGCE.git) (下载项目)
|
137
|
+
|
138
|
+
- `pnpm i` or `npm i` (安装依赖)
|
139
|
+
|
140
|
+
- `pnpm dev` or `npm run dev` (运行项目,使用示例参考`src/views`下两个页面)
|