index.js 75.5 KB
Newer Older
1
/* eslint-disable */
涂茜's avatar
涂茜 committed
2 3 4 5
import React, { useState, useEffect, useRef, useContext } from 'react';
import classNames from 'classnames';
import moment from 'moment';
import sha1 from 'sha1';
6 7
import Empty from '@wisdom-components/empty';
import LoadBox from '@wisdom-components/loadbox';
李纪文's avatar
李纪文 committed
8
import { Input, message, Modal, Form, ConfigProvider, Button } from 'antd';
9 10 11 12 13 14 15
import {
  ExclamationCircleOutlined,
  DoubleLeftOutlined,
  LeftOutlined,
  RightOutlined,
  DoubleRightOutlined,
} from '@ant-design/icons';
涂茜's avatar
涂茜 committed
16 17
import MqttView from '@wisdom-components/mqttview';
import PropTypes from 'prop-types';
李纪文's avatar
李纪文 committed
18
import HistoryView from '@wisdom-components/ec_historyview';
李纪文's avatar
李纪文 committed
19
import * as go from './js/go';
涂茜's avatar
涂茜 committed
20 21 22 23
import GuidedDraggingTool from './js/GuidedDraggingTool';
import TopRotatingTool from './js/RotatingTool';
import BarLink from './js/BarLink';
import WaterFlowControlView from './js/WaterFlowControlView';
24 25
import ConfigurationDetail from './js/ConfigurationDetail';
import DragModal from './js/DragModal';
李纪文's avatar
李纪文 committed
26
import { getSketchPadList, getSketchPadContent, getPointAddress, getDeviceRealInfo } from './apis';
27 28 29 30 31 32 33 34 35
import {
  isNumber,
  createGuid,
  deepCopy,
  hexToRgba,
  addNumMethod,
  hexSwitch,
  textStyle,
} from './js/utils';
涂茜's avatar
涂茜 committed
36 37 38 39 40 41 42 43 44 45
import './index.less';

const goJS = go.GraphObject.make;
let online = false;
let imgUrl = null;
let modalComponent = null; // 点击节点展示的模态框内容
let modalConfirmFn = null; // 点击节点展示的模态框的确定事件
let auModalConfirmFn = null; // 登录模态框的确定事件
let jumpModalProps = null;
let modalProps = {};
46
let modalWidth = 520;
李纪文's avatar
李纪文 committed
47
let historyInfoParams = [];
48
let nodeData = null; // 选中节点的数据
李纪文's avatar
李纪文 committed
49
let twoID = '';
50

涂茜's avatar
涂茜 committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
const waterFlow = new WaterFlowControlView();

const StationList = [
  'A',
  'B',
  'C',
  'D',
  'E',
  'F',
  'G',
  'H',
  'I',
  'J',
  'K',
  'L',
  'M',
  'N',
  'O',
  'P',
  'Q',
  'R',
  'S',
  'T',
  'U',
  'V',
  'W',
  'X',
  'Y',
  'Z',
];

const ConfigurationView = (props) => {
83 84 85 86 87 88
  let myDiagram = null;
  let mqttView = null;
  let editionArr = [];
  const guidAggre = {};
  const bindData = [];
  const stationList = [];
涂茜's avatar
涂茜 committed
89 90
  const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
  const prefixCls = getPrefixCls('ec-configuration-view');
李纪文's avatar
李纪文 committed
91
  const componentPrefix = getPrefixCls('');
涂茜's avatar
涂茜 committed
92 93 94 95
  const [isModalVisible, setIsModalVisible] = useState(false);
  const [isAuModalVisible, setIsAuModalVisible] = useState(false); // 登录模态框
  const [isHIModalVisible, setIsHIModalVisible] = useState(false); // 历史曲线模态框
  const [isJumpModalVisible, setIsJumpModalVisible] = useState(false); // 画板跳转模态框
96 97
  const [spinning, setSpinning] = useState(true); // 画板loading
  const [isEmpty, setIsEmpty] = useState(false); // 画板无数据状态
李纪文's avatar
李纪文 committed
98
  const [description, setDescription] = useState(''); // 画板无数据描述
涂茜's avatar
涂茜 committed
99 100 101 102

  twoID = `TDG${Date.now().toString(36)}`;
  const AdjustControlInput = useRef();
  const AuthorFrom = useRef();
李纪文's avatar
李纪文 committed
103
  const ConfigurationRef = useRef();
涂茜's avatar
涂茜 committed
104
  const customBack = props.customBack ? props.customBack : () => {};
李纪文's avatar
李纪文 committed
105
  const { devices = [], config, isZoom = false, flowShow = true, deviceName = [] } = props;
106
  const globalConfig = window.globalConfig || config;
李纪文's avatar
李纪文 committed
107
  let isClose = false;
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

  /** **********************************获取工艺图画板信息*********************** */
  const getConfiguraList = async () => {
    imgUrl = online
      ? 'https://panda-water.cn/PandaConfiguration/Raw/'
      : `${globalConfig.baseURI}/PandaConfiguration/Raw/`;
    // 获取画板信息
    const drawInfo = await getSketchPadList({
      name: props.name,
      siteCode:
        globalConfig.userInfo && globalConfig.userInfo.LocalSite
          ? globalConfig.userInfo.LocalSite
          : '',
      version: '全部',
      _site: globalConfig.userInfo && globalConfig.userInfo.site ? globalConfig.userInfo.site : '',
    });
    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) {
            stationList.push(StationList[remain] + round);
          } else {
            stationList.push(StationList[remain]);
          }
        }
        getDiagramJson(data[0], siteInfo);
涂茜's avatar
涂茜 committed
139
      } else {
李纪文's avatar
李纪文 committed
140
        setDescription('咦~未查询到工艺图画板信息哦~');
141 142
        setIsEmpty(true);
        setSpinning(false);
李纪文's avatar
李纪文 committed
143
        return false;
涂茜's avatar
涂茜 committed
144
      }
