RealModel.js 114 KB
Newer Older
1
/* eslint-disable */
2
import React, { useState, useEffect, useRef, useContext, useMemo, useCallback } from 'react';
3 4
import classNames from 'classnames';
import moment from 'moment';
5
import axios from 'axios';
6 7 8
import sha1 from 'sha1';
import Empty from '@wisdom-components/empty';
import LoadBox from '@wisdom-components/loadbox';
李纪文's avatar
李纪文 committed
9
import VideoSliderModal from '@wisdom-components/videoslidermodal';
10 11 12 13 14 15 16
import { Input, message, Modal, Form, ConfigProvider, Button } from 'antd';
import {
  ExclamationCircleOutlined,
  DoubleLeftOutlined,
  LeftOutlined,
  RightOutlined,
  DoubleRightOutlined,
李纪文's avatar
李纪文 committed
17 18
  EyeOutlined,
  EyeInvisibleOutlined,
19 20 21 22
} from '@ant-design/icons';
import MqttView from '@wisdom-components/mqttview';
import PropTypes from 'prop-types';
import HistoryView from '@wisdom-components/ec_historyview';
李纪文's avatar
李纪文 committed
23
import StatisticalHistoryView from '@wisdom-components/ec_statisticalhistoryview';
24 25 26 27 28 29 30
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';
import ConfigurationDetail from './js/ConfigurationDetail';
import DragModal from './js/DragModal';
李纪文's avatar
李纪文 committed
31 32 33 34 35 36
import {
  getSketchPadList,
  getSketchPadContent,
  getPointAddress,
  getDeviceRealInfo,
  getVideoDetail,
李纪文's avatar
李纪文 committed
37
  getDictionaryInfo,
李纪文's avatar
李纪文 committed
38
} from './apis';
39 40 41 42 43 44 45 46
import {
  isNumber,
  createGuid,
  deepCopy,
  hexToRgba,
  addNumMethod,
  hexSwitch,
  textStyle,
47
  querySkipUrl,
48
  queryProduct,
李纪文's avatar
李纪文 committed
49
  isJson,
李纪文's avatar
李纪文 committed
50
  stationData,
李纪文's avatar
李纪文 committed
51
  getVideoUrl,
李纪文's avatar
李纪文 committed
52
  loginauthen,
李纪文's avatar
李纪文 committed
53
  encipher,
54 55 56 57 58 59 60 61 62 63 64 65 66
} from './js/utils';
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 = {};
let modalWidth = 520;
let historyInfoParams = [];
李纪文's avatar
李纪文 committed
67
let statisticalInfoParams = {};
68 69 70 71 72
let nodeData = null; // 选中节点的数据
let twoID = '';
const waterFlow = new WaterFlowControlView();

const ConfigurationView = (props) => {
73
  let myDiagram = null;
74 75
  let mqttView = null;
  let editionArr = [];
李纪文's avatar
李纪文 committed
76
  let globalControl = false;
77 78 79 80 81 82
  const guidAggre = {};
  const bindData = [];
  const stationList = [];
  const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
  const prefixCls = getPrefixCls('ec-configuration-view');
  const componentPrefix = getPrefixCls('');
83
  const [isDiagram, setIsDiagram] = useState(null);
84 85 86
  const [isModalVisible, setIsModalVisible] = useState(false);
  const [isAuModalVisible, setIsAuModalVisible] = useState(false); // 登录模态框
  const [isHIModalVisible, setIsHIModalVisible] = useState(false); // 历史曲线模态框
李纪文's avatar
李纪文 committed
87
  const [isSTHIModalVisible, setIsSTHIModalVisible] = useState(false); // 统计历史曲线模态框
88 89 90 91
  const [isJumpModalVisible, setIsJumpModalVisible] = useState(false); // 画板跳转模态框
  const [spinning, setSpinning] = useState(true); // 画板loading
  const [isEmpty, setIsEmpty] = useState(false); // 画板无数据状态
  const [description, setDescription] = useState(''); // 画板无数据描述
92
  const [first, setFirst] = useState(true); // 第一次加载
李纪文's avatar
李纪文 committed
93 94 95
  const [isVideoVisible, setIsVideoVisible] = useState(false);
  const [videoData, setVideoData] = useState([]);
  const [videoTitle, setVideoTitle] = useState('');
李纪文's avatar
李纪文 committed
96 97
  const [viewType, setViewType] = useState(false);
  const [currentUser, setCurrentUser] = useState(false);
98 99 100 101
  const [noInitial, setNoInitial] = useState(false);
  const [domFlag, setDomFlag] = useState(true);
  const [numerals, setNumerals] = useState(1);
  // twoID = `TDG${Date.now().toString(36)}`;
102
  const navigatorAgent = /(iPhone|iOS|Android|Windows Phone)/i.test(navigator.userAgent);
103 104 105
  const AdjustControlInput = useRef();
  const AuthorFrom = useRef();
  const ConfigurationRef = useRef();
李纪文's avatar
李纪文 committed
106
  const DomRef = useRef();
李纪文's avatar
李纪文 committed
107
  const TwoRef = useRef();
李纪文's avatar
李纪文 committed
108
  const loginTimer = useRef();
109
  const ConfigurationViewRef = useCallback((dom) => {
李纪文's avatar
李纪文 committed
110
    if (DomRef) DomRef.current = !!dom;
111 112
    setDomFlag(!!dom);
  });
113 114
  const customBack = props.customBack ? props.customBack : () => {};
  const { devices = [], config, isZoom = false, flowShow = true, deviceName = [] } = props;
李纪文's avatar
李纪文 committed
115
  let devicesCode = [];
116
  const globalConfig = window.globalConfig || config;
117
  let isClose = false;
118
  // 子应用包名查找
119
  const widgets = queryProduct(globalConfig?.widgets || [], decodeURI(window.location.pathname));
李纪文's avatar
李纪文 committed
120 121 122 123 124
  const _JessibucaObj = {
    operateBtns: {
      screenshot: false,
    },
    loadingText: '视频加载中',
125 126 127
    decoder: widgets
      ? `/${widgets.product}/JessibucaVideo/decoder.js`
      : '/JessibucaVideo/decoder.js',
李纪文's avatar
李纪文 committed
128 129
  };

130 131
  /** **********************************获取工艺图画板信息*********************** */
  const getConfiguraList = async () => {
李纪文's avatar
李纪文 committed
132 133
    const url = globalConfig.mainserver ? globalConfig.mainserver : 'https://panda-water.cn/';
    imgUrl = online ? `${url}PandaMonitor/Monitor/` : `/PandaMonitor/Monitor/`;
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
    // 获取画板信息
    const drawInfo = await getSketchPadList({
      name: props.name,
      siteCode:
        globalConfig.userInfo && globalConfig.userInfo.LocalSite
          ? globalConfig.userInfo.LocalSite
          : '',
      version: '全部',
      _site:
        globalConfig.userInfo && globalConfig.userInfo.LocalSite
          ? globalConfig.userInfo.LocalSite
          : '',
    });
    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
156
            stationList.push(stationData[remain] + round);
157
          } else {
李纪文's avatar
李纪文 committed
158
            stationList.push(stationData[remain]);
159 160
          }
        }
