HistoryModel.js 89.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* eslint-disable */
import React, { useState, useEffect, useRef, useContext } from 'react';
import classNames from 'classnames';
import moment from 'moment';
import Empty from '@wisdom-components/empty';
import LoadBox from '@wisdom-components/loadbox';
import { message, Modal, ConfigProvider } from 'antd';
import PropTypes from 'prop-types';
import HistoryView from '@wisdom-components/ec_historyview';
import * as go from './js/go';
import GuidedDraggingTool from './js/GuidedDraggingTool';
import TopRotatingTool from './js/RotatingTool';
import BarLink from './js/BarLink';
import WaterFlowControlView from './js/WaterFlowControlView';
15 16 17 18 19 20 21
import {
  getSketchPadList,
  getSketchPadContent,
  getPointAddress,
  getHistoryInfo,
  getStatisticsInfo,
} from './apis';
22 23 24 25 26 27 28 29 30
import {
  deepCopy,
  hexToRgba,
  textStyle,
  querySkipUrl,
  isJson,
  stationData,
  isNumber,
} from './js/utils';
31 32 33 34 35 36 37 38 39 40
import './index.less';

const goJS = go.GraphObject.make;
let online = false;
let imgUrl = null;
let historyInfoParams = [];
let twoID = '';

let myDiagram = null;
let editionArr = [];
李纪文's avatar
李纪文 committed
41
// const guidAggre = {};
李纪文's avatar
李纪文 committed
42
let bindData = [];
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
const stationList = [];

let historyData = []; // 历史数据
let timeData = []; // 历史数据时间列表
let speed = 0; // 历史数据播放当前进度值
let times = 2; // 历史数据播放速度
let play = false; // 历史数据是否播放
let historyParams = {};

const waterFlow = new WaterFlowControlView();