145
    } else {
李纪文's avatar
李纪文 committed
146
      setDescription('咦~工艺图画板信息报错啦~');
147 148 149
      setIsEmpty(true);
      setSpinning(false);
      return message.error(drawInfo.msg);
涂茜's avatar
涂茜 committed
150 151
    }

152 153 154 155 156 157
    // 获取点表信息
    const pointInfo = await getPointAddress({
      code: devices.join(','),
      _site: globalConfig.userInfo && globalConfig.userInfo.site ? globalConfig.userInfo.site : '',
    });
    editionArr = deepCopy(pointInfo && pointInfo.data ? pointInfo.data : [], []);
涂茜's avatar
涂茜 committed
158 159 160 161 162 163 164 165
  };

  /** *********************************节点展示逻辑****************************** */
  const showNodeMethod = (node, list) => {
    const realVal = list.Value * 1;
    let switchState;
    myDiagram.model.setDataProperty(node, 'realVal', realVal);
    if (node.switch === '是') {
166
      switchState = openValState(node.openVal, realVal) ? '开' : '关';
涂茜's avatar
涂茜 committed
167 168 169
      myDiagram.model.setDataProperty(node, 'switchState', switchState);
    }
    if (!node.shType) return false;
170
    const patt = /[><=]/gi;
涂茜's avatar
涂茜 committed
171
    let shRule = [];
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    try {
      switch (node.category) {
        case 'svgCase': // 图片模型
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(node, 'imgSrc', shRule ? shRule.attr : node.dtImgSrc);
          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': // 实时值模型
          if (node.shType === '值显示') {
            myDiagram.model.setDataProperty(node, 'showVal', realVal < 0 ? 0 : realVal);
          } else {
            myDiagram.model.setDataProperty(node, 'showVal', realVal);
          }
          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),
              );
涂茜's avatar
涂茜 committed
218
          });
219 220 221
          break;
        case 'switchCase': // 开关模型
          shRule = ruleOperation(node, realVal);
涂茜's avatar
涂茜 committed
222 223
          myDiagram.model.setDataProperty(
            node,
224 225
            'fillColor',
            hexToRgba(shRule ? shRule.attr : node.fill, node.opacity),
涂茜's avatar
涂茜 committed
226
          );
227 228 229 230 231 232 233 234
          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);
涂茜's avatar
涂茜 committed
235 236 237 238 239
          myDiagram.model.setDataProperty(
            node,
            'fillColor',
            hexToRgba(shRule ? shRule.attr : node.fill, node.opacity),
          );
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 274 275 276 277 278 279 280
          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);
          myDiagram.model.setDataProperty(node, 'zOrder', shRule ? shRule.text : node.dtzOrder);
          break;
        case 'ellipseCase': // 圆形模型
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(
            node,
            'zOrder',
            shRule ? shRule.text * 1 || 0 : node.dtzOrder,
          );
          break;
        default:
          break;
      }
    } catch (err) {
      console.log(err);
涂茜's avatar
涂茜 committed
281 282 283
    }
  };