李纪文's avatar
李纪文 committed
161 162 163 164 165 166 167 168 169 170 171 172
        const siteInfoArr = Object.getOwnPropertyNames(siteInfo);
        devicesCode = [];
        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);
        });
李纪文's avatar
李纪文 committed
173
        await getPublicInfo();
174 175 176 177 178 179 180 181 182 183 184 185 186
        getDiagramJson(data[0], siteInfo);
      } else {
        setDescription('咦~未查询到工艺图画板信息哦~');
        setIsEmpty(true);
        setSpinning(false);
        return false;
      }
    } else {
      setDescription('咦~工艺图画板信息报错啦~');
      setIsEmpty(true);
      setSpinning(false);
      return message.error(drawInfo.msg);
    }
李纪文's avatar
李纪文 committed
187
  };
188

李纪文's avatar
李纪文 committed
189 190
  /** *********************************获取基本信息****************************** */
  const getPublicInfo = async () => {
191
    // 获取点表信息
李纪文's avatar
李纪文 committed
192
    const pointInfo = devicesCode.length
193
      ? await getPointAddress({
李纪文's avatar
李纪文 committed
194
          code: devicesCode.join(','),
195 196 197 198 199 200
          _site:
            globalConfig.userInfo && globalConfig.userInfo.LocalSite
              ? globalConfig.userInfo.LocalSite
              : '',
        })
      : null;
201
    editionArr = deepCopy(pointInfo && pointInfo.data ? pointInfo.data : [], []);
李纪文's avatar
李纪文 committed
202 203 204 205 206 207 208 209 210 211

    // 获取数据字典组态控制权限
    const dictInfoRes = await getDictionaryInfo({
      level: '组态控制权限',
    });
    const dictInfo = dictInfoRes?.data || [];
    const dictList = dictInfo.find((item) => {
      return item.fieldName === '控制人员' && item.fieldValue === '当前用户';
    });
    globalControl = dictList ? true : false;
212 213 214 215 216 217
  };

  /** *********************************节点展示逻辑****************************** */
  const showNodeMethod = (node, list) => {
    const realVal = list.Value * 1;
    let switchState;
李纪文's avatar
李纪文 committed
218
    myDiagram.model.setDataProperty(node, 'realVal', realVal);
219 220 221 222 223 224 225 226 227 228 229
    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);
230 231 232 233 234
          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);
          }
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
          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': // 实时值模型
255
          const division = node.division || false;
256
          // 动画翻转
李纪文's avatar
李纪文 committed
257 258
          if (node.effect)
            myDiagram.model.setDataProperty(node, 'flip', go.GraphObject.FlipHorizontal);
259
          if (node.shType === '值显示') {
260 261 262 263 264
            myDiagram.model.setDataProperty(
              node,
              'showVal',
              realVal < 0 ? 0 : division ? realVal.toLocaleString() : realVal,
            );
265
          } else {
266 267 268 269 270
            myDiagram.model.setDataProperty(
              node,
              'showVal',
              division ? realVal.toLocaleString() : realVal,
            );
271
          }
272 273 274 275
          // 动画还原
          myTimeout(() => {
            myDiagram.model.setDataProperty(node, 'flip', go.GraphObject.None);
          }, 100);
276
          // 颜色规则
李纪文's avatar
李纪文 committed
277
          if (node.stateName) return false;
278 279 280 281
          shRule = ruleOperation(node, realVal);
          myDiagram.model.setDataProperty(
            node,
            'fontStroke',
282 283 284
            node.realType === '在线'
              ? shRule
                ? shRule.attr
李纪文's avatar
李纪文 committed
285
                : node.dtStroke
286
              : node.oflColor || '#999999',
287
          );
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 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 351
          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);
352 353 354 355 356 357 358 359 360
          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);
          }
361 362 363
          break;
        case 'ellipseCase': // 圆形模型
          shRule = ruleOperation(node, realVal);
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
          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);
          }
385
          break;
386 387 388 389 390 391
        case 'groupCase': // 分组模型
          shRule = ruleOperation(node, realVal);
          if (node.shType === '显隐展示') {
            myDiagram.model.setDataProperty(node, 'visible', shRule ? shRule.visible : true);
          }
          break;
392 393 394
        default:
          break;
      }
395 396
    } catch (e) {
      // console.log(e);
397 398 399
    }
  };

李纪文's avatar
李纪文 committed
400 401 402 403 404 405 406 407 408 409 410 411 412
  /** *********************************节点状态展示逻辑****************************** */
  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',
413 414 415
            node.realType === '在线'
              ? shRule
                ? shRule.attr
李纪文's avatar
李纪文 committed
416
                : node.dtStroke
417
              : node.oflColor || '#999999',
李纪文's avatar
李纪文 committed
418 419 420 421 422
          );
          break;
        default:
          break;
      }
423 424
    } catch (e) {
      // console.log(e);
李纪文's avatar
李纪文 committed
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
  /** ***********************************展示规则运算********************************* */
  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;
    }
  };

  /** ***********************************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) => {
477
    if (isClose || !myDiagram) return false;
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
    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;
    const json = JSON.parse(myDiagram.model.toJson());
    const jsonCopy = JSON.parse(JSON.stringify(json));
    const oldJson = deepCopy(jsonCopy, {});
    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;
          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) {
      // 水流样式
    }

李纪文's avatar
李纪文 committed
516 517 518 519 520 521 522
    // 离线判断
    try {
      onlineColorMethod(jsonCopy.nodeDataArray, name, mqttData);
    } catch (err) {
      // console.log(err)
    }

523 524
    try {
      jsonCopy.nodeDataArray.forEach((item) => {
李纪文's avatar
李纪文 committed
525
        if (!(item.shName || item.category === 'timeCase') || item.stationName !== name)
526 527 528 529 530 531 532 533
          return false;
        const node = myDiagram.model.findNodeDataForKey(item.key);
        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;
李纪文's avatar
李纪文 committed
534 535 536 537
          if (
            (list.Value == null || shName !== item.shName || item.realVal === list.Value) &&
            shName !== item.stateName
          )
538
            return false;
李纪文's avatar
李纪文 committed
539 540 541 542 543 544 545 546 547
          if (node.category === 'timeCase' && shName === item.shName) {
            myDiagram.model.setDataProperty(node, 'text', moment(list.Time).format(node.format));
            myDiagram.model.setDataProperty(
              node,
              'timeStr',
              moment(list.Time).format('YYYY-MM-DD HH:mm:ss'),
            );
            return false;
          }
李纪文's avatar
李纪文 committed
548 549
          if (shName === item.shName) showNodeMethod(node, list);
          if (shName === item.stateName) stateMethod(node, list);
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
        });
      });
    } 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) {
      // 水流展示
    }
  };

586 587 588 589 590 591 592 593 594 595 596
  /** **************************************是否在线数据获取****************************************** */
  const onLineDataMethod = (data) => {
    const onlineList = data.find((list) => {
      const itemID = list.ItemID;
      const num = itemID.lastIndexOf('.');
      const shName = itemID.substring(num + 1, Infinity);
      return shName === '是否在线';
    });
    return onlineList;
  };

597
  /** **************************************是否在线颜色变化****************************************** */