const ConfigurationView = (props) => {
  const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
  const prefixCls = getPrefixCls('ec-configuration-view');
  const [isHIModalVisible, setIsHIModalVisible] = useState(false); // 历史曲线模态框
  const [spinning, setSpinning] = useState(true); // 画板loading
59
  const [spinLoad, setSpinLoad] = useState(false);
60 61 62 63
  const [isEmpty, setIsEmpty] = useState(false); // 画板无数据状态
  const [description, setDescription] = useState(''); // 画板无数据描述

  twoID = `TDG${Date.now().toString(36)}`;
64

65 66
  const ConfigurationRef = useRef();
  const customBack = props.customBack ? props.customBack : () => {};
67 68 69 70 71 72
  const {
    devices = [],
    config,
    isZoom = false,
    flowShow = true,
    deviceName = [],
李纪文's avatar
李纪文 committed
73
    dataType = '历史',
74 75
    statisticType = [],
  } = props;
李纪文's avatar
李纪文 committed
76
  let devicesCode = [];
77
  const globalConfig = window.globalConfig || config;
78
  const siteCodeStr = globalConfig?.userInfo?.LocalSite || globalConfig?.userInfo?.site || '';
79 80 81 82
  let isClose = false;

  /** **********************************获取工艺图画板信息*********************** */
  const getConfiguraList = async () => {
李纪文's avatar
李纪文 committed
83 84
    const url = globalConfig.mainserver ? globalConfig.mainserver : 'https://panda-water.cn/';
    imgUrl = online ? `${url}PandaMonitor/Monitor/` : `/PandaMonitor/Monitor/`;
85 86 87
    // 获取画板信息
    const drawInfo = await getSketchPadList({
      name: props.name,
88
      siteCode: siteCodeStr,
89
      version: '全部',
90
      _site: siteCodeStr,
91 92 93 94 95 96 97 98 99 100
    });
    if (drawInfo.code === 0) {
      const data = drawInfo.data ? (drawInfo.data.list ? drawInfo.data.list : []) : [];
      if (data.length > 0) {
        const num = data.length ? (data[0].num ? data[0].num * 1 : 0) : 0;
        const siteInfo = data.length ? (data[0].siteInfo ? JSON.parse(data[0].siteInfo) : {}) : {};
        for (let i = 0; i < num; i++) {
          const round = parseInt(i / 26);
          const remain = i % 26;
          if (round) {
李纪文's avatar
李纪文 committed
101
            stationList.push(stationData[remain] + round);
102
          } else {
李纪文's avatar
李纪文 committed
103
            stationList.push(stationData[remain]);
104 105
          }
        }
李纪文's avatar
李纪文 committed
106 107 108 109 110 111 112 113 114 115 116 117 118
        const siteInfoArr = Object.getOwnPropertyNames(siteInfo);
        devicesCode = [];
        bindData = [];
        siteInfoArr.forEach((name, index) => {
          const deviceList =
            devices[index] || (siteInfo && siteInfo[name] ? siteInfo[name].Code || '' : '');
          bindData.push({
            code: deviceList,
            name,
            type: siteInfo && siteInfo[name] ? siteInfo[name].Type : '',
          });
          devicesCode.push(deviceList);
        });
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
        getDiagramJson(data[0], siteInfo);
      } else {
        setDescription('咦~未查询到工艺图画板信息哦~');
        setIsEmpty(true);
        setSpinning(false);
        return false;
      }
    } else {
      setDescription('咦~工艺图画板信息报错啦~');
      setIsEmpty(true);
      setSpinning(false);
      return message.error(drawInfo.msg);
    }

    // 获取点表信息
    const pointInfo = await getPointAddress({
李纪文's avatar
李纪文 committed
135
      code: devicesCode.join(','),
136
      _site: siteCodeStr,
137 138 139 140 141 142 143 144
    });
    editionArr = deepCopy(pointInfo && pointInfo.data ? pointInfo.data : [], []);
  };

  /** *********************************节点展示逻辑****************************** */
  const showNodeMethod = (node, list) => {
    const realVal = list.Value * 1;
    let switchState;
李纪文's avatar
李纪文 committed
145
    myDiagram.model.setDataProperty(node, 'realVal', realVal);
146 147 148 149 150 151 152 153 154 155 156
    if (node.switch === '是') {
      switchState = openValState(node.openVal, realVal) ? '开' : '关';
      myDiagram.model.setDataProperty(node, 'switchState', switchState);
    }
    if (!node.shType) return false;
    const patt = /[><=]/gi;
    let shRule = [];
    try {
      switch (node.category) {
        case 'svgCase': // 图片模型
          shRule = ruleOperation(node, realVal);
157 158 159 160 161
          if (node.shType === '模型切换') {
            myDiagram.model.setDataProperty(node, 'imgSrc', shRule ? shRule.attr : node.dtImgSrc);
          } else if (node.shType === '显隐展示') {
            myDiagram.model.setDataProperty(node, 'visible', shRule ? shRule.visible : true);
          }
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
          break;
        case 'nameCase': // 名称模型
          if (node.shType === '文本变化') {
            shRule = ruleOperation(node, realVal);
            myDiagram.model.setDataProperty(
              node,
              'fontStroke',
              shRule ? shRule.attr : node.dtFontStroke,
            );
            myDiagram.model.setDataProperty(node, 'text', shRule ? shRule.text : node.dtText);
          } else {
            shRule = ruleOperation(node, realVal);
            myDiagram.model.setDataProperty(
              node,
              'fillColor',
              hexToRgba(shRule ? shRule.attr : node.fill, node.opacity),
            );
          }
          break;
        case 'valCase': // 实时值模型
182
          const division = node.division || false;
183
          // 动画翻转
李纪文's avatar
李纪文 committed
184 185
          if (node.effect)
            myDiagram.model.setDataProperty(node, 'flip', go.GraphObject.FlipHorizontal);
186
          if (node.shType === '值显示') {
187 188 189 190 191
            myDiagram.model.setDataProperty(
              node,
              'showVal',
              realVal < 0 ? 0 : division ? realVal.toLocaleString() : realVal,
            );
192
          } else {
193 194 195 196 197
            myDiagram.model.setDataProperty(
              node,
              'showVal',
              division ? realVal.toLocaleString() : realVal,
            );
198
          }
199 200 201 202
          // 动画还原
          myTimeout(() => {
            myDiagram.model.setDataProperty(node, 'flip', go.GraphObject.None);
          }, 100);
李纪文's avatar
李纪文 committed
203
          if (node.stateName) return false;
204 205 206 207 208 209
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(
            node,
            'fontStroke',
            shRule ? shRule.attr : node.fontStroke,
          );
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
          break;
        case 'waterCase': // 水池模型
          const height = node.height - node.strokeWidth * 2;
          let waterHight = (realVal * height) / node.poolHight;
          waterHight = waterHight >= height ? height : waterHight;
          myDiagram.model.setDataProperty(node, 'waterHight', waterHight);
          shRule = JSON.parse(node.shRule);
          shRule.forEach((item) => {
            const min = item.min && !isNaN(item.min * 1) ? item.min * 1 : 0;
            const max = item.max && !isNaN(item.max * 1) ? item.max * 1 : 0;
            if (realVal >= min && realVal < max)
              myDiagram.model.setDataProperty(
                node,
                'fillColor',
                hexToRgba(item.attr ? item.attr : node.fill, node.fillAlpha),
              );
          });
          break;
        case 'switchCase': // 开关模型
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(
            node,
            'fillColor',
            hexToRgba(shRule ? shRule.attr : node.fill, node.opacity),
          );
          myDiagram.model.setDataProperty(node, 'switch', shRule ? '是' : '否');
          break;
        case 'rotateCase': // 状态模型
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(node, 'imgSrc', shRule ? shRule.attr : node.dtImgSrc);
          break;
        case 'pointCase': // 点状态模型
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(
            node,
            'fillColor',
            hexToRgba(shRule ? shRule.attr : node.fill, node.opacity),
          );
          break;
        case 'blenderCase': // 搅拌机模型
          break;
        case 'HBar': // 合管模型
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(node, 'stroke', shRule ? shRule.attr : node.stroke);
          myDiagram.model.setDataProperty(
            node,
            'waterStroke',
            shRule ? shRule.text : node.waterStroke,
          );
          break;
        case 'speedCase': // 进度条模型
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(
            node,
            'fillColor',
            hexToRgba(shRule ? shRule.attr : node.fill, node.opacity),
          );
          const { width } = node;
          let speedWidth = (realVal * width) / node.speedWidth;
          speedWidth = speedWidth >= width ? width : speedWidth;
          myDiagram.model.setDataProperty(node, 'lineWidth', speedWidth);
          break;
        case 'modelCase': // 模板块模型
          shRule = ruleOperation(node, realVal);
274 275 276 277 278 279 280 281 282
          if (node.shType === '层级展示') {
            myDiagram.model.setDataProperty(
              node,
              'zOrder',
              shRule ? shRule.text * 1 || node.dtzOrder : node.dtzOrder,
            );
          } else if (node.shType === '显隐展示') {
            myDiagram.model.setDataProperty(node, 'visible', shRule ? shRule.visible : true);
          }
283 284 285
          break;
        case 'ellipseCase': // 圆形模型
          shRule = ruleOperation(node, realVal);
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
          if (node.shType === '层级展示') {
            myDiagram.model.setDataProperty(
              node,
              'zOrder',
              shRule ? shRule.text * 1 || node.dtzOrder : node.dtzOrder,
            );
          } else if (node.shType === '显隐展示') {
            myDiagram.model.setDataProperty(node, 'visible', shRule ? shRule.visible : true);
          }
          break;
        case 'imgCase': // 图片模型
          shRule = ruleOperation(node, realVal);
          if (node.shType === '层级展示') {
            myDiagram.model.setDataProperty(
              node,
              'zOrder',
              shRule ? shRule.text * 1 || node.dtzOrder : node.dtzOrder,
            );
          } else if (node.shType === '显隐展示') {
            myDiagram.model.setDataProperty(node, 'visible', shRule ? shRule.visible : true);
          }
307
          break;
308 309 310 311 312 313
        case 'groupCase': // 分组模型
          shRule = ruleOperation(node, realVal);
          if (node.shType === '显隐展示') {
            myDiagram.model.setDataProperty(node, 'visible', shRule ? shRule.visible : true);
          }
          break;
314 315 316 317
        default:
          break;
      }
    } catch (err) {
318
      // console.log(err);
319 320 321
    }
  };

李纪文's avatar
李纪文 committed
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
  /** *********************************节点状态展示逻辑****************************** */
  const stateMethod = (node, list) => {
    const realVal = list.Value * 1;
    if (!node.shType) return false;
    let shRule = [];
    try {
      switch (node.category) {
        case 'valCase': // 实时值模型
          // 颜色规则
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(
            node,
            'fontStroke',
            shRule ? shRule.attr : node.fontStroke,
          );
          break;
        default:
          break;
      }
    } catch (err) {
342
      // console.log(err);
李纪文's avatar
李纪文 committed
343 344 345
    }
  };

346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
  /** ***********************************展示规则运算********************************* */
  const ruleOperation = (node, realVal) => {
    const patt = /[><=]/gi;
    const shRule = JSON.parse(node.shRule).find((rule) => {
      if (rule.val.toString().match(patt)) {
        const ruleStr = 'if(' + rule.val + '){ return true } else { return false }';
        try {
          return new Function('x', 'X', ruleStr)(realVal, realVal);
        } catch (err) {
          return false;
        }
      } else {
        return rule.val.toString().split(',').indexOf(realVal.toString()) > -1;
      }
    });
    return shRule;
  };

  /** ***********************************运行值规则运算********************************* */
  const openValState = (openVal, realVal) => {
    const patt = /[><=]/gi;
    if (openVal.toString().match(patt)) {
      const ruleStr = 'if(' + openVal + '){ return true } else { return false }';
      try {
        return new Function('x', 'X', ruleStr)(realVal, realVal);
      } catch (err) {
        return false;
      }
    } else {
      return openVal.toString().split(',').indexOf(realVal.toString()) > -1;
    }
  };

  /** **************************************合管****************************************** */
  const changLinkRouting = (e) => {
    const link = e.subject;
    if (link.toNode == null || link.fromNode == null) {
      return false;
    }
    if (link.fromNode.category === 'HBar' || link.toNode.category === 'HBar') {
      e.subject.routing = go.Link.Normal;
    }
  };

  /** ************************************创建连接点*********************************** */
  // 创建一个port,ID为name,spot控制其怎么被连接,放置于node的什么位置,output/input决定其哪里可以from和to
  const makePort = (name, spot, output, input) => {
    // the port is basically just a small transparent square
    return goJS(go.Shape, 'Circle', {
      fill: null, // not seen, by default; set to a translucent gray by showSmallPorts, defined below
      stroke: null,
      desiredSize: new go.Size(7, 7),
      alignment: spot, // align the port on the main Shape
      alignmentFocus: spot, // just inside the Shape
      portId: name, // declare this object to be a "port"
      fromSpot: spot,
      toSpot: spot, // declare where links may connect at this port
      fromLinkable: output,
      toLinkable: input, // declare whether the user may draw links to/from here
      cursor: 'pointer', // show a different cursor to indicate potential link point
    });
  };

  /** 动画设置*********************************************** */
  const animationSvg = () => {
    const diagram = myDiagram;
    const oldskips = diagram.skipsUndoManager;
    diagram.skipsUndoManager = true;
    diagram.nodes.map((node) => {
      const shape = node.findObject('animateSvg');
      if (!shape) return false;
      const gpRule = JSON.parse(node.data.gpRule || '[]').concat();
      const amTime = node.data.amTime || 0;
      if (!amTime) return false;
      gpRule.map((item) => {
        mySetInterval(() => {
          const { time = 0, fill = 100, scale = 1, angle = 0 } = item;
          myTimeout(() => {
            shape.opacity = (fill || 100) / 100;
            shape.scale = (scale || 1) * 1;
            shape.angle = (angle || 0) * 1;
          }, 0.01 * amTime * time);
        }, amTime * 1);
      });
    });
    diagram.skipsUndoManager = oldskips;
  };

  const myTimeout = (fn, delay) => {
    let timer;
    const stime = +new Date();
    const myLoop = () => {
      if (isClose) return timer && cancelAnimationFrame(timer);
      const etime = +new Date();
      if (stime + delay <= etime) {
        fn();
        return;
      }
      timer = requestAnimationFrame(myLoop);
    };
    timer = requestAnimationFrame(myLoop);
    return () => {
      cancelAnimationFrame(timer);
    };
  };

  const mySetInterval = (fn, interval) => {
    let timer;
    let stime = +new Date();
    let etime;
    let myLoop = () => {
      etime = +new Date();
      if (isClose) return timer && cancelAnimationFrame(timer);
      timer = requestAnimationFrame(myLoop);
      if (etime - stime >= interval) {
        stime = etime = +new Date();
        fn();
      }
    };
    return requestAnimationFrame(myLoop);
  };

  /** ******************************************水池效果****************************** */
  const waterSvg = () => {
    const diagram = myDiagram;
    // poolWater = setInterval(() => {
    mySetInterval(() => {
      const oldskips = diagram.skipsUndoManager;
      diagram.skipsUndoManager = true;
      diagram.nodes.each((node) => {
        const shape = node.findObject('waterSvg');
        if (!shape) return false;
        const range = (shape.range ? shape.range : 0) + 0.5;
        shape.range = range >= 5 ? 0 : range;
        shape.geometryString = `F M0 ${shape.range} L${shape.width} ${5 - shape.range} L${
          shape.width
        } ${shape.height} L0 ${shape.height}z`;
      });
      diagram.skipsUndoManager = oldskips;
    }, 100);
  };

  /** ***********************************水流效果********************************** */
  const loop = () => {
    const diagram = myDiagram;
    // tubeWater = setInterval(() => {
    mySetInterval(() => {
      const oldskips = diagram.skipsUndoManager;
      diagram.skipsUndoManager = true;
      diagram.links.each((link) => {
        const shape = link.findObject('PIPE');
        if (!shape) return false;
        if (link.data.isHavingDash) {
          link.zOrder = 1;
          shape.strokeWidth = link.data.defaultWidth || 3;
          const off = shape.strokeDashOffset - 3;
          shape.strokeDashOffset = off <= 0 ? 60 : off;
        } else {
          link.zOrder = 0;
          shape.strokeWidth = 0;
          shape.strokeDashOffset = 0;
        }
      });
      diagram.skipsUndoManager = oldskips;
    }, 60);
  };

  /** **************************************泵状态效果*************************** */
  const rotateSvg = () => {
    const diagram = myDiagram;
    // pumpType = setInterval(() => {
    mySetInterval(() => {
      const oldskips = diagram.skipsUndoManager;
      diagram.skipsUndoManager = true;
      diagram.nodes.each((node) => {
        const shape = node.findObject('rotateSvg');
        if (!shape) return false;
        const _node = node.data;
        if (_node.switchState !== '开' || _node.realVal === '--' || _node.switch !== '是')
          return false;
        const off = shape.angle + 60;
        shape.angle = off <= 360 ? off : 0;
      });
      diagram.skipsUndoManager = oldskips;
    }, 60);
  };

  /** *********************************搅拌机状态效果************************* */
  const blenderSvg = () => {
    const diagram = myDiagram;
    // blenderType = setInterval(() => {
    mySetInterval(() => {
      const oldskips = diagram.skipsUndoManager;
      diagram.skipsUndoManager = true;
      diagram.nodes.each((node) => {
        const shape = node.findObject('blenderSvg');
        if (!shape) return false;
        const _node = node.data;
        const srcStr = _node.dtImgSrc.split('/').pop();
        if (_node.switchState !== '开' || _node.realVal === '--' || _node.switch !== '是') {
          shape.source = require(`./images/组态/状态/${srcStr.replace(/[0-9]/gi, 1)}`);
          return false;
        }
        shape.flag = shape.flag || 1;
        const num = shape.source.match(/\d/)[0] * 1;
        let _num = 1;
        if (shape.flag === 1) {
          _num = num < 5 ? num + 1 : 4;
          if (num >= 5) shape.flag = 2;
        } else {
          _num = num > 1 ? num - 1 : 2;
          if (num <= 1) shape.flag = 1;
        }
        shape.source = require(`./images/组态/状态/${srcStr.replace(/[0-9]/gi, _num)}`);
      });
      diagram.skipsUndoManager = oldskips;
    }, 100);
  };

  /** *******************将myDiagram.model中的信息展示在画板上*********************** */
  const loadDiagramProperties = (e) => {
    const pos = myDiagram.model.modelData.position;
    if (pos) myDiagram.initialPosition = go.Point.parse(pos);
  };

  /** *******************绑定角色可见*************************** */
  const roleVisibleBinding = () => {
    return new go.Binding('visible', '', function (data) {
      if (!data.roles) return true;
      const roles = data.roles.split(',');
      const curRoleMap = {};
      globalConfig &&
        globalConfig.userInfo &&
        globalConfig.userInfo.roles &&
        globalConfig.userInfo.roles.forEach(function (role) {
          curRoleMap[role.OID] = role;
        });
      const samerole = roles.filter(function (roleID) {
        return !!curRoleMap[roleID];
      });
      return samerole.length > 0;
    });
  };

  /** ***********************************节点样式********************************** */
  const nodeStyle = () => {
    return [
      new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
      {
        locationSpot: go.Spot.Center,
      },
    ];
  };

  /** ************************************联网判断******************************* */
  const onlineMethod = (pathImg, url) => {
    const ImgObj = new Image();
    ImgObj.src = pathImg;
    ImgObj.onload = () => {
      online = ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0);
      getConfiguraList();
    };
    ImgObj.onerror = () => {
      online = false;
      getConfiguraList();
    };
  };

  useEffect(() => {
李纪文's avatar
李纪文 committed
615
    if (!props.name) {
616 617 618 619 620 621 622 623 624
      setDescription('咦~工艺图配置信息不全哦~');
      setIsEmpty(true);
      setSpinning(false);
      return false;
    }
    const url = globalConfig.mainserver ? globalConfig.mainserver : 'https://panda-water.cn/';
    onlineMethod(`${url}civweb4/assets/images/bootPage/熊猫图标.png`, url);
    return () => {
      isClose = true;
625 626 627 628
      if (myDiagram) {
        myDiagram.div = null;
        myDiagram = null;
      }
629 630 631 632 633 634 635 636 637 638 639 640 641 642
    };
  }, []);

  useEffect(() => {
    play = props.play || false;
    times = props.times || 2;
  }, [props.play, props.times]);

  useEffect(() => {
    speed = props.speed || 0;
  }, [props.speed]);

  useEffect(() => {
    historyParams = props.params;
643 644
    if (dataType === '历史') getHistoryData(false);
    if (dataType === '统计') getStatisticsData(false);
645 646 647 648 649 650 651 652
  }, [props.params]);

  /** ************************************获取画板JSON******************************* */
  const getDiagramJson = async (list, siteInfo) => {
    const response = await getSketchPadContent({
      dimension: list.dimension,
      siteCode: list.siteCode,
      fileName: list.deployURL.split('\\').pop(),
653
      _site: siteCodeStr,
654 655 656 657 658 659 660 661 662 663 664
    });
    if (response.code === 0) {
      if (isClose) return false;
      const fromJson = response.data
        ? response.data
        : {
            linkFromPortIdProperty: 'fromPort',
            linkToPortIdProperty: 'toPort',
            nodeDataArray: [],
            linkDataArray: [],
          };
李纪文's avatar
李纪文 committed
665 666 667 668 669 670 671 672 673
      // bindData = [];
      // devices.forEach((item, index) => {
      //   const name = `设备${stationList[index]}`;
      //   bindData.push({
      //     code: item,
      //     name,
      //     type: siteInfo && siteInfo[name] ? siteInfo[name].Type : '',
      //   });
      // });
李纪文's avatar
李纪文 committed
674
      diagramRender(typeof fromJson === 'string' ? fromJson : JSON.stringify(fromJson), list);
675 676
      if (dataType === '历史') getHistoryData(true);
      if (dataType === '统计') getStatisticsData(true);
677 678 679 680 681 682 683 684
    } else {
      message.error(response.msg);
    }
  };

  /** ************************************历史数据获取******************************* */
  const getHistoryData = async (flag) => {
    try {
685 686
      if (!myDiagram) return false;
      setSpinLoad(true);
687 688 689
      speed = 0;
      const json = JSON.parse(myDiagram.model.toJson());
      const jsonCopy = JSON.parse(JSON.stringify(json));
李纪文's avatar
李纪文 committed
690 691
      const acrossTables = [];
      bindData.map((list) => {
692 693 694 695 696 697 698
        let sensors = [];
        jsonCopy.nodeDataArray.forEach((item) => {
          item.shName && item.stationName === list.name && sensors.push(item.shName);
        });
        jsonCopy.linkDataArray.forEach((item) => {
          item.shName && item.stationName === list.name && sensors.push(item.shName);
        });
李纪文's avatar
李纪文 committed
699
        if (sensors.length && list.code)
李纪文's avatar
李纪文 committed
700 701 702 703 704
          acrossTables.push({
            deviceType: list.type,
            sensors: Array.from(new Set(sensors)).join(','),
            deviceCode: list.code,
          });
705 706
      });
      const params = {
707 708
        isDilute: false,
        zoom: '30',
709 710 711 712 713 714 715 716 717 718 719 720 721
        unit: 'h',
        ignoreOutliers: false,
        isVertical: false, // 是否查询竖表
        dateFrom: moment(new Date()).format('yyyy-MM-DD 00:00:00'),
        dateTo: moment(new Date()).format('yyyy-MM-DD 23:59:59'),
        ...historyParams,
        acrossTables,
      };
      const results = await getHistoryInfo(params);
      historyData = results?.data || [];
      let timeArr = [];
      historyData.forEach((item) => {
        const timeList = item.dataModel.map((list) => {
李纪文's avatar
李纪文 committed
722
          return moment(list.pt).format('yyyy-MM-DD HH:mm:ss');
723 724 725 726 727 728 729 730 731
        });
        timeArr = timeArr.concat(timeList);
      });
      const _timeData = dataUnique(timeArr);
      timeData = _timeData.sort(function (a, b) {
        return new Date(a).getTime() - new Date(b).getTime();
      });
      chartHistoryDataRender(historyData);
      if (flag) historyTimeRender();
732 733 734 735
      setSpinLoad(false);
    } catch (err) {
      setSpinLoad(false);
    }
736 737
  };

