@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.
Files changed (39) hide show
  1. package/README.md +135 -92
  2. package/dist/style.css +1 -1
  3. package/dist/vgce.js +11044 -10941
  4. package/dist/vgce.umd.cjs +33 -33
  5. package/package.json +1 -1
  6. package/src/assets/base.less +69 -68
  7. package/src/assets/svgs/text-box.svg +1 -0
  8. package/src/assets/variables.less +6 -6
  9. package/src/components/svg-editor/center-panel.vue +3 -2
  10. package/src/components/svg-editor/index.vue +7 -5
  11. package/src/components/svg-viewer.vue +7 -4
  12. package/src/config/files/text-box.vue +72 -0
  13. package/src/config/index.ts +5 -3
  14. package/src/config/svg/animation/index.ts +3 -2
  15. package/src/config/svg/animation/thermometer.ts +2 -1
  16. package/src/config/svg/custom/clock-a.ts +2 -1
  17. package/src/config/svg/custom/index.ts +6 -5
  18. package/src/config/svg/custom/light.ts +2 -1
  19. package/src/config/svg/custom/svg-text.ts +2 -1
  20. package/src/config/svg/custom/switch-r.ts +2 -1
  21. package/src/config/svg/index.ts +6 -10
  22. package/src/config/svg/stateful/alert-light.ts +2 -1
  23. package/src/config/svg/stateful/index.ts +3 -2
  24. package/src/config/svg/stateless/bot-2.ts +2 -1
  25. package/src/config/svg/stateless/bot-9.ts +2 -1
  26. package/src/config/svg/stateless/hamburger.ts +2 -1
  27. package/src/config/svg/stateless/hotpot.ts +2 -1
  28. package/src/config/svg/stateless/index.ts +6 -5
  29. package/src/config/vue/component/button.ts +2 -1
  30. package/src/config/vue/component/common-table.ts +2 -1
  31. package/src/config/vue/component/index.ts +9 -7
  32. package/src/config/vue/component/now-time.ts +2 -1
  33. package/src/config/vue/component/progress.ts +2 -1
  34. package/src/config/vue/component/tag.ts +2 -1
  35. package/src/config/vue/component/text-box.ts +66 -0
  36. package/src/config/vue/echarts/index.ts +3 -2
  37. package/src/config/vue/echarts/pie-charts.ts +2 -1
  38. package/src/config/vue/index.ts +4 -3
  39. 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
- 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
10
- ```
11
- or
12
- ```
13
- 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
14
- ```
15
-
16
- 2. change main.ts or main.js
17
- ```
18
- //main.js or main.ts
19
-
20
- import '@zhangqingcq/vgce/dist/style.css'
21
- ```
22
-
23
- 3. use editor
24
- ```
25
- <script setup lang="ts">
26
- import {SvgEditor} from '@zhangqingcq/vgce'
27
-
28
- function preview(d: any) {
29
- //save d and send it to SvgViewer's data
30
- }
31
- </script>
32
- <template>
33
- <SvgEditor @onPreview="preview"/>
34
- </template>
35
- ```
36
- 4. use viewer
37
- ```
38
- <script setup lang="ts">
39
- import {SvgViewer} from '@zhangqingcq/vgce'
40
- </script>
41
- <template>
42
- <SvgViewer :data="xxx"/>
43
- </template>
44
- ```
45
- 5. custom toolbar
46
- - copy `src/config/` and change as you want
47
-
48
- - put svg files into `src/asset/svgs` , then file name need to be same with config.name
49
-
50
- - put custom vue components file into `src/config/files`, then import in `src/config/index.ts` and export with `vueComp`
51
-
52
- - PS: you have to install `vite-plugin-svg-icons` plugin to append your svg to html dom.
53
- ```
54
- <script setup lang="ts">
55
- import {SvgEditor} from '@zhangqingcq/vgce'
56
- import {config} from '@/config'
57
- </script>
58
- <template>
59
- <SvgEditor :customToolbar="config"/>
60
- </template>
61
- ```
62
- 6. how to use `vite-plugin-svg-icons`
63
- - `npm i vite-plugin-svg-icons -D` or `pnpm add vite-plugin-svg-icons -D`
64
- - change `vite.config.ts`
65
- ```
66
- // vite.config.ts
67
-
68
- import { fileURLToPath, URL } from 'node:url'
69
- import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
70
-
71
- export default defineConfig({
72
- plugins: [
73
- xxx,
74
- createSvgIconsPlugin({
75
- iconDirs: [fileURLToPath(new URL('./src/assets/svgs', import.meta.url))],
76
- symbolId: 'svg-[name]',
77
- svgoOptions: false,
78
- customDomId: '__svg__icons__dom__'//your id, do not use this id!
79
- })
80
- ],
81
- xxx
82
- })
83
- ```
84
- - change `main.ts`
85
- ```
86
- // main.ts
87
-
88
- import 'virtual:svg-icons-register'
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
- - PS: if there is error: `Cannot find module ‘fast-glob’`,then run `npm i fast-glob -D` or `pnpm add fast-glob -D`
91
-
92
- 7. example
93
- - download [VGCE](https://github.com/RickyHeaven/VGCE.git)
94
-
95
- - `pnpm i` or `npm i`
96
-
97
- - `pnpm dev` or `npm run dev`
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`下两个页面)