李纪文's avatar
李纪文 committed
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
  const onlineColorMethod = (nodeDataArray, name, mqttData) => {
    const onlineList = onLineDataMethod(mqttData);
    if (!onlineList) return false;
    const onlineType = onlineList.Value * 1 ? '在线' : '离线';
    nodeDataArray.forEach((item) => {
      if (
        item.shName &&
        item.stationName === name &&
        item.category === 'valCase' &&
        !item.stateName
      ) {
        const node = myDiagram.model.findNodeDataForKey(item.key);
        const shRule = node.realVal !== '--' ? ruleOperation(node, node.realVal) : null;
        switch (node.category) {
          case 'valCase': // 实时值模型
            myDiagram.model.setDataProperty(
              node,
              'fontStroke',
              onlineType === '在线'
                ? shRule
                  ? shRule.attr
                  : node.dtStroke
                : node.oflColor || '#999999',
            );
            myDiagram.model.setDataProperty(node, 'realType', onlineType);
            break;
          default:
            break;
        }
627
      }
李纪文's avatar
李纪文 committed
628
    });
629 630
  };

631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
  /** **************************************合管****************************************** */
  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 = () => {
690
      if (isClose) return timer && cancelAnimationFrame(timer);
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
      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();
710
      if (isClose) return timer && cancelAnimationFrame(timer);
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 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 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 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
      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) => {
854
    if (!first) return getConfiguraList();
855 856 857 858
    const ImgObj = new Image();
    ImgObj.src = pathImg;
    ImgObj.onload = () => {
      online = ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0);
859
      setFirst(false);
860 861 862 863
      getConfiguraList();
    };
    ImgObj.onerror = () => {
      online = false;
864
      setFirst(false);
865 866 867 868
      getConfiguraList();
    };
  };

869
  useEffect(() => {
870 871 872 873
    if (noInitial && domFlag) {
      setNumerals(numerals + 1);
    }
  }, [noInitial, domFlag]);
874

875
  useEffect(() => {
李纪文's avatar
李纪文 committed
876
    TwoRef.current = `TDG${Date.now().toString(36)}`;
李纪文's avatar
李纪文 committed
877
    if (!props.name) {
878 879 880 881 882
      setDescription('咦~工艺图配置信息不全哦~');
      setIsEmpty(true);
      setSpinning(false);
      return false;
    }
883
    setSpinning(true);
884 885 886
    const url = globalConfig.mainserver ? globalConfig.mainserver : 'https://panda-water.cn/';
    onlineMethod(`${url}civweb4/assets/images/bootPage/熊猫图标.png`, url);
    return () => {
887
      isClose = true;
888 889
      mqttView && mqttView.disSaveWaconnect();
      mqttView = null;
890 891 892
      if (myDiagram) {
        myDiagram.div = null;
        myDiagram = null;
893
        setIsDiagram(null);
894
      }
895
    };
896
  }, [props.name, numerals]);
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911

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

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

李纪文's avatar
李纪文 committed
912 913 914 915
  useEffect(() => {
    loginauthen();
    loginTimer.current = setInterval(() => {
      loginauthen();
916
    }, 1000 * 28800);
李纪文's avatar
李纪文 committed
917 918 919 920 921 922
    return () => {
      clearInterval(loginTimer.current);
      loginTimer.current = null;
    };
  }, []);

923 924 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
  useEffect(() => {
    try {
      const { messaged = {} } = props;
      if (isDiagram && Object.keys(messaged).length > 0) {
        const json = JSON.parse(isDiagram.model.toJson());
        const jsonCopy = JSON.parse(JSON.stringify(json));
        jsonCopy.nodeDataArray.forEach((item) => {
          if (item.category === 'groupCase' && !item.shName) {
            const node = isDiagram.model.findNodeDataForKey(item.key);
            messagedMethod(node, messaged);
          }
        });
      }
    } catch (err) {
      // console.log(err);
    }
  }, [props.messaged, isDiagram]);

  // 信息通信
  const messagedMethod = (node, messaged) => {
    let shRule = [];
    try {
      switch (node.category) {
        case 'groupCase': // 分组模型
          shRule = ruleMessaged(node, messaged);
          if (node.shType === '显隐展示') {
            isDiagram.model.setDataProperty(
              node,
              'visible',
              shRule ? shRule.visible : node.dtVisible,
            );
          }
          break;
        default:
          break;
      }
    } catch (e) {
      // console.log(e);
    }
  };

  // 信息通信语句解析
  const ruleMessaged = (node, messaged) => {
    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)(messaged, messaged);
        } catch (err) {
          return false;
        }
      } else {
        return false;
      }
    });
    return shRule;
  };

982 983 984 985 986 987 988 989 990 991 992
  /** ************************************获取画板JSON******************************* */
  const getDiagramJson = async (list, siteInfo) => {
    const response = await getSketchPadContent({
      dimension: list.dimension,
      siteCode: list.siteCode,
      fileName: list.deployURL.split('\\').pop(),
      _site:
        globalConfig.userInfo && globalConfig.userInfo.LocalSite
          ? globalConfig.userInfo.LocalSite
          : '',
    });
993
    setSpinning(false);
994
    if (response.code === 0) {
995
      if (isClose) return false;
996 997 998 999 1000 1001 1002 1003
      const fromJson = response.data
        ? response.data
        : {
            linkFromPortIdProperty: 'fromPort',
            linkToPortIdProperty: 'toPort',
            nodeDataArray: [],
            linkDataArray: [],
          };
1004 1005
      const twoDom = document.getElementById(TwoRef.current);
      if ((DomRef && !DomRef.current) || !twoDom) return setNoInitial(true);
李纪文's avatar
李纪文 committed
1006
      mqttView = devicesCode.length
1007 1008 1009 1010
        ? new MqttView({
            mqttIP: globalConfig.mqtt_iotIP,
            mqttPath: globalConfig.mqtt_path,
            mqttSsl: globalConfig.mqtt_IsSSL,
1011
            siteCode: globalConfig?.mqtt_mess?.site_code || '',
李纪文's avatar
李纪文 committed
1012
            devices: devicesCode,
1013 1014 1015 1016
            callback: refreshData,
            controlback: controlData,
          })
        : null;
1017
      const diagramJson = typeof fromJson === 'string' ? fromJson : JSON.stringify(fromJson);
1018
      diagramRender(diagramJson, list);
1019
      setNoInitial(false);
1020
      try {
1021 1022 1023 1024
        let dataSources = 'MQTT';
        const nodeDataArray = JSON.parse(diagramJson)?.nodeDataArray || [];
        nodeDataArray.forEach((item) => {
          if (item.category === 'bgCase') dataSources = item.dataSources || 'MQTT';
1025
        });
1026 1027 1028 1029 1030
        if (dataSources === 'MQTT') {
          mqttView && mqttView.saveWaterMqtt();
        } else {
          getRealData(siteInfo);
        }
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
      } catch (e) {
        // 获取实时数据
        getRealData(siteInfo);
      }
    } 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 = {
李纪文's avatar
李纪文 committed
1051
        equipmentCode: devicesCode.join(','),
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
        accountFieldParams,
      };
      const results = await getDeviceRealInfo(params);
      const realData = results && results.data && results.data.list ? results.data.list : [];
      chartDataRender(flatten(realData));
    } catch (err) {}
  };

  // 实时数据父子级平铺
  const flatten = (arr) => {
    return [].concat(
      ...arr.map((item) =>
        item.child ? [].concat(item, ...flatten(item.child)) : [].concat(item),
      ),
    );
  };

