1.0.5 • Published 2 years ago

@fan-z/viewers v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

二维地图与组态图预览工具

基于react,通过SVG(snapsvg.js)展示cad二维地图与组态图

 npm install @fan-z/viewers

GraphicViewer组态图

用法

import { GraphicViewer } from '@fan-z/viewers'
// 或 import GraphicViewer from '@fan-z/viewers/dist/graphic-viewer.js'

export const PageGraphicDemo = () => {
  import React, {useState} from 'react'
  const [designInfo, setDesignInfo] = useState({
    title: '标题',
    template: '',
  });
  return <div style={{ width: '100%', height: '100vh' }}>
    <GraphicViewer designInfo={designInfo}
                        absPath={'http://xxx:8181/spms-ibms/download/'}
                        dataList={[]} 
                        onCompClick={(data) => console.log('点击组件', data)}/>
    </div>
}

GraphicViewer API

参数说明类型默认值
designInfo组态图基础结构信息Object{title: '', template: ''} 参考designInfo API
dataList画布内的控件相关绑定设备值Array参考dataList API
loading画布展示状态Booleanfalse
onCompClick画布上控件点击事件Function(compData)参数为当前点击控件的基础配置及设备绑定等完整数据
absPath画布上资源文件(如图片)路径源String-

designInfo API(组态图基础结构信息)

参数字段说明类型必选项参考值
title组件标题String
template组件模板JOSN.String参考template.canvasConfig等 API "{ canvasConfig:Object, compSymbols: Array,componentList: Array, curActivedId: String<"当前选中控件ID">}"

dataList API(绑定设备值)

参数字段说明类型必选项参考值
attId属性IDstring-
name控件名称string-
value属性值,用于开关、单列面板等,column值格式 "1:start,2:normal,3:manual,4:6"string-
color属性颜色,用于显示绑定后的状态颜色值string-
scadaComponentId控件IDstring-
path图片路径string-
label用于设置显示“键值对”的键值,针对组件:键值对(名称 + 值)string-
uuid图层UUIDstring-
attOptionstring-
deviceId预留,可弃用string-
optionId选项ID,用于获取开关默认的展示值(将从colors内去过滤 )string-
designDetailId组态IDstring-
serialNumber-number-

PlanarViewer二维地图

使用时,如果已绑定对应的设备图标,需要另外引入相应的图标库文件,使用iconFontJs

用法

import React, {useState} from 'react'
import { PlanarViewer } from '@fan-z/viewers'
// 或 import PlanarViewer from '@fan-z/viewers/dist/planar-viewer.js'

export const PagePlanarDemo = () => {

  const handleHoverSticky = (nodeData, callUpdate, e, node) => {
    const [planarEvent, setPlanarEvent] = useState({});
    console.log('浮层经过事件', nodeData)
    callUpdate({
      deviceBrand: '通用送风品牌',
      deviceDesc: '大厦-1层- -一楼会议室送风机',
      deviceId: '84ff20cd-14a5-11ea-af93-0050568cb502',
      deviceModel: '通用送风型号',
      deviceName: '一楼会议室送风机',
      deviceSubType: '送风机',
      deviceSubTypeNo: 'blower',
      deviceTypeNo: 'supplyAirSystem',
      uuid: '1e0c2048-d329-43aa-8851-e9d6f001acdc',
      widgetUuid: '1e0c2048-d329-43aa-8851-e9d6f001acdc',
    }, e, nodeData, node);
  };
  const handleClickSticky = (nodeData) => {
    console.log('展示模式下点击事件', nodeData);
  };
  return <div style={{ width: '100%', height: '100vh' }}>
    <PlanarViewer id="pViewerId"
                  layerFile={editorComponentsList}
                  planarGraphFile={'http://xxx/map/layout/20191118142438207_23.svg'}
                  iconFontJs={'http://xxx/iconFont/75ae892f-1f57-11eb-b61f-0050568cb502.js'}
                  usePlanarEvent={(evnts) => setPlanarEvent(evnts)}
                  onHoverSticky={handleHoverSticky}
                  onClickSticky={handleClickSticky}
                  //  用renderPopover方法返回自定义浮层内容结果
                  /* renderPopover={(data,nodeData)=> {
                     return <>
                       <div className='device-name'>{data?.deviceDesc || '-'}</div>
                       <div className='device-params'><label>设备类型:</label> {data?.deviceSubType || '-'}</div>
                       <div className='device-params'><label>设备品牌:</label> {data?.deviceBrand || '-'}</div>
                       <div className='device-params'><label>设备型号:</label> {data?.deviceModel || '-'} </div>
                       <div className='device-params'><label>UUID:</label> {nodeData?.widgetUuid || '-'} </div>
                     </>
                   }}*/
    />
  </div>
}

PlanarViewer API

参数说明类型默认值参考值
planarGraphFile图纸文件(.svg文件)String--
layerFile设备图层文件Array(参考layerFileArray API)/File/String--
onHoverSticky鼠标经过图形控件事件Function(nodeData, callUpdate, e, node)-callUpdate()调用显示浮层可与renderPopover结合使用
onClickSticky鼠标点击图形控件事件Function(item)-
extraEmpty暂无图纸时显示ReactNode--
renderPopover自定义鼠标经过时浮层显示内容结构Function(deviceData, nodeData)/ReactNode--
iconFontJs图标库源文件(url地址)String--
usePlanarEvent获取当前组件内部事件Function(events)-参考 usePlanarEvent API

usePlanarEvent 组件内容常用事件 API

参数字段说明类型参考值
setWidgetHighLight设置指定控件高亮Function(uuids)-
clearWidgetHighLight清空或移除控件高亮Function(keys)keys为string且值为'all'表未全部清空 ,keys 为数组时,表示指定清空相关的uuid高亮状态
setIconConnection绘制指定图标之间的连线(有箭头动画)Function(list, setting)list=[{id: 'xxx', group: 'uuid','uuid', ..., setting: { fillColor: '#f00'}]: 多条,每条都是一个数组
removeIconConnection移除绘制连线Function(type, groupId)type 'all'全部移除, 'single'指定groupId移除, groupId 传String时,只移除单个, Array可移除指定多个groupId
updateWidgetStatus更新指定控件状态Function(option, status)单个:option为string用status是有值,多个:option为数组<{uuid: 'xxx', status:'danger'}>
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-beta

3 years ago