738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
  /** ************************************统计数据获取******************************* */
  const getStatisticsData = async (flag) => {
    try {
      if (!myDiagram) return false;
      setSpinLoad(true);
      speed = 0;
      const json = JSON.parse(myDiagram.model.toJson());
      const jsonCopy = JSON.parse(JSON.stringify(json));
      const acrossTables = [];
      bindData.map((list) => {
        let sensors = [];
        jsonCopy.nodeDataArray.forEach((item) => {
          item.shName && item.stationName === list.name && sensors.push(item.shName);
        });
        jsonCopy.linkDataArray.forEach((item) => {
          item.shName && item.stationName === list.name && sensors.push(item.shName);
        });
        if (sensors.length && list.code)
          acrossTables.push({
            accountName: list.type,
            nameTypeList: sensors.map((item) => {
              const listType = statisticType.find((arr) => {
                return arr.name === item;
761
              });
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
              return {
                name: item,
                type: listType?.type || 'Sub',
              };
            }),
            dateFrom: historyParams.dateFrom || moment(new Date()).format('yyyy-MM-DD 00:00:00'),
            dateTo: historyParams.dateTo || moment(new Date()).format('yyyy-MM-DD 23:59:59'),
            deviceCode: list.code,
          });
      });
      const params = {
        pageIndex: 1,
        pageSize: 999,
        q_DeviceReports: acrossTables,
        dateType: 'day',
        ...historyParams,
      };
      const results = await getStatisticsInfo(params);
      const res = results?.data?.list || [];
      let timeArr = [];
      let statisticsData = [];
      res.forEach((item) => {
        const listData = item.dNameDataList.map((list) => {
          return {
            code: item.code,
            eName: item.eName,
            eShortName: item.eShortName,
            ...list,
          };
        });
        statisticsData = statisticsData.concat(listData);
      });
      historyData = [].concat(statisticsData);
      historyData.forEach((item) => {
        const timeList = item.nameDate.map((list) => {
          return moment(list.time).format('yyyy-MM-DD HH:mm:ss');
        });
        timeArr = timeArr.concat(timeList);
      });
      const _timeData = dataUnique(timeArr);
      timeData = _timeData.sort(function (a, b) {
        return new Date(a).getTime() - new Date(b).getTime();
      });
      chartStatisticsDataRender(historyData);
      if (flag) historyTimeRender();
      setSpinLoad(false);
    } catch (err) {
      setSpinLoad(false);
    }
  };

