Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@zhangqingcq/vgce
Advanced tools
Vector graphics configure editor. svg组态编辑器。基于vue3.3+ts+element-plus+vite
Vector graphics configure editor. 矢量图组态编辑器。
npm i @zhangqingcq/vgce element-plus@2.8.6 ace-builds@1.14.0 lodash-es@^4.17.21 vue-echarts@6.5.1 animate.css@4.1.1
or
pnpm add @zhangqingcq/vgce element-plus@2.8.6 ace-builds@1.14.0 lodash-es@^4.17.21 vue-echarts@6.5.1 animate.css@4.1.1
//main.js or main.ts
import '@zhangqingcq/vgce/dist/style.css'
<script setup lang="ts">
import {SvgEditor} from '@zhangqingcq/vgce'
function preview(d: any) {
//save d and send it to SvgViewer's data
}
</script>
<template>
<SvgEditor @onPreview="preview"/>
</template>
<script setup lang="ts">
import {SvgViewer} from '@zhangqingcq/vgce'
</script>
<template>
<SvgViewer :data="xxx"/>
</template>
copy src/config/
and change as you want (复制src/config/
文件夹,然后更改里面的配置)
put svg files into src/asset/svgs
, then file name need to be same with config.name (将svg文件放到src/asset/svgs
,文件名需要和配置文件里的name
的值一致)
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
的值一致)
send the vue components to the editor and viewer with the props vueComp (在编辑器和查看器使用处把src/config/index.ts
导出的vueComp引入并以vueComp
作为props传递给编辑器和查看器组件)
// editor
<script setup lang="ts">
import {SvgEditor} from '@zhangqingcq/vgce'
import {config,vueComp} from '@/config'
</script>
<template>
<SvgEditor :customToolbar="config" :vueComp="vueComp"/>
</template>
//viewer
<script setup lang="ts">
import {SvgViewer} from '@zhangqingcq/vgce'
import {vueComp} from '@/config'
</script>
<template>
<SvgViewer :vueComp="vueComp" :data="xxx"/>
</template>
PS: you have to install vite-plugin-svg-icons
plugin to append your svg to html
dom.(你需要在项目安装npm依赖vite-plugin-svg-icons
,用以把svg文件添加到项目入口html文件中进行使用)
vite-plugin-svg-icons
如何使用 vite-plugin-svg-iconsnpm i vite-plugin-svg-icons -D
or pnpm add vite-plugin-svg-icons -D
(安装依赖)
change vite.config.ts
(修改项目vite配置文件)
// vite.config.ts
import { fileURLToPath, URL } from 'node:url'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
export default defineConfig({
plugins: [
xxx,
createSvgIconsPlugin({
iconDirs: [fileURLToPath(new URL('./src/assets/svgs', import.meta.url))],
symbolId: 'svg-[name]',
svgoOptions: false,
customDomId: '__svg__icons__dom__'//your id, do not use this id!(使用你自己定义的id,不能使用__svg__icons__dom__,这是内置svg文件使用的id)
})
],
xxx
})
```
change main.ts
(修改项目主文件)
// main.ts
import 'virtual:svg-icons-register'
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 依赖)
// editor
<SvgEditor :data="xxx" slotBackground @onPreview="previewHandle">
<template #background>
<div style="height: 100%; width: 100%; background-color: red"></div>
</template>
</SvgEditor>
//注意:使用自定义背景功能时,editor的slotBackground属性传true,让‘图纸’面板‘背景色’功能不可见,避免让操作者产生‘背景色设置不生效’的错觉
// viewer
<SvgViewer :data="xxx">
<template #background>
<div style="height: 100%; width: 100%; background-color: red"></div>
</template>
</SvgViewer>
方案1.通过编辑器(editor)的
mqtt
属性传递配置,如:
<SvgEditor :mqtt="{cover:true,url:'xxx',user:'xxx',pwd:'xxx',topics:'xxx'}">
// cover:是否使用这里的配置覆盖通信面板设置(也就是后面将介绍的第二种方案)的配置,为ture则覆盖,一般这里进行配置了,通信面板就无需再配置,
所以这里一般都要传true。当然,如果你只想将这里的配置作为备选方案,如果使用者在编辑器通信面板进行了配置,则使用通信面板的配置,这里传false。
方案2.在编辑器右侧‘通信’菜单下配置好mqtt通信需要的url、username、password、topics,注意:关闭通信面板‘外部配置’选项方可进行独立配置且使配置生效。
onMessage
事件,并处理事件返回的数据{ topics, message }
如何找到指定组件的两种方案:
- 用你的项目里前后端约定的svg组件唯一标识符替换掉编辑器生成的id(必须保证唯一),然后调用setNodeAttrByID改变组件属性。
- 如果不想改动id(避免因不能保证手动改过的id唯一性导致编辑器功能异常),可以在config里给想要改变的组件的配置文件的props里增加一个字段, 如deviceCode(svg-text的配置文件里有被注释的例子),然后在编辑组态时,给对应组件填上对应的deviceCode(这样deviceCode就和组件id实现 了映射关系),并保存,后台给前台推MQTT消息时带上指定的deviceCode,前台预览时,在收到MQTT消息后,凭借消息里的deviceCode在done_json 找到组件的id(可以用vue的computed计算一份deviceCode和id的映射关系存到一个对象里,这样在需要id时可直接在计算出的对象凭借deviceCode 直接取到),即可用setNodeAttrByID改变组件属性
on-change
事件(一般为自定义vue组件才具备这个能力)时触发on-event
事件,并传递{event,target}数据,event即当前事件的详细数据,target即当前组件的详细数据download VGCE (下载项目)
pnpm i
or npm i
(安装依赖)
pnpm dev
or npm run dev
(运行项目,使用示例参考src/views
下两个页面)
element-plus
,所以你需要在你的项目安装 element-plus 依赖,依赖版本按上面给出的版本FAQs
Vector graphics configure editor. svg组态编辑器。基于vue3.3+ts+element-plus+vite
We found that @zhangqingcq/vgce demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.