284 285 286 287
  /** ***********************************展示规则运算********************************* */
  const ruleOperation = (node, realVal) => {
    const patt = /[><=]/gi;
    const shRule = JSON.parse(node.shRule).find((rule) => {
李纪文's avatar
李纪文 committed
288
      if (rule.val.toString().match(patt)) {
289 290 291 292 293 294 295 296 297 298 299 300 301
        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;
  };

302 303 304
  /** ***********************************运行值规则运算********************************* */
  const openValState = (openVal, realVal) => {
    const patt = /[><=]/gi;
李纪文's avatar
李纪文 committed
305
    if (openVal.toString().match(patt)) {
306 307 308 309 310 311 312 313 314 315 316
      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;
    }
  };

涂茜's avatar
涂茜 committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
  /** ***********************************MQTT控制结果回调********************************* */
  const controlData = (mqttDatas, code) => {
    const controlInfo = JSON.parse(mqttDatas);
    if (guidAggre[code]) {
      const guid = guidAggre[code];
      if (!controlInfo.result) {
        message.warning(`${guid.tag}控制失败,${controlInfo.message}!`);
      } else {
        message.success(`${guid.tag}控制下发成功。`);
      }
      delete guidAggre[code];
    }
  };

  /** *********************************MQTT请求数据回调****************************** */
  const refreshData = (mqttDatas, code) => {
    const bindList = bindData.find((item) => {
      return item.code === code;
    });
    const name = bindList ? bindList.name : '';
    const mqttData = JSON.parse(mqttDatas)[code];
    const editionList = editionArr.find((item) => {
      return item.code === code;
    });
    if (!mqttData) return false;

    try {
      if (unitRender) unitRender.tipRender({ deviceID: code, data: mqttData });
    } catch (err) {
      // 三维调用
    }

    const json = JSON.parse(myDiagram.model.toJson());
    const jsonCopy = JSON.parse(JSON.stringify(json));
351
    const oldJson = deepCopy(jsonCopy, {});
涂茜's avatar
涂茜 committed
352 353 354 355 356 357 358 359 360 361 362 363
    try {
      myDiagram.model.linkDataArray.forEach((item) => {
        if (!item.shName || item.stationName !== name || item.shType !== '线条展示') return false;
        mqttData.forEach((list) => {
          const itemID = list.ItemID;
          const num = itemID.lastIndexOf('.');
          const ptName = itemID.substring(0, num);
          const shName = itemID.substring(num + 1, Infinity);
          if (editionList && `${editionList.name}.${editionList.version}` !== ptName) return false;
          if (list.Value == null || shName !== item.shName || item.realVal === list.Value)
            return false;
          item.realVal = list.Value * 1;
364
          const shRule = ruleOperation(item, item.realVal);
涂茜's avatar
涂茜 committed
365 366 367 368 369 370 371 372 373 374
          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) {
375
      // 水流样式
涂茜's avatar
涂茜 committed
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
    }

    try {
      jsonCopy.nodeDataArray.forEach((item) => {
        if (!(item.shName || item.figure === 'updateTime') || item.stationName !== name)
          return false;
        const node = myDiagram.model.findNodeDataForKey(item.key);
        mqttData.forEach((list) => {
          if (node.figure === 'updateTime') {
            myDiagram.model.setDataProperty(
              node,
              'text',
              moment(list.Time).format('yyyy-MM-DD hh:mm:ss'),
            );
            return false;
          }
          const itemID = list.ItemID;
          const num = itemID.lastIndexOf('.');
          const ptName = itemID.substring(0, num);
          const shName = itemID.substring(num + 1, Infinity);
          if (editionList && `${editionList.name}.${editionList.version}` !== ptName) return false;
          if (list.Value == null || shName !== item.shName || item.realVal === list.Value)
            return false;
          showNodeMethod(node, list);
        });
      });
    } 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 = { ...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) {
      // 水流展示
    }
  };

  /** **************************************合管****************************************** */
  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
    });
  };

李纪文's avatar
李纪文 committed
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
  /** 动画设置*********************************************** */
  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);
  };

525
  /** ******************************************水池效果****************************** */
涂茜's avatar
涂茜 committed
526 527
  const waterSvg = () => {
    const diagram = myDiagram;
李纪文's avatar
李纪文 committed
528 529
    // poolWater = setInterval(() => {
    mySetInterval(() => {
涂茜's avatar
涂茜 committed
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
      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);
  };

545
  /** ***********************************水流效果********************************** */
涂茜's avatar
涂茜 committed
546 547
  const loop = () => {
    const diagram = myDiagram;
李纪文's avatar
李纪文 committed
548 549
    // tubeWater = setInterval(() => {
    mySetInterval(() => {
涂茜's avatar
涂茜 committed
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
      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);
  };

570
  /** **************************************泵状态效果*************************** */
涂茜's avatar
涂茜 committed
571 572
  const rotateSvg = () => {
    const diagram = myDiagram;
李纪文's avatar
李纪文 committed
573 574
    // pumpType = setInterval(() => {
    mySetInterval(() => {
涂茜's avatar
涂茜 committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
      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);
  };

590
  /** *********************************搅拌机状态效果************************* */
涂茜's avatar
涂茜 committed
591 592
  const blenderSvg = () => {
    const diagram = myDiagram;
李纪文's avatar
李纪文 committed
593 594
    // blenderType = setInterval(() => {
    mySetInterval(() => {
涂茜's avatar
涂茜 committed
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
      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);
  };

622
  /** *******************将myDiagram.model中的信息展示在画板上*********************** */
涂茜's avatar
涂茜 committed
623 624 625 626 627
  const loadDiagramProperties = (e) => {
    const pos = myDiagram.model.modelData.position;
    if (pos) myDiagram.initialPosition = go.Point.parse(pos);
  };

628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
  /** *******************绑定角色可见*************************** */
  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;
    });
  };

  /** ***********************************节点样式********************************** */
涂茜's avatar
涂茜 committed
648 649 650 651 652 653 654 655 656
  const nodeStyle = () => {
    return [
      new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
      {
        locationSpot: go.Spot.Center,
      },
    ];
  };

657 658
  /** ************************************联网判断******************************* */
  const onlineMethod = (pathImg, url) => {
涂茜's avatar
涂茜 committed
659 660 661 662 663 664 665 666 667 668 669 670 671
    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
672 673 674 675 676 677
    if (!props.name || !props.devices || !props.devices.length) {
      setDescription('咦~工艺图配置信息不全哦~');
      setIsEmpty(true);
      setSpinning(false);
      return false;
    }
678 679
    const url = globalConfig.mainserver ? globalConfig.mainserver : 'https://panda-water.cn/';
    onlineMethod(`${url}civweb4/assets/images/bootPage/熊猫图标.png`, url);
涂茜's avatar
涂茜 committed
680
    return () => {
李纪文's avatar
李纪文 committed
681
      isClose = true;
涂茜's avatar
涂茜 committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
      mqttView && mqttView.disSaveWaconnect();
      mqttView = null;
    };
  }, []);

  useEffect(() => {
    if (!isModalVisible) {
      modalConfirmFn = null;
      modalComponent = null;
      modalProps = {};
    }
  }, [isModalVisible]);

  useEffect(() => {
    if (!isAuModalVisible) {
      auModalConfirmFn = null;
    }
  }, [isAuModalVisible]);

701 702 703
  /** ************************************获取画板JSON******************************* */
  const getDiagramJson = async (list, siteInfo) => {
    const response = await getSketchPadContent({
涂茜's avatar
涂茜 committed
704 705 706
      dimension: list.dimension,
      siteCode: list.siteCode,
      fileName: `${list.name}.json`,
707 708 709
      _site: globalConfig.userInfo && globalConfig.userInfo.site ? globalConfig.userInfo.site : '',
    });
    if (response.code === 0) {
李纪文's avatar
李纪文 committed
710
      if (isClose) return false;
711 712 713 714 715 716 717 718 719 720 721 722 723 724
      const fromJson = response.data
        ? response.data
        : {
            linkFromPortIdProperty: 'fromPort',
            linkToPortIdProperty: 'toPort',
            nodeDataArray: [],
            linkDataArray: [],
          };
      devices.forEach((item, index) => {
        const name = `设备${stationList[index]}`;
        bindData.push({
          code: item,
          name,
          type: siteInfo && siteInfo[name] ? siteInfo[name].Type : '',
涂茜's avatar
涂茜 committed
725
        });
726 727 728 729 730 731 732 733 734 735 736 737
      });
      mqttView = new MqttView({
        mqttIP: globalConfig.mqtt_iotIP,
        mqttPath: globalConfig.mqtt_path,
        mqttSsl: globalConfig.mqtt_IsSSL,
        siteCode: globalConfig.mqtt_mess.site_code,
        devices,
        callback: refreshData,
        controlback: controlData,
      });
      diagramRender(typeof fromJson === 'string' ? fromJson : JSON.stringify(fromJson));
      try {
涂茜's avatar
涂茜 committed
738
        mqttView.saveWaterMqtt();
739 740 741
      } catch (e) {
        // 获取实时数据
        getRealData(siteInfo);
涂茜's avatar
涂茜 committed
742
      }
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
    } else {
      message.error(response.msg);
    }
  };

  /** ************************************实时数据获取******************************* */
  const getRealData = async (siteInfo) => {
    try {
      if (!siteInfo) return false;
      const accountFieldParams = [];
      for (let i in siteInfo) {
        accountFieldParams.push({
          aName: siteInfo[i].Type,
        });
      }
      const params = {
        equipmentCode: devices.join(','),
        accountFieldParams,
      };
      const results = await getDeviceRealInfo(params);
李纪文's avatar
李纪文 committed
763 764
      const realData = results && results.data && results.data.list ? results.data.list : [];
      chartDataRender(flatten(realData));
765 766 767
    } catch (err) {}
  };

李纪文's avatar
李纪文 committed
768 769 770 771 772 773 774 775 776
  // 实时数据父子级平铺
  const flatten = (arr) => {
    return [].concat(
      ...arr.map((item) =>
        item.child ? [].concat(item, ...flatten(item.child)) : [].concat(item),
      ),
    );
  };

777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
  /** ************************************图表数据处理******************************* */
  const chartDataRender = (mqttData) => {
    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.dataList.find((arr) => {
            return arr.dName === item.shName;
          });
          if (!bindList || item.stationName !== bindList.name) return false;
          if (
            !pvList ||
            pvList.pv == null ||
            pvList.dName != item.shName ||
            item.realVal == pvList.pv
          )
            return false;
          item.realVal = pvList.pv * 1;
李纪文's avatar
李纪文 committed
801
          const shRule = ruleOperation(item, item.realVal);
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 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 875 876 877
          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',
              new Date(list.PT).format('yyyy-MM-dd hh:mm:ss'),
            );
            return false;
          }
          const bindList = bindData.find((arr) => {
            return arr.code === list.code;
          });
          const pvList = list.dataList.find((arr) => {
            return arr.dName === item.shName;
          });
          if (!bindList || item.stationName !== bindList.name) return false;
          if (
            !pvList ||
            pvList.pv == null ||
            pvList.dName != item.shName ||
            item.realVal == pvList.pv
          )
            return false;
          pvList.Value = pvList.pv;
          showNodeMethod(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) {
      // 水流展示
    }
涂茜's avatar
涂茜 committed
878 879 880 881
  };

  /** **************************************历史模态渲染****************************************** */
  const historyModalRender = (data, list) => {
李纪文's avatar
李纪文 committed
882 883 884 885 886 887 888
    historyInfoParams = [
      {
        deviceCode: list.code,
        sensors: data.shName,
        deviceType: list.type,
      },
    ];
涂茜's avatar
涂茜 committed
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
    setIsHIModalVisible(true);
  };

  /** **************************************渲染按钮控制****************************************** */
  const renderSwitchControlModal = () => {
    return (
      <div className={classNames('switchControlContent')}>
        <ExclamationCircleOutlined />
        {`确定要${nodeData.text}${nodeData.ctName}?`}
      </div>
    );
  };

  /** **************************************渲染输入控制****************************************** */
  const renderAdjustControlModal = () => {
    const ctRule = nodeData.ctRule ? JSON.parse(nodeData.ctRule) : [];
905
    const step = ctRule.length ? ctRule[0].step || 0.1 : 0.1;
涂茜's avatar
涂茜 committed
906 907 908 909 910 911 912
    return (
      <div className={classNames('adjustControlContent')}>
        <div className={classNames('label')}>设置</div>
        <Input
          placeholder="请输入设置值"
          ref={AdjustControlInput}
          defaultValue={nodeData.realVal}
913
          onChange={() => {}}
涂茜's avatar
涂茜 committed
914 915
          suffix={ctRule.length ? ctRule[0].text : ''}
        />
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
        <div className={classNames('adjustControlGroup')}>
          <Button
            type="primary"
            ghost={true}
            icon={<DoubleLeftOutlined />}
            onClick={() => adjustControlStep(step * -10)}
          />
          <Button
            type="primary"
            ghost={true}
            icon={<LeftOutlined />}
            onClick={() => adjustControlStep(step * -1)}
          />
          <Button
            type="primary"
            ghost={true}
            icon={<RightOutlined />}
            onClick={() => adjustControlStep(step)}
          />
          <Button
            type="primary"
            ghost={true}
            icon={<DoubleRightOutlined />}
            onClick={() => adjustControlStep(step * 10)}
          />
        </div>
涂茜's avatar
涂茜 committed
942 943 944 945
      </div>
    );
  };