813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
  /** ****************************************数据去重******************************* */
  const dataUnique = (arr) => {
    return Array.from(new Set(arr));
  };

  /** ***********************************图表历史数据处理**************************** */
  const chartHistoryDataRender = (mqttData) => {
    const time = timeData[speed];
    loopLoadMethod(time);
    const json = JSON.parse(myDiagram.model.toJson());
    const jsonCopy = JSON.parse(JSON.stringify(json));
    const oldJson = deepCopy(jsonCopy);
    try {
      jsonCopy.linkDataArray.forEach((item) => {
        if (!item.shName || item.shType !== '线条展示') return false;
        mqttData.forEach((list) => {
          const bindList = bindData.find((arr) => {
            return arr.code === list.stationCode;
          });
          const pvList = list.dataModel.find((arr) => {
李纪文's avatar
李纪文 committed
833
            return moment(arr.pt).format('yyyy-MM-DD HH:mm:ss') === time;
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
          });
          if (!bindList || item.stationName !== bindList.name) return false;
          if (
            !pvList ||
            pvList.PV === null ||
            list.sensorName !== item.shName ||
            item.realVal === pvList.pv
          )
            return false;
          item.realVal = pvList.pv * 1;
          const shRule = ruleOperation(item, item.realVal);
          if (shRule) {
            myDiagram.model.setDataProperty(item, 'stroke', shRule.attr);
            myDiagram.model.setDataProperty(item, 'waterStroke', shRule.text);
          } else {
            myDiagram.model.setDataProperty(item, 'stroke', item.stroke);
            myDiagram.model.setDataProperty(item, 'waterStroke', item.waterStroke);
          }
        });
      });
    } catch (e) {
      // 水流展示
    }

    try {
      jsonCopy.nodeDataArray.forEach((item) => {
        if (!(item.shName || item.figure === 'updateTime')) return false;
        const node = myDiagram.model.findNodeDataForKey(item.key);
        mqttData.forEach((list) => {
          if (node.figure === 'updateTime') {
            myDiagram.model.setDataProperty(
              node,
              'text',
              moment(list.pt).format('yyyy-MM-DD HH:mm:ss'),
            );
            return false;
          }
          const bindList = bindData.find((arr) => {
            return arr.code === list.stationCode;
          });
          const pvList = list.dataModel.find((arr) => {
李纪文's avatar
李纪文 committed
875
            return moment(arr.pt).format('yyyy-MM-DD HH:mm:ss') === time;
876 877 878
          });
          if (!bindList || item.stationName !== bindList.name) return false;
          if (
李纪文's avatar
李纪文 committed
879 880 881 882 883
            (!pvList ||
              pvList.pv === null ||
              list.sensorName !== item.shName ||
              item.realVal === pvList.pv) &&
            list.sensorName !== item.stateName
884 885 886
          )
            return false;
          pvList.Value = pvList.pv;
李纪文's avatar
李纪文 committed
887 888
          if (list.sensorName === item.shName) showNodeMethod(node, pvList);
          if (list.sensorName === item.stateName) stateMethod(node, pvList);
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
        });
      });
    } catch (e) {
      // 节点展示
    }

    try {
      const jsonModel = waterFlow.waterFlowControlByDiagramJson(oldJson, myDiagram);
      if (!jsonModel) return false;
      const oldLink = myDiagram.model.linkDataArray;
      const dataLink = [];
      jsonModel.linkDataArray.forEach((item, index) => {
        const list = Object.assign({}, oldLink[index]);
        list.isHavingDash = item.isHavingDash;
        dataLink.push(list);
      });
      jsonModel.nodeDataArray.forEach((item) => {
        if (item.category === 'HBar') {
          const node = myDiagram.model.findNodeDataForKey(item.key);
          const waterStroke = item.typeDash ? 'transparent' : item.hBarClolor;
          if (item.typeDash != node.typeDash) {
            myDiagram.model.setDataProperty(node, 'waterStroke', waterStroke);
            myDiagram.model.setDataProperty(node, 'typeDash', item.typeDash);
          }
        }
      });
      dataLink.forEach((item) => {
        const node = myDiagram.findLinkForData(item);
        if (item.isHavingDash != node.data.isHavingDash)
          myDiagram.model.setDataProperty(node.data, 'isHavingDash', item.isHavingDash);
      });
    } catch (e) {
      // 水流展示
    }
  };

925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
  /** ***********************************图表历史数据处理**************************** */
  const chartStatisticsDataRender = (mqttData) => {
    const time = timeData[speed];
    loopLoadMethod(time);
    const json = JSON.parse(myDiagram.model.toJson());
    const jsonCopy = JSON.parse(JSON.stringify(json));
    const oldJson = deepCopy(jsonCopy);
    try {
      jsonCopy.linkDataArray.forEach((item) => {
        if (!item.shName || item.shType !== '线条展示') return false;
        mqttData.forEach((list) => {
          const bindList = bindData.find((arr) => {
            return arr.code === list.code;
          });
          const pvList = list.nameDate.find((arr) => {
            return moment(arr.time).format('yyyy-MM-DD HH:mm:ss') === time;
          });
          if (!bindList || item.stationName !== bindList.name) return false;
          if (
            !pvList ||
            pvList.value === null ||
            list.dName !== item.shName ||
            item.realVal === pvList.value
          )
            return false;
          item.realVal = pvList.value * 1;
          const shRule = ruleOperation(item, item.realVal);
          if (shRule) {
            myDiagram.model.setDataProperty(item, 'stroke', shRule.attr);
            myDiagram.model.setDataProperty(item, 'waterStroke', shRule.text);
          } else {
            myDiagram.model.setDataProperty(item, 'stroke', item.stroke);
            myDiagram.model.setDataProperty(item, 'waterStroke', item.waterStroke);
          }
        });
      });
    } catch (e) {
      // 水流展示
    }

    try {
      jsonCopy.nodeDataArray.forEach((item) => {
        if (!(item.shName || item.figure === 'updateTime')) return false;
        const node = myDiagram.model.findNodeDataForKey(item.key);
        mqttData.forEach((list) => {
          if (node.figure === 'updateTime') {
            myDiagram.model.setDataProperty(
              node,
              'text',
              moment(list.value).format('yyyy-MM-DD HH:mm:ss'),
            );
            return false;
          }
          const bindList = bindData.find((arr) => {
            return arr.code === list.code;
          });
          const pvList = list.nameDate.find((arr) => {
            return moment(arr.time).format('yyyy-MM-DD HH:mm:ss') === time;
          });
          if (!bindList || item.stationName !== bindList.name) return false;
          if (
            (!pvList ||
              pvList.value === null ||
              list.dName !== item.shName ||
              item.realVal === pvList.value) &&
            list.dName !== item.stateName
          )
            return false;
          pvList.Value = pvList.value;
          if (list.dName === item.shName) showNodeMethod(node, pvList);
          if (list.dName === item.stateName) stateMethod(node, pvList);
        });
      });
    } catch (e) {
      // 节点展示
    }

    try {
      const jsonModel = waterFlow.waterFlowControlByDiagramJson(oldJson, myDiagram);
      if (!jsonModel) return false;
      const oldLink = myDiagram.model.linkDataArray;
      const dataLink = [];
      jsonModel.linkDataArray.forEach((item, index) => {
        const list = Object.assign({}, oldLink[index]);
        list.isHavingDash = item.isHavingDash;
        dataLink.push(list);
      });
      jsonModel.nodeDataArray.forEach((item) => {
        if (item.category === 'HBar') {
          const node = myDiagram.model.findNodeDataForKey(item.key);
          const waterStroke = item.typeDash ? 'transparent' : item.hBarClolor;
          if (item.typeDash != node.typeDash) {
            myDiagram.model.setDataProperty(node, 'waterStroke', waterStroke);
            myDiagram.model.setDataProperty(node, 'typeDash', item.typeDash);
          }
        }
      });
      dataLink.forEach((item) => {
        const node = myDiagram.findLinkForData(item);
        if (item.isHavingDash != node.data.isHavingDash)
          myDiagram.model.setDataProperty(node.data, 'isHavingDash', item.isHavingDash);
      });
    } catch (e) {
      // 水流展示
    }
  };

1032 1033 1034 1035 1036 1037 1038
  /** **********************历史数据循环**************************** */
  const historyTimeRender = () => {
    historyInterval(() => {
      if (!play || !historyData.length || !timeData.length) return false;
      speed = speed + 1;
      if (speed >= timeData.length) {
        play = false;
李纪文's avatar
李纪文 committed
1039
        loopLoadMethod(timeData.slice(-1)[0]);
1040 1041
        return false;
      }
1042 1043
      if (dataType === '历史') chartHistoryDataRender(historyData);
      if (dataType === '统计') chartStatisticsDataRender(historyData);
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
    });
  };

  /** **********************历史数据循环函数**************************** */
  const historyInterval = (fn) => {
    let timer;
    let stime = +new Date();
    let etime;
    let myLoop = () => {
      etime = +new Date();
      if (isClose) return timer && cancelAnimationFrame(timer);
      if (etime - stime >= times * 1000) {
        stime = etime = +new Date();
        fn();
      }
      timer = requestAnimationFrame(myLoop);
    };
    return requestAnimationFrame(myLoop);
  };

  // 数据回调
  const loopLoadMethod = (time) => {
    props.callback && props.callback(speed, timeData.length, play, time);
  };

1069
  /** **************************************跳转方法****************************************** */
李纪文's avatar
李纪文 committed
1070
  const menuJumpMethod = (data) => {
1071 1072
    const opRule = JSON.parse(data.opRule);
    const widget = opRule && opRule.widget ? opRule.widget : '';
李纪文's avatar
李纪文 committed
1073 1074
    const params =
      opRule && opRule.params ? (isJson(opRule.params) && JSON.parse(opRule.params)) || {} : {};
1075 1076
    const list = querySkipUrl(globalConfig?.widgets || [], widget);
    if (!list || !widget) return false;
李纪文's avatar
李纪文 committed
1077
    window.history.pushState(params, null, `/civbase/${list.product || 'civweb4'}/${list.url}`);
1078 1079
  };

1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
  /** **************************************历史模态渲染****************************************** */
  const historyModalRender = (data, list) => {
    historyInfoParams = [
      {
        deviceCode: list.code,
        sensors: data.shName,
        deviceType: list.type,
      },
    ];
    setIsHIModalVisible(true);
  };

  /** **********************************画布渲染************************************ */