1069
  /** ************************************数据源数据获取******************************* */
1070 1071
  const getDataModel = () => {
    const json = JSON.parse(myDiagram.model.toJson());
1072
    const nodeDataArray = json.nodeDataArray;
1073 1074 1075 1076 1077 1078
    const dataCaseArr = nodeDataArray.filter((item) => {
      return item.category === 'dataSource' && item.url;
    });
    try {
      dataCaseArr.forEach((item, index) => {
        const time = new Date().getTime() + index;
李纪文's avatar
李纪文 committed
1079 1080 1081
        let params,
          data = {};
        try {
李纪文's avatar
李纪文 committed
1082
          params = new Function('moment', (item && item.parameters) || '')(moment) || {};
李纪文's avatar
李纪文 committed
1083 1084 1085 1086
        } catch (err) {}
        try {
          data = new Function('moment', (item && item.body) || '')(moment) || {};
        } catch (err) {}
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 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
        axios({
          method: item.method,
          url: item.url,
          params: {
            ...params,
            time: time,
          },
          data: data,
        })
          .then((res) => {
            realValueHandle(nodeDataArray, item, getDataFilter(item, res?.data || {}));
          })
          .catch((err) => {
            realValueHandle(nodeDataArray, item, null);
          });
      });
    } catch (err) {}
  };

  /** ************************************数据源过滤器******************************* */
  const getDataFilter = (item, data) => {
    try {
      const script = item && item.filter ? item.filter : '';
      if (!script) return data;
      const list = new Function('data', script)(data);
      return list;
    } catch (err) {
      return null;
    }
  };

  /** ************************************源数据模型处理******************************* */
  const realValueHandle = (nodeDataArray, list, data) => {
    nodeDataArray.forEach((item) => {
      if (item.category !== 'dataCase' || item.dataSource !== list.sname || !item.shType)
        return false;
      try {
        const script = item && item.filter ? item.filter : '';
        const value = new Function('data', script)(data);
        const node = myDiagram.model.findNodeDataForKey(item.key);
1127 1128 1129 1130 1131
        myDiagram.model.setDataProperty(
          node,
          'showVal',
          typeof value !== 'undefined' ? value : '--',
        );
1132 1133 1134 1135
      } catch (err) {}
    });
  };

1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 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 1191 1192 1193 1194
  /** ************************************图表数据处理******************************* */
  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;
          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',
              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 (
李纪文's avatar
李纪文 committed
1195 1196 1197 1198 1199
            (!pvList ||
              pvList.pv === null ||
              pvList.dName !== item.shName ||
              item.realVal === pvList.pv) &&
            pvList.dName !== item.stateName
1200 1201 1202
          )
            return false;
          pvList.Value = pvList.pv;
李纪文's avatar
李纪文 committed
1203 1204
          if (pvList.dName === item.shName) showNodeMethod(node, pvList);
          if (pvList.dName === item.stateName) stateMethod(node, list);
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
        });
      });
    } 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) {
      // 水流展示
    }
  };

  /** **************************************历史模态渲染****************************************** */
  const historyModalRender = (data, list) => {
1243
    if (!data.shName) return false;
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
    historyInfoParams = [
      {
        deviceCode: list.code,
        sensors: data.shName,
        deviceType: list.type,
      },
    ];
    setIsHIModalVisible(true);
  };

李纪文's avatar
李纪文 committed
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
  /** **************************************统计历史模态渲染****************************************** */
  const statisticalModalRender = (data, list) => {
    const opRule = JSON.parse(data.opRule);
    const stType = opRule && opRule.stType ? opRule.stType : '';
    if (!data.shName) return false;
    statisticalInfoParams = {
      deviceCode: list.code,
      sensors: data.shName,
      deviceType: list.type,
      statisticType: stType,
    };
    setIsSTHIModalVisible(true);
  };

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

  /** **************************************渲染输入控制****************************************** */
  const renderAdjustControlModal = () => {
    const ctRule = nodeData.ctRule ? JSON.parse(nodeData.ctRule) : [];
    const step = ctRule.length ? ctRule[0].step || 0.1 : 0.1;
    return (
      <div className={classNames('adjustControlContent')}>
        <div className={classNames('label')}>设置</div>
        <Input
          placeholder="请输入设置值"
          ref={AdjustControlInput}
          defaultValue={nodeData.realVal}
          onChange={() => {}}
          suffix={ctRule.length ? ctRule[0].text : ''}
        />
        <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>
      </div>
    );
  };

  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);
      }
    }
  };

  /** **************************************权限控制确认****************************************** */
  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);
1348 1349 1350
    mqttView &&
      mqttView.onSendWaMessageArrived(
        userName,
李纪文's avatar
李纪文 committed
1351
        encipher(password).toUpperCase(),
1352 1353 1354 1355 1356 1357
        guid,
        code,
        tag,
        value,
        flag ? value * 1 : '',
      );
1358 1359 1360
  };

  /** **************************************权限控制方法****************************************** */
李纪文's avatar
李纪文 committed
1361 1362 1363 1364 1365
  const authoMethod = async (code, tag, node, guid, value) => {
    const { people = '' } = node;
    const userName =
      people === '当前用户' || globalControl ? globalConfig?.userInfo?.loginName || '' : '';
    setCurrentUser(userName);
1366 1367 1368 1369
    setIsAuModalVisible(true);
    auModalConfirmFn = () => defineAutho(code, tag, node, guid, value);
  };

李纪文's avatar
李纪文 committed
1370 1371 1372 1373 1374
  // 查看密码
  const viewTypeChange = (e) => {
    setViewType(!viewType);
  };