946 947 948 949 950 951 952 953 954 955 956 957 958
  const adjustControlStep = (step) => {
    const value = AdjustControlInput.current.state
      ? AdjustControlInput.current.state.value
      : AdjustControlInput.current.input.value;
    if (!isNaN(value * 1)) {
      if (AdjustControlInput.current.state) {
        AdjustControlInput.current.setState({ value: addNumMethod(value * 1, step * 1) });
      } else {
        AdjustControlInput.current.input.value = addNumMethod(value * 1, step * 1);
      }
    }
  };

涂茜's avatar
涂茜 committed
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
  /** **************************************权限控制确认****************************************** */
  const defineAutho = (code, tag, node, guid, value) => {
    const { userName, password } = AuthorFrom.current.getFieldsValue(true);
    if (!userName || !password) {
      message.warning('用户名或密码不能为空!');
      return false;
    }
    setIsAuModalVisible(false);
    guidAggre[guid] = {
      tag,
      code,
    };
    const flag = isNumber(value);
    mqttView.onSendWaMessageArrived(
      userName,
      sha1(password).toUpperCase(),
      guid,
      code,
      tag,
      value,
      flag ? value * 1 : '',
    );
  };

  /** **************************************权限控制方法****************************************** */
  const authoMethod = (code, tag, node, guid, value) => {
    setIsAuModalVisible(true);
    auModalConfirmFn = () => defineAutho(code, tag, node, guid, value);
  };

  /** **************************************开关控制确定****************************************** */
  const defineSwitch = (code, tag, node) => {
    const guid = createGuid();
    setIsModalVisible(false);
    const ctRule = JSON.parse(node.ctRule);
    if (node.isControl === '是') {
      authoMethod(code, tag, node, guid, ctRule[0].val);
      return false;
    }
998
    guidAggre[guid] = { tag, code };
涂茜's avatar
涂茜 committed
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
    const { val } = ctRule[0];
    const flag = isNumber(val);
    mqttView.onSendWaMessageArrived(
      globalConfig.token || '',
      '',
      guid,
      code,
      tag,
      val,
      flag ? val * 1 : '',
    );
  };

  /** **************************************控制方法****************************************** */
  const controlMethod = (code, tag, node) => {
    const ctRule = JSON.parse(node.ctRule);
    const min = ctRule.length ? ctRule[0].min : '';
    const max = ctRule.length ? ctRule[0].max : '';
1017 1018 1019 1020 1021 1022
    const hexfrom = ctRule.length ? ctRule[0].hexfrom : '';
    const hexto = ctRule.length ? ctRule[0].hexto : '';
    let value = AdjustControlInput.current.state
      ? AdjustControlInput.current.state.value
      : AdjustControlInput.current.input.value;
    if (value != 0 && !value) {
涂茜's avatar
涂茜 committed
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
      message.warning('设置值不能为空!');
      return false;
    }
    if (isNaN(value * 1)) {
      message.warning('设置值不合理!');
      return false;
    }
    if (value < 0) {
      message.warning('设置值不合理!');
      return false;
    }
    if (min !== '' && !isNaN(min * 1) && value < min * 1) {
      message.warning(`设置值不能小于${min}!`);
      return false;
    }
    if (max !== '' && !isNaN(max * 1) && value > max * 1) {
      message.warning(`设置值不能大于${max}!`);
      return false;
    }
1042
    if (hexfrom && hexto) value = hexSwitch(value, hexfrom, hexto);
涂茜's avatar
涂茜 committed
1043 1044 1045 1046 1047 1048
    const guid = createGuid();
    setIsModalVisible(false);
    if (node.isControl === '是') {
      authoMethod(code, tag, node, guid, value);
      return false;
    }
1049
    guidAggre[guid] = { tag, code };
涂茜's avatar
涂茜 committed
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
    mqttView.onSendWaMessageArrived(
      globalConfig.token || '',
      '',
      guid,
      code,
      tag,
      node.switchType,
      value * 1,
    );
  };

  const moreControlMethod = (code, tag, node, value) => {
    const guid = createGuid();
    setIsModalVisible(false);
    if (node.isControl === '是') {
      authoMethod(code, tag, node, guid, value);
      return false;
    }
1068
    guidAggre[guid] = { tag, code };
涂茜's avatar
涂茜 committed
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
    const flag = isNumber(value);
    mqttView.onSendWaMessageArrived(
      globalConfig.token || '',
      '',
      guid,
      code,
      tag,
      value,
      flag ? value * 1 : '',
    );
  };

  /** **************************************渲染多选控制****************************************** */
  const renderMoreControlModal = () => {
    const ctRule = nodeData.ctRule ? JSON.parse(nodeData.ctRule) : [];
    const list = bindData.find((item) => {
      return item.name === nodeData.stationName;
    });
    return (
      <div className={classNames('moreControlContent')}>
        {ctRule.length > 0 &&
          ctRule.map((rule, index) => {
            if (rule.val !== '' && rule.text !== '') {
              return (
                <div key={index} className={classNames('moreControlList')}>
                  <span>状态设置</span>
                  <div
                    onClick={(e) =>
                      moreControlMethod(list.code, nodeData.ctName, nodeData, rule.val)
                    }
                  >
                    {rule.text}
                  </div>
                </div>
              );
            }
          })}
      </div>
    );
  };

  /** **************************************控制模态渲染****************************************** */
  const controlModalRender = (data, list) => {
1112 1113
    const ctRule = data && data.ctRule ? JSON.parse(data.ctRule) : '';
    switch (data.ctType) {
涂茜's avatar
涂茜 committed
1114
      case '按钮控制':
1115
        if (data.switch === '是') message.warning(`当前设备已是${data.text}状态,请勿重复操作!`);
涂茜's avatar
涂茜 committed
1116
        if (
1117 1118 1119 1120
          data.realVal === '--' ||
          data.switch === '是' ||
          !data.ctName ||
          !data.ctName.length ||
涂茜's avatar
涂茜 committed
1121 1122 1123 1124 1125 1126
          ctRule[0].val === ''
        )
          return false;
        modalComponent = renderSwitchControlModal;
        modalConfirmFn = () => defineSwitch(list.code, data.ctName, data);
        modalProps = { title: '状态控制' };
1127
        modalWidth = 520;
涂茜's avatar
涂茜 committed
1128 1129 1130
        setIsModalVisible(true);
        break;
      case '输入控制':
1131
        if (data.realVal === '--' || !data.ctName) return false;
涂茜's avatar
涂茜 committed
1132 1133
        modalComponent = renderAdjustControlModal;
        modalConfirmFn = () => controlMethod(list.code, data.ctName, data);
1134 1135
        modalProps = { title: `${data.ctName}设置` };
        modalWidth = 520;
涂茜's avatar
涂茜 committed
1136 1137 1138
        setIsModalVisible(true);
        break;
      case '多选控制':
1139
        if (!data.ctName) return false;
涂茜's avatar
涂茜 committed
1140
        modalComponent = renderMoreControlModal;
1141 1142
        modalProps = { footer: null, title: `${data.ctName}设置` };
        modalWidth = 'auto';
涂茜's avatar
涂茜 committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
        setIsModalVisible(true);
        break;
      default:
        break;
    }
  };

  /** **************************************跳转方法****************************************** */
  const drawBoardMethod = (data) => {
    const opRule = JSON.parse(data.opRule);
    const name = opRule && opRule.name ? opRule.name : '';
    const title = opRule && opRule.title ? opRule.title : '';
    const device = opRule && opRule.device ? opRule.device : [];
    const width = opRule && opRule.width ? opRule.width : '';
    const height = opRule && opRule.height ? opRule.height : '';
1158
    const color = opRule && opRule.color ? opRule.color : '#282d3b';
涂茜's avatar
涂茜 committed
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
    if (!name) return false;
    const deviceArr = [];
    device.forEach((item) => {
      const list = bindData.find((item1) => {
        return item1.name === item;
      });
      deviceArr.push(list ? list.code : item);
    });
    jumpModalProps = {
      width,
      height,
      title,
      name,
      device: deviceArr,
1173
      color,
涂茜's avatar
涂茜 committed
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
    };
    setIsJumpModalVisible(true);
  };

  const handleOk = (e) => {
    e.stopPropagation();
    modalConfirmFn && modalConfirmFn();
  };

  const handleCancel = () => {
    setIsModalVisible(false);
  };

  const handleAuOk = (e) => {
    e.stopPropagation();
    auModalConfirmFn && auModalConfirmFn();
  };

  const renderModalContent = () => {
    return modalComponent && nodeData ? modalComponent() : null;
  };