李纪文's avatar
李纪文 committed
1093
  const diagramRender = (jsonStr, chartInfo) => {
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
    myDiagram = goJS(
      go.Diagram,
      twoID, // must name or refer to the DIV HTML element
      {
        initialContentAlignment: go.Spot.Center,
        contentAlignment: go.Spot.Center,
        allowDrop: false, // must be true to accept drops from the Palette 右边的面板允许防止图形
        draggingTool: new GuidedDraggingTool(),
        allowZoom: isZoom ? true : false,
        allowSelect: false,
        'draggingTool.dragsLink': true,
        isReadOnly: true,
        autoScale: isZoom ? go.Diagram.None : go.Diagram.Uniform, // 自适应,默认不自适应
        initialAutoScale: go.Diagram.Uniform, // 自适应,默认不自适应
        'draggingTool.isGridSnapEnabled': true,
        'linkingTool.isUnconnectedLinkValid': true,
        'animationManager.duration': 100,
        allowHorizontalScroll: isZoom ? true : false,
李纪文's avatar
李纪文 committed
1112
        // padding: 20,
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
        allowVerticalScroll: isZoom ? true : false,
        'linkingTool.portGravity': 20,
        'relinkingTool.isUnconnectedLinkValid': true,
        'relinkingTool.portGravity': 20,
        'draggingTool.horizontalGuidelineColor': 'blue',
        'draggingTool.verticalGuidelineColor': 'blue',
        'draggingTool.centerGuidelineColor': 'green',
        rotatingTool: goJS(TopRotatingTool), // defined below
        'rotatingTool.snapAngleMultiple': 15,
        'rotatingTool.snapAngleEpsilon': 15,
        'undoManager.isEnabled': true,
        LinkDrawn: changLinkRouting,
        // LinkReshaped: (e) => {
        //   e.subject.routing = go.Link.Orthogonal;
        // },
        'linkingTool.direction': go.LinkingTool.ForwardsOnly,
      },
    );

李纪文's avatar
李纪文 committed
1132 1133 1134 1135 1136 1137
    /** **********************************分组模型************************************* */
    myDiagram.groupTemplate =
      ('groupCase',
      goJS(
        go.Group,
        'Auto',
1138
        { ungroupable: true, zOrder: 1, visible: true },
1139 1140 1141
        {
          // 设置其可选择
          selectable: false,
1142
          layerName: 'Background',
1143
        },
1144
        new go.Binding('visible', 'visible').makeTwoWay(),
李纪文's avatar
李纪文 committed
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
        goJS(
          go.Shape,
          'RoundedRectangle', // surrounds everything
          {
            parameter1: 10,
            fill: 'transparent',
            strokeWidth: 0,
            stroke: 'transparent',
          },
        ),
        goJS(
          go.Panel,
          'Auto', // position header above the subgraph
          goJS(
            go.Placeholder, // represents area for all member parts
            { background: 'transparent' },
          ),
        ),
      ));

1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
    // 自定义矩形
    go.Shape.defineFigureGenerator('RoundedRectanglePlus', (shape, w, h) => {
      // this figure takes one parameter, the size of the corner
      let p1 = Infinity; // default corner size
      if (shape !== null) {
        const param1 = shape.parameter1;
        if (!isNaN(param1) && param1 >= 0) p1 = param1; // can't be negative or NaN
      }
      p1 = Math.min(p1, w / 2);
      p1 = Math.min(p1, h / 2); // limit by whole height or by half height?
      const geo = new go.Geometry();
      // a single figure consisting of straight lines and quarter-circle arcs
      geo.add(
        new go.PathFigure(0, p1)
          .add(new go.PathSegment(go.PathSegment.Arc, 180, 90, p1, p1, p1, p1))
          .add(new go.PathSegment(go.PathSegment.Line, w - p1, 0))
          .add(new go.PathSegment(go.PathSegment.Arc, 270, 90, w - p1, p1, p1, p1))
          .add(new go.PathSegment(go.PathSegment.Arc, 0, 90, w - p1, h - p1, p1, p1))
          .add(new go.PathSegment(go.PathSegment.Arc, 90, 90, p1, h - p1, p1, p1).close()),
      );
      // don't intersect with two top corners when used in an "Auto" Panel
      geo.spot1 = new go.Spot(0, 0, 0.3 * p1, 0.3 * p1);
      geo.spot2 = new go.Spot(1, 1, -0.3 * p1, 0);
      return geo;
    });

1191
    /** *********************************节点模板************************************* */
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
    // 背景模板定义
    myDiagram.nodeTemplateMap.add(
      'bgCase',
      goJS(
        go.Node,
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 0 },
        // new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('visible', 'visible').makeTwoWay(),
        new go.Binding('angle').makeTwoWay(),
        {
          // 设置其可选择
          selectable: false,
          layerName: 'Background',
        },
        // the main object is a Panel that surrounds a TextBlock with a Shape ~图形:Panel包围着TextBlock
        goJS(
          go.Panel,
          'Auto',
          {
            name: 'PANEL',
          },
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
          goJS(
            go.Picture,
            { width: 56, height: 56, scale: 1, source: '', background: '#2e3343' },
            new go.Binding('source', 'imgSrc', function (v) {
李纪文's avatar
李纪文 committed
1220 1221
              const own = myDiagram ? myDiagram.model.findNodeDataForKey('bgCase') : {};
              props.bgMethod && props.bgMethod(own);
1222
              return v
1223
                ? `/PandaMonitor/Monitor/SketchPad/PreviewResource?name=${v}&_site=${siteCodeStr}`
1224
                : '';
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234
            }).makeTwoWay(),
            new go.Binding('scale', 'scale').makeTwoWay(),
            new go.Binding('width', 'width').makeTwoWay(),
            new go.Binding('height', 'height').makeTwoWay(),
            new go.Binding('background', 'background').makeTwoWay(),
          ),
        ),
      ),
    );

1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
    // 表格节点定义
    myDiagram.nodeTemplateMap.add(
      'tableCase',
      goJS(
        go.Node,
        'Auto',
        { locationSpot: go.Spot.Center, zOrder: 1 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        goJS(
          go.Shape,
          {
            fill: 'white',
            strokeWidth: 1,
            stroke: '#808080',
          },
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
        ),
        goJS(
          go.Panel,
          'Table',
          {
            padding: 0,
            defaultRowSeparatorStroke: '#808080',
            defaultColumnSeparatorStroke: '#808080',
            defaultRowSeparatorStrokeWidth: 1,
            defaultColumnSeparatorStrokeWidth: 1,
            background: '#ffffff',
          },
          new go.Binding('background', 'fillColor').makeTwoWay(),
          new go.Binding('defaultRowSeparatorStroke', 'stroke').makeTwoWay(),
          new go.Binding('defaultRowSeparatorStrokeWidth', 'strokeWidth').makeTwoWay(),
          new go.Binding('defaultColumnSeparatorStroke', 'stroke').makeTwoWay(),
          new go.Binding('defaultColumnSeparatorStrokeWidth', 'strokeWidth').makeTwoWay(),
          new go.Binding('itemArray', 'content').makeTwoWay(),
          {
            // 表内容
            defaultAlignment: go.Spot.Left,
            itemTemplate: goJS(
              go.Panel,
              'TableRow',
              new go.Binding('itemArray', 'columns').makeTwoWay(),
              {
                itemTemplate: goJS(
                  go.Panel, // each of which as "attr" and "text" properties
                  'Spot',
                  { background: 'transparent', alignment: go.Spot.Center },
                  new go.Binding('column').makeTwoWay(),
                  new go.Binding('columnSpan', 'cSpan').makeTwoWay(),
                  new go.Binding('rowSpan', 'rSpan').makeTwoWay(),
                  new go.Binding('padding', 'padding', function (v) {
                    if (v && isNumber(v)) return v;
                    const padding = v ? v.split(',') : null;
                    return padding
                      ? new go.Margin(
1292 1293 1294 1295
                          padding?.[0] * 1 || 0,
                          padding?.[1] * 1 || 0,
                          padding?.[2] * 1 || 0,
                          padding?.[3] * 1 || 0,
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
                        )
                      : 0;
                  }).makeTwoWay(),
                  goJS(
                    go.Shape,
                    'RoundedRectanglePlus',
                    {
                      name: 'SHAPE',
                      fill: 'transparent',
                      stroke: '#ffffff',
                      strokeWidth: 0,
                      parameter1: 0,
                    },
                    new go.Binding('fill', 'background').makeTwoWay(),
                    new go.Binding('parameter1', 'radius').makeTwoWay(),
1311 1312
                    new go.Binding('stroke', 'bdColor').makeTwoWay(),
                    new go.Binding('strokeWidth', 'bdWidth').makeTwoWay(),
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
                    new go.Binding('width').makeTwoWay(),
                    new go.Binding('height').makeTwoWay(),
                  ),
                  goJS(
                    go.TextBlock,
                    textStyle(),
                    { editable: true },
                    {
                      // margin: new go.Margin(2, 10, 10, 2),
                      wrap: go.TextBlock.WrapFit,
                      textAlign: 'center',
                      font: 'bold 12px Helvetica, Arial, sans-serif',
                      stroke: '#454545',
                    },
                    new go.Binding('text').makeTwoWay(),
                    new go.Binding('font', 'style').makeTwoWay(),
                    new go.Binding('stroke', 'color').makeTwoWay(),
                    new go.Binding('textAlign', 'align').makeTwoWay(),
                    new go.Binding('maxSize', 'width', function (v) {
1332 1333 1334 1335 1336
                      try {
                        return new go.Size(v - 20, NaN);
                      } catch (err) {
                        return new go.Size(NaN, NaN);
                      }
1337 1338
                    }).makeTwoWay(),
                    new go.Binding('minSize', 'width', function (v) {
1339 1340 1341 1342 1343
                      try {
                        return new go.Size(v - 20, NaN);
                      } catch (err) {
                        return new go.Size(NaN, NaN);
                      }
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353
                    }).makeTwoWay(),
                  ),
                ),
              },
            ),
          },
        ),
      ),
    );

1354 1355 1356 1357 1358 1359
    // img节点定义
    myDiagram.nodeTemplateMap.add(
      'imgCase',
      goJS(
        go.Node,
        'Spot',
李纪文's avatar
李纪文 committed
1360
        { locationSpot: go.Spot.Center, zOrder: 1, cursor: 'default' },
1361
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
1362
        new go.Binding('cursor', 'cursor').makeTwoWay(),
1363 1364
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
1365
        roleVisibleBinding(), // 绑定角色可见
1366 1367 1368 1369 1370 1371 1372 1373 1374

        // the main object is a Panel that surrounds a TextBlock with a Shape ~图形:Panel包围着TextBlock
        goJS(
          go.Panel,
          'Auto',
          {
            name: 'PANEL',
          },
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
1375
          new go.Binding('visible', 'visible').makeTwoWay(),
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
          goJS(
            go.Picture,
            {
              name: 'animateSvg',
              width: 56,
              height: 56,
              column: 0,
              scale: 1,
              source: require('./images/组态/默认.png'),
            },
            new go.Binding('source', 'imgSrc', function (v) {
              return !v
                ? require('./images/组态/默认.png')
1389
                : `/PandaMonitor/Monitor/SketchPad/PreviewResource?name=${v}&_site=${siteCodeStr}`;
1390 1391 1392 1393 1394 1395
            }).makeTwoWay(),
            new go.Binding('scale', 'scale').makeTwoWay(),
            new go.Binding('width', 'width').makeTwoWay(),
            new go.Binding('height', 'height').makeTwoWay(),
          ),
        ),
李纪文's avatar
李纪文 committed
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417
        {
          click(e, node) {
            const { data } = node;
            const list = bindData.find((item) => {
              return item.name === data.stationName;
            });
            if (!list) return false;
            // 画板跳转
            switch (data.opType) {
              case '画板跳转': // 图片模型
                break;
              case '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
              case '自定义交互': // 自定义交互
                customBack(data);
                break;
              default:
                break;
            }
          },
        },
1418 1419 1420
      ),
    );

1421 1422 1423 1424 1425 1426
    // svg节点定义
    myDiagram.nodeTemplateMap.add(
      'svgCase',
      goJS(
        go.Node,
        'Spot',
李纪文's avatar
李纪文 committed
1427
        { locationSpot: go.Spot.Center, zOrder: 1, cursor: 'default' },
1428
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
1429
        new go.Binding('cursor', 'cursor').makeTwoWay(),
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Panel,
          'Auto',
          {
            name: 'PANEL',
          },
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
1440
          new go.Binding('visible', 'visible').makeTwoWay(),
1441 1442 1443 1444
          goJS(
            go.Picture,
            { name: 'animateSvg', width: 56, height: 56, column: 0, scale: 1, source: '' },
            new go.Binding('source', 'imgSrc', (v) => {
李纪文's avatar
李纪文 committed
1445
              return `${imgUrl}Model/Preview/${encodeURIComponent(v)}`;
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
            }),
            new go.Binding('scale', 'scale').makeTwoWay(),
            new go.Binding('width', 'width').makeTwoWay(),
            new go.Binding('height', 'height').makeTwoWay(),
          ),
        ),
        {
          click(e, node) {
            const { data } = node;
            // 画板跳转
            switch (data.opType) {
              case '画板跳转': // 图片模型
                break;
1459 1460 1461
              case '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
              case '自定义交互': // 自定义交互
                customBack(data);
                break;
              default:
                break;
            }
          },
        },
      ),
    );

    // 模板块定义
    myDiagram.nodeTemplateMap.add(
      'modelCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 1 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        {
          // 设置其可改变大小
          resizeObjectName: 'SHAPE',
        },
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
1492 1493
          'RoundedRectanglePlus',
          { name: 'SHAPE', fill: 'rgba(128,128,128,0.2)', stroke: 'gray', parameter1: 0 },