1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386
  /** **************************************开关控制确定****************************************** */
  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;
    }
    guidAggre[guid] = { tag, code };
    const { val } = ctRule[0];
    const flag = isNumber(val);
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
    mqttView &&
      mqttView.onSendWaMessageArrived(
        globalConfig.token || '',
        '',
        guid,
        code,
        tag,
        val,
        flag ? val * 1 : '',
      );
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
  };

  /** **************************************控制方法****************************************** */
  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 : '';
    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) {
      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;
    }
    if (hexfrom && hexto) value = hexSwitch(value, hexfrom, hexto);
    const guid = createGuid();
    setIsModalVisible(false);
    if (node.isControl === '') {
      authoMethod(code, tag, node, guid, value);
      return false;
    }
    guidAggre[guid] = { tag, code };
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
    mqttView &&
      mqttView.onSendWaMessageArrived(
        globalConfig.token || '',
        '',
        guid,
        code,
        tag,
        node.switchType,
        value * 1,
      );
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
  };

  const moreControlMethod = (code, tag, node, value) => {
    const guid = createGuid();
    setIsModalVisible(false);
    if (node.isControl === '') {
      authoMethod(code, tag, node, guid, value);
      return false;
    }
    guidAggre[guid] = { tag, code };
    const flag = isNumber(value);
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
    mqttView &&
      mqttView.onSendWaMessageArrived(
        globalConfig.token || '',
        '',
        guid,
        code,
        tag,
        value,
        flag ? value * 1 : '',
      );
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 1505 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
  };

  /** **************************************渲染多选控制****************************************** */
  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) => {
    const ctRule = data && data.ctRule ? JSON.parse(data.ctRule) : '';
    switch (data.ctType) {
      case '按钮控制':
        if (data.switch === '') message.warning(`当前设备已是${data.text}状态,请勿重复操作!`);
        if (
          data.realVal === '--' ||
          data.switch === '' ||
          !data.ctName ||
          !data.ctName.length ||
          ctRule[0].val === ''
        )
          return false;
        modalComponent = renderSwitchControlModal;
        modalConfirmFn = () => defineSwitch(list.code, data.ctName, data);
        modalProps = { title: '状态控制' };
        modalWidth = 520;
        setIsModalVisible(true);
        break;
      case '输入控制':
        if (data.realVal === '--' || !data.ctName) return false;
        modalComponent = renderAdjustControlModal;
        modalConfirmFn = () => controlMethod(list.code, data.ctName, data);
        modalProps = { title: `${data.ctName}设置` };
        modalWidth = 520;
        setIsModalVisible(true);
        break;
      case '多选控制':
        if (!data.ctName) return false;
        modalComponent = renderMoreControlModal;
        modalProps = { footer: null, title: `${data.ctName}设置` };
        modalWidth = 'auto';
        setIsModalVisible(true);
        break;
      default:
        break;
    }
  };

李纪文's avatar
李纪文 committed
1539 1540 1541 1542
  /** **************************************视频查看****************************************** */
  const videoScanMethod = async (data) => {
    try {
      const opRule = JSON.parse(data.opRule);
1543 1544 1545 1546 1547 1548
      const bindList = bindData.find((item) => {
        return item.name === data.stationName;
      });
      const { vdCode = bindList.code, vdList = '', vdName = '', vdType = '' } = opRule;
      if (!vdCode) return setVideoData([]);
      if (vdType && !vdList) return setVideoData([]);
李纪文's avatar
李纪文 committed
1549
      const detail = await getVideoDetail({
1550 1551
        UserID: 1,
        DeviceCode: vdCode,
李纪文's avatar
李纪文 committed
1552 1553 1554 1555 1556 1557 1558 1559
        _site:
          globalConfig.userInfo && globalConfig.userInfo.LocalSite
            ? globalConfig.userInfo.LocalSite
            : '',
      });
      const dataList = detail?.data;
      if (!dataList) return setVideoData([]);
      const detailList = [];
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
      if (vdType) {
        const videoList = vdList.split(',');
        videoList.forEach((item, index) => {
          const list = dataList.find((obj) => {
            return item === obj.vmS_DeviceID;
          });
          if (list)
            detailList.push({
              id: list.vmS_DeviceID,
              name: list.channelName,
              protocol: list.protocol,
              username: list.username,
              password: list.password,
              dataRate: 'Sub',
              pandavmsHost: getVideoUrl(),
              gateway: true,
              address: list.address,
              channel: list.channelID * 1,
            });
李纪文's avatar
李纪文 committed
1579
        });
1580 1581
      } else {
        dataList.forEach((list) => {
1582 1583 1584 1585 1586 1587 1588 1589
          detailList.push({
            id: list.vmS_DeviceID,
            name: list.channelName,
            protocol: list.protocol,
            username: list.username,
            password: list.password,
            dataRate: 'Sub',
            pandavmsHost: getVideoUrl(),
1590
            gateway: true,
1591
            address: list.address,
1592
            channel: list.channelID * 1,
1593
          });
1594 1595
        });
      }
李纪文's avatar
李纪文 committed
1596
      setVideoTitle(vdName + '视频查看');
李纪文's avatar
李纪文 committed
1597
      setVideoData(detailList);
1598
      detailList.length && setIsVideoVisible(true);
李纪文's avatar
李纪文 committed
1599 1600 1601 1602 1603
    } catch (e) {
      // console.log(e)
    }
  };

李纪文's avatar
李纪文 committed
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614
  /** **************************************交互脚本****************************************** */
  const interactiveScript = (data) => {
    try {
      const opRule = JSON.parse(data.opRule);
      const script = opRule && opRule.script ? opRule.script : '';
      new Function('diagram', 'list', 'props', script)(myDiagram, data, props);
    } catch (e) {
      // console.log(e)
    }
  };

1615
  /** **************************************跳转方法****************************************** */
1616 1617 1618
  const menuJumpMethod = (data) => {
    const opRule = JSON.parse(data.opRule);
    const widget = opRule && opRule.widget ? opRule.widget : '';
李纪文's avatar
李纪文 committed
1619 1620
    const params =
      opRule && opRule.params ? (isJson(opRule.params) && JSON.parse(opRule.params)) || {} : {};
1621 1622
    const list = querySkipUrl(globalConfig?.widgets || [], widget);
    if (!list || !widget) return false;
李纪文's avatar
李纪文 committed
1623
    window.history.pushState(params, null, `/civbase/${list.product || 'civweb4'}/${list.url}`);
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
  /** **************************************跳转方法****************************************** */
  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 : '';
    const color = opRule && opRule.color ? opRule.color : '#282d3b';
    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,
      color,
    };
    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;
  };

  /** **********************************画布渲染************************************ */
1673
  const diagramRender = (jsonStr, chartInfo) => {
1674 1675
    myDiagram = goJS(
      go.Diagram,
李纪文's avatar
李纪文 committed
1676
      TwoRef.current, // must name or refer to the DIV HTML element
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
      {
        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
1692
        // padding: 20,
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
        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
1712 1713 1714 1715 1716 1717
    /** **********************************分组模型************************************* */
    myDiagram.groupTemplate =
      ('groupCase',
      goJS(
        go.Group,
        'Auto',
1718
        { ungroupable: true, zOrder: 1, visible: true },
1719 1720 1721
        {
          // 设置其可选择
          selectable: false,
1722
          layerName: 'Background',
1723
        },
1724
        new go.Binding('visible', 'visible').makeTwoWay(),
李纪文's avatar
李纪文 committed
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
        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' },
          ),
        ),
      ));

1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770
    // 自定义矩形
    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;
    });

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
    // 背景模板定义
    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
1800 1801
              const own = myDiagram ? myDiagram.model.findNodeDataForKey('bgCase') : {};
              props.bgMethod && props.bgMethod(own);
1802
              return v
1803
                ? `/PandaMonitor/Monitor/SketchPad/PreviewResource?name=${v}&_site=${
1804 1805 1806
                    globalConfig?.userInfo?.LocalSite || ''
                  }`
                : '';
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816
            }).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(),
          ),
        ),
      ),
    );

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 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 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
    // 表格节点定义
    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(
                          padding[0] * 1 || 0,
                          padding[1] * 1 || 0,
                          padding[2] * 1 || 0,
                          padding[3] * 1 || 0,
                        )
                      : 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(),
1893 1894
                    new go.Binding('stroke', 'bdColor').makeTwoWay(),
                    new go.Binding('strokeWidth', 'bdWidth').makeTwoWay(),
