ceshi.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. /*@WebApiFunc@*/
  2. var varList = [];
  3. var varListObj = {};
  4. var tagInfoDic={};
  5. // 用于保存所有的lib
  6. var mouseX=0,mouseY=0;
  7. var zoomNodeList = zoomNodeList || [];
  8. zoomNodeList.length = 0;
  9. var contextMenuOnViewList = contextMenuOnViewList || [];
  10. var globalVarNameList = globalVarNameList || [];
  11. var ratio = {ratioX: 1, ratioY: 1};
  12. // 保存加上图形旋转之后的缩放比例
  13. var _ratio = {ratioX: 1, ratioY: 1};
  14. var autoAdaptive = '@autoAdaptive@';
  15. var browserSize = {
  16. width: window.innerWidth || $window.innerWidth(),
  17. height: window.innerHeight || $window.innerHeight()
  18. }
  19. var globalVarObj = {};
  20. var globarParamsObj = {};
  21. var globalAliasObj = {};
  22. var pageSizeRatioValue;
  23. var PAGESCALABLE; // 页面是否可通过滚轮缩放
  24. var PageAdaptMode = {
  25. value: 'adaptBrowser',
  26. minWidth: 1366,
  27. minHeight: 768
  28. };
  29. function calcRatio (backSize, browserSize, ratio) {
  30. var value = GD.getParams('pageSizeRatioValue') || {}, rt;
  31. function cr(adaptMode) {
  32. var rx=1, ry=1, w, h;
  33. switch (adaptMode) {
  34. case 'adaptWidth':
  35. rx = ry = browserSize.width / backSize.width;
  36. break;
  37. case 'adaptHeight':
  38. rx = ry = browserSize.width / backSize.width;
  39. break;
  40. case 'adaptBrowser':
  41. rx = browserSize.width / backSize.width;
  42. ry = browserSize.height / backSize.height;
  43. break;
  44. case 'originSize':
  45. rx = ry = 1;
  46. break;
  47. case 'autoResize':
  48. w = browserSize.width < PageAdaptMode.minWidth ? PageAdaptMode.minWidth : browserSize.width;
  49. h = browserSize.height < PageAdaptMode.minHeight ? PageAdaptMode.minHeight : browserSize.height;
  50. rx = w / backSize.width;
  51. ry = h / backSize.height;
  52. rx > ry ? rx = ry : ry = rx;
  53. break;
  54. }
  55. return {rx: rx,ry: ry}
  56. }
  57. value = value.value || PageAdaptMode.value;
  58. pageSizeRatioValue = value;
  59. if ($.isNumeric(value)) {
  60. rt = cr(PageAdaptMode.value);
  61. ratio.ratioX = value*rt.rx;
  62. ratio.ratioY = value*rt.ry;
  63. } else {
  64. rt = cr(value);
  65. ratio.ratioX = rt.rx;
  66. ratio.ratioY = rt.ry;
  67. }
  68. ratio.originRatioX = rt.rx;
  69. ratio.originRatioY = rt.ry;
  70. window.backSize = backSize;
  71. }
  72. // 页面的依赖
  73. (function (W, GD) {
  74. W.GD = GD = GD || {};
  75. GD.relationship = {
  76. // hash: ['a.js', 'b.js', 'c.js'],
  77. }
  78. })(window, window.GD);
  79. (function () {
  80. for (var i = 0, len = varList.length; i < len; i++) {
  81. var varStr = varList[i];
  82. varStr = varStr && varStr.toLowerCase && varStr.toLowerCase();
  83. varStr && (varListObj[varStr] = 0);
  84. }
  85. })();
  86. jQuery.support.cors = true;
  87. ht.Default.appendTimeStamp = function(url) { return url };
  88. function init() {
  89. initPage();
  90. // dataModel._libModel = _libModel;
  91. try {
  92. VarValue = JSON.parse(sessionStorage.getItem(location.pathname)) || VarValue;
  93. } catch (err) {}
  94. for(var i=0;i< 0 ;i++){VarValue[i] =0;}
  95. graphView.handleScroll = function () {}; graphView.setPannable(false); graphView.setMovableFunc(function(data){return false});PAGESCALABLE = false
  96. view.style.background = 'rgba(255,255,255,1)';
  97. /*@PageBeforeInit@*/
  98. ;(function () {
  99. var GD = window.GD;
  100. if (!GD || typeof GD.useParams !== 'function') return ;
  101. GD.useParams();
  102. })();
  103. var backSize = {width: 1280, height: 1024};calcRatio(backSize, browserSize, ratio);_ratio = GD.getRatioWithRotation(0*Math.PI/180, ratio);
  104. var PageBackgroundtype = 'rect';
  105. var PageBackground = new ht.Node(),
  106. PageBackgroundBorderWidth = 0*2;
  107. if (PageBackgroundtype === 'arc') {
  108. PageBackgroundBorderWidth *= 0;
  109. }
  110. PageBackground.setImage(GD.getRectJSON(1280*_ratio.ratioX, 1024*_ratio.ratioY, PageBackgroundtype, '@arcFrom@', '@arcTo@', '@arcClose@'));
  111. PageBackground.setPosition(640*ratio.ratioX, 512*ratio.ratioY);
  112. PageBackground.setSize(1280*_ratio.ratioX, 1024*_ratio.ratioY);
  113. PageBackground.s({
  114. 'pixelPerfect':true
  115. /*@AddPara@*/
  116. });
  117. PageBackground.a('node.width', 1280*_ratio.ratioX);
  118. PageBackground.a('node.height', 1024*_ratio.ratioY);
  119. PageBackground.a('node.type', PageBackgroundtype);
  120. PageBackground.a('node.rect', [0, 0, 1280*_ratio.ratioX, 1024*_ratio.ratioY]);
  121. PageBackground.a('node.background', 'rgba(255,255,255,1)');
  122. PageBackground.a('node.gradientcolor', 'rgba(255,255,255,1)');
  123. PageBackground.a('node.gradient', '');
  124. PageBackground.a('node.borderwidth', PageBackgroundBorderWidth);
  125. PageBackground.a('node.color', 'rgba(0,0,0,1)');
  126. PageBackground.a('node.fillrect', [0,0,0,0]);
  127. PageBackground.a('node.fillbackcolor', 'rgba(0,0,0,0)');
  128. PageBackground.a('node.fillgradientcolor', 'rgba(0,0,0,0)');
  129. PageBackground.a('node.fillgradient', '');
  130. if (PageBackgroundtype !== 'rect') {
  131. PageBackground.a('node.arcFrom', parseFloat('@arcFrom@'));
  132. PageBackground.a('node.arcTo', parseFloat('@arcTo@'));
  133. PageBackground.a('node.arcClose', '@arcClose@' === 'true' ? true : false);
  134. }
  135. if (PageBackgroundtype === 'arc') {
  136. PageBackground.a('node.arcOval', true);
  137. }
  138. PageBackground.setRotation(0*Math.PI/180);
  139. PageBackground.borderWidth = PageBackgroundBorderWidth;
  140. PageBackground.borderFillwidth = PageBackgroundBorderWidth;
  141. dataModel.add(PageBackground);
  142. PageBackground._nodename = 'PageBackground'
  143. PageBackground._nodeType = 'rect';
  144. zoomNodeList.push({
  145. node: PageBackground,
  146. attr: 'node.borderwidth'
  147. });
  148. (function (node, _img) {
  149. var setWidth = node.setWidth,
  150. setHeight = node.setHeight;
  151. node.setWidth = function (width) {
  152. if (width === this.getWidth()) return ;
  153. var height = this.getHeight();
  154. this.a('node.width', width);
  155. this.a('node.rect', [0,0,width, height]);
  156. setWidth.apply(this, arguments);
  157. }
  158. node.setHeight = function (height) {
  159. if (height === this.getHeight()) return ;
  160. var width = this.getWidth();
  161. this.a('node.height', height);
  162. this.a('node.rect', [0,0,width, height]);
  163. setHeight.apply(this, arguments);
  164. }
  165. })(PageBackground, PageBackground.getImage());PageBackground.s({'2d.selectable': false,'2d.movable': false});
  166. /*@GraphList@*/
  167. var datas = dataModel.getDatas();
  168. /*@PageInit@*/
  169. function DatarefreshTask(callback){
  170. /*@DataVarText@*/
  171. callback = callback || function () {};
  172. if(varList.length <= 0){
  173. return callback();
  174. }
  175. var ajaxdata = {};
  176. var ajaxtype = 'GET';
  177. var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot?tagName=";
  178. var para = "";
  179. for(var i=0;i<varList.length;i++){
  180. para = para + varList[i];
  181. if(i!==varList.length-1)
  182. para = para +',';
  183. }
  184. str = str + encodeURIComponent(para);
  185. if (str.length > 2000) {
  186. para = encodeURIComponent(para);
  187. str = "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot/tags";
  188. ajaxdata = {'': para};
  189. ajaxtype = 'POST';
  190. }
  191. $.ajax({
  192. url: str ,
  193. type: ajaxtype,
  194. dataType: 'json',
  195. data: ajaxdata,
  196. cache: false,
  197. success: function (data) {
  198. if (data === null) return;
  199. var snapshots = eval(data);
  200. //判断快照是否为空
  201. if (snapshots != null) {
  202. for (var i = 0; i < snapshots.length; i++) {
  203. var index = varList.indexOf (snapshots[i].TagName);
  204. var tagName = snapshots[i].TagName.toLowerCase();
  205. if(index >= 0 && index< varList.length){
  206. if(parseFloat(snapshots[i].Value).toString()==snapshots[i].Value){
  207. varListObj[tagName] = VarValue[index] = parseFloat(snapshots[i].Value);
  208. VarSnapshotTime[tagName]=snapshots[i].Time;
  209. }else{
  210. varListObj[tagName] = VarValue[index] = snapshots[i].Value;
  211. VarSnapshotTime[tagName]=snapshots[i].Time;
  212. }
  213. }
  214. }
  215. }
  216. },
  217. complete: function (XHR, TS) {
  218. XHR = null;
  219. callback();
  220. }
  221. }
  222. );
  223. }
  224. ;(function () {
  225. var i = 0;
  226. function getdata() {
  227. DatarefreshTask(function () {
  228. i++;
  229. Timer1sCmd();
  230. Timer100msCmd();
  231. Timer500msCmd();
  232. if (i <= 4) {
  233. setTimeout(getdata, 50);
  234. }
  235. });
  236. }
  237. setTimeout(getdata, 20);
  238. })();
  239. intervalTimers.push(setInterval(DatarefreshTask, 500));
  240. /*@DataRefresh@*/
  241. function GetTagsProperty(){
  242. /*@DataVarText@*/
  243. if(varList.length <= 0){
  244. return;
  245. }
  246. var ajaxtype = 'GET';
  247. var ajaxdata = {};
  248. var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Point?tagName=";
  249. var para = "";
  250. for(var i=0;i<varList.length;i++){
  251. para = para + varList[i];
  252. if(i!==varList.length-1)
  253. para = para +',';
  254. }
  255. str = str + encodeURIComponent(para);
  256. if (str.length > 2000) {
  257. para = encodeURIComponent(para);
  258. str = "http://" + webServiceIP + ":" + webServicePort + "/api/Point/property";
  259. ajaxdata = {'': para};
  260. ajaxtype = 'POST';
  261. }
  262. $.ajax({
  263. url: str ,
  264. type: ajaxtype,
  265. dataType: 'json',
  266. data: ajaxdata,
  267. cache: false,
  268. success: function (data) {
  269. if (data === null) return;
  270. for(var i=0;i<data.length;i++){
  271. var basePointInfo=data[i].BasePointInfo;
  272. tagInfoDic[basePointInfo.TableDotTag.toLowerCase()]=basePointInfo;
  273. // console.log(tagInfoDic);
  274. }
  275. },
  276. complete: function (XHR, TS) {
  277. XHR = null;
  278. }
  279. }
  280. );
  281. }
  282. GetTagsProperty();
  283. window.GD && (GD.GetTagsProperty = GetTagsProperty);
  284. /*@TagInfoDic@*/
  285. var syscurrentTime="";
  286. function getCurrentTime(timeformat){
  287. syscurrentTime= moment().format(timeformat);
  288. if(timeformat=="d"){
  289. if(syscurrentTime==1){
  290. syscurrentTime="星期一";
  291. }
  292. if(syscurrentTime==2){
  293. syscurrentTime="星期二";
  294. }
  295. if(syscurrentTime==3){
  296. syscurrentTime="星期三";
  297. }
  298. if(syscurrentTime==4){
  299. syscurrentTime="星期四";
  300. }
  301. if(syscurrentTime==5){
  302. syscurrentTime="星期五";
  303. }
  304. if(syscurrentTime==6){
  305. syscurrentTime="星期六";
  306. }
  307. if(syscurrentTime==7){
  308. syscurrentTime="星期日";
  309. }
  310. }
  311. }
  312. getCurrentTime();
  313. /*@SysCurrentTime@*/
  314. var Counter10ms = 0;
  315. var Counter100ms = 0;
  316. var Counter500ms = 0;
  317. var Counter1s = 0;
  318. var Counter5s = 0;
  319. function Timer10msCmd() {
  320. Counter10ms++;
  321. /*@Timer10ms@*/
  322. }
  323. // intervalTimers.push(setInterval(Timer10msCmd, 10));
  324. function Timer100msCmd() {
  325. Counter100ms++;
  326. /*@Timer100ms@*/
  327. // graphView.redraw();
  328. }
  329. intervalTimers.push(setInterval(Timer100msCmd, 100));
  330. function Timer500msCmd() {
  331. Counter500ms++;
  332. /*@Timer500ms@*/
  333. // graphView.redraw();
  334. }
  335. intervalTimers.push(setInterval(Timer500msCmd, 500));
  336. function Timer1sCmd() {
  337. Counter1s++;
  338. if (moment(Date.now()).format('HH:mm:ss') === '23:59:59' && Counter1s > 5) location.reload();
  339. /*@Timer1000ms@*/
  340. // graphView.redraw();
  341. }
  342. Timer1sCmd();
  343. intervalTimers.push(setInterval(Timer1sCmd, 1000));
  344. function Timer5sCmd() {
  345. Counter5s++;
  346. /*@Timer5000ms@*/
  347. // graphView.redraw();
  348. }
  349. // intervalTimers.push(setInterval(Timer5sCmd, 5000));
  350. /*@EventTimer@*/
  351. //graphView.setInteractors(null);
  352. if (!!view) {
  353. view.eventList = view.eventList || {};
  354. }
  355. function blockDataFilter (data) {
  356. return !(data instanceof ht.Block || data.isLibBackground || data.__clickable === false);
  357. }
  358. var type ='mousedown';
  359. function doMouseDown (e, origin) {
  360. if(!ht.Default.isLeftButton(e)){return;}
  361. mouseX=e.clientX;
  362. mouseY=e.clientY;
  363. origin = origin || graphView;
  364. window.GD && GD.hideTagInfo();
  365. var data = origin.getDataAt(e, blockDataFilter);
  366. if (data && data.__parentLib) {
  367. _libModel.getDataByKey(data.__parentLib).onEvent(e, data, 'mousedown', origin);
  368. return;
  369. }
  370. /*@EvnentMouseDown@*/
  371. }
  372. view.eventList[type] = doMouseDown;
  373. view['on'+type] = function(e){
  374. doMouseDown(e);
  375. e.preventDefault();
  376. };
  377. type ='mouseup';
  378. function doMouseUp (e, origin) {
  379. if(!ht.Default.isLeftButton(e)){return;}
  380. origin = origin || graphView;
  381. var data = origin.getDataAt(e, blockDataFilter);
  382. if (data && data.__parentLib) {
  383. _libModel.getDataByKey(data.__parentLib).onEvent(e, data, 'mouseup', origin);
  384. return;
  385. }
  386. /*@EvnentMouseUp@*/
  387. }
  388. view.eventList[type] = doMouseUp;
  389. view['on'+type] = function(e){
  390. doMouseUp(e);
  391. e.preventDefault();
  392. };
  393. type ='click';
  394. function doClick (e, origin) {
  395. if(!ht.Default.isLeftButton(e)){return;}
  396. origin = origin || graphView;
  397. var data = origin.getDataAt(e, blockDataFilter);
  398. if (data && data.__parentLib) {
  399. _libModel.getDataByKey(data.__parentLib).onEvent(e, data, 'click', origin);
  400. return;
  401. }
  402. /*@EvnentClicked@*/
  403. }
  404. view.eventList[type] = doClick;
  405. view['on'+type] = function(e){
  406. doClick(e);
  407. e.preventDefault();
  408. };
  409. type ='mousemove';
  410. var objMouseOn = null, _objMouseOn = null;
  411. function doMouseMove (e, origin, offset) {
  412. var positon, data, zoom, _data, libData;
  413. origin = origin || graphView;
  414. position=origin.getLogicalPoint(e);
  415. zoom = graphView.getZoom();
  416. if (origin === graphView) {
  417. mouseX= position.x + origin.tx();
  418. mouseY = position.y + origin.ty();
  419. } else {
  420. offset = offset || {x: 0, y: 0};
  421. mouseX = position.x / zoom + offset.x + origin.tx();
  422. mouseY = position.y / zoom + offset.y + origin.ty();
  423. }
  424. data = origin.getDataAt(e, function (data) {return !(data instanceof ht.Block)});
  425. if(data === objMouseOn || data === _objMouseOn) return;
  426. // 如果是图元内的小图形,给libData赋值为图元本身,方便下面使用
  427. if (data && data.__parentLib && _libModel.getDataByKey(data.__parentLib)) {
  428. _data = data;
  429. data = libData = _libModel.getDataByKey(_data.__parentLib);
  430. }
  431. /*@EvnentMouseLeave@*/
  432. if (objMouseOn && objMouseOn._baseClass && objMouseOn._baseClass.match(/^ht.lib/)) {
  433. objMouseOn.onEvent(e, _data, 'mousemove', origin, offset, _objMouseOn);
  434. }
  435. objMouseOn = data;
  436. _objMouseOn = _data;
  437. /*@EvnentMouseOver@*/
  438. if (data && data._baseClass && data._baseClass.match(/^ht.lib/)) {
  439. data.onEvent(e, _data, 'mousemove', origin, offset, _objMouseOn);
  440. }
  441. }
  442. view.eventList[type] = doMouseMove;
  443. view['on'+type] = function(e){
  444. doMouseMove(e);
  445. e.preventDefault();
  446. };
  447. window.onkeydown = function doKeyDown(e) {
  448. var keyID = e.keyCode ? e.keyCode :e.which;
  449. //if(keyID === 87) { }
  450. /*@EvnentKeyDown@*/
  451. // if (keyID === 27 && graphView) {
  452. // graphView.setZoom(1);
  453. // graphView.tx(0);
  454. // graphView.ty(0);
  455. // }
  456. return;
  457. }
  458. /*@Event@*/
  459. /*@Declare@*/
  460. var contextmenu = new ht.widget.ContextMenu();
  461. contextmenu.contextMenuHoverBackground='rgb(104,216,255)';
  462. contextmenu.contextMenuBackground='rgb(255,255,255)';
  463. contextmenu.contextMenuHoverLabelColor='rgb(255,255,255)';
  464. contextmenu.contextMenuLabelColor='rgb(48,48,48)';
  465. contextmenu.beforeShow = function(e, gv) {
  466. gv = gv || graphView;
  467. if (e.originEvent && e.originEvent.currentTarget && e.originEvent.currentTarget.className === 'main') {
  468. gv = graphView;
  469. }
  470. this.setItems(null);
  471. window.GD && GD.hideTagInfo();
  472. var data = gv.getDataAt(e) || graphView.getDataAt(e);
  473. if (data && data.__parentLib) {
  474. _libModel.getDataByKey(data.__parentLib).onEvent(e, data, 'contextmenu', gv, {}, {}, this);
  475. return;
  476. }
  477. //if(false);
  478. /*@SetNodeContextMenu@*/
  479. /*@SetPageContextMenu@*/
  480. };
  481. contextmenu.afterShow = function (e) {
  482. var fontSize = 14,
  483. screenWidth = window.screen.width,
  484. screenHeight = window.screen.height,
  485. rx = screenWidth / 1920,
  486. ry = screenHeight / 1080,
  487. itemHeight = 30 * ry,
  488. fontFamily = '',
  489. width = 150 * rx;
  490. itemHeight = itemHeight > 30 ? itemHeight : 30;
  491. var $contextMenu = $(this.getView());
  492. $contextMenu.find('.contextmenu-item-icon').css({
  493. width: 14,
  494. height: 14,
  495. marginRight: 10
  496. });
  497. $contextMenu.find('li.menu-item').css({
  498. fontSize: fontSize,
  499. fontWeight: 600,
  500. height: itemHeight,
  501. minHeight: 25,
  502. lineHeight: itemHeight + 'px',
  503. fontFamily: fontFamily,
  504. padding: 0
  505. });
  506. $contextMenu.find('ul').css({
  507. width: width,
  508. minWidth: 100
  509. });
  510. contextmenu.setLabelMaxWidth((width > 120 ? width : 120) - 40);
  511. };
  512. view.eventList && (view.eventList['contextMenu'] = contextmenu);
  513. contextmenu.addTo(view);
  514. contextMenuOnViewList.push(contextmenu);
  515. /*@ControlContextMenu@*/
  516. graphView.getSelectWidth = function() { return 0; };
  517. (function () {
  518. var $mainContainer,
  519. mainContainerHeight,
  520. mainContainerWidth,
  521. originHeight,
  522. originWidth,
  523. ratioX,
  524. ratioY,
  525. isPageContainer = false;
  526. graphView._pageBackgroundNode = PageBackground;
  527. if (pageSizeRatioValue !== 'adaptBrowser') {
  528. window.GD && GD.setPageToCenterOrLeftTop();
  529. }
  530. function throttle () {
  531. var timer = null;
  532. return function () {
  533. timer && clearTimeout(timer);
  534. timer = setTimeout(function () {
  535. var value = GD.getParams('pageSizeRatioValue') || {};
  536. value = value.value || PageAdaptMode.value;
  537. GD.setPageSizeWithRatio(value, ratio, backSize);
  538. }, 200)
  539. }
  540. }
  541. try {
  542. if (window.parent && window.parent.openDialog) {
  543. autoAdaptive = false;
  544. }
  545. } catch (error) {}
  546. try {
  547. if (window.parent && window.parent.pageContainer) {
  548. graphView.handleScroll = function (data) {
  549. var t = graphView.ty() - data.deltaY;
  550. var contentSize = graphView.getContentRect();
  551. var min = contentSize.height - graphView.getHeight() + 50;
  552. if (min <= 50)
  553. return ;
  554. graphView.setTranslate(0, t, true);
  555. graphView.setScrollBarSize(8);
  556. }
  557. graphView.adjustTranslateY = function (value) {
  558. var contentSize = graphView.getContentRect();
  559. var min = graphView.getHeight() - contentSize.height - 50;
  560. value = value > 0 ? 0 : value;
  561. value = value < min ? min : value;
  562. return value;
  563. }
  564. autoAdaptive = false;
  565. isPageContainer = true;
  566. }
  567. } catch (error) {}
  568. if (autoAdaptive !== false && autoAdaptive !== 'false' && autoAdaptive !== 'False') {
  569. graphView.setScrollBarVisible(false);
  570. if (!graphView._pannable) {
  571. graphView.adjustTranslateX = function () {return 0};
  572. graphView.adjustTranslateY = function () {return 0};
  573. }
  574. $window.off('resize').on('resize', throttle());
  575. // setTimeout(resizePage, 100);
  576. showPage();
  577. } else {
  578. showPage();
  579. graphView.fitContent(false,0,true);
  580. $window.off('resize').on('resize', function (e) {
  581. if (!!isPageContainer) {
  582. window.parent.postMessage('getZoom', '*');
  583. } else {
  584. graphView.fitContent(false,0,true);
  585. }
  586. })
  587. }
  588. var graphViewTimer = null;
  589. // 监听鼠标缩放页面事件
  590. graphView.adjustZoom = function (value) {
  591. graphViewTimer && clearTimeout(graphViewTimer);
  592. graphViewTimer = setTimeout(function () {
  593. $window.trigger('graphViewZoomEnded', [value]);
  594. GD.resetNodeBorderWidth(zoomNodeList, 1/value);
  595. }, 80)
  596. return value;
  597. }
  598. $window.off('customEventResizeNodes').on('customEventResizeNodes', function (e) {
  599. var data = e.args;
  600. var value = GD.getParams('pageSizeRatioValue') || {};
  601. value = value.value || PageAdaptMode.value;
  602. GD.setPageSizeWithRatio(value, ratio, backSize);
  603. graphView.setZoom(data.zoom);
  604. graphView.tx(0);
  605. graphView.ty(0);
  606. });
  607. $window.off('beforeunload').on("beforeunload", function( event ) {
  608. try {
  609. sessionStorage.setItem(location.pathname, JSON.stringify(VarValue));
  610. } catch (error) {console.log(error.message);}
  611. ;(function () {
  612. var GD = window.GD;
  613. if (!GD || typeof GD.removeParams !== 'function') return ;
  614. GD.removeParams();
  615. GD.removeParams('pageSizeRatioValue');
  616. })();
  617. });
  618. graphView.setScrollBarColor('rgba(211,211,211,1)');
  619. graphView.setAutoHideScrollBar(false);
  620. GD.autoToggleScrollBar();
  621. // ;(function () {
  622. // var oriX=browserSize.width/backSize.width;
  623. // var oriY=browserSize.height/backSize.height;
  624. // var json = [
  625. // {
  626. // label: "25%",
  627. // action: function(item, event) {
  628. // GD.setPageSizeWithRatio(0.25);
  629. // }
  630. // },
  631. // {
  632. // label: "50%",
  633. // action: function(item, event) {
  634. // GD.setPageSizeWithRatio(0.5);
  635. // }
  636. // },
  637. // {
  638. // label: "100%",
  639. // action: function(item, event) {
  640. // GD.setPageSizeWithRatio(1);
  641. // }
  642. // },
  643. // {
  644. // label: "200%",
  645. // action: function(item, event) {
  646. // GD.setPageSizeWithRatio(2);
  647. // }
  648. // },
  649. // {
  650. // label: "400%",
  651. // action: function(item, event) {
  652. // GD.setPageSizeWithRatio(4);
  653. // }
  654. // },
  655. // {
  656. // label: "实际大小",
  657. // action: function(item, event) {
  658. // GD.setPageSizeWithRatio('originSize');
  659. // }
  660. // },
  661. // {
  662. // label: '适合屏幕',
  663. // action: function (item, event) {
  664. // GD.setPageSizeWithRatio('adaptBrowser');
  665. // }
  666. // },
  667. // {
  668. // label: "适合宽度",
  669. // action: function(item, event) {
  670. // GD.setPageSizeWithRatio('adaptWidth');
  671. // }
  672. // },
  673. // {
  674. // label: "适合高度",
  675. // action: function(item, event) {
  676. // GD.setPageSizeWithRatio('adaptHeight');
  677. // }
  678. // },
  679. // ];
  680. // var zoomMenu = new ht.widget.ContextMenu(json);
  681. // zoomMenu.disableGlobalKey();
  682. // zoomMenu.setLabelMaxWidth(100);
  683. // zoomMenu.addTo($('.main')[0]);
  684. // })();
  685. (function () {
  686. var btnstr="停止数据刷新";
  687. var json = [], item1, item2;
  688. item1 = {
  689. label: btnstr,
  690. action: function(item, event) {
  691. if(btnstr=="停止数据刷新"){
  692. clearInterval(intervalTimers[0]);
  693. intervalTimers.shift(intervalTimers[0]);
  694. btnstr="开启数据刷新";
  695. json[0].label=btnstr;
  696. }else{
  697. intervalTimers.unshift(setInterval(DatarefreshTask, 1000));
  698. btnstr="停止数据刷新";
  699. json[0].label=btnstr;
  700. }
  701. }
  702. };
  703. item2 = {
  704. label: "下载本页所有测点",
  705. action: function(item, event) {
  706. var time = new Date();
  707. var t=time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
  708. var str= "测点名\n";
  709. for(var i=0;i<varList.length;i++){
  710. str+=varList[i]+"\n"
  711. }
  712. str = encodeURIComponent(str);
  713. var link = document.createElement("a");
  714. link.download = t+"测点名称集合.csv";
  715. link.href ="data:text/csv;charset=utf-8,\ufeff"+str;
  716. link.click();
  717. }
  718. };
  719. item3 = {
  720. label: "历史回放",
  721. action: function(item, event) {
  722. createHisBackDialog(DatarefreshTask);
  723. }
  724. };
  725. item4 = {
  726. label: "保存页面图片",
  727. action: function(item, event) {
  728. savehtmlToJpg();
  729. }
  730. };
  731. if (false) {
  732. json.push(item1);
  733. }
  734. if (false) {
  735. json.push(item2);
  736. }
  737. if(false){
  738. json.push(item3);
  739. }
  740. if(false){
  741. json.push(item4);
  742. }
  743. function addContextMenu() {
  744. var dataMenu = new ht.widget.ContextMenu();
  745. dataMenu.enableGlobalKey();
  746. dataMenu.setLabelMaxWidth(120);
  747. dataMenu.addTo(view);
  748. contextMenuOnViewList.push(dataMenu);
  749. dataMenu.beforeShow=function(e){
  750. if(e.originEvent.target.className=="main"){
  751. if(typeof(graphView.getDataAt(e))=="undefined"){
  752. this.setItems(json);
  753. }else if(typeof(graphView.getDataAt(e)._attrObject)=="undefined"){
  754. this.setItems(json);
  755. }else{
  756. this.setItems(null);
  757. }
  758. }else{
  759. this.setItems(null);
  760. }
  761. }
  762. };
  763. if (json.length > 0) {
  764. addContextMenu();
  765. }
  766. })();
  767. })();
  768. }