1494
          new go.Binding('visible', 'visible').makeTwoWay(),
1495
          new go.Binding('parameter1', 'radius').makeTwoWay(),
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
      ),
    );

    // 圆形定义
    myDiagram.nodeTemplateMap.add(
      'ellipseCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 1 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        {
          // 设置其可改变大小
          resizeObjectName: 'SHAPE',
        },
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
          'Ellipse',
          { name: 'SHAPE', fill: 'rgba(128,128,128,0.2)', stroke: 'gray' },
1525
          new go.Binding('visible', 'visible').makeTwoWay(),
1526 1527 1528 1529 1530 1531 1532 1533
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
      ),
    );

1534
    // 设备名称定义
1535 1536 1537 1538 1539 1540 1541
    myDiagram.nodeTemplateMap.add(
      'deviceCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
李纪文's avatar
李纪文 committed
1542
        { locationSpot: go.Spot.Center, zOrder: 3, cursor: 'default' },
1543
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
1544
        new go.Binding('cursor', 'cursor').makeTwoWay(),
1545 1546 1547 1548 1549
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
1550 1551
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
1552 1553 1554
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
1555
          new go.Binding('parameter1', 'radius').makeTwoWay(),
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
        goJS(
          go.TextBlock,
          textStyle(),
          {
            margin: 5,
            maxSize: new go.Size(NaN, NaN),
            minSize: new go.Size(NaN, 1),
            wrap: go.TextBlock.WrapFit,
            textAlign: 'center',
            editable: true,
            font: 'bold 12px Helvetica, Arial, sans-serif',
            stroke: '#454545',
          },
          new go.Binding('text').makeTwoWay(),
          new go.Binding('font', 'fontStyle'),
          new go.Binding('stroke', 'fontStroke').makeTwoWay(),
          new go.Binding('textAlign', 'fontAlign'),
李纪文's avatar
李纪文 committed
1575 1576
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
        ),
        {
          click(e, node) {
            const { data } = node;
            const list = bindData.find((item) => {
              return item.name === data.stationName;
            });
            if (!list) return false;
            switch (data.opType) {
              case '画板跳转': // 图片模型
                break;
1588 1589 1590
              case '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
1591 1592
              case '自定义交互': // 自定义交互
                customBack(data);
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708
                break;
              default:
                break;
            }
          },
        },
      ),
    );

    // 数据源模型定义
    myDiagram.nodeTemplateMap.add(
      'dataSource',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 3, cursor: 'default', visible: false },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('cursor', 'cursor').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        goJS(
          go.Shape,
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
          new go.Binding('parameter1', 'radius').makeTwoWay(),
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
        goJS(
          go.TextBlock,
          textStyle(),
          {
            maxSize: new go.Size(NaN, NaN),
            minSize: new go.Size(NaN, 1),
            wrap: go.TextBlock.WrapFit,
            textAlign: 'center',
            editable: true,
            font: 'bold 12px Helvetica, Arial, sans-serif',
            stroke: '#454545',
          },
          new go.Binding('text').makeTwoWay(),
          new go.Binding('font', 'fontStyle'),
          new go.Binding('stroke', 'fontStroke').makeTwoWay(),
          new go.Binding('textAlign', 'fontAlign'),
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
        ),
      ),
    );

    // 源数据模型定义
    myDiagram.nodeTemplateMap.add(
      'dataCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 3, cursor: 'default' },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('cursor', 'cursor').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
          new go.Binding('parameter1', 'radius').makeTwoWay(),
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
        goJS(
          go.TextBlock,
          textStyle(),
          {
            // margin: 5,
            maxSize: new go.Size(NaN, NaN),
            minSize: new go.Size(NaN, 1),
            wrap: go.TextBlock.WrapFit,
            textAlign: 'center',
            editable: true,
            font: 'bold 12px Helvetica, Arial, sans-serif',
            stroke: '#454545',
          },
          new go.Binding('text').makeTwoWay(),
          new go.Binding('font', 'fontStyle'),
          new go.Binding('stroke', 'fontStroke').makeTwoWay(),
          new go.Binding('textAlign', 'fontAlign'),
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
        ),
        {
          click(e, node) {
            const { data } = node;
            const list = bindData.find((item) => {
              return item.name === data.stationName;
            });
            if (!list) return false;
            switch (data.opType) {
              case '画板跳转': // 图片模型
                drawBoardMethod(data);
                break;
              case '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
              case '视频查看': // 视频查看
                break;
              case '自定义交互': // 自定义交互
                customBack(data);
1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725
                break;
              default:
                break;
            }
          },
        },
      ),
    );

    // 名称定义
    myDiagram.nodeTemplateMap.add(
      'nameCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
李纪文's avatar
李纪文 committed
1726
        { locationSpot: go.Spot.Center, zOrder: 3, cursor: 'default' },
1727
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
1728
        new go.Binding('cursor', 'cursor').makeTwoWay(),
1729 1730 1731 1732 1733
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
1734 1735
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
1736 1737 1738
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
1739
          new go.Binding('parameter1', 'radius').makeTwoWay(),
1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
        goJS(
          go.TextBlock,
          textStyle(),
          {
            margin: 5,
            maxSize: new go.Size(NaN, NaN),
            minSize: new go.Size(NaN, 1),
            wrap: go.TextBlock.WrapFit,
            textAlign: 'center',
            editable: true,
            font: 'bold 12px Helvetica, Arial, sans-serif',
            stroke: '#454545',
          },
          new go.Binding('text').makeTwoWay(),
          new go.Binding('font', 'fontStyle'),
          new go.Binding('stroke', 'fontStroke').makeTwoWay(),
          new go.Binding('textAlign', 'fontAlign'),
李纪文's avatar
李纪文 committed
1759 1760
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
1761 1762 1763 1764 1765 1766 1767
        ),
        {
          click(e, node) {
            const { data } = node;
            switch (data.opType) {
              case '画板跳转': // 图片模型
                break;
1768 1769 1770
              case '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
              case '自定义交互': // 自定义交互
                customBack(data);
                break;
              default:
                break;
            }
          },
        },
      ),
    );

1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841
    // 更新时间定义
    myDiagram.nodeTemplateMap.add(
      'timeCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 3, cursor: 'default' },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('cursor', 'cursor').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
          new go.Binding('parameter1', 'radius').makeTwoWay(),
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
        goJS(
          go.TextBlock,
          textStyle(),
          {
            // margin: 5,
            maxSize: new go.Size(NaN, NaN),
            minSize: new go.Size(NaN, 1),
            wrap: go.TextBlock.WrapFit,
            textAlign: 'center',
            editable: true,
            font: 'bold 12px Helvetica, Arial, sans-serif',
            stroke: '#454545',
          },
          new go.Binding('text').makeTwoWay(),
          new go.Binding('font', 'fontStyle'),
          new go.Binding('stroke', 'fontStroke').makeTwoWay(),
          new go.Binding('textAlign', 'fontAlign'),
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
        ),
        {
          // define a tooltip for each node that displays the color as text
          toolTip: goJS(
            'ToolTip',
            goJS(
              go.TextBlock,
              { margin: 2 },
              new go.Binding('text', 'timeStr'),
              new go.Binding('visible', 'toolTip'),
            ),
            new go.Binding('visible', 'toolTip'),
          ),
        },
      ),
    );