1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913
                    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) {
1914 1915 1916 1917 1918
                      try {
                        return new go.Size(v - 20, NaN);
                      } catch (err) {
                        return new go.Size(NaN, NaN);
                      }
1919 1920
                    }).makeTwoWay(),
                    new go.Binding('minSize', 'width', function (v) {
1921 1922 1923 1924 1925
                      try {
                        return new go.Size(v - 20, NaN);
                      } catch (err) {
                        return new go.Size(NaN, NaN);
                      }
1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
                    }).makeTwoWay(),
                  ),
                ),
              },
            ),
          },
        ),
      ),
    );

1936 1937 1938 1939 1940 1941
    // img节点定义
    myDiagram.nodeTemplateMap.add(
      'imgCase',
      goJS(
        go.Node,
        'Spot',
李纪文's avatar
李纪文 committed
1942
        { locationSpot: go.Spot.Center, zOrder: 1, cursor: 'default' },
1943
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
1944
        new go.Binding('cursor', 'cursor').makeTwoWay(),
1945 1946
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
1947
        roleVisibleBinding(), // 绑定角色可见
1948 1949 1950 1951 1952 1953 1954 1955 1956

        // 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),
1957
          new go.Binding('visible', 'visible').makeTwoWay(),
1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970
          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')
1971
                : `/PandaMonitor/Monitor/SketchPad/PreviewResource?name=${v}&_site=${
1972 1973 1974 1975 1976 1977 1978 1979
                    globalConfig?.userInfo?.LocalSite || ''
                  }`;
            }).makeTwoWay(),
            new go.Binding('scale', 'scale').makeTwoWay(),
            new go.Binding('width', 'width').makeTwoWay(),
            new go.Binding('height', 'height').makeTwoWay(),
          ),
        ),
李纪文's avatar
李纪文 committed
1980 1981
        {
          click(e, node) {
1982
            if (navigatorAgent) return false;
李纪文's avatar
李纪文 committed
1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
            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 '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
李纪文's avatar
李纪文 committed
1997 1998 1999
              case '视频查看': // 视频查看
                videoScanMethod(data);
                break;
李纪文's avatar
李纪文 committed
2000 2001
              case '自定义交互': // 自定义交互
                customBack(data);
李纪文's avatar
李纪文 committed
2002
                interactiveScript(data);
李纪文's avatar
李纪文 committed
2003 2004 2005 2006 2007 2008
                break;
              default:
                break;
            }
          },
        },
2009 2010 2011
      ),
    );

2012 2013 2014 2015 2016 2017
    // svg节点定义
    myDiagram.nodeTemplateMap.add(
      'svgCase',
      goJS(
        go.Node,
        'Spot',
李纪文's avatar
李纪文 committed
2018
        { locationSpot: go.Spot.Center, zOrder: 1, cursor: 'default' },
2019
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
2020
        new go.Binding('cursor', 'cursor').makeTwoWay(),
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
        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),
2031
          new go.Binding('visible', 'visible').makeTwoWay(),
2032 2033 2034 2035
          goJS(
            go.Picture,
            { name: 'animateSvg', width: 56, height: 56, column: 0, scale: 1, source: '' },
            new go.Binding('source', 'imgSrc', (v) => {
李纪文's avatar
李纪文 committed
2036
              return `${imgUrl}Model/Preview/${encodeURIComponent(v)}`;
2037 2038 2039 2040 2041 2042 2043 2044
            }),
            new go.Binding('scale', 'scale').makeTwoWay(),
            new go.Binding('width', 'width').makeTwoWay(),
            new go.Binding('height', 'height').makeTwoWay(),
          ),
        ),
        {
          click(e, node) {
2045
            if (navigatorAgent) return false;
2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061
            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;
2062 2063 2064
              case '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
李纪文's avatar
李纪文 committed
2065 2066 2067
              case '视频查看': // 视频查看
                videoScanMethod(data);
                break;
2068 2069
              case '自定义交互': // 自定义交互
                customBack(data);
李纪文's avatar
李纪文 committed
2070
                interactiveScript(data);
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
                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,
2099 2100
          'RoundedRectanglePlus',
          { name: 'SHAPE', fill: 'rgba(128,128,128,0.2)', stroke: 'gray', parameter1: 0 },
2101
          new go.Binding('visible', 'visible').makeTwoWay(),
2102
          new go.Binding('parameter1', 'radius').makeTwoWay(),
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
          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' },
2132
          new go.Binding('visible', 'visible').makeTwoWay(),
2133 2134 2135 2136 2137 2138 2139 2140
          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),
        ),
      ),
    );

2141
    // 设备名称定义
2142 2143 2144 2145 2146 2147 2148
    myDiagram.nodeTemplateMap.add(
      'deviceCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
李纪文's avatar
李纪文 committed
2149
        { locationSpot: go.Spot.Center, zOrder: 3, cursor: 'default' },
2150
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
2151
        new go.Binding('cursor', 'cursor').makeTwoWay(),
2152 2153 2154 2155 2156
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
2157 2158
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
2159 2160 2161
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
2162
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2163 2164 2165 2166 2167 2168
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
        goJS(
          go.TextBlock,
          textStyle(),
          {
李纪文's avatar
李纪文 committed
2169
            // margin: 5,
2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181
            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
2182 2183
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
2184 2185 2186
        ),
        {
          click(e, node) {
2187
            if (navigatorAgent) return false;
2188 2189 2190 2191 2192 2193 2194 2195 2196 2197
            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;
2198 2199 2200
              case '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
李纪文's avatar
李纪文 committed
2201 2202 2203
              case '视频查看': // 视频查看
                videoScanMethod(data);
                break;
2204 2205
              case '自定义交互': // 自定义交互
                customBack(data);
李纪文's avatar
李纪文 committed
2206
                interactiveScript(data);
2207 2208 2209 2210 2211 2212 2213 2214 2215
                break;
              default:
                break;
            }
          },
        },
      ),
    );

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
    // 数据源模型定义
    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'),
        ),
      ),
    );

    // 源数据模型定义
2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
    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', 'showVal').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) {
            if (navigatorAgent) return false;
            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 '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
              case '视频查看': // 视频查看
                videoScanMethod(data);
                break;
              case '自定义交互': // 自定义交互
                customBack(data);
                interactiveScript(data);
                break;
              default:
                break;
            }
          },
        },
      ),
    );

2336 2337 2338 2339 2340 2341 2342 2343
    // 名称定义
    myDiagram.nodeTemplateMap.add(
      'nameCase',
      goJS(
        go.Node,
        'Auto',
        nodeStyle(),
        'Spot',
李纪文's avatar
李纪文 committed
2344
        { locationSpot: go.Spot.Center, zOrder: 3, cursor: 'default' },
2345
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
2346
        new go.Binding('cursor', 'cursor').makeTwoWay(),
2347 2348 2349 2350 2351
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
2352 2353
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
2354 2355 2356
          new go.Binding('fill', 'fillColor').makeTwoWay(),
          new go.Binding('stroke').makeTwoWay(),
          new go.Binding('strokeWidth').makeTwoWay(),
2357
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2358 2359 2360 2361 2362 2363
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
        ),
        goJS(
          go.TextBlock,
          textStyle(),
          {
李纪文's avatar
李纪文 committed
2364
            // margin: 5,
2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376
            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
2377 2378
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
2379 2380 2381
        ),
        {
          click(e, node) {
2382
            if (navigatorAgent) return false;
2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397
            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;
2398 2399 2400
              case '功能跳转': // 功能模型
                menuJumpMethod(data);
                break;
李纪文's avatar
李纪文 committed
2401 2402 2403
              case '视频查看': // 视频查看
                videoScanMethod(data);
                break;
2404 2405
              case '自定义交互': // 自定义交互
                customBack(data);
李纪文's avatar
李纪文 committed
2406
                interactiveScript(data);
2407 2408 2409 2410 2411 2412 2413 2414 2415
                break;
              default:
                break;
            }
          },
        },
      ),
    );

