| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214 |
- <template>
- <wrapper
- class="c-mesh"
- fill
- margin
- padding
- background
- >
- <div class="l-flex__none l-flex--row c-mesh__header c-sibling-item--v">
- <i
- class="l-flex__none c-sibling-item o-icon medium o-icon--hover el-icon-arrow-left u-bold u-pointer"
- @click="onBack"
- />
- <div class="l-flex__auto l-flex--row c-sibling-item near u-color--black u-font-size--md u-bold u-ellipsis">
- {{ name }}
- </div>
- </div>
- <div
- v-loading="loading"
- class="l-flex__fill l-flex--col c-sibling-item--v"
- >
- <template v-if="!loading">
- <warning
- v-if="error"
- class="l-flex__auto"
- @click="getMesh"
- />
- <template v-else>
- <div class="l-flex__none l-flex--row c-sibling-item--v u-line-height">
- <div class="c-sibling-item u-font-size--md u-ellipsis">节点</div>
- <i
- class="l-flex__none c-sibling-item el-icon-circle-plus-outline u-font-size--lg u-color--blue u-bold has-active"
- @click.stop="onAddNode"
- />
- <i
- class="l-flex__none c-sibling-item el-icon-refresh-left u-font-size--lg u-color--blue u-bold has-active"
- @click.stop="getMesh"
- />
- </div>
- <div
- v-if="!hasNodes"
- class="has-padding u-text--center u-bold"
- >
- 暂无结点,请添加节点
- </div>
- <div
- ref="canvas"
- class="l-flex__fill"
- style="z-index: 0;"
- />
- <confirm-dialog
- ref="nodeDialog"
- :title="nodeDialogTitle"
- @confirm="onSubmit"
- >
- <template #default>
- <div class="c-grid-form u-align-self--center">
- <span class="c-grid-form__label u-required">类型</span>
- <schema-select
- v-model="item.nodeType"
- :schema="thirdPartyDeviceSelectSchema"
- />
- <span class="c-grid-form__label">别名</span>
- <el-input
- v-model.trim="item.name"
- placeholder="最多30个字符"
- maxlength="30"
- clearable
- />
- <template v-if="needPort">
- <span class="c-grid-form__label u-required">端口</span>
- <div
- class="has-info"
- data-info="若设备上的端口从1开始,填入时需减1处理"
- >
- <el-input-number
- v-model="item.port"
- controls-position="right"
- :min="0"
- step-strictly
- />
- </div>
- </template>
- </div>
- </template>
- </confirm-dialog>
- <confirm-dialog
- ref="nodeEditDialog"
- title="修改节点"
- @confirm="onSubmit"
- >
- <div class="c-grid-form u-align-self--center">
- <span class="c-grid-form__label">别名</span>
- <el-input
- v-model.trim="item.name"
- placeholder="最多30个字符"
- maxlength="30"
- clearable
- />
- </div>
- </confirm-dialog>
- <confirm-dialog
- ref="portEditDialog"
- title="端口设置"
- @confirm="onSubmitPort"
- >
- <template #default>
- <div class="c-grid-form auto u-align-self--center">
- <span class="c-grid-form__label u-required">端口</span>
- <div
- class="has-info u-width--md"
- data-info="若设备上的端口从1开始,填入时需减1处理"
- >
- <el-input-number
- v-model="item.port"
- controls-position="right"
- :min="0"
- step-strictly
- />
- </div>
- </div>
- </template>
- </confirm-dialog>
- <radio-table-dialog
- ref="instanceDialog"
- title="设备绑定"
- size="lg"
- message="请选择设备"
- :schema="thirdPartySchema"
- @confirm="onSubmitBind"
- />
- <component
- :is="thirdPartyComponent"
- v-if="thirdPartyComponent"
- ref="thirdPartyConfigDialog"
- @confirm="onConfirmThirdPaty"
- />
- <el-card
- v-show="menuVisible"
- ref="card"
- class="c-contentmenu"
- @click.native.stop
- >
- <template v-if="isNode">
- <div
- v-if="canHasFollow"
- class="l-flex--row c-contentmenu__item has-active"
- @click="onAddChildNode"
- >
- <i class="c-sibling-item el-icon-circle-plus-outline" />
- <span class="c-sibling-item">新增子节点</span>
- </div>
- <div
- v-if="canHasAhead"
- class="l-flex--row c-contentmenu__item has-active"
- @click="onAddParentNode"
- >
- <i class="c-sibling-item el-icon-circle-plus-outline" />
- <span class="c-sibling-item">新增父节点</span>
- </div>
- <div
- v-if="canLink"
- class="l-flex--row c-contentmenu__item has-active"
- @click="onLinkTo"
- >
- <i class="c-sibling-item el-icon-edit" />
- <span class="c-sibling-item">连接至</span>
- </div>
- <div
- class="l-flex--row c-contentmenu__item has-active"
- @click="onEditNode"
- >
- <i class="c-sibling-item el-icon-edit" />
- <span class="c-sibling-item">修改别名</span>
- </div>
- <div
- class="l-flex--row c-contentmenu__item has-active"
- @click="onToggleInstance"
- >
- <i class="c-sibling-item el-icon-edit" />
- <span class="c-sibling-item">{{ hasInstance ? '解绑' : '绑定' }}</span>
- </div>
- </template>
- <template v-else>
- <div
- v-if="hasPort"
- class="l-flex--row c-contentmenu__item has-active"
- @click="onEditPort"
- >
- <i class="c-sibling-item el-icon-edit" />
- <span class="c-sibling-item">端口</span>
- </div>
- </template>
- <div
- class="l-flex--row c-contentmenu__item has-active"
- @click="onDel"
- >
- <i class="c-sibling-item el-icon-remove-outline" />
- <span class="c-sibling-item">删除</span>
- </div>
- </el-card>
- </template>
- </template>
- </div>
- </wrapper>
- </template>
- <script>
- import {
- ThirdPartyDevice,
- ThirdPartyDeviceInfo,
- SendingCard,
- SendingCardFeatures,
- ReceivingCard,
- ReceivingCardFeatures,
- ThirdPartyToSensorMap,
- SensorToThirdPartyMap,
- ThirdPartyToCameraMap
- } from '@/constant'
- import {
- getMesh,
- addNodeToMesh,
- deleteNode,
- addEdgeToMesh,
- deleteEdge,
- updateEdgePort,
- updateNode,
- addNodeBeforeNode,
- addNodeAfterNode,
- bindInstanceToNode,
- releaseInstanceFormNode
- } from '@/api/mesh'
- import {
- getManufacturersByType,
- getGateways,
- getScreens,
- getSendingCards,
- getReceivingCards,
- getMultifunctionCards,
- getSensors,
- getPLCs,
- getCameras
- } from '@/api/external'
- import { getDevices } from '@/api/device'
- import * as echarts from 'echarts'
- import GatewayConfigDialog from '../components/GatewayConfigDialog.vue'
- import ScreenConfigDialog from '../components/ScreenConfigDialog.vue'
- import SendingCardConfigDialog from '../components/SendingCardConfigDialog.vue'
- import ReceivingCardConfigDialog from '../components/ReceivingCardConfigDialog.vue'
- import PlcConfigDialog from '../components/PlcConfigDialog.vue'
- import MultifunctionCardConfigDialog from '../components/MultifunctionCardConfigDialog.vue'
- import SensorConfigDialog from '../components/SensorConfigDialog.vue'
- import CameraConfigDialog from '../components/CameraConfigDialog.vue'
- const sensors = Object.values(SensorToThirdPartyMap)
- const PortThirdPartyDevices = [
- ThirdPartyDevice.PLC,
- ThirdPartyDevice.MULTI_FUNCTION_CARD,
- ...sensors
- ]
- const SoloThirdPartyDevices = [
- ThirdPartyDevice.RECEIVING_CARD,
- ThirdPartyDevice.SENDING_CARD,
- ThirdPartyDevice.SCREEN,
- ThirdPartyDevice.BOX
- ]
- const ThirdPartyDeviceOption = {
- 'all': Object.values(ThirdPartyDevice),
- follow: {
- [ThirdPartyDevice.GATEWAY]: [
- ThirdPartyDevice.PLC,
- ...sensors
- ],
- [ThirdPartyDevice.RECEIVING_CARD]: [
- ThirdPartyDevice.SCREEN
- ],
- [ThirdPartyDevice.SENDING_CARD]: [
- ThirdPartyDevice.RECEIVING_CARD,
- ThirdPartyDevice.SCREEN
- ],
- [ThirdPartyDevice.RECEIVING_CARD]: [
- ThirdPartyDevice.SCREEN
- ],
- [ThirdPartyDevice.BOX]: [
- ThirdPartyDevice.RECEIVING_CARD,
- ThirdPartyDevice.SENDING_CARD,
- ThirdPartyDevice.SCREEN,
- ThirdPartyDevice.PLC,
- ThirdPartyDevice.MULTI_FUNCTION_CARD,
- ...sensors
- ],
- [ThirdPartyDevice.MULTI_FUNCTION_CARD]: [
- ThirdPartyDevice.PLC,
- ...sensors
- ]
- },
- ahead: {
- [ThirdPartyDevice.RECEIVING_CARD]: [
- ThirdPartyDevice.SENDING_CARD,
- ThirdPartyDevice.BOX
- ],
- [ThirdPartyDevice.SENDING_CARD]: [
- ThirdPartyDevice.BOX
- ],
- [ThirdPartyDevice.SCREEN]: [
- ThirdPartyDevice.RECEIVING_CARD,
- ThirdPartyDevice.BOX
- ],
- [ThirdPartyDevice.PLC]: [
- ThirdPartyDevice.GATEWAY,
- ThirdPartyDevice.BOX,
- ThirdPartyDevice.MULTI_FUNCTION_CARD
- ],
- [ThirdPartyDevice.MULTI_FUNCTION_CARD]: [
- ThirdPartyDevice.BOX
- ],
- [ThirdPartyDevice.SMOKE_SENSOR]: [
- ThirdPartyDevice.GATEWAY,
- ThirdPartyDevice.BOX,
- ThirdPartyDevice.MULTI_FUNCTION_CARD
- ],
- [ThirdPartyDevice.TEMPERATURE_SENSOR]: [
- ThirdPartyDevice.GATEWAY,
- ThirdPartyDevice.BOX,
- ThirdPartyDevice.MULTI_FUNCTION_CARD
- ],
- [ThirdPartyDevice.LIGHT_SENSOR]: [
- ThirdPartyDevice.GATEWAY,
- ThirdPartyDevice.BOX,
- ThirdPartyDevice.MULTI_FUNCTION_CARD
- ],
- [ThirdPartyDevice.FLOODING_SENSOR]: [
- ThirdPartyDevice.GATEWAY,
- ThirdPartyDevice.BOX,
- ThirdPartyDevice.MULTI_FUNCTION_CARD
- ],
- [ThirdPartyDevice.TRANSLOCATION_SENSOR]: [
- ThirdPartyDevice.GATEWAY,
- ThirdPartyDevice.BOX,
- ThirdPartyDevice.MULTI_FUNCTION_CARD
- ]
- }
- }
- export default {
- name: 'Mesh',
- components: {
- GatewayConfigDialog,
- ScreenConfigDialog,
- SendingCardConfigDialog,
- ReceivingCardConfigDialog,
- PlcConfigDialog,
- MultifunctionCardConfigDialog,
- SensorConfigDialog,
- CameraConfigDialog
- },
- data () {
- return {
- loading: true,
- error: false,
- mesh: null,
- defaultProps: { label: 'name' },
- thirdPartyDeviceSelectSchema: null,
- item: {},
- nodes: [],
- menuVisible: false,
- clickTargetType: '',
- targetItem: null
- }
- },
- computed: {
- meshId () {
- return this.$route.params.id
- },
- name () {
- return this.mesh?.name
- },
- hasNodes () {
- return this.nodes.length > 0
- },
- isNode () {
- return this.hasNodes && this.clickTargetType === 'node'
- },
- hasInstance () {
- return this.targetItem?.instanceId
- },
- nodeType () {
- return this.targetItem?.nodeType
- },
- canHasAhead () {
- return !!ThirdPartyDeviceOption.ahead[this.nodeType]
- },
- canHasFollow () {
- return !!ThirdPartyDeviceOption.follow[this.nodeType]
- },
- canLink () {
- if (this.isNode && this.canHasFollow) {
- const options = ThirdPartyDeviceOption.follow[this.nodeType]
- return options
- ? this.nodes.some(({ nodeType }) => options.includes(nodeType))
- : false
- }
- return false
- },
- hasPort () {
- return this.targetItem?.port >= 0
- },
- nodeSelectSchema () {
- return {
- options: this.nodes.map(({ id, name }) => {
- return {
- value: id,
- label: name
- }
- })
- }
- },
- nodeDialogTitle () {
- const { action } = this.item
- switch (action) {
- case 'addParentNode':
- return '新增父节点'
- case 'addChildNode':
- return '新增子节点'
- default:
- return '新增节点'
- }
- },
- needPort () {
- const { action } = this.item
- switch (action) {
- case 'addParentNode':
- return PortThirdPartyDevices.includes(this.targetItem.nodeType)
- case 'addChildNode':
- return PortThirdPartyDevices.includes(this.item.nodeType)
- default:
- return false
- }
- },
- thirdPartyType () {
- return this.targetItem?.nodeType
- },
- thirdPartyComponent () {
- switch (this.thirdPartyType) {
- case ThirdPartyDevice.GATEWAY:
- return 'GatewayConfigDialog'
- case ThirdPartyDevice.SCREEN:
- return 'ScreenConfigDialog'
- case ThirdPartyDevice.SENDING_CARD:
- return 'SendingCardConfigDialog'
- case ThirdPartyDevice.RECEIVING_CARD:
- return 'ReceivingCardConfigDialog'
- case ThirdPartyDevice.PLC:
- return 'PlcConfigDialog'
- case ThirdPartyDevice.MULTI_FUNCTION_CARD:
- return 'MultifunctionCardConfigDialog'
- case ThirdPartyDevice.SMOKE_SENSOR:
- case ThirdPartyDevice.TEMPERATURE_SENSOR:
- case ThirdPartyDevice.LIGHT_SENSOR:
- case ThirdPartyDevice.FLOODING_SENSOR:
- case ThirdPartyDevice.TRANSLOCATION_SENSOR:
- return 'SensorConfigDialog'
- case ThirdPartyDevice.LED_CAMERA:
- case ThirdPartyDevice.TRAFFIC_CAMERA:
- return 'CameraConfigDialog'
- default:
- return null
- }
- },
- thirdPartySchema () {
- switch (this.thirdPartyType) {
- case ThirdPartyDevice.GATEWAY:
- return {
- list: getGateways,
- condition: { boundFlag: 0 },
- buttons: [
- { type: 'add', on: this.onAddThirdParty }
- ],
- filters: [
- { key: 'manufacturerKey', type: 'select', placeholder: '厂商', remote: this.getManufacturersByType, value: 'manufacturerKey', label: 'manufacturerName' },
- { key: 'identifier', type: 'search', placeholder: '唯一标识' }
- ],
- cols: [
- { prop: 'manufacturerName', label: '厂商' },
- { prop: 'model', label: '型号' },
- { prop: 'ip', label: '服务器地址' },
- { prop: 'identifier', label: '唯一标识' }
- ]
- }
- case ThirdPartyDevice.SCREEN:
- return {
- list: getScreens,
- condition: { boundFlag: 0 },
- buttons: [
- { type: 'add', on: this.onAddThirdParty }
- ],
- filters: [
- { key: 'manufacturerKey', type: 'select', placeholder: '厂商', remote: this.getManufacturersByType, value: 'manufacturerKey', label: 'manufacturerName' },
- { key: 'identifier', type: 'search', placeholder: '唯一标识' }
- ],
- cols: [
- { prop: 'manufacturerName', label: '厂商' },
- { prop: 'model', label: '型号' },
- { prop: 'identifier', label: '唯一标识' },
- { prop: 'measure', label: '屏宽高(m²)' },
- { prop: 'pitch', label: '点间距(mm)' },
- { prop: 'resolutionRatio', label: '分辨率' }
- ]
- }
- case ThirdPartyDevice.SENDING_CARD:
- return {
- list: getSendingCards,
- condition: { boundFlag: 0 },
- buttons: [
- { type: 'add', on: this.onAddThirdParty }
- ],
- filters: [
- { key: 'manufacturerKey', type: 'select', placeholder: '厂商', remote: this.getManufacturersByType, value: 'manufacturerKey', label: 'manufacturerName' },
- { key: 'identifier', type: 'search', placeholder: '唯一标识' }
- ],
- cols: [
- { prop: 'manufacturerName', label: '厂商' },
- { prop: 'model', label: '型号' },
- { prop: 'identifier', label: '唯一标识' },
- { label: '特性', type: 'tag', render: ({ flag }) => SendingCardFeatures.map(({ key, label }) => {
- return { type: flag & SendingCard[key] ? 'success' : 'danger', label }
- }), width: 364 }
- ]
- }
- case ThirdPartyDevice.RECEIVING_CARD:
- return {
- list: getReceivingCards,
- condition: { boundFlag: 0 },
- buttons: [
- { type: 'add', on: this.onAddThirdParty }
- ],
- filters: [
- { key: 'manufacturerKey', type: 'select', placeholder: '厂商', remote: this.getManufacturersByType, value: 'manufacturerKey', label: 'manufacturerName' },
- { key: 'identifier', type: 'search', placeholder: '唯一标识' }
- ],
- cols: [
- { prop: 'manufacturerName', label: '厂商' },
- { prop: 'model', label: '型号' },
- { prop: 'identifier', label: '唯一标识' },
- { label: '特性', type: 'tag', render: ({ flag }) => ReceivingCardFeatures.map(({ key, label }) => {
- return { type: flag & ReceivingCard[key] ? 'success' : 'danger', label }
- }), width: 364 }
- ]
- }
- case ThirdPartyDevice.PLC:
- return {
- list: getPLCs,
- condition: { boundFlag: 0 },
- buttons: [
- { type: 'add', on: this.onAddThirdParty }
- ],
- filters: [
- { key: 'manufacturerKey', type: 'select', placeholder: '厂商', remote: this.getManufacturersByType, value: 'manufacturerKey', label: 'manufacturerName' },
- { key: 'identifier', type: 'search', placeholder: '唯一标识' }
- ],
- cols: [
- { prop: 'manufacturerName', label: '厂商' },
- { prop: 'model', label: '型号' },
- { prop: 'identifier', label: '唯一标识' },
- { prop: 'portCount', label: '端口数' }
- ]
- }
- case ThirdPartyDevice.BOX:
- return {
- list: getDevices,
- condition: { boundFlag: 0 },
- filters: [
- { key: 'serialNumber', type: 'search', placeholder: '序列号' },
- { key: 'mac', type: 'search', placeholder: 'MAC' },
- { key: 'name', type: 'search', placeholder: '设备名称' }
- ],
- cols: [
- { prop: 'name', label: '设备名称' },
- { prop: 'serialNumber', label: '序列号' },
- { prop: 'mac', label: 'MAC' }
- ]
- }
- case ThirdPartyDevice.MULTI_FUNCTION_CARD:
- return {
- list: getMultifunctionCards,
- condition: { boundFlag: 0 },
- buttons: [
- { type: 'add', on: this.onAddThirdParty }
- ],
- filters: [
- { key: 'manufacturerKey', type: 'select', placeholder: '厂商', remote: this.getManufacturersByType, value: 'manufacturerKey', label: 'manufacturerName' },
- { key: 'identifier', type: 'search', placeholder: '唯一标识' }
- ],
- cols: [
- { prop: 'manufacturerName', label: '厂商' },
- { prop: 'model', label: '型号' },
- { prop: 'identifier', label: '唯一标识' },
- { prop: 'portCount', label: '端口数', align: 'center' },
- { prop: 'rs485Count', label: '485接口数', align: 'center' }
- ]
- }
- case ThirdPartyDevice.SMOKE_SENSOR:
- case ThirdPartyDevice.TEMPERATURE_SENSOR:
- case ThirdPartyDevice.LIGHT_SENSOR:
- case ThirdPartyDevice.FLOODING_SENSOR:
- case ThirdPartyDevice.TRANSLOCATION_SENSOR:
- return {
- list: getSensors,
- condition: { sensorType: ThirdPartyToSensorMap[this.thirdPartyType], boundFlag: 0 },
- buttons: [
- { type: 'add', on: this.onAddThirdParty }
- ],
- filters: [
- { key: 'manufacturerKey', type: 'select', placeholder: '厂商', remote: this.getManufacturersByType, value: 'manufacturerKey', label: 'manufacturerName' },
- { key: 'identifier', type: 'search', placeholder: '唯一标识' }
- ],
- cols: [
- { prop: 'manufacturerName', label: '厂商' },
- { prop: 'model', label: '型号' },
- { prop: 'identifier', label: '唯一标识' }
- ]
- }
- case ThirdPartyDevice.LED_CAMERA:
- case ThirdPartyDevice.TRAFFIC_CAMERA:
- return {
- list: getCameras,
- condition: { boundFlag: 0, cameraType: ThirdPartyToCameraMap[this.thirdPartyType] },
- buttons: [
- { type: 'add', on: this.onAddThirdParty }
- ],
- filters: [
- { key: 'manufacturerKey', type: 'select', placeholder: '厂商', remote: this.getManufacturersByType, value: 'manufacturerKey', label: 'manufacturerName' },
- { key: 'identifier', type: 'search', placeholder: '唯一标识' },
- { key: 'remark', type: 'search', placeholder: '备注' }
- ],
- cols: [
- { prop: 'manufacturerName', label: '厂商' },
- { prop: 'model', label: '型号' },
- { prop: 'identifier', label: '唯一标识' },
- { prop: 'remark', label: '备注' }
- ]
- }
- default:
- return {
- list: () => Promise.resolve({ data: [] }),
- cols: [
- { label: '唯一标识' }
- ]
- }
- }
- }
- },
- watch: {
- meshId: {
- handler () {
- this.getMesh()
- },
- immediate: true
- }
- },
- beforeDestroy () {
- this.disposeChart()
- },
- methods: {
- getManufacturersByType () {
- return getManufacturersByType(this.thirdPartyType)
- },
- onAddThirdParty () {
- let type = null
- switch (this.thirdPartyType) {
- case ThirdPartyDevice.SMOKE_SENSOR:
- case ThirdPartyDevice.TEMPERATURE_SENSOR:
- case ThirdPartyDevice.LIGHT_SENSOR:
- case ThirdPartyDevice.FLOODING_SENSOR:
- case ThirdPartyDevice.TRANSLOCATION_SENSOR:
- type = ThirdPartyToSensorMap[this.thirdPartyType]
- break
- case ThirdPartyDevice.LED_CAMERA:
- case ThirdPartyDevice.TRAFFIC_CAMERA:
- type = ThirdPartyToCameraMap[this.thirdPartyType]
- break
- default:
- break
- }
- this.$refs.thirdPartyConfigDialog.show(type)
- },
- onConfirmThirdPaty ({ manufacturerKey, identifier, remark }) {
- this.$refs.instanceDialog.getTable().resetCondition({
- manufacturerKey,
- identifier,
- remark
- })
- },
- collectNodes (nodes) {
- this.$nodeMap = {}
- if (nodes) {
- nodes.forEach((node, index) => {
- this.$nodeMap[node.id] = index
- })
- }
- return nodes || []
- },
- onBack () {
- this.$router.replace({
- name: 'mesh-list'
- })
- },
- disposeChart () {
- if (this.mesh) {
- this.mesh = null
- this.nodes = []
- this.edges = []
- this.$chart?.dispose()
- this.$chart = null
- this.closeContentMenu()
- }
- this.$nodeMap = {}
- this.$waitTarget = false
- },
- getMesh () {
- this.disposeChart()
- this.loading = true
- this.error = false
- getMesh(this.meshId).then(
- ({ data }) => {
- if (data) {
- this.mesh = data.mesh
- this.edges = data.bondList || []
- this.nodes = this.collectNodes(data.nodeList)
- } else {
- this.$message({
- type: 'warning',
- message: '数据不存在'
- })
- this.onBack()
- }
- },
- () => {
- this.error = true
- }
- ).finally(() => {
- this.loading = false
- if (this.nodes?.length) {
- this.$nextTick(this.onDraw)
- }
- })
- },
- onDraw () {
- if (!this.$chart) {
- this.$chart = echarts.init(this.$refs.canvas)
- this.$chart.on('click', this.onClick)
- }
- const options = this.$waitTarget && ThirdPartyDeviceOption.follow[this.targetItem.nodeType]
- this.$chart.setOption({
- // title: {
- // text: 'Basic Graph'
- // },
- animationDurationUpdate: 1500,
- animationEasingUpdate: 'quinticInOut',
- tooltip: {},
- series: [
- {
- type: 'graph',
- // roam: true,
- layout: 'circular',
- // layout: 'force',
- // force: {
- // edgeLength: 100
- // },
- label: {
- show: true,
- position: 'top'
- },
- itemStyle: {
- color ({ data, color }) {
- return data.proxy.instanceId ? '#67c23a' : color
- }
- },
- edgeSymbol: ['none', 'arrow'], // circle
- edgeSymbolSize: 8,
- // edgeLabel: {
- // fontSize: 20
- // },
- lineStyle: {
- // color: '#ff0000',
- width: 2,
- opacity: 0.9,
- curveness: 0
- },
- nodes: this.nodes.map(node => {
- const { id, name, nodeType } = node
- const canClick = options ? options.includes(nodeType) : true
- return {
- proxy: node,
- id,
- name,
- tooltip: {
- formatter: this.formatterNode
- },
- canClick,
- emphasis: {
- disabled: !canClick
- },
- symbolSize: canClick ? 24 : 12
- }
- }),
- edges: this.edges.map(edge => {
- const { preNodeId, nextNodeId, port } = edge
- return {
- proxy: edge,
- value: port,
- source: this.$nodeMap[preNodeId],
- target: this.$nodeMap[nextNodeId],
- label: {
- show: port >= 0,
- // position: 'start',
- formatter: '{c}'
- }
- }
- })
- }
- ]
- })
- },
- formatterNode ({ marker, data: { proxy: { nodeType, instance } } }) {
- let tooltip = `${marker} ${ThirdPartyDeviceInfo[nodeType]}`
- if (instance) {
- switch (nodeType) {
- case ThirdPartyDevice.SENDING_CARD:
- case ThirdPartyDevice.SMOKE_SENSOR:
- case ThirdPartyDevice.TEMPERATURE_SENSOR:
- case ThirdPartyDevice.LIGHT_SENSOR:
- case ThirdPartyDevice.FLOODING_SENSOR:
- case ThirdPartyDevice.TRANSLOCATION_SENSOR:
- tooltip += `<br/>唯一标识:${instance.identifier}<br/>厂商:${instance.manufacturerName}<br/>型号:${instance.model}`
- break
- case ThirdPartyDevice.RECEIVING_CARD:
- tooltip += `<br/>唯一标识:${instance.identifier}<br/>厂商:${instance.manufacturerName}<br/>型号:${instance.model}<br/>规格:${instance.rowCount} x ${instance.colCount}`
- break
- case ThirdPartyDevice.GATEWAY:
- tooltip += `<br/>唯一标识:${instance.identifier}<br/>厂商:${instance.manufacturerName}<br/>型号:${instance.model}<br/>服务器:${instance.ip}`
- break
- case ThirdPartyDevice.SCREEN:
- tooltip += `<br/>唯一标识:${instance.identifier}<br/>厂商:${instance.manufacturerName}<br/>型号:${instance.model}<br/>规格:${instance.measure}m² ${instance.pitch}mm`
- break
- case ThirdPartyDevice.PLC:
- tooltip += `<br/>唯一标识:${instance.identifier}<br/>厂商:${instance.manufacturerName}<br/>型号:${instance.model}<br/>端口数:${instance.portCount}`
- break
- case ThirdPartyDevice.BOX:
- tooltip += `<br/>设备名称:${instance.name}<br/>序列号:${instance.serialNumber}<br/>MAC:${instance.mac}`
- break
- case ThirdPartyDevice.MULTI_FUNCTION_CARD:
- tooltip += `<br/>唯一标识:${instance.identifier}<br/>厂商:${instance.manufacturerName}<br/>型号:${instance.model}<br/>端口数:${instance.portCount}<br/>485接口数:${instance.rs485Count}`
- break
- case ThirdPartyDevice.LED_CAMERA:
- case ThirdPartyDevice.TRAFFIC_CAMERA:
- tooltip += `<br/>唯一标识:${instance.identifier}<br/>厂商:${instance.manufacturerName}<br/>型号:${instance.model}<br/>备注:${instance.remark}`
- break
- default:
- break
- }
- }
- return tooltip
- },
- onClick (eventProxy) {
- console.log('click', eventProxy)
- const targetItem = eventProxy.data.proxy
- const targetType = eventProxy.dataType
- if (this.$waitTarget) {
- this.onChangeLinkStatus(false)
- if (targetType === 'node') {
- if (eventProxy.data.canClick) {
- this.addEdge(this.targetItem, targetItem)
- return
- } else if (this.targetItem.id === targetItem.id) {
- this.$message({
- type: 'warning',
- message: '节点不能连接自身'
- })
- } else {
- this.$message({
- type: 'warning',
- message: '无法连接至该节点'
- })
- }
- return
- }
- }
- this.clickTargetType = targetType
- if (this.isNode) {
- this.targetItem = this.nodes[this.$nodeMap[targetItem.id]]
- } else {
- const id = targetItem.nodeBondId
- this.targetItem = this.edges.find(edge => edge.nodeBondId === id)
- }
- const event = eventProxy.event.event
- this.$refs.card.$el.style.left = `${Math.min(event.clientX, document.body.clientWidth - 160)}px`
- this.$refs.card.$el.style.top = `${Math.min(event.clientY, document.body.clientHeight - 240)}px`
- event.stopPropagation()
- if (!this.menuVisible) {
- this.menuVisible = true
- document.addEventListener('click', this.closeContentMenu)
- }
- },
- closeContentMenu () {
- if (this.menuVisible) {
- this.menuVisible = false
- document.removeEventListener('click', this.closeContentMenu)
- }
- },
- createOptions (action) {
- let arr = null
- switch (action) {
- case 'create':
- arr = ThirdPartyDeviceOption.all
- break
- case 'addChildNode':
- arr = ThirdPartyDeviceOption.follow[this.targetItem.nodeType]
- break
- case 'addParentNode':
- arr = ThirdPartyDeviceOption.ahead[this.targetItem.nodeType]
- break
- default:
- break
- }
- return arr?.length
- ? arr.map(key => {
- return {
- value: key,
- label: ThirdPartyDeviceInfo[key]
- }
- })
- : null
- },
- showNodeDialog (action) {
- const options = this.createOptions(action)
- if (!options) {
- this.$message({
- type: 'warning',
- message: '暂未能满足执行操作的条件'
- })
- return
- }
- this.item = {
- action,
- nodeType: options[0].value,
- name: '',
- port: 0
- }
- this.thirdPartyDeviceSelectSchema = { options }
- this.$refs.nodeDialog.show()
- },
- onAddNode () {
- this.closeContentMenu()
- this.showNodeDialog('create')
- },
- onAddChildNode () {
- this.closeContentMenu()
- this.showNodeDialog('addChildNode')
- },
- onAddParentNode () {
- this.closeContentMenu()
- this.showNodeDialog('addParentNode')
- },
- onEditNode () {
- this.closeContentMenu()
- this.item = {
- action: 'update',
- ...this.targetItem
- }
- this.$refs.nodeEditDialog.show()
- },
- isExist (type) {
- return SoloThirdPartyDevices.includes(type) && this.nodes.some(({ nodeType }) => nodeType === type)
- },
- addNode (item) {
- if (this.isExist(item.nodeType)) {
- this.$message({
- type: 'warning',
- message: `${ThirdPartyDeviceInfo[item.nodeType]}仅能存在一个`
- })
- return Promise.reject()
- }
- return addNodeToMesh(this.meshId, item).then(({ data }) => {
- this.nodes.push(data)
- this.collectNodes(this.nodes)
- this.onDraw()
- })
- },
- addNodeBeforeNode (item, port) {
- if (this.isExist(item.nodeType)) {
- this.$message({
- type: 'warning',
- message: `${ThirdPartyDeviceInfo[item.nodeType]}仅能存在一个`
- })
- return Promise.reject()
- }
- return addNodeBeforeNode(this.targetItem, item, port).then(({ data }) => {
- this.nodes.push(data.node)
- this.edges.push(data.bonds[0])
- this.collectNodes(this.nodes)
- this.onDraw()
- })
- },
- addNodeAfterNode (item, port) {
- if (this.isExist(item.nodeType)) {
- this.$message({
- type: 'warning',
- message: `${ThirdPartyDeviceInfo[item.nodeType]}仅能存在一个`
- })
- return Promise.reject()
- }
- return addNodeAfterNode(this.targetItem, item, port).then(({ data }) => {
- this.nodes.push(data.node)
- this.edges.push(data.bonds[0])
- this.collectNodes(this.nodes)
- this.onDraw()
- })
- },
- onSubmit (done) {
- const { action, nodeType, name, port } = this.item
- const item = {
- name: name || ThirdPartyDeviceInfo[nodeType],
- nodeType
- }
- switch (action) {
- case 'addParentNode':
- this.addNodeBeforeNode(item, this.needPort ? port : -1).then(done)
- break
- case 'addChildNode':
- if (this.needPort && this.isPortUsed(this.targetItem, port)) {
- return
- }
- this.addNodeAfterNode(item, this.needPort ? port : -1).then(done)
- break
- case 'update':
- if (!name || this.targetItem.name === name) {
- done()
- } else {
- updateNode({
- id: this.targetItem.id,
- ...item
- }).then(() => {
- done()
- this.targetItem.name = name
- this.onDraw()
- })
- }
- break
- default:
- this.addNode(item).then(done)
- break
- }
- },
- isPortUsed ({ id }, targetPort) {
- const edge = this.edges.find(({ preNodeId, port }) => preNodeId === id && port === targetPort)
- if (edge) {
- this.$message({
- type: 'warning',
- message: `端口已被${this.nodes[this.$nodeMap[edge.nextNodeId]].name}占用`
- })
- return true
- }
- return false
- },
- onSubmitPort (done) {
- const { action, port } = this.item
- switch (action) {
- case 'edge':
- if (this.isPortUsed(this.targetItem, port)) {
- return
- }
- this.onAddEdge(this.targetItem, this.$targetNode, port).then(done)
- break
- case 'portEdit':
- if (port === this.targetItem.port) {
- done()
- return
- }
- if (this.isPortUsed(this.nodes[this.$nodeMap[this.targetItem.preNodeId]], port)) {
- return
- }
- updateEdgePort(this.targetItem, port).then(() => {
- done()
- this.targetItem.port = port
- this.onDraw()
- })
- break
- default:
- done()
- break
- }
- },
- onLinkTo () {
- this.closeContentMenu()
- this.$message({
- type: 'success',
- message: '源节点已记录,请选择目标节点'
- })
- this.onChangeLinkStatus(true)
- },
- onChangeLinkStatus (bool) {
- this.$waitTarget = bool
- this.onDraw()
- },
- addEdge (source, target) {
- const sourceId = source.id
- const targetId = target.id
- if (this.edges.some(({ preNodeId, nextNodeId }) => sourceId === preNodeId && targetId === nextNodeId)) {
- this.$message({
- type: 'warning',
- message: '连接已存在,请勿重复连接'
- })
- return
- }
- if (PortThirdPartyDevices.includes(target.nodeType)) {
- this.item = {
- action: 'edge',
- port: 0
- }
- this.$targetNode = target
- this.$refs.portEditDialog.show()
- } else {
- this.onAddEdge(source, target, -1)
- }
- },
- onAddEdge (source, target, port) {
- return addEdgeToMesh(this.meshId, source, target, port).then(({ data }) => {
- this.$targetNode = null
- this.edges.push(data)
- this.onDraw()
- })
- },
- onDel () {
- this.closeContentMenu()
- if (this.isNode) {
- deleteNode(this.targetItem).then(() => {
- const id = this.targetItem.id
- this.nodes.splice(this.nodes.findIndex(node => node.id === id), 1)
- this.edges = this.edges.filter(({ preNodeId, nextNodeId }) => preNodeId !== id && nextNodeId !== id)
- this.collectNodes(this.nodes)
- this.onDraw()
- })
- } else {
- deleteEdge(this.targetItem).then(() => {
- const id = this.targetItem.nodeBondId
- this.edges.splice(this.edges.findIndex(edge => edge.id === id), 1)
- this.collectNodes(this.nodes)
- this.onDraw()
- })
- }
- },
- onToggleInstance () {
- this.closeContentMenu()
- if (this.hasInstance) {
- releaseInstanceFormNode(this.targetItem).then(() => {
- this.targetItem.instanceId = null
- this.targetItem.instance = null
- this.onDraw()
- })
- } else {
- this.$refs.instanceDialog.show()
- }
- },
- onSubmitBind ({ value, done }) {
- if (value.id === this.targetItem.instanceId) {
- done()
- return
- }
- bindInstanceToNode(this.targetItem, value).then(() => {
- done()
- this.targetItem.instanceId = value.id
- this.targetItem.instance = value
- this.onDraw()
- })
- },
- onEditPort () {
- this.closeContentMenu()
- this.item = {
- action: 'portEdit',
- port: this.targetItem.port
- }
- this.$refs.portEditDialog.show()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .c-mesh {
- &__header {
- height: $height--md;
- border-bottom: 1px solid $border;
- }
- }
- .c-contentmenu {
- position: fixed;
- width: 150px;
- z-index: 99;
- &__item {
- & + & {
- padding-top: 6px;
- margin-top: 6px;
- border-top: 1px solid $border;
- }
- }
- }
- </style>
|