1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853
    // 公用管定义
    myDiagram.nodeTemplateMap.add(
      'HBar',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 1 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
1854 1855 1856 1857 1858
        {
          // 设置其可选择
          selectable: false,
          layerName: 'Background',
        },
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
          'Rectangle',
          {
            name: 'SHAPE',
            height: 0,
            width: 120,
            fill: '#41BFEC',
            stroke: null,
            strokeWidth: 0,
            minSize: new go.Size(20, 0),
            maxSize: new go.Size(Infinity, 0),
          },
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
          new go.Binding('minSize', 'minSize').makeTwoWay(),
          new go.Binding('maxSize', 'maxSize').makeTwoWay(),
          new go.Binding('stroke', 'stroke').makeTwoWay(),
          new go.Binding('strokeWidth', 'strokeWidth').makeTwoWay(),
        ),
        goJS(
          go.Shape,
          {
            isPanelMain: true,
            stroke: 'white',
            strokeWidth: 3,
            height: 0,
            width: 100,
            name: 'PIPE',
            strokeDashArray: [20, 40],
          },
          new go.Binding('width').makeTwoWay(),
          new go.Binding('stroke', 'waterStroke').makeTwoWay(),
          new go.Binding('strokeWidth', 'waterWidth').makeTwoWay(),
          new go.Binding('strokeDashArray', 'strokeDashArray').makeTwoWay(),
          {
            portId: '',
            toLinkable: true,
            fromLinkable: true,
          },
        ),
      ),
    );

    // 值定义
    myDiagram.nodeTemplateMap.add(
      'valCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
李纪文's avatar
李纪文 committed
1911
        { locationSpot: go.Spot.Center, zOrder: 2, cursor: 'default' },
1912
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
1913
        new go.Binding('cursor', 'cursor').makeTwoWay(),
1914 1915 1916 1917
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988
          go.Panel,
          'Horizontal',
          goJS(
            go.Panel,
            'Auto',
            goJS(
              go.Shape,
              'RoundedRectanglePlus',
              { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
              new go.Binding('fill', 'fillColor'),
              new go.Binding('stroke'),
              new go.Binding('strokeWidth'),
              new go.Binding('parameter1', 'radius').makeTwoWay(),
              new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
            ),
            goJS(
              go.TextBlock,
              textStyle(),
              {
                maxSize: new go.Size(NaN, NaN),
                minSize: new go.Size(NaN, 1),
                wrap: go.TextBlock.WrapFit,
                textAlign: 'center',
                editable: true,
                font: 'bold 12px Helvetica, Arial, sans-serif',
                stroke: '#454545',
                flip: go.GraphObject.None,
              },
              new go.Binding('text', 'showVal'),
              new go.Binding('font', 'fontStyle'),
              new go.Binding('stroke', 'fontStroke'),
              new go.Binding('textAlign', 'fontAlign'),
              new go.Binding('maxSize', 'textSize'),
              new go.Binding('minSize', 'textSize'),
              new go.Binding('flip', 'flip'),
            ),
          ),
          goJS(
            go.TextBlock,
            textStyle(),
            {
              wrap: go.TextBlock.WrapFit,
              textAlign: 'center',
              editable: false,
              font: 'normal 10px Helvetica,Arial,sans-serif',
              stroke: '#ffffff',
            },
            new go.Binding('text', 'unitText'),
            new go.Binding('font', '', (v) => {
              return `normal ${v?.unitSize || 10}pt ${
                v?.unitStyle || 'Helvetica,Arial,sans-serif'
              }`;
            }),
            new go.Binding('stroke', 'unitColor'),
            new go.Binding('visible', '', (v) => {
              return (v?.unitSwitch && !!v?.unitText) || false;
            }),
            new go.Binding('margin', '', (v) => {
              const unitGap = v?.unitGap || '0,0,0,5';
              if (unitGap && isNumber(unitGap)) return unitGap;
              const margin = unitGap?.split(',') || null;
              return margin
                ? new go.Margin(
                    margin?.[0] * 1 || 0,
                    margin?.[1] * 1 || 0,
                    margin?.[2] * 1 || 0,
                    margin?.[3] * 1 || 0,
                  )
                : 0;
            }),
          ),
1989 1990 1991 1992 1993 1994 1995 1996 1997
        ),
        {
          click(e, node) {
            const { data } = node;
            const list = bindData.find((item) => {
              return item.name === data.stationName;
            });
            if (!list) return false;
            // 历史查看
李纪文's avatar
李纪文 committed
1998
            if (data.opType && data.shName) historyModalRender(data, list);
1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137
          },
        },
      ),
    );

    // 连接点定义
    myDiagram.nodeTemplateMap.add(
      'linkPort',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 1 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色
        goJS(
          go.Panel,
          'Auto',
          {
            name: 'PANEL',
          },
          goJS(go.Shape, 'Rectangle', {
            fill: 'transparent',
            strokeWidth: 0,
            width: 8,
            height: 8,
            minSize: new go.Size(5, 5),
          }),
        ),
      ),
    );

    // 水池动效
    go.Shape.defineFigureGenerator('Pool', (shape, w, h) => {
      const geo = new go.Geometry();
      const fig = new go.PathFigure(0, 0, true); // starting point
      geo.add(fig);
      fig.add(new go.PathSegment(go.PathSegment.Line, 0.75 * w, 0));
      fig.add(new go.PathSegment(go.PathSegment.Line, w, 0.25 * h));
      fig.add(new go.PathSegment(go.PathSegment.Line, w, h));
      fig.add(new go.PathSegment(go.PathSegment.Line, 0, h).close());
      return geo;
    });

    // 定义水池
    myDiagram.nodeTemplateMap.add(
      'waterCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 1 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
          'Rectangle',
          {
            name: 'SHAPE',
            alignment: go.Spot.Bottom,
            alignmentFocus: go.Spot.Bottom,
            fill: 'transparent',
            strokeWidth: 10,
            stroke: 'red',
            desiredSize: new go.Size(NaN, 26),
          },
          new go.Binding('width').makeTwoWay(),
          new go.Binding('height').makeTwoWay(),
          new go.Binding('stroke', 'stroke').makeTwoWay(),
          new go.Binding('strokeWidth', 'strokeWidth').makeTwoWay(),
        ),
        goJS(
          go.Shape,
          'Rectangle',
          {
            name: 'SHAPE',
            alignment: go.Spot.Bottom,
            alignmentFocus: go.Spot.Bottom,
            fill: '#ccc',
            strokeWidth: 10,
            stroke: 'transparent',
            desiredSize: new go.Size(NaN, 26),
          },
          new go.Binding('width').makeTwoWay(),
          new go.Binding('height').makeTwoWay(),
          new go.Binding('fill', 'waterColor').makeTwoWay(),
          new go.Binding('strokeWidth', 'strokeWidth').makeTwoWay(),
        ),
        goJS(
          go.Shape,
          'Pool',
          {
            name: 'waterSvg',
            alignment: go.Spot.Bottom,
            alignmentFocus: go.Spot.Bottom,
            fill: '#DEE0A3',
            stroke: 'transparent',
            strokeWidth: 10,
            minSize: new go.Size(NaN, 5),
            desiredSize: new go.Size(NaN, 20),
          },
          new go.Binding('width').makeTwoWay(),
          new go.Binding('height', 'waterHight').makeTwoWay(),
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('strokeWidth', 'strokeWidth').makeTwoWay(),
        ),
      ),
    );

    // 定义进度条
    myDiagram.nodeTemplateMap.add(
      'speedCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 1 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
          'RoundedRectanglePlus',
          {
            name: 'SHAPE',
            alignment: go.Spot.Left,
            alignmentFocus: go.Spot.Left,
            strokeWidth: 2,
            stroke: '#FFFFFF',
            desiredSize: new go.Size(NaN, 26),
            fill: 'transparent',
2138
            parameter1: 5,
2139 2140 2141 2142
          },
          new go.Binding('width').makeTwoWay(),
          new go.Binding('height').makeTwoWay(),
          new go.Binding('strokeWidth', 'strokeWidth').makeTwoWay(),
2143
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156
          new go.Binding('stroke', 'stroke').makeTwoWay(),
        ),
        goJS(
          go.Shape,
          'RoundedRectanglePlus',
          {
            name: 'SHAPE',
            alignment: go.Spot.Left,
            alignmentFocus: go.Spot.Left,
            fill: '#CCCCCC',
            strokeWidth: 2,
            stroke: 'transparent',
            desiredSize: new go.Size(NaN, 26),
2157
            parameter1: 5,
2158 2159 2160 2161
          },
          new go.Binding('width').makeTwoWay(),
          new go.Binding('height').makeTwoWay(),
          new go.Binding('fill', 'waterColor').makeTwoWay(),
2162
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176
          new go.Binding('strokeWidth', 'strokeWidth').makeTwoWay(),
        ),
        goJS(
          go.Shape,
          'RoundedRectanglePlus',
          {
            name: 'speedSvg',
            alignment: go.Spot.Left,
            alignmentFocus: go.Spot.Left,
            fill: '#DEE0A3',
            stroke: 'transparent',
            strokeWidth: 2,
            minSize: new go.Size(NaN, 5),
            desiredSize: new go.Size(NaN, 20),
2177
            parameter1: 5,
2178 2179 2180
          },
          new go.Binding('width', 'lineWidth').makeTwoWay(),
          new go.Binding('height', 'height').makeTwoWay(),
2181
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('strokeWidth', 'strokeWidth'),
        ),
      ),
    );

    // 泵状态设置
    myDiagram.nodeTemplateMap.add(
      'rotateCase',
      goJS(
        go.Node,
        'Table',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 2 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        {
          // 设置其可改变大小
          resizeObjectName: 'SHAPE',
          rotatable: true,
        },
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Panel,
          'Table',
          {
            name: 'PANEL',
          },
          goJS(
            go.Shape,
            'Ellipse', // 定义形状
            { width: 37, height: 37, fill: 'transparent', stroke: 'transparent', strokeWidth: 1 },
            new go.Binding('width', 'widthBox').makeTwoWay(),
            new go.Binding('height', 'heightBox').makeTwoWay(),
          ),
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),

          goJS(
            go.Picture,
            {
              name: 'rotateSvg',
              width: 26,
              height: 26,
              column: 0,
              scale: 1,
              source: require('./images/组态/状态/泵离线.svg'),
              angle: 0,
            },
            new go.Binding('source', 'imgSrc', (v) => {
              return require(`./images/组态/状态/${v.split('/').pop()}`);
            }).makeTwoWay(),
            new go.Binding('scale', 'scale').makeTwoWay(),
            new go.Binding('width', 'width').makeTwoWay(),
            new go.Binding('angle', 'angle').makeTwoWay(),
            new go.Binding('height', 'height').makeTwoWay(),
          ),
        ),
      ),
    );

    // 点状态设置
    myDiagram.nodeTemplateMap.add(
      'pointCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 2 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
          'Ellipse',
          {
            width: 14,
            height: 14,
            name: 'SHAPE',
            fill: 'rgba(109, 122, 151, 1)',
            stroke: '#ffffff',
          },
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
          new go.Binding('height', 'height').makeTwoWay(),
          new go.Binding('width', 'height').makeTwoWay(),
        ),
      ),
    );

    // 开关开设置
    myDiagram.nodeTemplateMap.add(
      'switchCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
李纪文's avatar
李纪文 committed
2283
        { locationSpot: go.Spot.Center, zOrder: 2, cursor: 'default' },
2284
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
2285
        new go.Binding('cursor', 'cursor').makeTwoWay(),
2286 2287 2288 2289 2290
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
2291 2292
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 5 },
2293 2294 2295
          new go.Binding('fill', 'fillColor'),
          new go.Binding('stroke'),
          new go.Binding('strokeWidth'),