李纪文's avatar
李纪文 committed
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 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463
    // 更新时间定义
    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',
李纪文's avatar
李纪文 committed
2464 2465 2466 2467 2468 2469 2470
            goJS(
              go.TextBlock,
              { margin: 2 },
              new go.Binding('text', 'timeStr'),
              new go.Binding('visible', 'toolTip'),
            ),
            new go.Binding('visible', 'toolTip'),
李纪文's avatar
李纪文 committed
2471 2472 2473 2474 2475
          ),
        },
      ),
    );

2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487
    // 公用管定义
    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(),
2488 2489 2490 2491 2492
        {
          // 设置其可改变大小
          resizable: false,
          layerName: 'Background',
        },
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 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544
        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
2545
        { locationSpot: go.Spot.Center, zOrder: 2, cursor: 'default' },
2546
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
2547
        new go.Binding('cursor', 'cursor').makeTwoWay(),
2548 2549 2550 2551 2552
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
2553 2554
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
2555 2556 2557
          new go.Binding('fill', 'fillColor'),
          new go.Binding('stroke'),
          new go.Binding('strokeWidth'),
2558
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571
          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',
2572
            flip: go.GraphObject.None,
2573 2574 2575 2576 2577
          },
          new go.Binding('text', 'showVal'),
          new go.Binding('font', 'fontStyle'),
          new go.Binding('stroke', 'fontStroke'),
          new go.Binding('textAlign', 'fontAlign'),
李纪文's avatar
李纪文 committed
2578 2579
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
2580
          new go.Binding('flip', 'flip'),
2581 2582 2583
        ),
        {
          click(e, node) {
2584
            if (navigatorAgent) return false;
2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596
            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;
            }
            // 历史查看
李纪文's avatar
李纪文 committed
2597 2598 2599 2600 2601
            if (data.opType && data.opType === '历史查看' && data.shName)
              historyModalRender(data, list);
            // 统计历史查看
            if (data.opType && data.opType === '统计查看' && data.shName)
              statisticalModalRender(data, list);
2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740
          },
        },
      ),
    );

    // 连接点定义
    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',
2741
            parameter1: 5,
2742 2743 2744 2745
          },
          new go.Binding('width').makeTwoWay(),
          new go.Binding('height').makeTwoWay(),
          new go.Binding('strokeWidth', 'strokeWidth').makeTwoWay(),
2746
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759
          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),
2760
            parameter1: 5,
2761 2762 2763 2764
          },
          new go.Binding('width').makeTwoWay(),
          new go.Binding('height').makeTwoWay(),
          new go.Binding('fill', 'waterColor').makeTwoWay(),
2765
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779
          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),
2780
            parameter1: 5,
2781 2782 2783
          },
          new go.Binding('width', 'lineWidth').makeTwoWay(),
          new go.Binding('height', 'height').makeTwoWay(),
2784
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806
          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,
        },
李纪文's avatar
李纪文 committed
2807
        new go.Binding('angle').makeTwoWay(),
2808 2809 2810
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Panel,
李纪文's avatar
李纪文 committed
2811
          'Auto',
2812 2813 2814 2815 2816 2817 2818
          {
            name: 'PANEL',
          },
          goJS(
            go.Shape,
            'Ellipse', // 定义形状
            { width: 37, height: 37, fill: 'transparent', stroke: 'transparent', strokeWidth: 1 },
李纪文's avatar
李纪文 committed
2819 2820 2821 2822 2823 2824
            new go.Binding('width', 'width', (v) => {
              return v * 1.5;
            }).makeTwoWay(),
            new go.Binding('height', 'height', (v) => {
              return v * 1.5;
            }).makeTwoWay(),
2825 2826
          ),
          new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
李纪文's avatar
李纪文 committed
2827
          new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
2828 2829 2830 2831 2832 2833 2834 2835 2836
          goJS(
            go.Picture,
            {
              name: 'rotateSvg',
              width: 26,
              height: 26,
              column: 0,
              scale: 1,
              source: require('./images/组态/状态/泵离线.svg'),
李纪文's avatar
李纪文 committed
2837
              imageAlignment: go.Spot.Center,
2838 2839 2840 2841 2842 2843 2844
              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(),
李纪文's avatar
李纪文 committed
2845
            // new go.Binding('angle', 'angle').makeTwoWay(),
2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891
            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
2892
        { locationSpot: go.Spot.Center, zOrder: 2, cursor: 'default' },
2893
        new go.Binding('zOrder', 'zOrder').makeTwoWay(),
李纪文's avatar
李纪文 committed
2894
        new go.Binding('cursor', 'cursor').makeTwoWay(),
2895 2896 2897 2898 2899
        new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
        new go.Binding('angle').makeTwoWay(),
        roleVisibleBinding(), // 绑定角色可见
        goJS(
          go.Shape,
2900 2901
          'RoundedRectanglePlus',
          { name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 5 },
2902 2903 2904
          new go.Binding('fill', 'fillColor'),
          new go.Binding('stroke'),
          new go.Binding('strokeWidth'),
2905
          new go.Binding('parameter1', 'radius').makeTwoWay(),
2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923
          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
2924 2925
          new go.Binding('maxSize', 'textSize'),
          new go.Binding('minSize', 'textSize'),
2926 2927 2928
        ),
        {
          click(e, node) {
2929
            if (navigatorAgent) return false;
2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017
            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(),
        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,
3018
        zOrder: 1,
3019
      },
3020
      new go.Binding('layerName', 'layerName').makeTwoWay(),
3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067
      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,
3068
          zOrder: 1,
3069
        },
3070
        new go.Binding('layerName', 'layerName').makeTwoWay(),
3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117
        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,
    //     }),
    //   ),
    // );
3118

3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135
    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 = '--';
3136
      item.realType = '在线';
3137 3138 3139 3140 3141 3142 3143
      item.Unit = '';
      item.switchState = '开';
      item.dtImgSrc = item.imgSrc || '';
      if (item.category === 'HBar') {
        item.hBarClolor = item.waterStroke;
        item.typeDash = false;
      }
3144 3145
      if (item.category === 'valCase') {
        if (item.shType === '') item.showVal = item.text;
3146
        item.dtStroke = item.fontStroke;
3147
      }
3148 3149 3150 3151 3152 3153 3154 3155 3156
      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;
      }
3157
      if (item.category == 'deviceCase' && item.shType && deviceName && deviceName.length) {
3158 3159 3160 3161 3162
        var device = deviceName.find(function (arr, index) {
          return '设备' + stationList[index] == item.stationName;
        });
        if (device) item.text = device;
      }
李纪文's avatar
李纪文 committed
3163 3164 3165
      if (item.category == 'timeCase') {
        item.timeStr = item.text;
      }
3166
      if (item.category === 'bgCase') {
李纪文's avatar
李纪文 committed
3167
        myDiagram.defaultScale = item.scaling || item.scaling === 0 ? item.scaling * 1 : 1;
3168
      }
3169 3170 3171
      if (item.category === 'groupCase') {
        item.dtVisible = item?.visible || false;
      }
3172

李纪文's avatar
李纪文 committed
3173 3174 3175 3176 3177 3178
      // 兼容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 = '值显示';
3179 3180
    });
    myDiagram.model = go.Model.fromJson(json);