1196
  /** **********************************画布渲染************************************ */
涂茜's avatar
涂茜 committed
1197 1198 1199 1200 1201 1202 1203 1204 1205
  const diagramRender = (jsonStr) => {
    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(),
1206
        allowZoom: isZoom ? true : false,
涂茜's avatar
涂茜 committed
1207 1208 1209
        allowSelect: false,
        'draggingTool.dragsLink': true,
        isReadOnly: true,
1210
        autoScale: isZoom ? go.Diagram.None : go.Diagram.Uniform, // 自适应,默认不自适应
涂茜's avatar
涂茜 committed
1211 1212 1213 1214
        initialAutoScale: go.Diagram.Uniform, // 自适应,默认不自适应
        'draggingTool.isGridSnapEnabled': true,
        'linkingTool.isUnconnectedLinkValid': true,
        'animationManager.duration': 100,
1215
        allowHorizontalScroll: isZoom ? true : false,
涂茜's avatar
涂茜 committed
1216
        padding: 20,
1217
        allowVerticalScroll: isZoom ? true : false,
涂茜's avatar
涂茜 committed
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
        '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,
1229 1230 1231
        // LinkReshaped: (e) => {
        //   e.subject.routing = go.Link.Orthogonal;
        // },
涂茜's avatar
涂茜 committed
1232 1233 1234 1235
        'linkingTool.direction': go.LinkingTool.ForwardsOnly,
      },
    );