2296
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
        goJS(
          go.TextBlock,
          textStyle(),
          {
            maxSize: new go.Size(NaN, NaN),
            minSize: new go.Size(NaN, 1),
            wrap: go.TextBlock.WrapFit,
            textAlign: 'center',
            editable: true,
            font: 'bold 12px Helvetica, Arial, sans-serif',
            stroke: '#454545',
          },
          new go.Binding('text'),
          new go.Binding('font', 'fontStyle'),
          new go.Binding('stroke', 'fontStroke'),
          new go.Binding('textAlign', 'fontAlign'),
李纪文's avatar
李纪文 committed
2315 2316
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400
        ),
        {
          click(e, node) {
            const { data } = node;
          },
        },
      ),
    );

    // 搅拌机状态设置
    myDiagram.nodeTemplateMap.add(
      'blenderCase',
      goJS(
        go.Node,
        'Table',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 2 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        {
          // 设置其可改变大小
          resizeObjectName: 'SHAPE',
          rotatable: true,
        },
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Panel,
          'Auto',
          {
            name: 'PANEL',
          },
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),

          goJS(
            go.Picture,
            {
              name: 'blenderSvg',
              width: 42.5,
              height: 56,
              column: 0,
              scale: 1,
              source: require('./images/组态/状态/搅拌机双头1.svg'),
              angle: 0,
            },
            new go.Binding('source', 'imgSrc', (v) => {
              return require(`./images/组态/状态/${v.split('/').pop()}`);
            }).makeTwoWay(),
            new go.Binding('scale', 'scale').makeTwoWay(),
            new go.Binding('width', 'width').makeTwoWay(),
            new go.Binding('angle', 'angle').makeTwoWay(),
            new go.Binding('height', 'height').makeTwoWay(),
          ),
        ),
      ),
    );

    // 连接线装饰模板
    const linkSelectionAdornmentTemplate = goJS(
      go.Adornment,
      'Link',
      goJS(go.Shape, {
        isPanelMain: true,
        fill: null,
        stroke: 'deepskyblue',
        strokeWidth: 0,
      }),
    );

    /** *******************************单管连接方式****************************** */
    myDiagram.linkTemplate = goJS(
      BarLink,
      {
        curve: go.Link.JumpOver,
        toShortLength: 0,
        fromShortLength: 0,
        layerName: 'Background',
        routing: go.Link.Orthogonal, // 不同的位置进行不同的routing
        corner: 2,
        reshapable: true,
        resegmentable: true,
        relinkableFrom: true,
        relinkableTo: true,
2401
        zOrder: 1,
2402
      },
2403
      new go.Binding('layerName', 'layerName').makeTwoWay(),
2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450
      new go.Binding('fromSpot', 'fromPort', (d) => {
        return spotConverter(d);
      }),
      new go.Binding('toSpot', 'toPort', (d) => {
        return spotConverter(d);
      }),
      new go.Binding('points').makeTwoWay(),
      roleVisibleBinding(), // 绑定角色可见
      goJS(
        go.Shape,
        { isPanelMain: true, stroke: '#41BFEC' /* blue */, strokeWidth: 6, name: 'changecolor' },
        new go.Binding('stroke', 'stroke'),
        new go.Binding('strokeWidth', 'strokeWidth'),
      ),
      goJS(
        go.Shape,
        {
          isPanelMain: true,
          stroke: 'white',
          strokeWidth: 3,
          name: 'PIPE',
          strokeDashArray: [20, 40],
        },
        new go.Binding('strokeWidth', 'waterWidth'),
        new go.Binding('stroke', 'waterStroke'),
      ),
    );

    /** *******************************sharpLine线条****************************** */
    myDiagram.linkTemplateMap.add(
      'sharpLine',
      goJS(
        BarLink,
        {
          curve: go.Link.JumpOver,
          resegmentable: true,
          adjusting: go.Link.Stretch,
          routing: go.Link.Normal,
          layerName: 'Background',
          routing: go.Link.Normal, //不同的位置进行不同的routing
          corner: 0,
          reshapable: true,
          resegmentable: true,
          relinkableFrom: true,
          relinkableTo: true,
          relinkableFrom: true,
          relinkableTo: true,
2451
          zOrder: 1,
2452
        },
2453
        new go.Binding('layerName', 'layerName').makeTwoWay(),
2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526
        new go.Binding('fromSpot', 'fromPort', function (d) {
          return spotConverter(d);
        }),
        new go.Binding('toSpot', 'toPort', function (d) {
          return spotConverter(d);
        }),
        new go.Binding('points').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        // mark each Shape to get the link geometry with isPanelMain: true
        goJS(
          go.Shape,
          {
            isPanelMain: true,
            stroke: '#41BFEC' /* blue*/,
            strokeWidth: 6,
            name: 'changecolor',
          },
          new go.Binding('stroke', 'stroke'),
          new go.Binding('strokeWidth', 'strokeWidth'),
        ),
        goJS(
          go.Shape,
          {
            isPanelMain: true,
            stroke: 'white',
            strokeWidth: 3,
            name: 'PIPE',
            strokeDashArray: [20, 40],
          },
          new go.Binding('strokeWidth', 'waterWidth'),
          new go.Binding('stroke', 'waterStroke'),
        ),
      ),
    );

    /** **************************************合管连接方式****************************************** */
    // myDiagram.linkTemplateMap.add(
    //   'linkToLink',
    //   goJS(
    //     'Link',
    //     { relinkableFrom: true, relinkableTo: true },
    //     goJS('Shape', {
    //       stroke: '#2D9945',
    //       strokeWidth: 2,
    //     }),
    //   ),
    // );

    const fromJson = JSON.parse(jsonStr);
    myTimeout(() => {
      loop();
      waterSvg();
      rotateSvg();
      blenderSvg();
      animationSvg();
    }, 100);
    const json = JSON.parse(JSON.stringify(fromJson));
    json.linkDataArray.forEach((item) => {
      item.isHavingDash = flowShow;
      item.realVal = '--';
      item.defaultWidth = item.waterWidth;
    });
    json.nodeDataArray.forEach((item) => {
      item.showVal = '--';
      item.realVal = '--';
      item.realType = '离线';
      item.Unit = '';
      item.switchState = '开';
      item.dtImgSrc = item.imgSrc || '';
      if (item.category === 'HBar') {
        item.hBarClolor = item.waterStroke;
        item.typeDash = false;
      }
2527 2528 2529
      if (item.category === 'valCase') {
        if (item.shType === '') item.showVal = item.text;
      }
2530 2531 2532 2533 2534 2535 2536 2537 2538
      if (item.category === 'nameCase') {
        item.dtFillColor = item.fillColor;
        item.dtStroke = item.stroke;
        item.dtFontStroke = item.fontStroke;
        item.dtText = item.text;
      }
      if (item.category === 'modelCase' || item.category === 'ellipseCase') {
        item.dtzOrder = item.zOrder;
      }
2539
      if (item.category == 'deviceCase' && item.shType && deviceName && deviceName.length) {
2540 2541 2542 2543 2544
        var device = deviceName.find(function (arr, index) {
          return '设备' + stationList[index] == item.stationName;
        });
        if (device) item.text = device;
      }
李纪文's avatar
李纪文 committed
2545 2546 2547 2548 2549 2550
      // 兼容V1之前版本(部分展示可支持)
      if (chartInfo.version === 'V1') return false;
      item.shName = item.showName || '';
      item.hbControl = item.authoControl || '否';
      if (item.controlType === '开关展示') item.switch = '是';
      if (item.category === 'valCase') item.shType = '值显示';
2551 2552 2553 2554 2555 2556 2557 2558 2559 2560
    });
    myDiagram.model = go.Model.fromJson(json);
  };

  return (
    <div className={classNames(prefixCls)} ref={ConfigurationRef}>
      <div id={twoID} className={classNames('configurationView')}>
        <LoadBox spinning={spinning} />
        {isEmpty && <Empty theme={'dark'} description={description} />}
      </div>
2561 2562 2563 2564 2565
      {spinLoad && (
        <div className={classNames('configurationLoad')}>
          <LoadBox spinning={spinLoad} />
        </div>
      )}
2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591
      {/* 历史曲线 */}
      {isHIModalVisible && (
        <Modal
          centered
          width={1200}
          footer={null}
          open={isHIModalVisible}
          onOk={() => setIsHIModalVisible(false)}
          onCancel={() => setIsHIModalVisible(false)}
          getContainer={ConfigurationRef.current}
          wrapClassName={classNames(`${prefixCls}-historyInfoModal`)}
        >
          <HistoryView deviceParams={historyInfoParams} />
        </Modal>
      )}
    </div>
  );
};

ConfigurationView.defaultProps = {
  name: '',
  devices: [],
  deviceName: [],
  config: {},
  isZoom: false,
  flowShow: true,
李纪文's avatar
李纪文 committed
2592
  customBack: () => {},
2593 2594 2595 2596 2597
  speed: 0,
  play: false,
  times: 2,
  callback: (speed, total, play, time) => {},
  params: {},
2598
  statisticType: [],
2599 2600 2601 2602 2603 2604 2605 2606 2607
};

ConfigurationView.propTypes = {
  name: PropTypes.string,
  devices: PropTypes.array,
  deviceName: PropTypes.array,
  config: PropTypes.object,
  isZoom: PropTypes.bool,
  flowShow: PropTypes.bool,
李纪文's avatar
李纪文 committed
2608
  customBack: PropTypes.func,
2609 2610 2611 2612 2613
  speed: PropTypes.number,
  play: PropTypes.bool,
  times: PropTypes.number,
  callback: PropTypes.func,
  params: PropTypes.object,
2614
  statisticType: PropTypes.array,
2615 2616 2617
};

export default ConfigurationView;