3181
    getDataModel();
3182
    setIsDiagram(myDiagram);
3183 3184 3185 3186
  };

  return (
    <div className={classNames(prefixCls)} ref={ConfigurationRef}>
3187 3188 3189 3190 3191
      <div
        id={TwoRef.current}
        ref={ConfigurationViewRef}
        className={classNames('configurationView')}
      >
3192
        {/* <LoadBox spinning={spinning} /> */}
3193 3194
        {isEmpty && <Empty theme={'dark'} description={description} />}
      </div>
3195 3196 3197 3198 3199
      {spinning && (
        <div className={classNames('configurationLoad')}>
          <LoadBox spinning={spinning} />
        </div>
      )}
3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231
      {/* 远程控制 */}
      {isModalVisible && (
        <Modal
          centered
          okText={'确定'}
          width={modalWidth}
          cancelText={'取消'}
          open={isModalVisible}
          onOk={handleOk}
          onCancel={handleCancel}
          wrapClassName={classNames(`${prefixCls}-baseModal`)}
          getContainer={ConfigurationRef.current}
          {...modalProps}
        >
          {renderModalContent()}
        </Modal>
      )}
      {/* 权限登录 */}
      {isAuModalVisible && (
        <Modal
          centered
          title={'权限认证'}
          okText={'确定'}
          cancelText={'取消'}
          open={isAuModalVisible}
          onOk={handleAuOk}
          onCancel={() => setIsAuModalVisible(false)}
          getContainer={ConfigurationRef.current}
          width={520}
          wrapClassName={classNames(`${prefixCls}-baseModal`)}
        >
          <Form className={classNames('authorizeControlContent')} ref={AuthorFrom} name="loginForm">
李纪文's avatar
李纪文 committed
3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243
            <Form.Item
              className={classNames('authorizeControlItem')}
              name="userName"
              label="账户"
              initialValue={currentUser}
            >
              <Input.TextArea
                placeholder="请输入用户名"
                autoComplete={'off'}
                autoSize={{ minRows: 1, maxRows: 1 }}
                disabled={!!currentUser}
              />
3244 3245
            </Form.Item>
            <Form.Item className={classNames('authorizeControlItem')} name="password" label="密码">
李纪文's avatar
李纪文 committed
3246 3247 3248 3249 3250 3251 3252 3253 3254 3255
              <Input
                className={classNames(viewType ? '' : 'hidePassWord')}
                placeholder="请输入密码"
                autoComplete={'off'}
                addonAfter={
                  <div className={classNames('viewPassWord')} onClick={viewTypeChange}>
                    {viewType ? <EyeOutlined /> : <EyeInvisibleOutlined />}
                  </div>
                }
              />
3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269
            </Form.Item>
          </Form>
        </Modal>
      )}
      {/* 历史曲线 */}
      {isHIModalVisible && (
        <Modal
          centered
          width={1200}
          footer={null}
          open={isHIModalVisible}
          onOk={() => setIsHIModalVisible(false)}
          onCancel={() => setIsHIModalVisible(false)}
          getContainer={ConfigurationRef.current}
李纪文's avatar
李纪文 committed
3270
          // title={historyInfoParams.length ? historyInfoParams[0].sensors || '' : ''}
3271 3272
          wrapClassName={classNames(`${prefixCls}-historyInfoModal`)}
        >
3273 3274 3275 3276
          <HistoryView
            deviceParams={historyInfoParams}
            title={historyInfoParams.length ? historyInfoParams[0].sensors || '' : ''}
          />
3277 3278
        </Modal>
      )}
李纪文's avatar
李纪文 committed
3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294
      {/* 统计历史曲线 */}
      {isSTHIModalVisible && (
        <Modal
          centered
          width={1200}
          footer={null}
          open={isSTHIModalVisible}
          onOk={() => setIsSTHIModalVisible(false)}
          onCancel={() => setIsSTHIModalVisible(false)}
          getContainer={ConfigurationRef.current}
          title={statisticalInfoParams.sensors || ''}
          wrapClassName={classNames(`${prefixCls}-historyInfoModal`)}
        >
          <StatisticalHistoryView deviceParams={statisticalInfoParams} />
        </Modal>
      )}
3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323
      {/* 画板跳转 */}
      {isJumpModalVisible && jumpModalProps && (
        <DragModal
          centered
          width={jumpModalProps.width ? `${jumpModalProps.width}px` : '100vw'}
          title={jumpModalProps.title}
          footer={null}
          visible={isJumpModalVisible}
          limit={true}
          onCancel={() => setIsJumpModalVisible(false)}
          wrapClassName={classNames(`${prefixCls}-jumpModal`)}
          getContainer={ConfigurationRef.current}
          componentPrefix={componentPrefix}
          destroyOnClose={true}
          style={{
            height: jumpModalProps.height ? `${Number(jumpModalProps.height) + 103}px` : '100vh',
            left: `calc(50% - ${jumpModalProps.width ? jumpModalProps.width / 2 + 'px' : '50%'})`,
            top: `calc(50% - ${
              jumpModalProps.height ? (Number(jumpModalProps.height) + 103) / 2 + 'px' : '50%'
            })`,
          }}
        >
          <ConfigurationDetail
            {...props}
            name={jumpModalProps.name}
            devices={jumpModalProps.device}
          />
        </DragModal>
      )}
李纪文's avatar
李纪文 committed
3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336
      {isVideoVisible && (
        <VideoSliderModal
          modalInfo={{
            title: videoTitle,
            open: isVideoVisible,
            onCancel: () => {
              setIsVideoVisible(false);
            },
          }}
          videoInfos={videoData}
          JessibucaObj={_JessibucaObj}
        />
      )}
3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347
    </div>
  );
};

ConfigurationView.defaultProps = {
  name: '',
  devices: [],
  deviceName: [],
  config: {},
  isZoom: false,
  flowShow: true,
3348
  messaged: {},
李纪文's avatar
李纪文 committed
3349
  customBack: () => {},
3350 3351 3352 3353 3354 3355 3356 3357 3358
};

ConfigurationView.propTypes = {
  name: PropTypes.string,
  devices: PropTypes.array,
  deviceName: PropTypes.array,
  config: PropTypes.object,
  isZoom: PropTypes.bool,
  flowShow: PropTypes.bool,
3359
  messaged: PropTypes.object,
李纪文's avatar
李纪文 committed
3360
  customBack: PropTypes.func,
3361 3362 3363
};

export default ConfigurationView;