1236
    /** *********************************节点模板************************************* */
涂茜's avatar
涂茜 committed
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246
    // svg节点定义
    myDiagram.nodeTemplateMap.add(
      'svgCase',
      goJS(
        go.Node,
        '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(),
1247
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257
        goJS(
          go.Panel,
          'Auto',
          {
            name: 'PANEL',
          },
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),

          goJS(
            go.Picture,
李纪文's avatar
李纪文 committed
1258
            { name: 'animateSvg', width: 56, height: 56, column: 0, scale: 1, source: '' },
涂茜's avatar
涂茜 committed
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 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
            new go.Binding('source', 'imgSrc', (v) => {
              return `${imgUrl}File/ModelManage/ModelFilePreview/${encodeURIComponent(v)}`;
            }),
            new go.Binding('scale', 'scale').makeTwoWay(),
            new go.Binding('width', 'width').makeTwoWay(),
            new go.Binding('height', 'height').makeTwoWay(),
          ),
        ),
        makePort('T', go.Spot.Top, true, true),
        makePort('L', go.Spot.Left, true, true),
        makePort('R', go.Spot.Right, true, true),
        makePort('B', go.Spot.Bottom, true, true),
        makePort('RB', go.Spot.BottomRight, true, true),
        makePort('LB', go.Spot.BottomLeft, true, true),
        makePort('RT', go.Spot.TopRight, true, true),
        makePort('LT', go.Spot.TopLeft, true, true),
        {
          click(e, node) {
            const { data } = node;
            nodeData = data;
            const list = bindData.find((item) => {
              return item.name === data.stationName;
            });
            if (!list) return false;
            // 控制方法
            if (data.ctName && data.ctType) {
              controlModalRender(data, list);
              return false;
            }
            // 画板跳转
            switch (data.opType) {
              case '画板跳转': // 图片模型
                drawBoardMethod(data);
                break;
              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(),
1320
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
        goJS(
          go.Shape,
          'Rectangle',
          { name: 'SHAPE', fill: 'rgba(128,128,128,0.2)', stroke: 'gray' },
          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(),
1349
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
        goJS(
          go.Shape,
          'Ellipse',
          { name: 'SHAPE', fill: 'rgba(128,128,128,0.2)', stroke: 'gray' },
          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(
      'deviceCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
李纪文's avatar
李纪文 committed
1370
        { locationSpot: go.Spot.Center, zOrder: 3 },
涂茜's avatar
涂茜 committed
1371 1372 1373
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
1374
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
        goJS(
          go.Shape,
          'Rectangle',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000' },
          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),
        ),
        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
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
        {
          click(e, node) {
            const { data } = node;
            nodeData = data;
            const list = bindData.find((item) => {
              return item.name === data.stationName;
            });
            if (!list) return false;
            switch (data.opType) {
              case '画板跳转': // 图片模型
                drawBoardMethod(data);
                break;
              case '自定义交互': // 自定义交互
                customBack(data);
                break;
              default:
                break;
            }
          },
        },
涂茜's avatar
涂茜 committed
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
      ),
    );

    // 名称定义
    myDiagram.nodeTemplateMap.add(
      'nameCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
        { locationSpot: go.Spot.Center, zOrder: 3 },
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
1437
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 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 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
        goJS(
          go.Shape,
          'Rectangle',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000' },
          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),
        ),
        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'),
        ),
        {
          click(e, node) {
            const { data } = node;
            nodeData = data;
            const list = bindData.find((item) => {
              return item.name === data.stationName;
            });
            if (!list) return false;
            // 控制方法
            if (data.ctName && data.ctType) {
              controlModalRender(data, list);
              return false;
            }
            switch (data.opType) {
              case '画板跳转': // 图片模型
                drawBoardMethod(data);
                break;
              case '自定义交互': // 自定义交互
                customBack(data);
                break;
              default:
                break;
            }
          },
        },
      ),
    );

    // 公用管定义
    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(),
1505
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
        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',
        { 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(),
1561
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 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
        goJS(
          go.Shape,
          'Rectangle',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000' },
          new go.Binding('fill', 'fillColor'),
          new go.Binding('stroke'),
          new go.Binding('strokeWidth'),
          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', 'showVal'),
          new go.Binding('font', 'fontStyle'),
          new go.Binding('stroke', 'fontStroke'),
          new go.Binding('textAlign', 'fontAlign'),
        ),
        {
          click(e, node) {
            const { data } = node;
            nodeData = data;
            const list = bindData.find((item) => {
              return item.name === data.stationName;
            });
            if (!list) return false;
            // 控制方法
            if (data.ctName && data.ctType) {
              controlModalRender(data, list);
              return false;
            }
            // 历史查看
            if (data.opType) historyModalRender(data, list);
          },
        },
      ),
    );

    // 连接点定义
    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(),
1620
        roleVisibleBinding(), // 绑定角色
涂茜's avatar
涂茜 committed
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
        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(),
1662
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
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 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755
        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(),
        ),
      ),
    );

    // 进度条设置
    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;
    });

    // 定义进度条
    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(),
1756
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 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
        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',
          },
          new go.Binding('width').makeTwoWay(),
          new go.Binding('height').makeTwoWay(),
          new go.Binding('strokeWidth', 'strokeWidth').makeTwoWay(),
          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),
          },
          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,
          '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),
          },
          new go.Binding('width', 'lineWidth').makeTwoWay(),
          new go.Binding('height', 'height').makeTwoWay(),
          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,
        },
1828
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878
        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(),
1879
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
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
        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',
        { 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(),
1911
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1912 1913 1914 1915 1916 1917 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
        goJS(
          go.Shape,
          'RoundedRectangle',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000' },
          new go.Binding('fill', 'fillColor'),
          new go.Binding('stroke'),
          new go.Binding('strokeWidth'),
          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'),
        ),
        {
          click(e, node) {
            const { data } = node;
            nodeData = data;
            const list = bindData.find((item) => {
              return item.name === data.stationName;
            });
            if (!list) return false;
            // 控制方法
            controlModalRender(data, list);
          },
        },
      ),
    );

    // 搅拌机状态设置
    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(),
1970
        roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
        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,
      }),
    );

2014
    /** *******************************单管连接方式****************************** */
涂茜's avatar
涂茜 committed
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035
    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,
      },
      new go.Binding('fromSpot', 'fromPort', (d) => {
        return spotConverter(d);
      }),
      new go.Binding('toSpot', 'toPort', (d) => {
        return spotConverter(d);
      }),
      new go.Binding('points').makeTwoWay(),
2036
      roleVisibleBinding(), // 绑定角色可见
涂茜's avatar
涂茜 committed
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056
      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'),
      ),
    );

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
    /** *******************************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,
        },
        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'),
        ),
      ),
    );

涂茜's avatar
涂茜 committed
2112
    /** **************************************合管连接方式****************************************** */
李纪文's avatar
李纪文 committed
2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123
    // myDiagram.linkTemplateMap.add(
    //   'linkToLink',
    //   goJS(
    //     'Link',
    //     { relinkableFrom: true, relinkableTo: true },
    //     goJS('Shape', {
    //       stroke: '#2D9945',
    //       strokeWidth: 2,
    //     }),
    //   ),
    // );
涂茜's avatar
涂茜 committed
2124
    const fromJson = JSON.parse(jsonStr);
李纪文's avatar
李纪文 committed
2125 2126
    // const setTime = setTimeout(() => {
    myTimeout(() => {
涂茜's avatar
涂茜 committed
2127 2128 2129 2130
      loop();
      waterSvg();
      rotateSvg();
      blenderSvg();
李纪文's avatar
李纪文 committed
2131
      animationSvg();
涂茜's avatar
涂茜 committed
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158
    }, 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;
      }
      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;
      }
李纪文's avatar
李纪文 committed
2159 2160 2161 2162 2163 2164
      if (item.category == 'deviceCase' && deviceName && deviceName.length) {
        var device = deviceName.find(function (arr, index) {
          return '设备' + stationList[index] == item.stationName;
        });
        if (device) item.text = device;
      }
涂茜's avatar
涂茜 committed
2165 2166 2167 2168 2169
    });
    myDiagram.model = go.Model.fromJson(json);
  };

  return (
李纪文's avatar
李纪文 committed
2170
    <div className={classNames(prefixCls)} ref={ConfigurationRef}>
2171 2172
      <div id={twoID} className={classNames('configurationView')}>
        <LoadBox spinning={spinning} />
李纪文's avatar
李纪文 committed
2173
        {isEmpty && <Empty theme={'dark'} description={description} />}
2174
      </div>
涂茜's avatar
涂茜 committed
2175 2176 2177 2178 2179
      {/* 远程控制 */}
      {isModalVisible && (
        <Modal
          centered
          okText={'确定'}
2180
          width={modalWidth}
涂茜's avatar
涂茜 committed
2181
          cancelText={'取消'}
李纪文's avatar
李纪文 committed
2182
          open={isModalVisible}
涂茜's avatar
涂茜 committed
2183 2184
          onOk={handleOk}
          onCancel={handleCancel}
李纪文's avatar
李纪文 committed
2185
          wrapClassName={classNames(`${prefixCls}-baseModal`)}
李纪文's avatar
李纪文 committed
2186
          getContainer={ConfigurationRef.current}
涂茜's avatar
涂茜 committed
2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198
          {...modalProps}
        >
          {renderModalContent()}
        </Modal>
      )}
      {/* 权限登录 */}
      {isAuModalVisible && (
        <Modal
          centered
          title={'权限认证'}
          okText={'确定'}
          cancelText={'取消'}
李纪文's avatar
李纪文 committed
2199
          open={isAuModalVisible}
涂茜's avatar
涂茜 committed
2200 2201
          onOk={handleAuOk}
          onCancel={() => setIsAuModalVisible(false)}
李纪文's avatar
李纪文 committed
2202
          getContainer={ConfigurationRef.current}
李纪文's avatar
李纪文 committed
2203
          width={520}
李纪文's avatar
李纪文 committed
2204
          wrapClassName={classNames(`${prefixCls}-baseModal`)}
涂茜's avatar
涂茜 committed
2205 2206 2207 2208 2209 2210
        >
          <Form className={classNames('authorizeControlContent')} ref={AuthorFrom} name="loginForm">
            <Form.Item className={classNames('authorizeControlItem')} name="userName" label="账户">
              <Input placeholder="请输入用户名" />
            </Form.Item>
            <Form.Item className={classNames('authorizeControlItem')} name="password" label="密码">
李纪文's avatar
李纪文 committed
2211
              <Input.Password placeholder="请输入密码" />
涂茜's avatar
涂茜 committed
2212 2213 2214 2215 2216 2217 2218 2219
            </Form.Item>
          </Form>
        </Modal>
      )}
      {/* 历史曲线 */}
      {isHIModalVisible && (
        <Modal
          centered
李纪文's avatar
李纪文 committed
2220
          width={1100}
涂茜's avatar
涂茜 committed
2221
          footer={null}
李纪文's avatar
李纪文 committed
2222
          open={isHIModalVisible}
涂茜's avatar
涂茜 committed
2223 2224
          onOk={() => setIsHIModalVisible(false)}
          onCancel={() => setIsHIModalVisible(false)}
李纪文's avatar
李纪文 committed
2225
          getContainer={ConfigurationRef.current}
2226
          wrapClassName={classNames(`${prefixCls}-historyInfoModal`)}
涂茜's avatar
涂茜 committed
2227
        >
李纪文's avatar
李纪文 committed
2228
          <HistoryView deviceParams={historyInfoParams} />
涂茜's avatar
涂茜 committed
2229 2230 2231 2232
        </Modal>
      )}
      {/* 画板跳转 */}
      {isJumpModalVisible && jumpModalProps && (
2233
        <DragModal
涂茜's avatar
涂茜 committed
2234 2235 2236 2237 2238
          centered
          width={jumpModalProps.width ? `${jumpModalProps.width}px` : '100%'}
          title={jumpModalProps.title}
          footer={null}
          visible={isJumpModalVisible}
2239
          limit={true}
涂茜's avatar
涂茜 committed
2240
          onCancel={() => setIsJumpModalVisible(false)}
2241
          wrapClassName={classNames(`${prefixCls}-jumpModal`)}
李纪文's avatar
李纪文 committed
2242
          getContainer={ConfigurationRef.current}
李纪文's avatar
李纪文 committed
2243
          componentPrefix={componentPrefix}
涂茜's avatar
涂茜 committed
2244 2245
          style={{
            height: jumpModalProps.height ? `${Number(jumpModalProps.height) + 103}px` : '100%',
2246 2247 2248 2249
            left: `calc(50% - ${jumpModalProps.width ? jumpModalProps.width / 2 + 'px' : '50%'})`,
            top: `calc(50% - ${
              jumpModalProps.height ? (Number(jumpModalProps.height) + 103) / 2 + 'px' : '50%'
            })`,
涂茜's avatar
涂茜 committed
2250 2251
          }}
        >
2252 2253 2254 2255 2256 2257
          <ConfigurationDetail
            {...props}
            name={jumpModalProps.name}
            devices={jumpModalProps.device}
          />
        </DragModal>
涂茜's avatar
涂茜 committed
2258 2259 2260 2261 2262 2263 2264 2265
      )}
    </div>
  );
};

ConfigurationView.defaultProps = {
  name: '',
  devices: [],
李纪文's avatar
李纪文 committed
2266
  deviceName: [],
2267 2268 2269
  config: {},
  isZoom: false,
  flowShow: true,
涂茜's avatar
涂茜 committed
2270 2271 2272 2273 2274
};

ConfigurationView.propTypes = {
  name: PropTypes.string,
  devices: PropTypes.array,
李纪文's avatar
李纪文 committed
2275
  deviceName: PropTypes.array,
2276 2277 2278
  config: PropTypes.object,
  isZoom: PropTypes.bool,
  flowShow: PropTypes.bool,
涂茜's avatar
涂茜 committed
2279 2280 2281
};

export default ConfigurationView;