control.js 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856
  1. var dialog = new ht.widget.Dialog();
  2. function setNumberControl(x, y, varName, quality, maxValue, minValue, desc, groupid) {
  3. if (!isdowncontrol()) {
  4. return;
  5. }
  6. if (isAuthEnable == "True" && groupid >= 0) {
  7. getAuthInfoByGroupId(groupid, function (data) {
  8. if (data) {
  9. showDialog(x, y, varName, quality, maxValue, minValue, desc, groupid);
  10. }
  11. });
  12. } else {
  13. showDialog(x, y, varName, quality, maxValue, minValue, desc, groupid);
  14. }
  15. }
  16. function showDialog(x, y, varName, quality, maxValue, minValue, desc, groupid) {
  17. var w = $(window).width(),
  18. h = $(window).height();
  19. x += 40;
  20. y += 40;
  21. if (x + 290 > w) {
  22. x = x - 380;
  23. }
  24. if (y + 190 > h) {
  25. y = y - 280;
  26. }
  27. var content = '<div style="text-align: center;"><label style="font-size: 18px; font-weight: 600;">'+ desc +':</label><input focus type="number" style="height: 36px; font-size: 16px; width: 140px;" id="isetnumber" /></div>';
  28. GD.createMessageDialog(300, 200, content, function () {
  29. var value = $("#isetnumber").val();
  30. if (checkNumber(value) == true && value.length > 0) {
  31. if (value-0 > maxValue-0) {
  32. GD.createErrorDialog(300, 200, '设定值不能高于上限值!');
  33. } else if (value-0 < minValue-0) {
  34. GD.createErrorDialog(300, 200, '设定值不能低于下限值!');
  35. } else {
  36. submitAddSingle(varName, value, "", quality, desc + ' ' + value, groupid);
  37. }
  38. } else {
  39. $("#isetnumber").val("");
  40. }
  41. }, function (){}, null, null, ' ', x, y);
  42. $('#isetnumber').focus();
  43. }
  44. var openPageDialog = new ht.widget.Dialog();
  45. function setPageDialogControl(x, y, width, height, src, center, titleshow, autoAdaptX, autoAdaptY) {
  46. var clientWidth = browserSize.width,
  47. clientHeight = browserSize.height;
  48. var ratioX = clientWidth / backSize.width,
  49. ratioY = clientHeight / backSize.height;
  50. var savedTags = GD.getParams('trendtags') || {},
  51. savedTagsStr = '',
  52. searchObj = GD.getSearchObjFromUrl(src) || {},
  53. tag = searchObj.tagName || '';
  54. savedTags = savedTags.trendTags || [];
  55. if (savedTags.indexOf(tag) !== -1) {
  56. savedTags.splice(savedTags.indexOf(tag), 1);
  57. }
  58. if (savedTags.length > 0)
  59. savedTagsStr = ',' + savedTags.join(',');
  60. if (height > clientHeight) {
  61. center = "false";
  62. }
  63. if (!titleshow) {
  64. var positionX = x + width * 0.5;
  65. var positionY = y + height * 0.5;
  66. width *= ratioX;
  67. height *= ratioY;
  68. positionX *= ratioX;
  69. positionY *= ratioY;
  70. if (!!autoAdaptX) {
  71. width = clientWidth;
  72. positionX = width * 0.5;
  73. }
  74. if (!!autoAdaptY) {
  75. height = clientHeight;
  76. positionY = height * 0.5;
  77. }
  78. if (center === 'true') {
  79. positionX = clientWidth * 0.5;
  80. positionY = clientHeight * 0.5;
  81. }
  82. src = PAGEROOTDIR + src + savedTagsStr;
  83. var content = "<iframe src='" + src + "' name='' width='" + width + "' height='" + height + "' scrolling='no' frameborder='0'></iframe>";
  84. openPageDialog = new ht.HtmlNode();
  85. openPageDialog.setPosition(positionX, positionY);
  86. openPageDialog.setSize(width, height);
  87. openPageDialog.setHtml(content);
  88. dataModel.add(openPageDialog);
  89. // resizeOneNodes(openPageDialog, ratioX, ratioY);
  90. } else {
  91. if (width > clientWidth) {
  92. width = document.body.clientWidth;
  93. }
  94. if (!!autoAdaptX) {
  95. width = clientWidth;
  96. x = 0;
  97. }
  98. if (!!autoAdaptY) {
  99. height = clientHeight;
  100. y = 0;
  101. }
  102. src = PAGEROOTDIR + src + savedTagsStr;
  103. var content = "<iframe src='" + src + "' name='' width='100%' height='100%' scrolling='no' frameborder='0'></iframe>";
  104. var obj = {
  105. titleAlign: "left",
  106. closable: true,
  107. maximizable: true,
  108. draggable: true,
  109. width: width,
  110. height: height,
  111. content: content
  112. };
  113. if (center == "true") {
  114. openPageDialog.setConfig(obj);
  115. } else {
  116. obj.position = { x: x, y: y };
  117. }
  118. openPageDialog.setConfig(obj);
  119. openPageDialog.setModal(false);
  120. openPageDialog.show();
  121. }
  122. openPageDialog.onHidden = function (e) {
  123. GD.removeParams('trendtags');
  124. }
  125. $('.main').off('click').on('click', function () {
  126. (typeof openPageDialog.hide === 'function') && openPageDialog.hide(true);
  127. setTimeout(function () {
  128. savedTags.push(tag);
  129. savedTags = GD.removeRepeated(savedTags);
  130. GD.setParams({ trendTags: savedTags }, 'trendtags');
  131. }, 500);
  132. });
  133. }
  134. var customEventMap = {
  135. "jumpPage": "customEventJump", //跳转页面
  136. "resizeNodes": "customEventResizeNodes", // 重新设置元素大小
  137. "setPageSize": "customEventSetPageSizeWithRatio", // 能过设置比例改变页面大小
  138. }
  139. /**
  140. * data = e.data;
  141. * data {
  142. * action: '',
  143. * args: {
  144. * foo: 'bar',
  145. * url: 'XXX'
  146. * }
  147. * }
  148. */
  149. window.addEventListener('message', function (e) {
  150. var data = e.data || {};
  151. if (data == 'close') {
  152. closePageDialogControl()
  153. }
  154. if (data === 'getZoom') {
  155. e.source.postMessage({
  156. action: 'resizeNodes',
  157. args: {
  158. ratioX: 1,
  159. ratioY: 1,
  160. zoom: graphView.getZoom()
  161. }
  162. }, '*');
  163. }
  164. if (customEventMap[data.action]) {
  165. $(window).trigger(customEventMap[data.action], data.args)
  166. }
  167. });
  168. //关闭弹出面板
  169. function closePageDialogControl() {
  170. if (typeof openPageDialog.isShowing == "function") {
  171. if (openPageDialog.isShowing()) {
  172. //隐藏对话框
  173. openPageDialog.hide();
  174. }
  175. } else {
  176. dataModel.remove(openPageDialog);
  177. }
  178. }
  179. function initData(data, direct, nodeArrows, nodeArrowe) {
  180. var arrowNames = [nodeArrows];
  181. var arrowNamee = [nodeArrowe];
  182. var fromArrow = {
  183. position: 16,
  184. names: arrowNames,
  185. rotation: Math.PI,
  186. keepOrien: true,
  187. offsetX: -60,
  188. offsetY: 5
  189. };
  190. var endArrow = {
  191. position: 19,
  192. names: arrowNamee,
  193. keepOrien: true,
  194. offsetX: 10,
  195. offsetY: -5
  196. }
  197. if (direct == "start") { endArrow = {} };
  198. if (direct == "end") { fromArrow = {} };
  199. if (direct == "no") { fromArrow = {}; endArrow = {} };
  200. data.s({
  201. 'icons': {
  202. fromArrow: fromArrow,
  203. toArrow: endArrow
  204. }
  205. });
  206. }
  207. function createMessageDialog(width, height, content, surefunc, canclefunc) {
  208. var messageDialog = new ht.widget.Dialog();
  209. var content = '<p class="dialog-content-custom">' + content + '</p>';
  210. messageDialog.setConfig({
  211. title: "提示",
  212. titleIcon: 'node_image',
  213. titleAlign: "left",
  214. closable: true,
  215. draggable: true,
  216. //maximizable: true,
  217. width: width,
  218. height: height,
  219. content: content,
  220. contentPadding: 20,
  221. buttons: [{
  222. label: "确认",
  223. className: 'dialog-button-confirm'
  224. }, {
  225. label: "取消",
  226. className: 'dialog-button-cancel'
  227. }],
  228. buttonsAlign: "center",
  229. action: function (item, e) {
  230. if (item.label == "确认") {
  231. surefunc();
  232. messageDialog.hide();
  233. }
  234. else {
  235. canclefunc();
  236. messageDialog.hide();
  237. }
  238. }
  239. });
  240. messageDialog.setModal(false);
  241. messageDialog.show();
  242. }
  243. function getChartLineFeed(title, datas, fontSize, barContainerWidth, xWidth, x2Width, insertContent) {
  244. if (!datas || datas.length == 0) {
  245. //alert("用于计算柱状图柱子个数的参数datas不合法!");
  246. return false;
  247. }
  248. if (isNaN(barContainerWidth)) {
  249. //alert("柱状图初始化所在的容器的宽度不是一个数字");
  250. return false;
  251. }
  252. if (!fontSize) {
  253. fontSize = 12;
  254. }
  255. if (isNaN(xWidth)) {
  256. xWidth = 80;//默认与echarts的默认值一致
  257. }
  258. if (isNaN(x2Width)) {
  259. x2Width = 80;//默认与echarts的默认值一致
  260. }
  261. if (!insertContent) {
  262. insertContent = "\n";
  263. }
  264. var xAxisWidth = parseInt(barContainerWidth) - (parseInt(xWidth) + parseInt(x2Width));//柱状图x轴宽度=统计页面宽度-柱状图x轴的空白间隙(x + x2)
  265. var barCount = datas.length; //x轴单元格的个数(即为获取x轴的数据的条数)
  266. var preBarWidth = Math.floor(xAxisWidth / barCount); //统计x轴每个单元格的间隔
  267. var preBarFontCount = Math.floor(preBarWidth / fontSize); //柱状图每个柱所在x轴间隔能容纳的字数 = 每个柱子 x 轴间隔宽度 / 每个字的宽度(12px)
  268. if (preBarFontCount > 3) { //为了x轴标题显示美观,每个标题显示留两个字的间隙,如:原本一个格能一样显示5个字,处理后一行就只显示3个字
  269. preBarFontCount -= 2;
  270. } else if (preBarFontCount <= 3 && preBarFontCount >= 2) {//若每个间隔距离刚好能放两个或者字符时,则让其只放一个字符
  271. preBarFontCount -= 1;
  272. }
  273. var newTitle = ""; //拼接每次截取的内容,直到最后为完整的值
  274. var titleSuf = ""; //用于存放每次截取后剩下的部分
  275. var rowCount = Math.ceil(title.length / preBarFontCount); //标题显示需要换行的次数
  276. if (rowCount > 1) { //标题字数大于柱状图每个柱子x轴间隔所能容纳的字数,则将标题换行
  277. for (var j = 1; j <= rowCount; j++) {
  278. if (j == 1) {
  279. newTitle += title.substring(0, preBarFontCount) + insertContent;
  280. titleSuf = title.substring(preBarFontCount); //存放将截取后剩下的部分,便于下次循环从这剩下的部分中又从头截取固定长度
  281. } else {
  282. var startIndex = 0;
  283. var endIndex = preBarFontCount;
  284. if (titleSuf.length > preBarFontCount) { //检查截取后剩下的部分的长度是否大于柱状图单个柱子间隔所容纳的字数
  285. newTitle += titleSuf.substring(startIndex, endIndex) + insertContent;
  286. titleSuf = titleSuf.substring(endIndex); //更新截取后剩下的部分,便于下次继续从这剩下的部分中截取固定长度
  287. } else if (titleSuf.length > 0) {
  288. newTitle += titleSuf.substring(startIndex);
  289. }
  290. }
  291. }
  292. } else {
  293. newTitle = title;
  294. }
  295. return newTitle;
  296. }
  297. function vectorMoveRotate(nodename, sx, sy, x_relat, y_relat, min, max, directFun) {
  298. //var rotation=nodename.getRotation();
  299. //var relatXPosition=sx*Math.cos(rotation),relatYPosition=sy*(Math.sin(rotation));
  300. var relatXPosition = sx, relatYPosition = sy;
  301. if (x_relat) {
  302. relatXPosition = relatXPosition + nodename.getPosition().x;
  303. }
  304. if (y_relat) {
  305. relatYPosition = relatYPosition + nodename.getPosition().y;
  306. }
  307. if (directFun == "Horizontal") {
  308. relatXPosition = relatXPosition >= max ? max : relatXPosition;
  309. relatXPosition = relatXPosition <= min ? min : relatXPosition;
  310. }
  311. if (directFun == "Vertical") {
  312. relatYPosition = relatYPosition >= max ? max : relatYPosition;
  313. relatYPosition = relatYPosition <= min ? min : relatYPosition;
  314. }
  315. nodename.setPosition(relatXPosition, relatYPosition);
  316. }
  317. function createTagProperty(dic, tagname, width, height) {
  318. var tagPropsDialog = new ht.widget.Dialog();
  319. var tagprop = dic[tagname.toLowerCase()];
  320. var content = "";
  321. if (typeof (tagprop) == "undefined") {
  322. content = "<p style='color:cadetblue;font-size:15px'>" + "标签名称:" + tagname + "<br/>" + "描述:" + "" + "<br/>" + "单位:" + "" + "<br/>" + "量程上限:" + "" + "<br/>" + "量程下限:"
  323. + "" + "<br/>" + "快照时间:" + "" + "</p>";
  324. } else {
  325. content = "<p style='color:cadetblue;font-size:15px'>" + "标签名称:" + tagprop.TableDotTag + "<br/>" + "描述:" + tagprop.Desc + "<br/>" + "单位:" + tagprop.Unit + "<br/>" + "量程上限:" + tagprop.HighLimit + "<br/>" + "量程下限:"
  326. + tagprop.LowLimit + "<br/>" + "快照时间:" + VarSnapshotTime[tagname.toLowerCase()] + "</p>";
  327. }
  328. var tagpropConfig = {
  329. title: "属性",
  330. titleAlign: "left",
  331. closable: true,
  332. draggable: true,
  333. width: width,
  334. height: height,
  335. content: content,
  336. contentPadding: 0
  337. };
  338. tagPropsDialog.setConfig(tagpropConfig);
  339. tagPropsDialog.setModal(false);
  340. tagPropsDialog.show();
  341. var interval = setInterval(function () {
  342. if (typeof (tagprop) == "undefined") {
  343. return;
  344. }
  345. var content = "<p style='color:cadetblue;font-size:15px'>" + "标签名称:" + tagprop.TableDotTag + "<br/>" + "描述:" + tagprop.Desc + "<br/>" + "单位:" + tagprop.Unit + "<br/>" + "量程上限:" + tagprop.HighLimit + "<br/>" + "量程下限:"
  346. + tagprop.LowLimit + "<br/>" + "快照时间:" + VarSnapshotTime[tagname.toLowerCase()] + "</p>";
  347. tagpropConfig.content = content;
  348. if (tagPropsDialog.isShowing()) {
  349. tagPropsDialog.setConfig(tagpropConfig);
  350. } else {
  351. return;
  352. }
  353. tagPropsDialog.setModal(false);
  354. }, 2000);
  355. tagPropsDialog.onHidden = function () {
  356. tagPropsDialog.hide();
  357. clearInterval(interval);
  358. }
  359. }
  360. function PointSelectDialog(width, height, backcolor, dm, partdm, formPane, pageSize) {
  361. var pointSelectformPane = new ht.widget.FormPane();
  362. var pointSelectTags = new ht.DataModel();
  363. var pointSelecttablePane = new ht.widget.TablePane(pointSelectTags);
  364. var pointSelectAttr = [
  365. {
  366. name: 'id',
  367. displayName: 'Id',
  368. align: 'center',
  369. width: 50
  370. },
  371. {
  372. name: 'configPointDesc',
  373. displayName: '描述',
  374. align: 'center',
  375. accessType: 'attr',
  376. width: 200
  377. },
  378. {
  379. name: 'configPointName',
  380. displayName: '标签名',
  381. align: 'center',
  382. accessType: 'attr',
  383. width: 250
  384. }
  385. ];
  386. pointSelecttablePane.addColumns(pointSelectAttr);
  387. var pointSelecttableView = pointSelecttablePane.getTableView();
  388. pointSelecttableView.setCheckMode(true);
  389. var pointSelectPageIndex = 1;
  390. var pointSelectPageSize = 100;
  391. document.body.appendChild(pointSelectformPane.getView());
  392. pointSelectformPane.addRow([
  393. '表名称:',
  394. {
  395. id: 'tablename',
  396. textField: {
  397. text: '*'
  398. }
  399. },
  400. '标签点描述:',
  401. {
  402. id: 'pointDesc',
  403. textField: {
  404. text: '*'
  405. }
  406. },
  407. {
  408. button: {
  409. label: '查找',
  410. onClicked: function () {
  411. pointSelectTags.clear();
  412. var tagDesc = pointSelectformPane.v('pointDesc');
  413. var tablename = pointSelectformPane.v('tablename');
  414. pointSelectPageIndex = 1;
  415. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  416. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  417. }
  418. },
  419. }
  420. ],
  421. [0.12, 0.3, 0.2, 0.3, 0.3]);
  422. pointSelectformPane.addRow([pointSelecttablePane], [0.1], 0.1);
  423. pointSelectformPane.addRow([
  424. {
  425. button: {
  426. label: '<<',
  427. onClicked: function () {
  428. pointSelectTags.clear();
  429. pointSelectPageIndex = 1;
  430. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  431. var tagDesc = pointSelectformPane.v('pointDesc');
  432. var tablename = pointSelectformPane.v('tablename');
  433. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  434. }
  435. }
  436. },
  437. {
  438. button: {
  439. label: '<',
  440. onClicked: function () {
  441. pointSelectTags.clear();
  442. if (pointSelectPageIndex > 1) {
  443. pointSelectPageIndex = pointSelectPageIndex - 1;
  444. }
  445. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  446. var tagDesc = pointSelectformPane.v('pointDesc');
  447. var tablename = pointSelectformPane.v('tablename');
  448. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  449. }
  450. }
  451. },
  452. {
  453. id: "pageindex",
  454. element: pointSelectPageIndex.toString()
  455. },
  456. {
  457. element: "/",
  458. },
  459. {
  460. id: "pagecount",
  461. element: "1"
  462. },
  463. {
  464. button: {
  465. label: '>',
  466. onClicked: function () {
  467. pointSelectTags.clear();
  468. if (pointSelectPageIndex < pointSelectformPane.v('pagecount')) {
  469. pointSelectPageIndex = pointSelectPageIndex + 1;
  470. }
  471. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  472. var tagDesc = pointSelectformPane.v('pointDesc');
  473. var tablename = pointSelectformPane.v('tablename');
  474. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  475. }
  476. },
  477. },
  478. {
  479. button: {
  480. label: '>>',
  481. onClicked: function () {
  482. pointSelectTags.clear();
  483. pointSelectPageIndex = pointSelectformPane.v('pagecount');
  484. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  485. var tagDesc = pointSelectformPane.v('pointDesc');
  486. var tablename = pointSelectformPane.v('tablename'); //tablename;
  487. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  488. }
  489. }
  490. }
  491. ],
  492. [0.05, 0.05, 0.02, 0.02, 0.02, 0.05, 0.05]);
  493. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, "*", "*", pointSelectTags, pointSelectformPane);
  494. pointSelectformPane.getView().style.background = backcolor;
  495. var pointSelect = new ht.widget.Dialog();
  496. var pointSelectConfigObj = {
  497. title: "标签点选择",
  498. titleAlign: "left",
  499. closable: true,
  500. draggable: true,
  501. contentPadding: 5,
  502. width: width,
  503. height: height,
  504. content: pointSelectformPane,
  505. buttons: [
  506. {
  507. label: "确认",
  508. className: "button-yes"
  509. },
  510. {
  511. label: "取消",
  512. className: "button-yes"
  513. }
  514. ],
  515. buttonsAlign: "center",
  516. action: function (item, e) {
  517. if (item.label == "确认") {
  518. var selectpoint = pointSelecttableView.sm()._map;
  519. for (var key in selectpoint) {
  520. var pointspros = selectpoint[key];
  521. var data = new ht.Data();
  522. //data.setId(i+1);
  523. data.a('index', dm._datas._as.length + 1);
  524. data.a('configPointDesc', pointspros.a('configPointDesc'));
  525. data.a('configPointName', pointspros.a('configPointName'));
  526. data.a('pintunit', pointspros.a('pintunit'));
  527. data.a('pointtype', pointspros.a('pointtype'));
  528. data.a('snapvalue', "");
  529. data.a('timestamp', "");
  530. dm.add(data);
  531. }
  532. GetModelByPage(1, pageSize, dm, partdm, formPane);
  533. pointSelect.hide();
  534. }
  535. else {
  536. pointSelect.hide();
  537. }
  538. }
  539. }
  540. pointSelect.setConfig(pointSelectConfigObj);
  541. pointSelect.setModal(false);
  542. pointSelect.show();
  543. }
  544. function PointSnapPropsTable(width, height, backcolor, dm, partdm) {
  545. var pointSelectformPane = new ht.widget.FormPane();
  546. var pointSelecttablePane = new ht.widget.TablePane(partdm);
  547. var pointSelectAttr = [
  548. {
  549. name: 'index',
  550. displayName: 'ID',
  551. align: 'center',
  552. accessType: 'attr',
  553. width: 50
  554. },
  555. {
  556. name: 'configPointName',
  557. displayName: '标签名',
  558. align: 'center',
  559. accessType: 'attr',
  560. width: 250
  561. },
  562. {
  563. name: 'configPointDesc',
  564. displayName: '描述',
  565. align: 'center',
  566. accessType: 'attr',
  567. width: 200
  568. },
  569. {
  570. name: 'snapvalue',
  571. displayName: '值',
  572. align: 'center',
  573. accessType: 'attr',
  574. width: 200
  575. },
  576. {
  577. name: 'pintunit',
  578. displayName: '工程单位',
  579. align: 'center',
  580. accessType: 'attr',
  581. width: 100
  582. },
  583. {
  584. name: 'timestamp',
  585. displayName: '时间戳',
  586. align: 'center',
  587. accessType: 'attr',
  588. width: 150
  589. },
  590. {
  591. name: 'pointtype',
  592. displayName: '数值类型',
  593. align: 'center',
  594. accessType: 'attr',
  595. width: 100
  596. }
  597. ];
  598. pointSelecttablePane.addColumns(pointSelectAttr);
  599. var pointSelectPageIndex = 1;
  600. var pointSelectPageSize = 100;
  601. document.body.appendChild(pointSelectformPane.getView());
  602. pointSelectformPane.addRow([
  603. "",
  604. {
  605. button: {
  606. label: '追加',
  607. onClicked: function () {
  608. var pageSize = parseInt(pageRows.getValue());
  609. PointSelectDialog(600, 500, 'rgba(240,248,255,1)', dm, partdm, pointSelectformPane, pageSize);
  610. }
  611. }
  612. },
  613. {
  614. button: {
  615. label: '选择文件',
  616. width: 64,
  617. onClicked: function () {
  618. var input = document.createElement('input');
  619. input.type = 'file';
  620. input.style.display = "none";
  621. input.onchange = function () {
  622. dm.clear();
  623. partdm.clear();
  624. var fileSelector = input.files;
  625. var file = fileSelector[0];
  626. var reader = new FileReader();
  627. reader.readAsText(file);
  628. reader.onload = function () {
  629. var str = this.result;
  630. var lineArr;
  631. if (str.length >= 0) {
  632. lineArr = str.split('\n');
  633. for (var i = 1; i < lineArr.length - 1; i++) {
  634. var pointInfo = lineArr[i].split(',');
  635. var data = new ht.Data();
  636. data.a('index', pointInfo[0]);
  637. data.a('configPointDesc', pointInfo[2]);
  638. data.a('configPointName', pointInfo[1]);
  639. data.a('pintunit', pointInfo[4]);
  640. data.a('pointtype', pointInfo[6]);
  641. data.a('snapvalue', pointInfo[3]);
  642. data.a('timestamp', pointInfo[5]);
  643. dm.add(data);
  644. }
  645. pointSelectformPane.v('pageindex', "1");
  646. var pageSize = parseInt(pageRows.getValue());
  647. GetModelByPage(1, pageSize, dm, partdm, pointSelectformPane);
  648. //GetModelByPage(pointSelectPageIndex,pageSize,dm,partdm,pointSelectformPane);
  649. }
  650. }
  651. };
  652. document.body.appendChild(input);
  653. input.click();
  654. }
  655. }
  656. },
  657. {
  658. button: {
  659. label: '清除选择',
  660. onClicked: function () {
  661. pointSelectformPane.v('pagecount', "1");
  662. pointSelectformPane.v('pageindex', "1");
  663. dm.clear();
  664. partdm.clear();
  665. }
  666. }
  667. }
  668. ],
  669. [0.6, 0.05, 0.05, 0.05]);
  670. pointSelectformPane.addRow([pointSelecttablePane], [0.1], 0.1);
  671. var pageRows = new ht.widget.ComboBox();
  672. pageRows.setValues([10, 20, 30, 50, 100, 200, 300, 400, 500]);
  673. pageRows.setValue(50);
  674. pageRows.setEditable(true);
  675. //pageRows.setWidth(50);
  676. pageRows.setDropDownWidth(140);
  677. pageRows.onValueChanged = function () {
  678. pointSelectformPane.v('pageindex', "1");
  679. var pageSize = parseInt(pageRows.getValue());
  680. GetModelByPage(1, pageSize, dm, partdm, pointSelectformPane);
  681. //重新刷新数据
  682. };
  683. pointSelectformPane.addRow([
  684. "",
  685. {
  686. button: {
  687. label: '<<',
  688. onClicked: function () {
  689. pointSelectPageIndex = 1;
  690. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  691. var pageSize = parseInt(pageRows.getValue());
  692. GetModelByPage(pointSelectPageIndex, pageSize, dm, partdm, pointSelectformPane);
  693. }
  694. }
  695. },
  696. {
  697. button: {
  698. label: '<',
  699. onClicked: function () {
  700. pointSelectPageIndex = pointSelectformPane.v('pageindex');
  701. if (pointSelectPageIndex > 1) {
  702. pointSelectPageIndex = pointSelectPageIndex - 1;
  703. }
  704. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  705. var pageSize = parseInt(pageRows.getValue());
  706. GetModelByPage(pointSelectPageIndex, pageSize, dm, partdm, pointSelectformPane);
  707. }
  708. }
  709. },
  710. {
  711. id: "pageindex",
  712. element: pointSelectPageIndex.toString()
  713. },
  714. {
  715. element: "/",
  716. },
  717. {
  718. id: "pagecount",
  719. element: "1"
  720. },
  721. {
  722. button: {
  723. label: '>',
  724. onClicked: function () {
  725. pointSelectPageIndex = parseInt(pointSelectformPane.v('pageindex'));
  726. if (pointSelectPageIndex < pointSelectformPane.v('pagecount')) {
  727. pointSelectPageIndex = pointSelectPageIndex + 1;
  728. }
  729. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  730. var pageSize = parseInt(pageRows.getValue());
  731. GetModelByPage(pointSelectPageIndex, pageSize, dm, partdm, pointSelectformPane);
  732. }
  733. },
  734. },
  735. {
  736. button: {
  737. label: '>>',
  738. onClicked: function () {
  739. pointSelectPageIndex = pointSelectformPane.v('pagecount');
  740. if (pointSelectPageIndex == 0) {
  741. pointSelectPageIndex = 1;
  742. } else {
  743. pointSelectformPane.v('pagecount', "1");
  744. }
  745. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  746. var pageSize = parseInt(pageRows.getValue());
  747. GetModelByPage(pointSelectPageIndex, pageSize, dm, partdm, pointSelectformPane);
  748. }
  749. }
  750. },
  751. "rows:",
  752. {
  753. element: pageRows
  754. },
  755. {
  756. button: {
  757. label: '导出',
  758. onClicked: function () {
  759. var title = ["ID", "标签点", "描述", "值", "工程单位", "时间戳", "数值类型"];
  760. var titleKey = ["index", "configPointName", "configPointDesc", "snapvalue", "pintunit", "timestamp", "pointtype"];
  761. var csvdata = [];
  762. var datas = dm._datas._as;
  763. if (datas.length == 0) {
  764. } else {
  765. for (var i = 0; i < datas.length; i++) {
  766. var tagname = datas[i].a("configPointName");
  767. var json = {
  768. index: datas[i].a("index"),
  769. configPointName: tagname,
  770. configPointDesc: datas[i].a("configPointDesc"),
  771. snapvalue: getVarValue(tagname),
  772. pintunit: datas[i].a("pintunit"),
  773. timestamp: VarSnapshotTime[tagname.toLowerCase()],
  774. pointtype: datas[i].a("pointtype")
  775. };
  776. csvdata.push(json);
  777. }
  778. }
  779. var obj = { title: title, titleForKey: titleKey, data: csvdata };
  780. exportCsv(obj);
  781. }
  782. }
  783. },
  784. ""
  785. ],
  786. [0.3, 0.1, 0.1, 0.04, 0.02, 0.04, 0.1, 0.1, 0.05, 0.1, 0.1, 0.3]);
  787. //getPointsSelect(pointSelectPageIndex,pointSelectPageSize,"*","*",dm,pointSelectformPane);
  788. pointSelectformPane.getView().style.background = backcolor;
  789. return pointSelectformPane;
  790. }
  791. function GetModelByPage(pageIndex, pageSize, dm, partdm, formpane) {
  792. //改变页的条数
  793. var dataCount = dm._datas._as.length;
  794. var pageCount = 1;
  795. if (dataCount % pageSize == 0) {
  796. pageCount = dataCount / pageSize;
  797. } else {
  798. pageCount = Math.ceil(dataCount / pageSize);
  799. }
  800. if (pageCount == 0) { pageCount = 1 }
  801. formpane.v('pagecount', pageCount.toString());
  802. partdm.clear();
  803. var index = (pageIndex - 1) * pageSize;
  804. var pointspros = dm._datas._as;
  805. for (var i = index; i < index + pageSize; i++) {
  806. var data = new ht.Data();
  807. data.a('index', partdm._datas._as.length + 1);
  808. data.a('configPointDesc', pointspros[i].a('configPointDesc'));
  809. data.a('configPointName', pointspros[i].a('configPointName'));
  810. data.a('pintunit', pointspros[i].a('pintunit'));
  811. data.a('pointtype', pointspros[i].a('pointtype'));
  812. data.a('snapvalue', "");
  813. data.a('timestamp', "");
  814. partdm.add(data);
  815. }
  816. }
  817. function DirectPointDialogShow(data, callback) {
  818. var pointSelectformPane = new ht.widget.FormPane();
  819. var pointSelectTags = new ht.DataModel();
  820. var pointSelecttablePane = new ht.widget.TablePane(pointSelectTags);
  821. var pointSelectAttr = [
  822. {
  823. name: 'id',
  824. displayName: 'Id',
  825. align: 'center',
  826. width: 50
  827. },
  828. {
  829. name: 'configPointDesc',
  830. displayName: '描述',
  831. align: 'center',
  832. accessType: 'attr',
  833. width: 200
  834. },
  835. {
  836. name: 'configPointName',
  837. displayName: '标签名',
  838. align: 'center',
  839. accessType: 'attr',
  840. width: 250
  841. }
  842. ];
  843. pointSelecttablePane.addColumns(pointSelectAttr);
  844. var pointSelecttableView = pointSelecttablePane.getTableView();
  845. pointSelecttableView.setCheckMode(true);
  846. var pointSelectPageIndex = 1;
  847. var pointSelectPageSize = 100;
  848. document.body.appendChild(pointSelectformPane.getView());
  849. pointSelectformPane.addRow([
  850. '表名称:',
  851. {
  852. id: 'tablename',
  853. textField: {
  854. text: '*'
  855. }
  856. },
  857. '标签点描述:',
  858. {
  859. id: 'pointDesc',
  860. textField: {
  861. text: '*'
  862. }
  863. },
  864. {
  865. button: {
  866. label: '查找',
  867. onClicked: function () {
  868. pointSelectTags.clear();
  869. var tagDesc = pointSelectformPane.v('pointDesc');
  870. var tablename = pointSelectformPane.v('tablename');
  871. pointSelectPageIndex = 1;
  872. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  873. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  874. }
  875. },
  876. }
  877. ],
  878. [0.12, 0.3, 0.2, 0.3, 0.3]);
  879. pointSelectformPane.addRow([pointSelecttablePane], [0.1], 0.1);
  880. pointSelectformPane.addRow([
  881. {
  882. button: {
  883. label: '<<',
  884. onClicked: function () {
  885. pointSelectTags.clear();
  886. pointSelectPageIndex = 1;
  887. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  888. var tagDesc = pointSelectformPane.v('pointDesc');
  889. var tablename = pointSelectformPane.v('tablename');
  890. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  891. }
  892. }
  893. },
  894. {
  895. button: {
  896. label: '<',
  897. onClicked: function () {
  898. pointSelectTags.clear();
  899. if (pointSelectPageIndex > 1) {
  900. pointSelectPageIndex = pointSelectPageIndex - 1;
  901. }
  902. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  903. var tagDesc = pointSelectformPane.v('pointDesc');
  904. var tablename = pointSelectformPane.v('tablename');
  905. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  906. }
  907. }
  908. },
  909. {
  910. id: "pageindex",
  911. element: pointSelectPageIndex.toString()
  912. },
  913. {
  914. element: "/",
  915. },
  916. {
  917. id: "pagecount",
  918. element: "1"
  919. },
  920. {
  921. button: {
  922. label: '>',
  923. onClicked: function () {
  924. pointSelectTags.clear();
  925. if (pointSelectPageIndex < pointSelectformPane.v('pagecount')) {
  926. pointSelectPageIndex = pointSelectPageIndex + 1;
  927. }
  928. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  929. var tagDesc = pointSelectformPane.v('pointDesc');
  930. var tablename = pointSelectformPane.v('tablename');
  931. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  932. }
  933. },
  934. },
  935. {
  936. button: {
  937. label: '>>',
  938. onClicked: function () {
  939. pointSelectTags.clear();
  940. pointSelectPageIndex = pointSelectformPane.v('pagecount');
  941. pointSelectformPane.v('pageindex', pointSelectPageIndex.toString());
  942. var tagDesc = pointSelectformPane.v('pointDesc');
  943. var tablename = pointSelectformPane.v('tablename'); //tablename;
  944. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, tablename, tagDesc, pointSelectTags, pointSelectformPane);
  945. }
  946. }
  947. }
  948. ],
  949. [0.05, 0.05, 0.02, 0.02, 0.02, 0.05, 0.05]);
  950. getPointsSelect(pointSelectPageIndex, pointSelectPageSize, "*", "*", pointSelectTags, pointSelectformPane);
  951. pointSelectformPane.getView().style.background = "rgba(240,248,255,1)";
  952. var pointSelect = new ht.widget.Dialog();
  953. var pointSelectConfigObj = {
  954. title: "标签点选择",
  955. titleAlign: "left",
  956. closable: true,
  957. draggable: true,
  958. contentPadding: 5,
  959. width: 600,
  960. height: 500,
  961. content: pointSelectformPane,
  962. buttons: [
  963. {
  964. label: "确认",
  965. className: "button-yes"
  966. },
  967. {
  968. label: "取消",
  969. className: "button-yes"
  970. }
  971. ],
  972. buttonsAlign: "center",
  973. action: function (item, e) {
  974. if (item.label == "确认") {
  975. var selectpoint = pointSelecttableView.sm()._map;
  976. //console.log(selectpoint);
  977. var str = "";
  978. for (var key in selectpoint) {
  979. var tagInfo = selectpoint[key].a("configPointName") + ":" + selectpoint[key].a("configPointDesc") + ":true";
  980. str = str + tagInfo + ",";
  981. }
  982. if (str[str.length - 1] == ",") str = str.substring(0, str.length - 1);
  983. data.setName(str);
  984. callback();
  985. pointSelect.hide();
  986. }
  987. else {
  988. pointSelect.hide();
  989. }
  990. }
  991. }
  992. pointSelect.setConfig(pointSelectConfigObj);
  993. pointSelect.setModal(false);
  994. pointSelect.show();
  995. }
  996. //创建表格基本信息
  997. function createBaseTable(node, tableDataModel, rowheight, rowlinevisible, rowaltercolor, isrowalter, headcolor, headGradientcolor,
  998. columnlinevisible, linecolor, backcolor, fontsize, fontcolor, fontfamily) {
  999. var tableAttr = createTableAttr(rowheight, rowlinevisible, rowaltercolor, isrowalter, headcolor, headGradientcolor,
  1000. columnlinevisible, linecolor, backcolor, fontsize, fontcolor, fontfamily);
  1001. setTableStyle(node, tableAttr);
  1002. return node;
  1003. }
  1004. function createTableByObj(node, tableAttr) {
  1005. setTableStyle(node, tableAttr);
  1006. return node;
  1007. }
  1008. //根据指标,标签点前缀信息获取标签点全名称
  1009. function getTagInfos(indicator, tagFirstHalfInfos) {
  1010. var tagnames = "";
  1011. var indicatorStr = indicator.split(',');
  1012. var tagFirstHalfs = tagFirstHalfInfos.split(',');// column
  1013. // Node3RowVarName="Demo.A01:A01:true,Demo.A02:A02:true,Demo.A03:A03:true";
  1014. // Node3ColVarName="Speed:风速:true,State:状态:true,Line:线路:true";
  1015. if (indicatorStr.length > 0) {
  1016. for (var i = 0; i < tagFirstHalfs.length; i++) {
  1017. if (tagFirstHalfs[i].split(':').length >= 1) {
  1018. for (var j = 0; j < indicatorStr.length; j++) {
  1019. if (indicatorStr[j].split(':').length >= 1) {
  1020. tagnames += tagFirstHalfs[i].split(':')[0] + indicatorStr[j].split(':')[0] + ",";
  1021. }
  1022. }
  1023. }
  1024. }
  1025. }
  1026. else {
  1027. for (var j = 0; j < tagFirstHalfs.length; j++) {
  1028. if (tagFirstHalfs[j].split(':').length >= 1) {
  1029. tagnames += tagFirstHalfs[j].split(':')[0] + ",";
  1030. }
  1031. }
  1032. }
  1033. if (tagnames[tagnames.length - 1] == ",") {
  1034. tagnames = tagnames.substr(0, tagnames.length - 1);
  1035. }
  1036. return tagnames;
  1037. }
  1038. //初始化列
  1039. function getColumnsInfo(columns, rows, title, ishis) {
  1040. var shotTablecolumns = [];
  1041. if (ishis) {
  1042. shotTablecolumns.push({ name: "time", displayName: title, accessType: 'attr', align: 'center', width: 100 });
  1043. if (columns != "") {
  1044. shotTablecolumns.push({ name: "shebei", displayName: "设备", accessType: 'attr', align: 'center', width: 100 });
  1045. }
  1046. } else {
  1047. shotTablecolumns.push({ name: "title", displayName: title, accessType: 'attr', align: 'center', width: 100 });
  1048. }
  1049. if (columns == "") {
  1050. columns = rows;
  1051. }
  1052. var columnsArr = columns.split(',');
  1053. if (columnsArr.length > 0) {
  1054. for (var i = 0; i < columnsArr.length; i++) {
  1055. var columnsHeader = columnsArr[i].split(':');
  1056. if (columnsHeader.length >= 2) {
  1057. //width=columnsHeader[2]=="0"?100:Number(columnsHeader[2]);
  1058. if (columnsHeader[2] == "true") {
  1059. shotTablecolumns.push({ name: columnsHeader[0], displayName: columnsHeader[1], accessType: 'attr', align: 'center', width: 100 });
  1060. }
  1061. }
  1062. }
  1063. }
  1064. return shotTablecolumns;
  1065. }
  1066. function getColumnsOrRowInfo(dmshow, notdmshow) {
  1067. var datashow = dmshow._datas._as;
  1068. var datanotshow = notdmshow._datas._as;
  1069. var str = "";
  1070. if (datashow.length > 0) {
  1071. for (var i = 0; i < datashow.length; i++) {
  1072. var data = datashow[i];
  1073. str = str + data.a("name") + ":" + data.a("desc") + ":true" + ",";
  1074. }
  1075. }
  1076. if (datanotshow.length > 0) {
  1077. for (var j = 0; j < datanotshow.length; j++) {
  1078. var data = datanotshow[j];
  1079. str = str + data.a("name") + ":" + data.a("desc") + ":false" + ",";
  1080. }
  1081. }
  1082. str = str.substr(0, str.length - 1);
  1083. return str;
  1084. }
  1085. function getCellsStr(columns, cells) {
  1086. var shotTablecells = [];
  1087. var tagSecondHalf = [];
  1088. var columnsArr = columns.split(',');
  1089. if (columnsArr.length > 0) {
  1090. for (var i = 0; i < columnsArr.length; i++) {
  1091. var columnsHeader = columnsArr[i].split(':');
  1092. if (columnsHeader[2] == "true") {
  1093. tagSecondHalf.push(columnsHeader[0]);
  1094. }
  1095. }
  1096. }
  1097. var taginfos = cells.split(',');
  1098. if (taginfos.length > 0) {
  1099. for (var i = 0; i < taginfos.length; i++) {
  1100. var tagFirstHalf = taginfos[i].split(':')[0];
  1101. var isShow = taginfos[i].split(':')[2];
  1102. if (typeof tagFirstHalf != undefined && isShow == "true") {
  1103. var dicvalue = {};
  1104. dicvalue["tagFirstHalf"] = tagFirstHalf;
  1105. dicvalue["title"] = taginfos[i].split(':')[1];
  1106. for (var j = 0; j < tagSecondHalf.length; j++) {
  1107. dicvalue[tagSecondHalf[j]] = getVarValue(tagFirstHalf + tagSecondHalf[j]);
  1108. }
  1109. shotTablecells.push(dicvalue);
  1110. }
  1111. }
  1112. }
  1113. return shotTablecells;
  1114. }
  1115. //快照表格数据初始化
  1116. function tableDataInit(node, columns, cells, tableDataModel, title, ischeck) {
  1117. node.getColumnModel().clear();
  1118. tableDataModel.clear();
  1119. var shotTablecolumns = getColumnsInfo(columns, title);
  1120. node.addColumns(shotTablecolumns);
  1121. var cellsStr = getCellsStr(columns, cells);
  1122. if (ischeck) {
  1123. var tableView = node.getTableView();
  1124. tableView.setCheckMode(true);
  1125. var checkColumn = tableView.getCheckColumn();
  1126. checkColumn.setWidth(100);
  1127. }
  1128. for (var i = 0; i < cellsStr.length; i++) {
  1129. var data = new ht.Data();
  1130. data.a(cellsStr[i]);
  1131. data.setId(i);
  1132. tableDataModel.add(data);
  1133. }
  1134. }
  1135. function tableHisDataInit(node, columns, rows, tableDataModel, title) {
  1136. node.getColumnModel().clear();
  1137. tableDataModel.clear();
  1138. var shotTablecolumns = getColumnsInfo(columns, rows, title, true);
  1139. node.addColumns(shotTablecolumns);
  1140. }
  1141. //表格快照数据刷新
  1142. function tableRefresh(tableModel, columns, cells) {
  1143. var cellsStr = getCellsStr(columns, cells);
  1144. for (var i = 0; i < cellsStr.length; i++) {
  1145. var data = tableModel.getDataById(i);
  1146. data.a(cellsStr[i]);
  1147. }
  1148. }
  1149. function getIndicatorArr(indicators) {
  1150. var indicatorsAttr = [];
  1151. var indicatorsArr = indicators.split(',');
  1152. if (indicatorsArr.length >= 1) {
  1153. for (var i = 0; i < indicatorsArr.length; i++) {
  1154. var indicatorsFirst = indicatorsArr[i].split(':')[0];
  1155. if (indicatorsFirst.length > 0) {
  1156. indicatorsAttr.push(indicatorsFirst);
  1157. }
  1158. }
  1159. }
  1160. return indicatorsAttr;
  1161. }
  1162. function getHisData(indicators, tagfirstHalf, tableDataModel) {
  1163. tableDataModel.clear();
  1164. if (typeof (start) == "undefined") {
  1165. return;
  1166. }
  1167. if (typeof (end) == "undefined") {
  1168. return;
  1169. }
  1170. if (typeof (interval) == "undefined") {
  1171. return;
  1172. }
  1173. if (start == "") start = moment(new Date()).format("YYYY-MM-DD H:mm:ss");
  1174. if (end == "") end = moment(new Date(start)).add(30, 'seconds').format("YYYY-MM-DD H:mm:ss");
  1175. var taginfos = getTagInfos(indicators, tagfirstHalf);
  1176. var shotTableCmdStr = taginfos + '&beginTime=' + start + '&endTime=' + end + '&interval=' + interval + '&count=0';
  1177. var indicatorArr = getIndicatorArr(indicators);
  1178. getTableHisData(shotTableCmdStr, tableDataModel, indicatorArr);
  1179. }
  1180. function createTableHistory(tableNode, tableDataModel, indicators, tagfirstHalf, tableAttr) {
  1181. tableDataModel.clear();
  1182. var columns = getColumnsInfo(indicators, "time", true);
  1183. var taginfos = getTagInfos(indicators, tagfirstHalf);
  1184. setTableStyle(tableNode, tableAttr);
  1185. columnModel = tableNode.getColumnModel();
  1186. tableNode.setColumns(columns);
  1187. var tags = taginfos.split(",");
  1188. for (var i = 0; i < tags.length; i++) {
  1189. var data = new ht.Data();
  1190. data.a('time', "");
  1191. data.a('rowId', (i + 1).toString());
  1192. tableDataModel.add(data);
  1193. }
  1194. return tableNode;
  1195. }
  1196. function initFileSelector() {
  1197. }
  1198. function getIndicators(dmshow, dmhide, str) {
  1199. dmshow.clear();
  1200. dmhide.clear();
  1201. var datas = str.split(',');
  1202. if (datas.length > 0) {
  1203. for (var i = 0; i < datas.length; i++) {
  1204. var strArr = datas[i].split(":");
  1205. if (strArr.length == 3) {
  1206. var json = { "name": strArr[0], "desc": strArr[1] };
  1207. var data = new ht.Data();
  1208. data.a(json);
  1209. if (strArr[2] == "true") {
  1210. dmshow.add(data);
  1211. } else {
  1212. dmhide.add(data);
  1213. }
  1214. }
  1215. }
  1216. }
  1217. }
  1218. function listViewInit(listView) {
  1219. listView.setRowHeight(30);
  1220. listView.setRowLineVisible(true);
  1221. listView.setLabelColor('white');
  1222. listView.setLabelFont('黑体');
  1223. listView.setRowLineColor('#006666');
  1224. listView.setScrollBarColor('#27C5DB');
  1225. listView.getIcon = function (data) {
  1226. return 'productIcon';
  1227. };
  1228. listView.drawRowBackground = function (g, data, selected, x, y, width, height) {
  1229. g.fillStyle = 'rgb(8,44,50)';
  1230. g.beginPath();
  1231. g.rect(x, y, width, height);
  1232. g.fill();
  1233. };
  1234. listView.getLabel = function (data) {
  1235. return data.a('desc');
  1236. };
  1237. }
  1238. //指标设备面板选择框
  1239. /*function createSelectDialog(dmshow,dmnotshow,str,callback){
  1240. var controlDialog = new ht.widget.Dialog();
  1241. var borderPane = new ht.widget.BorderPane();
  1242. var listViewShow = new ht.widget.ListView(dmshow);
  1243. var listViewNotShow = new ht.widget.ListView(dmnotshow);
  1244. listViewInit(listViewShow);
  1245. listViewInit(listViewNotShow);
  1246. listViewShow.onDataDoubleClicked=function(data){
  1247. dmshow.remove(data);
  1248. dmnotshow.add(data);
  1249. };
  1250. listViewNotShow.onDataDoubleClicked=function(data){
  1251. dmnotshow.remove(data);
  1252. dmshow.add(data);
  1253. };
  1254. var formPane = new ht.widget.FormPane();
  1255. formPane.setHeight(40);
  1256. formPane.addRow([
  1257. {
  1258. element: '可见列信息',
  1259. color: 'white'
  1260. },
  1261. {
  1262. button: {
  1263. label: '清除全部',
  1264. labelColor: 'white',
  1265. borderColor:'transparent',
  1266. background: '',
  1267. onClicked: function(){
  1268. var datas=dmshow._datas._as;
  1269. for(var i=0;i<datas.length;i++){
  1270. var data=new ht.Data();
  1271. var json={"name":datas[i].a("name"),"desc":datas[i].a("desc")};
  1272. data.a(json);
  1273. dmnotshow.add(data);
  1274. }
  1275. dmshow.clear();
  1276. }
  1277. }
  1278. },
  1279. {
  1280. element: '隐藏列信息',
  1281. color: 'white'
  1282. },
  1283. {
  1284. button: {
  1285. label: '添加全部',
  1286. labelColor: 'white',
  1287. borderColor:'transparent',
  1288. background: '',
  1289. onClicked: function() {
  1290. var datas=dmnotshow._datas._as;
  1291. for(var i=0;i<datas.length;i++){
  1292. var data=new ht.Data();
  1293. var json={"name":datas[i].a("name"),"desc":datas[i].a("desc")};
  1294. data.a(json);
  1295. dmshow.add(data);
  1296. }
  1297. dmnotshow.clear();
  1298. }
  1299. }
  1300. }
  1301. ],
  1302. [0.01, 0.01,0.01, 0.01],25);
  1303. borderPane.setTopView(formPane);
  1304. borderPane.setLeftView(listViewShow,250-10);
  1305. borderPane.setCenterView(createDiv('#0c4D55'),'',20);
  1306. borderPane.setRightView(listViewNotShow,250-10);
  1307. borderPane.getView().style.backgroundColor="rgb(23,69,75)";
  1308. controlDialog.setConfig({
  1309. title: "选择列",
  1310. titleIcon:'node_image',
  1311. titleAlign: "left",
  1312. titleBackground:'rgb(12,77,85)',
  1313. background:'red',
  1314. closable: true, //关闭是否可用
  1315. draggable: true,
  1316. maximizable: false, //设置不可以被最大化
  1317. width:500,
  1318. height:300,
  1319. position:{x:400,y:100},//对话框的位置
  1320. content:borderPane,
  1321. buttons: [{
  1322. label: "恢复默认",
  1323. action: function(item, e) {
  1324. dmshow.clear();
  1325. dmnotshow.clear();
  1326. getIndicators(dmshow,dmnotshow,str);
  1327. }
  1328. }, {
  1329. label: "确定",
  1330. action: function(item, e) {
  1331. controlDialog.hide();
  1332. callback();
  1333. }
  1334. },{
  1335. label: "取消",
  1336. action:function(item,e){
  1337. getIndicators(dmshow,dmnotshow,str);
  1338. controlDialog.hide();
  1339. }
  1340. }]
  1341. });
  1342. controlDialog.setModal(false);
  1343. controlDialog.show();
  1344. //创建显示按钮,并设置点击事件
  1345. function createDiv(background, text,padding){
  1346. var div = document.createElement('div');
  1347. div.style.position = 'absolute';
  1348. div.style.background = background;
  1349. div.style.paddingLeft=padding;
  1350. div.style.lineHeight = '40px';
  1351. if(text) div.innerHTML = text;
  1352. return div;
  1353. }
  1354. }*/
  1355. function createSelectDialog(dm, controlDialog, callback, paneStyle, limit) {
  1356. if (controlDialog.isShowing()) {
  1357. controlDialog.hide();
  1358. }
  1359. limit = limit || 1000000;
  1360. var borderPane = new ht.widget.BorderPane();
  1361. var _datas = dm.getDatas()._as;
  1362. var datas = [];
  1363. (function () {
  1364. var _data;
  1365. for (var i = 0, len = _datas.length; i < len; i++) {
  1366. _data = _datas[i];
  1367. if (_data.a('isFrozenColumn')) continue;
  1368. datas.push(_data);
  1369. }
  1370. })();
  1371. var datalength = datas.length;
  1372. var formPane = new ht.widget.FormPane();
  1373. var selBtnsFormPane = new ht.widget.FormPane();
  1374. var dialogWidth = 860, dialogHeight = 460, colCount = 4, maxLength = 0;
  1375. var setValue = formPane.setValue,
  1376. getValue = formPane.getValue;
  1377. // formPane.setHeight(360);
  1378. // borderPane.setBackground("red");
  1379. borderPane.getView().style.background = paneStyle.paneBackColor;
  1380. $count = $('<span class="top-count">已选指标(<strong>6</strong>)项</span>');
  1381. $count.setValue = function (value) {
  1382. $count.find('strong').text(value);
  1383. }
  1384. $count.getValue = function () {
  1385. return $count.find('strong').text();
  1386. }
  1387. formPane.setValue = function (id, value) {
  1388. if (id === 'indicatorCount') {
  1389. $count.setValue(value);
  1390. } else {
  1391. setValue.call(formPane, id, value);
  1392. }
  1393. }
  1394. formPane.getValue = function (id) {
  1395. if (id === 'indicatorCount') {
  1396. return $count.getValue();
  1397. } else {
  1398. return getValue.cal(formPane, id);
  1399. }
  1400. }
  1401. formPane.addRow([
  1402. {
  1403. element: $('<span class="top-title">功能列表:</span>')[0]
  1404. },
  1405. {
  1406. id: 'selectall',
  1407. button: {
  1408. label: '全选',
  1409. labelColor: typeof (paneStyle) == "undefined" ? "black" : paneStyle.btnFontColor,
  1410. borderColor: 'transparent',
  1411. labelFont: 'bold 14px "苹方 粗体"',
  1412. background: 'rgba(0,0,0,0)',
  1413. icon: PAGEROOTDIR + 'script/image/noselected.png',
  1414. selectBackground: 'rgba(0,0,0,0)',
  1415. onClicked: function () {
  1416. selectAll(selBtnsFormPane, 'all');
  1417. formPane.getItemById('multiple').element.setIcon(PAGEROOTDIR + 'script/image/noselected.png');
  1418. formPane.getItemById('clear').element.setIcon(PAGEROOTDIR + 'script/image/noselected.png');
  1419. this.setIcon(PAGEROOTDIR + 'script/image/selected.png');
  1420. }
  1421. }
  1422. },
  1423. {
  1424. id: 'multiple',
  1425. button: {
  1426. label: '反选',
  1427. borderColor: 'transparent',
  1428. labelFont: 'bold 14px "苹方 粗体"',
  1429. labelColor: paneStyle.btnFontColor,
  1430. background: 'rgba(0,0,0,0)',
  1431. icon: PAGEROOTDIR + 'script/image/noselected.png',
  1432. selectBackground: 'rgba(0,0,0,0)',
  1433. onClicked: function () {
  1434. reverseSelect(selBtnsFormPane)
  1435. formPane.getItemById('selectall').element.setIcon(PAGEROOTDIR + 'script/image/noselected.png');
  1436. formPane.getItemById('clear').element.setIcon(PAGEROOTDIR + 'script/image/noselected.png');
  1437. this.setIcon(PAGEROOTDIR + 'script/image/selected.png');
  1438. }
  1439. }
  1440. }, {
  1441. id: 'clear',
  1442. button: {
  1443. label: '清除',
  1444. labelColor: paneStyle.btnFontColor,
  1445. borderColor: 'transparent',
  1446. labelFont: 'bold 14px "苹方 粗体"',
  1447. background: 'rgba(0,0,0,0)',
  1448. icon: PAGEROOTDIR + 'script/image/noselected.png',
  1449. selectBackground: 'rgba(0,0,0,0)',
  1450. onClicked: function () {
  1451. clearSelect(selBtnsFormPane);
  1452. formPane.getItemById('selectall').element.setIcon(PAGEROOTDIR + 'script/image/noselected.png');
  1453. formPane.getItemById('multiple').element.setIcon(PAGEROOTDIR + 'script/image/noselected.png');
  1454. this.setIcon(PAGEROOTDIR + 'script/image/selected.png');
  1455. }
  1456. }
  1457. },null,
  1458. {
  1459. element: $count[0]
  1460. }
  1461. ],[0.1, 0.1, 0.1, 0.1, 0.4, 0.2], 20, { index: 1 });
  1462. for (var i = 0, len = datas.length; i < len; i++) {
  1463. var l = datas[i].a('displayName') && GD.getStrLength(datas[i].a('displayName'));
  1464. maxLength = l > maxLength ? l : maxLength;
  1465. }
  1466. var initCount = 0, colCount = Math.floor(dialogWidth / (maxLength * 5 + 50));
  1467. var rowscount = Math.ceil(datas.length / colCount);
  1468. for (var m = 0; m < rowscount; m++) {
  1469. var buttonList = [];
  1470. var buttonWidthPercents = [];
  1471. for (var j = m * colCount; j < (m + 1) * colCount; j++) {
  1472. if (j < datas.length) {
  1473. buttonList.push({ id: datas[j].a("name"), element: createButton(datas[j].a("displayName"), datas[j].a("visible"), formPane, paneStyle, limit) });
  1474. if (datas[j].a("visible")) {
  1475. initCount = initCount + 1;
  1476. }
  1477. buttonWidthPercents.push(0.1);
  1478. } else {
  1479. buttonList.push(null);
  1480. buttonWidthPercents.push(0.1);
  1481. }
  1482. }
  1483. selBtnsFormPane.addRow(buttonList, buttonWidthPercents, 30, { index: m + 2 });
  1484. $count.setValue(initCount);
  1485. }
  1486. borderPane.setTopView(formPane, 50);
  1487. borderPane.setCenterView(selBtnsFormPane);
  1488. borderPane.setBottomView($('<div"></div>')[0], 9)
  1489. controlDialog.setConfig({
  1490. title: "设置名称",
  1491. titleBackground: paneStyle.paneTitleBackColor,
  1492. titleIcon: '',
  1493. titleColor: paneStyle.paneTitleFontColor,
  1494. //background:'red',
  1495. closable: true, //关闭是否可用
  1496. draggable: true,
  1497. maximizable: false, //设置不可以被最大化
  1498. width: dialogWidth,
  1499. height: dialogHeight,
  1500. // position: { x: 200, y: 100 },//对话框的位置
  1501. content: borderPane,
  1502. buttonsAlign: "left",
  1503. buttons: [
  1504. {
  1505. label: "确认",
  1506. className: 'dialog-confirm',
  1507. action: function (item, e) {
  1508. for (var i = 0; i < datalength; i++) {
  1509. var nameId = datas[i].a("name");
  1510. if (selBtnsFormPane.getItemById(nameId)["element"].isSelected()) {
  1511. datas[i].a("visible", true);
  1512. } else {
  1513. datas[i].a("visible", false);
  1514. }
  1515. }
  1516. var rows = selBtnsFormPane._rows,
  1517. items, element, row, item;
  1518. for (var i = 0, len = rows.length; i < len; i++) {
  1519. row = rows[i];
  1520. items = row.items || [];
  1521. for (var j = 0, l = items.length; j < l; j++) {
  1522. }
  1523. }
  1524. controlDialog.hide();
  1525. callback();
  1526. }
  1527. }, {
  1528. label: "取消",
  1529. width: 50,
  1530. height: 30,
  1531. className: 'dialog-cancel',
  1532. action: function (item, e) {
  1533. controlDialog.hide();
  1534. }
  1535. }]
  1536. });
  1537. function setStyle () {
  1538. var $topview = $(formPane.getView()),
  1539. $selBtnsPaneView = $(selBtnsFormPane.getView()),
  1540. $dialogView = $(controlDialog.getView()),
  1541. $borderPaneView = $(borderPane.getView());
  1542. $dialogView.find('.dialog-container').css({
  1543. padding: 0,
  1544. border: '1px solid rgb(31,90,150)',
  1545. borderRadius: 4,
  1546. padding: '5px 20px'
  1547. }).find('.dialog-content').css({
  1548. overflow: 'visible'
  1549. })
  1550. $topview.css({
  1551. border: '1px solid rgb(31,90,150)',
  1552. boxShadow: '0 2px 6px rgb(1,8,24)',
  1553. borderRadius: 4,
  1554. overflow: 'visible',
  1555. backgroundColor: 'rgb(7,45,118)',
  1556. minWidth: 860,
  1557. marginLeft: -22,
  1558. marginTop: 10,
  1559. maxHeight: 40
  1560. }).addClass('pane-topview').find('div').css({
  1561. cursor: 'pointer'
  1562. }).end().parent().css({
  1563. overflow: 'visible'
  1564. }).find('.top-title').css({
  1565. fontFamily: '苹方 粗体',
  1566. fontSize: 14,
  1567. color: 'rgb(18,203,249)',
  1568. fontWeight: 600,
  1569. lineHeight: '25px',
  1570. textAlign: 'center'
  1571. })
  1572. $count.css({
  1573. fontFamily: '苹方 粗体',
  1574. fontSize: 14,
  1575. color: 'rgb(18,203,249)',
  1576. fontWeight: 600,
  1577. lineHeight: '25px',
  1578. paddingLeft: 30
  1579. })
  1580. $borderPaneView.css({
  1581. // backgroundColor: 'rgb(5,32,87)'
  1582. })
  1583. $selBtnsPaneView.css({
  1584. backgroundColor: 'rgb(5,32,87)',
  1585. boxShadow: '0 0 8px rgb(4,4,4) inset',
  1586. borderRadius: 2,
  1587. height: 310
  1588. }).addClass('pane-container');
  1589. $dialogView.find('.dialog-container-buttons').css({
  1590. backgroundColor: paneStyle.paneBackColor,
  1591. textAlign: 'right'
  1592. }).find('.dialog-button').css({
  1593. backgroundColor: paneStyle.btnBackColor,
  1594. width: 100,
  1595. height: 30,
  1596. marginRight: 20,
  1597. marginBottom: 2,
  1598. position: 'relative',
  1599. cursor: 'pointer',
  1600. color: 'rgb(255,255,255)',
  1601. borderRadius: 2,
  1602. boxShadow: '1px 1px 4px #000',
  1603. fontFamily: '苹方 粗体',
  1604. fontWeight: 600,
  1605. fontSize: 14,
  1606. }).hover(function () {
  1607. $(this).css({
  1608. color: 'rgb(255,255,255)',
  1609. boxShadow: '0 0 8px rgb(66,160,194)'
  1610. })
  1611. }, function () {
  1612. $(this).css({
  1613. color: 'rgb(255,255,255)',
  1614. boxShadow: '1px 1px 4px #000',
  1615. })
  1616. }).end().find('.dialog-confirm').css({
  1617. }).prepend('<span style="position: absolute; line-height: 30px; width: 100px; text-align: center;">确认</span>').end().find('.dialog-cancel').css({
  1618. }).prepend('<span style="position: absolute; line-height: 30px; width: 100px; text-align: center;">取消</span>').end().find('canvas').css({
  1619. visibility: 'hidden'
  1620. })
  1621. }
  1622. setStyle();
  1623. controlDialog.setModal(true);
  1624. $(controlDialog.getView()).find('.dialog-overlay').css({
  1625. backgroundColor: 'rgba(20,20,20,0.6)'
  1626. })
  1627. controlDialog.show();
  1628. function selectAll(formPane, opt) {
  1629. var rows = formPane._rows || [];
  1630. var row, items, item, element, button, isSelected;
  1631. for (var i = 0, len = rows.length; i < len; i++) {
  1632. row = rows[i] || {};
  1633. items = row.items || [];
  1634. for (var j = 0, l = items.length; j < l; j++) {
  1635. item = items[j];
  1636. if (!item) continue;
  1637. element = item.element || {};
  1638. switch(opt) {
  1639. case 'all':
  1640. if (!element.isSelected()) {
  1641. element.setSelected(true);
  1642. element.onClicked && element.onClicked();
  1643. }
  1644. break;
  1645. case 'clear':
  1646. if (element.isSelected()) {
  1647. element.setSelected(false);
  1648. element.onClicked && element.onClicked();
  1649. }
  1650. break;
  1651. case 'reverse':
  1652. isSelected = !element.isSelected();
  1653. element.setSelected(isSelected);
  1654. element.onClicked && element.onClicked();
  1655. break;
  1656. }
  1657. }
  1658. }
  1659. }
  1660. function reverseSelect (formPane) {
  1661. selectAll(formPane, 'reverse');
  1662. }
  1663. function clearSelect(formPane) {
  1664. selectAll(formPane, 'clear');
  1665. }
  1666. }
  1667. function createHistorySelectDialog(deviceDM, indicatorDM, tagDM, controlDialog, selectedLimit, callback, hideExportButton, paneStyleParams) {
  1668. if (controlDialog.isShowing()) {
  1669. controlDialog.hide();
  1670. }
  1671. paneStyleParams = paneStyleParams || {}
  1672. var paneStyle = {
  1673. paneBackColor: 'rgb(7,42,114)',
  1674. paneTitleBackColor: 'rgb(7,42,114)',
  1675. paneTitleFontColor: 'rgb(195,208,241)',
  1676. paneTitleBtnFontColor: 'rgb(156,163,172)',
  1677. paneTitleBtnCheckedFontColor: 'rgb(7,164,234)',
  1678. btnBackColor: 'rgb(7,42,114)',
  1679. btnFontColor: 'rgb(255,255,255)',
  1680. btnBorderColor: 'rgba(0,0,0,0)',
  1681. btnCheckedFontColor: 'rgb(255,255,255)',
  1682. btnCheckedBackColor: 'rgb(18,172,221)',
  1683. tagBtnBackColor: 'rgba(0,0,0,0)',
  1684. tagBtnBorderColor: 'rgba(0,0,0,0)',
  1685. tagBtnFontColor: 'rgb(168,193,219)',
  1686. paneBorderColor: 'rgb(4,94,137)',
  1687. paneTopBarBackColor: 'rgb(7,42,114)',
  1688. paneTopBarBorderColor: 'rgb(4,94,137)',
  1689. paneShadowColor: 'rgb(1,13,33)',
  1690. formPaneBackColor: 'rgb(4,33,89)',
  1691. bottomButtonColor: 'rgb(255,255,255)',
  1692. bottomButtonHoverColor: 'white',
  1693. bottomButtonBackColor: 'rgb(7,41,107)',
  1694. bottomButtonHoverShadowColor: 'rgb(36,128,172)',
  1695. scrollBarColor: 'rgb(18,75,147)'
  1696. }
  1697. // $.extend(paneStyle, paneStyleParams);
  1698. var paneBackColor = paneStyle.paneBackColor;
  1699. var btnBackColor = paneStyle.btnBackColor;
  1700. var btnFontColor = paneStyle.btnFontColor;
  1701. selectedLimit = selectedLimit <= 0 ? 20 : selectedLimit;
  1702. var borderPane = new ht.widget.BorderPane();
  1703. borderPane.getView().style.background = paneBackColor;
  1704. var datas = deviceDM.getDatas()._as;
  1705. var indicatorDatas = indicatorDM.getDatas()._as;
  1706. var deviceArr = [];
  1707. var indicatorArr = [];
  1708. var tagArr = [];
  1709. var buttonMap = {};
  1710. function DMToArr(DM, arr) {
  1711. DM.each(function (data) {
  1712. if (data.a('name') != 'time' && data.a('name') != 'device') {
  1713. var d = {};
  1714. d.name = data.a('name');
  1715. d.displayName = data.a('displayName');
  1716. d.visible = data.a('visible');
  1717. d.Low = data.a('Low');
  1718. d.High = data.a('High');
  1719. d.width = data.a('width');
  1720. d.color = data.a('color');
  1721. data.a('position') && (d.position = data.a('position'));
  1722. arr.push(d);
  1723. }
  1724. });
  1725. }
  1726. DMToArr(deviceDM, deviceArr);
  1727. DMToArr(indicatorDM, indicatorArr);
  1728. DMToArr(tagDM, tagArr);
  1729. var datalength = datas.length;
  1730. var formPane = new ht.widget.FormPane();
  1731. var leftPane = new ht.widget.FormPane();
  1732. var rightPane = new ht.widget.FormPane();
  1733. var bottomPane = new ht.widget.FormPane();
  1734. var innerBorderPane = new ht.widget.BorderPane();
  1735. var innerTopBorderPane = new ht.widget.BorderPane();
  1736. // var innerTopFormPane = new ht.widget.FormPane();
  1737. var initCount = 0;
  1738. var rowscount = Math.ceil(datas.length / 4);
  1739. leftPane.setAutoHideScrollBar(false);
  1740. rightPane.setAutoHideScrollBar(false);
  1741. bottomPane.setAutoHideScrollBar(false);
  1742. leftPane.setScrollBarColor(paneStyle.scrollBarColor);
  1743. rightPane.setScrollBarColor(paneStyle.scrollBarColor);
  1744. bottomPane.setScrollBarColor(paneStyle.scrollBarColor);
  1745. var buttonIconMap = {
  1746. 'tagButton': 'sub.png',
  1747. 'deviceButton': 'DuiHao.png',
  1748. 'indicatorButton': 'plus.png',
  1749. }
  1750. function addButtonsToForm(form, datas, columnsCount, buttonType, cb) {
  1751. var maxLength = 0, formWidth = $(form.getView()).width(), l;
  1752. for (var i = 0, len = datas.length; i < len; i++) {
  1753. l = datas[i].displayName && GD.getStrLength(datas[i].displayName);
  1754. maxLength = l > maxLength ? l : maxLength;
  1755. }
  1756. columnsCount = Math.floor(formWidth / (maxLength * 5 + 50));
  1757. var rowsCount = Math.ceil(datas.length / columnsCount);
  1758. form.clear();
  1759. for (var i = 0; i < rowsCount; i++) {
  1760. var buttonList = [];
  1761. var buttonWidthList = [],
  1762. btn;
  1763. for (var j = i * columnsCount; j < ((i + 1) * columnsCount); j++) {
  1764. if (datas[j]) {
  1765. datas[j].buttonType = buttonType;
  1766. btn = createHistoryButton(datas[j], buttonType, cb);
  1767. buttonList.push(btn);
  1768. buttonWidthList.push(0.1);
  1769. } else {
  1770. buttonList.push(null);
  1771. buttonWidthList.push(0.1);
  1772. }
  1773. }
  1774. form.addRow(buttonList, buttonWidthList, 30);
  1775. }
  1776. }
  1777. function mergeToTagArr(obj, iArr, tArr) {
  1778. tArr = tArr || tagArr;
  1779. var tempArr = [];
  1780. if (!obj) {
  1781. return [];
  1782. }
  1783. for (var j = 0, leng = iArr.length; j < leng; j++) {
  1784. var ia = iArr[j];
  1785. if (!ia.isSelected) {
  1786. continue;
  1787. }
  1788. var t = {};
  1789. t.name = obj.type === 'device' ? obj.name + ia.name : ia.name + obj.name;
  1790. t.isSelected = true;
  1791. t.displayName = obj.type === 'device' ? obj.displayName + ' ' + ia.displayName : ia.displayName + ' ' + obj.displayName;
  1792. t.visible = true;
  1793. t.deviceName = obj.type === 'device' ? obj.name : ia.name;
  1794. t.indicatorName = obj.type === 'device' ? ia.name : obj.name;
  1795. t.Low = obj.type === 'device' ? ia.Low : obj.Low;
  1796. t.High = obj.type === 'device' ? ia.High : obj.High;
  1797. t.width = obj.type === 'device' ? ia.width : obj.width;
  1798. t.color = ia.color || obj.color;
  1799. t.position = ia.position || obj.position;
  1800. ia.inArr = ia.inArr || [];
  1801. if (obj.isSelected) {
  1802. ia.inArr.push(obj);
  1803. tArr.push(t);
  1804. } else {
  1805. deleteItemFromArray(ia.inArr, obj);
  1806. deleteItemFromArray(tArr, t);
  1807. }
  1808. }
  1809. deleteRepetition(tArr);
  1810. $rightPaneTitle.find('strong').text(tArr.length);
  1811. }
  1812. function tagButtonClicked() {
  1813. var isSelected = this.isSelected();
  1814. var label = $.trim(this.getLabel());
  1815. var tagObj, indicatorObj;
  1816. for (var i = 0, len = tagArr.length; i < len; i++) {
  1817. if (tagArr[i].displayName === label) {
  1818. tagObj = tagArr[i];
  1819. tagArr.splice(i, 1);
  1820. break;
  1821. }
  1822. }
  1823. for (var j = 0, leng = indicatorArr.length; j < leng; j++) {
  1824. if (indicatorArr[j].name === tagObj.indicatorName) {
  1825. indicatorArr[j].isSelected = false;
  1826. indicatorObj = indicatorArr[j];
  1827. break;
  1828. }
  1829. }
  1830. for (var k = 0, lengt = deviceArr.length; k < lengt; k++) {
  1831. if (deviceArr[k].name === tagObj.deviceName) {
  1832. if (deviceArr[k].inArr && deviceArr[k].inArr.length > 0) {
  1833. deleteItemFromArray(deviceArr[k].inArr, indicatorObj);
  1834. }
  1835. }
  1836. }
  1837. refreshButtonFrom(leftPane, deviceArr);
  1838. refreshButtonFrom(rightPane, indicatorArr);
  1839. addButtonsToForm(bottomPane, tagArr, 8, 'tagButton', tagButtonClicked);
  1840. $rightPaneTitle.find('strong').text(tagArr.length);
  1841. }
  1842. function createHistoryButton(data, buttonType, buttonOnClickedCB) {
  1843. var button = new ht.widget.Button(),
  1844. $buttonView = $(button.getView());
  1845. var lable = data.displayName,
  1846. show = data.visible,
  1847. id = data.name;
  1848. button.setLabel(lable);
  1849. button.setTogglable(true);
  1850. button.setWidth(100);
  1851. button.setHeight(40);
  1852. $buttonView.addClass('history-button');
  1853. $buttonView.prepend('<div class="button-icon"></div>')
  1854. button.__id = id;
  1855. var labelColor,
  1856. backColor,
  1857. checkedBackColor,
  1858. broderColor,
  1859. icon;
  1860. switch (buttonType) {
  1861. case 'tagButton':
  1862. backColor = paneStyle.tagBtnBackColor;
  1863. checkedBackColor = paneStyle.tagBtnBackColor;
  1864. broderColor = paneStyle.tagBtnBorderColor;
  1865. // icon = buttonIconMap['tagButton'];
  1866. icon = null;
  1867. button.setSelected(true);
  1868. button.setLabelSelectColor(paneStyle.tagBtnFontColor);
  1869. button.setClickable(false);
  1870. break;
  1871. case 'deviceButton':
  1872. backColor = paneStyle.btnBackColor;
  1873. checkedBackColor = paneStyle.btnCheckedBackColor;
  1874. broderColor = paneStyle.btnBorderColor;
  1875. // icon = buttonIconMap['deviceButton'];
  1876. icon = null;
  1877. break;
  1878. case 'indicatorButton':
  1879. backColor = paneStyle.btnBackColor;
  1880. checkedBackColor = paneStyle.btnCheckedBackColor;
  1881. broderColor = paneStyle.btnBorderColor;
  1882. icon = buttonIconMap['indicatorButton'];
  1883. break;
  1884. }
  1885. if (show) {
  1886. button.setSelected(true);
  1887. button.setSelectBackground(checkedBackColor);
  1888. button.setLabelSelectColor(paneStyle.btnCheckedFontColor);
  1889. button.setBorderColor(broderColor);
  1890. if (icon) {
  1891. button.setIcon(imagePath + icon);
  1892. button.setLabel(" " + lable);
  1893. } else {
  1894. button.setIcon(null);
  1895. button.setLabel(lable);
  1896. }
  1897. } else {
  1898. button.setSelected(false);
  1899. button.setIcon(null);
  1900. button.setLabel(lable);
  1901. button.setBackground(backColor);
  1902. button.setLabelColor(paneStyle.btnFontColor);
  1903. button.setBorderColor(broderColor);
  1904. }
  1905. button.onClicked = function (e) {
  1906. buttonOnClickedCB.call(this, e);
  1907. };
  1908. if (buttonType === 'tagButton') {
  1909. button.setLabel(lable + " ");
  1910. $(button.getView()).find('.button-icon').off('click').on('click', function (e) {
  1911. buttonOnClickedCB.call(button, e);
  1912. })
  1913. }
  1914. buttonMap[id] = button;
  1915. return button;
  1916. }
  1917. function deleteRepetition(arr) {
  1918. if (!arr) {
  1919. return;
  1920. }
  1921. var temp = {}, a;
  1922. var result = [];
  1923. for (var i = 0, len = arr.length; i < len; i++) {
  1924. a = arr[i];
  1925. if (temp[a.displayName]) {
  1926. } else {
  1927. temp[a.displayName] = true;
  1928. result.push(a);
  1929. }
  1930. }
  1931. arr.length = 0;
  1932. for (i = 0, len = result.length; i < len; i++) {
  1933. arr[i] = result[i];
  1934. }
  1935. return result;
  1936. }
  1937. function deleteItemFromArray(arr, item) {
  1938. var tempArr = [], a;
  1939. for (var i = 0, len = arr.length; i < len; i++) {
  1940. a = arr[i];
  1941. if ($.trim(a.displayName) != $.trim(item.displayName)) {
  1942. tempArr.push(a);
  1943. }
  1944. }
  1945. arr.length = 0;
  1946. for (i = 0, len = tempArr.length; i < len; i++) {
  1947. arr[i] = tempArr[i];
  1948. }
  1949. }
  1950. function refreshButtonFrom(pane, dataArr) {
  1951. var isSelected, icon, btn, btnType;
  1952. for (var i = 0, len = dataArr.length; i < len; i++) {
  1953. btn = buttonMap[(dataArr[i].name)];
  1954. if (!btn) continue;
  1955. btnType = dataArr[i].buttonType;
  1956. if (dataArr[i].isSelected) {
  1957. isSelected = true;
  1958. icon = imagePath + buttonIconMap[btnType];
  1959. if (btnType === 'deviceButton') {
  1960. icon = null;
  1961. }
  1962. } else {
  1963. isSelected = false;
  1964. icon = null;
  1965. }
  1966. btn.setSelected(isSelected);
  1967. btn.setIcon(icon);
  1968. }
  1969. }
  1970. function clearButtonForm(pane, dataArr) {
  1971. var btn;
  1972. for (var i = 0, len = dataArr.length; i < len; i++) {
  1973. btn = buttonMap[(dataArr[i].name)];
  1974. if (btn) {
  1975. btn.setSelected(false);
  1976. btn.setIcon(null);
  1977. }
  1978. }
  1979. }
  1980. function exportTagsToCSV(e) {
  1981. if (tagArr.length <= 0) {
  1982. return alert('请先选择测点指标!');
  1983. }
  1984. var result = '';
  1985. var tempArr, tag, titleArr = [];
  1986. for (var i = 0, len = tagArr.length; i < len; i++) {
  1987. tag = tagArr[i];
  1988. tempArr = [];
  1989. for (var key in tag) {
  1990. if (tag.hasOwnProperty(key)) {
  1991. tempArr.push(tag[key]);
  1992. if (i === 0) {
  1993. titleArr.push(key);
  1994. }
  1995. }
  1996. }
  1997. result += tempArr.join(',') + '\r\n';
  1998. }
  1999. result = '\uFEFF' + titleArr.join(',') + '\r\n' + result;
  2000. // var encodeResult = new TextEncoder('windows-1252').encode(result);
  2001. var blob = new Blob([result], { type: 'text/csv;charset=UTF-8' });//
  2002. saveAs(blob, 'data' + Date.now() + '.csv');
  2003. }
  2004. function importTagsFromCSV(e) {
  2005. var $fileInput = $('<input type="file" accept=".csv" id="fileInput">');
  2006. $(window.body).append($fileInput);
  2007. $fileInput.trigger('click');
  2008. $fileInput.change(function (e) {
  2009. var files = e.target.files;
  2010. for (var i = 0, len = files.length; i < len; i++) {
  2011. var file = files[i];
  2012. if (!(file && file.type.match('application/vnd.ms-excel'))) {
  2013. alert('不支持的文件格式!');
  2014. continue;
  2015. }
  2016. var reader = new FileReader();
  2017. reader.onload = function (evt) {
  2018. // var resultStr = e.target && e.target.result;
  2019. var data = evt.target.result;
  2020. var encoding = checkEncoding(data);
  2021. //转换成二维数组,需要引入Papaparse.js
  2022. Papa.parse(file, {
  2023. encoding: encoding,
  2024. complete: function (results) { // UTF8 \r\n与\n混用时有可能会出问题
  2025. var res = results.data;
  2026. if (res[res.length - 1] == "") { //去除最后的空行
  2027. res.pop();
  2028. }
  2029. addTagToTagArr(res);
  2030. }
  2031. });
  2032. };
  2033. reader.readAsDataURL(file);
  2034. }
  2035. });
  2036. }
  2037. function checkEncoding(base64Str) {
  2038. //这种方式得到的是一种二进制串
  2039. var str = atob(base64Str.split(";base64,")[1]);
  2040. //要用二进制格式
  2041. var encoding = jschardet.detect(str);
  2042. encoding = encoding.encoding;
  2043. if (encoding == "windows-1252") { //有时会识别错误(如UTF8的中文二字)
  2044. encoding = "ANSI";
  2045. }
  2046. return encoding;
  2047. }
  2048. function addTagToTagArr(resultArr) {
  2049. try {
  2050. tagArr = [];
  2051. var titleArr = resultArr[0];
  2052. for (var i = 1, len = resultArr.length; i < len; i++) {
  2053. var tagObj = {};
  2054. if (!resultArr[i]) {
  2055. continue;
  2056. }
  2057. var tempArr = resultArr[i];
  2058. for (var j = 0, leng = tempArr.length; j < leng; j++) {
  2059. var temp = tempArr[j];
  2060. if (temp.toLowerCase() === 'true') {
  2061. temp = true;
  2062. } else if (temp.toLowerCase() === 'false') {
  2063. temp = false;
  2064. }
  2065. tagObj[$.trim(titleArr[j])] = temp;
  2066. }
  2067. if (tagObj.isSelected)
  2068. tagArr.push(tagObj);
  2069. }
  2070. deleteRepetition(tagArr);
  2071. addButtonsToForm(bottomPane, tagArr, 8, 'tagButton', tagButtonClicked);
  2072. } catch (error) {
  2073. alert('导入的文件格式错误,请重新编辑后导入!');
  2074. console.log(error);
  2075. }
  2076. }
  2077. function confirmAndSearch() {
  2078. tagDM.clear();
  2079. for (var i = 0, len = tagArr.length; i < len; i++) {
  2080. var dt = new ht.Data();
  2081. var ta = tagArr[i];
  2082. dt.a('displayName', ta.displayName);
  2083. dt.a('name', ta.name);
  2084. dt.a('visible', ta.visible);
  2085. dt.a('Low', ta.Low);
  2086. dt.a('High', ta.High);
  2087. dt.a('width', ta.width);
  2088. dt.a('position', ta.position);
  2089. dt.a('color', ta.color);
  2090. dt.setName(ta.name);
  2091. dt.setDisplayName(ta.displayName);
  2092. dt.setTag(ta.name);
  2093. tagDM.add(dt);
  2094. }
  2095. controlDialog.hide();
  2096. // var device, indicator, name, data;
  2097. // for (var i = 0, len = deviceArr.length; i < len; i++) {
  2098. // device = deviceArr[i];
  2099. // if (device) {
  2100. // name = device.name;
  2101. // data = deviceDM.getDataByTag(name);
  2102. // data.a('visible', !!device.isSelected);
  2103. // }
  2104. // }
  2105. // for (var j = 0, len = indicatorArr.length; j < len; j++) {
  2106. // indicator = indicatorArr[j];
  2107. // if (indicator) {
  2108. // name = indicator.name;
  2109. // data = indicatorDM.getDataByTag(name);
  2110. // data.a('visible', !!indicator.isSelected);
  2111. // }
  2112. // }
  2113. callback('search');
  2114. }
  2115. function confirmAndExport() {
  2116. tagDM.clear();
  2117. for (var i = 0, len = tagArr.length; i < len; i++) {
  2118. var dt = new ht.Data();
  2119. var ta = tagArr[i];
  2120. dt.a('displayName', ta.displayName);
  2121. dt.a('name', ta.name);
  2122. dt.a('visible', ta.visible);
  2123. dt.setName(ta.name);
  2124. dt.setDisplayName(ta.displayName);
  2125. dt.setTag(ta.name);
  2126. tagDM.add(dt);
  2127. }
  2128. controlDialog.hide();
  2129. callback('export');
  2130. }
  2131. function cancel () {
  2132. controlDialog.hide();
  2133. }
  2134. function addButtonsToDialogBottom(dialog) {
  2135. var $bottomContainer = $(dialog.getView()).find('.dialog-container-buttons'),
  2136. $searchBtn = $('<div data-role="confirmandsearch" class="pull-left pane-bottom-btn-right"><a class="btn btn-defuault">确认并查询</a></div>'),
  2137. $exportBtn = $('<div data-role="confirmandexport" class="pull-left pane-bottom-btn-right"><a class="btn btn-defuault">确认并导出</a></div>'),
  2138. $cancelBtn = $('<div data-role="cancel" class="pull-left pane-bottom-btn-right"><a class="btn btn-defuault">取消</a></div>'),
  2139. $uploadBtn = $('<div data-role="upload" class="pull-left cursor-pointer pane-bottom-btn-left"><a>上传</a></div>'),
  2140. $downloadBtn = $('<div data-role="download" class="pull-left cursor-pointer pane-bottom-btn-left"><a>下载</a></div>'),
  2141. $clearBtn = $('<div data-role="clearall" class="pull-left cursor-pointer pane-bottom-btn-left"><a>清空</a></div>'),
  2142. $rightContainer = $('<div class="pull-right pane-bottom-container-right"></div>'),
  2143. $leftContainer = $('<div class="pull-left pane-bottom-container-left"></div>');
  2144. $bottomContainer.find('.dialog-button').remove();
  2145. $rightContainer.append($searchBtn).append($exportBtn).append($cancelBtn);
  2146. $leftContainer.append($uploadBtn).append($downloadBtn).append($clearBtn);
  2147. $bottomContainer.append($rightContainer).append($leftContainer);
  2148. if (hideExportButton) {
  2149. $searchBtn.find('a.btn').text('确认');
  2150. $exportBtn.css('display', 'none');
  2151. $uploadBtn.css('display', 'none');
  2152. $downloadBtn.css('display', 'none');
  2153. }
  2154. $bottomContainer.find('.pane-bottom-btn-right').css({
  2155. backgroundColor: paneStyle.bottomButtonBackColor,
  2156. }).hover(function () {
  2157. $(this).css({
  2158. }).find('a').css({
  2159. color: paneStyle.bottomButtonHoverColor
  2160. })
  2161. }, function() {
  2162. $(this).css({
  2163. }).find('a').css({
  2164. color: paneStyle.bottomButtonColor
  2165. })
  2166. }).find('a').css({
  2167. color: paneStyle.bottomButtonColor,
  2168. });
  2169. $bottomContainer.find('.pane-bottom-btn-left').css({
  2170. }).hover(function() {
  2171. $(this).css({
  2172. }).find('a').css({
  2173. color: paneStyle.bottomButtonHoverColor
  2174. })
  2175. }, function () {
  2176. $(this).css({
  2177. }).find('a').css({
  2178. color: paneStyle.bottomButtonColor
  2179. })
  2180. }).find('a').css({
  2181. color: paneStyle.bottomButtonColor,
  2182. });
  2183. $bottomContainer.find('div div.pull-left').off('click').on('click', function (e) {
  2184. var $this = $(this),
  2185. role = $this.data('role');
  2186. switch (role) {
  2187. case 'confirmandsearch':
  2188. confirmAndSearch();
  2189. break;
  2190. case 'confirmandexport':
  2191. confirmAndExport();
  2192. break;
  2193. case 'cancel':
  2194. cancel(e);
  2195. break;
  2196. case 'upload':
  2197. importTagsFromCSV(e);
  2198. break;
  2199. case 'download':
  2200. exportTagsToCSV(e);
  2201. break;
  2202. case 'clearall':
  2203. clearAllBtn(bottomPane);
  2204. break;
  2205. }
  2206. });
  2207. }
  2208. function selectAllBtn (formpane, opt) {
  2209. var rows = formpane._rows, row, items, item, element, selected;
  2210. for (var i = 0, len = rows.length; i < len; i++) {
  2211. row = rows[i];
  2212. if (row.items) {
  2213. items = row.items;
  2214. for (var j = 0, l = items.length; j < l; j++) {
  2215. item = items[j];
  2216. element = item && item.element;
  2217. if (element && typeof element.onClicked === 'function') {
  2218. // element._selected = !selected;
  2219. // element.onClicked();
  2220. switch(opt) {
  2221. case 'all':
  2222. if (element._selected === false) {
  2223. element._selected = true;
  2224. element.onClicked();
  2225. }
  2226. break;
  2227. case 'reverse':
  2228. element._selected = !element._selected;
  2229. element.onClicked();
  2230. break;
  2231. case 'clear':
  2232. if (element._selected === true) {
  2233. element._selected = false;
  2234. element.onClicked();
  2235. }
  2236. break;
  2237. }
  2238. }
  2239. }
  2240. }
  2241. }
  2242. }
  2243. function clearAllBtn (formpane) {
  2244. selectAllBtn(formpane, 'clear');
  2245. }
  2246. function multipleSelectBtn (formpane) {
  2247. }
  2248. function reverseSelectBtn(formpane) {
  2249. selectAllBtn(formpane, 'reverse');
  2250. }
  2251. var indicatorRowCount = Math.ceil(indicatorDatas.length / 4);
  2252. bottomPane.getView().className = "bottom-pane";
  2253. leftPane.setWidth(400);
  2254. rightPane.setWidth(400);
  2255. bottomPane.setWidth(840);
  2256. var $paneTitleContainer = $('<div class="pane-title-container"></div>'),
  2257. $leftPaneTitle = $('<div class="pane-title pane-title-left" ></div>'),
  2258. $rightPaneTitle = $('<div class="pane-title pane-title-right noselect"><span class="pull-left">功能列表:</span><ul class="pull-left"><li data-role="selectall"><a>全选</a></li><li data-role="reverseselect"><a>反选</a></li><li data-role="clearall"><a>清除</a></li></ul><div class="pull-right">已选指标( <strong>0</strong> )项</div></div>');
  2259. $leftPaneTitle.css({
  2260. 'box-shadow': '0 2px 10px ' + paneStyle.paneShadowColor
  2261. })
  2262. $rightPaneTitle.css({
  2263. 'box-shadow': '0 2px 10px ' + paneStyle.paneShadowColor
  2264. }).find('li').off('click').on('click', function () {
  2265. var $this = $(this),
  2266. role = $this.data('role');
  2267. $rightPaneTitle.find('li').removeClass('active').find('a').css({color: paneStyle.paneTitleBtnFontColor});
  2268. $this.addClass('active').find('a').css({
  2269. color: paneStyle.paneTitleBtnCheckedFontColor
  2270. });
  2271. switch(role) {
  2272. case 'selectall':
  2273. selectAllBtn(rightPane, 'all');
  2274. break;
  2275. case 'reverseselect':
  2276. reverseSelectBtn(rightPane);
  2277. break;
  2278. case 'clearall':
  2279. clearAllBtn(rightPane);
  2280. break;
  2281. }
  2282. }).find('a').css({
  2283. color: paneStyle.paneTitleBtnFontColor
  2284. })
  2285. $rightPaneTitle.find('li.active a').css({color: paneStyle.paneTitleBtnCheckedFontColor});
  2286. function setStyle() {
  2287. $(leftPane.getView()).css({
  2288. backgroundColor: paneStyle.formPaneBackColor,
  2289. 'box-shadow': '2px 2px 5px '+ paneStyle.paneShadowColor +' inset'
  2290. }).addClass('pane-left');
  2291. $(rightPane.getView()).css({
  2292. backgroundColor: paneStyle.formPaneBackColor,
  2293. 'box-shadow': '2px 2px 5px '+ paneStyle.paneShadowColor +' inset'
  2294. }).addClass('pane-right');
  2295. $(bottomPane.getView()).css({
  2296. backgroundColor: paneStyle.formPaneBackColor,
  2297. 'box-shadow': '2px 2px 5px '+ paneStyle.paneShadowColor +' inset'
  2298. }).addClass('pane-bottom');
  2299. $(controlDialog.getView()).find('.dialog-container').css({
  2300. borderWidth: '1px',
  2301. borderStyle: 'solid',
  2302. borderColor: paneStyle.paneBorderColor,
  2303. borderRadius: '4px',
  2304. zIndex: 99,
  2305. })
  2306. }
  2307. $paneTitleContainer.append($leftPaneTitle);
  2308. $paneTitleContainer.append($rightPaneTitle);
  2309. innerTopBorderPane.setTopView($paneTitleContainer[0], 35);
  2310. innerTopBorderPane.setLeftView(leftPane, 430);
  2311. innerTopBorderPane.setCenterView(rightPane);
  2312. // innerBorderPane.setTopView(innerTopFormPane, 35);
  2313. innerBorderPane.setCenterView(bottomPane);
  2314. borderPane.setCenterView(innerTopBorderPane);
  2315. borderPane.setBottomView(innerBorderPane, 280);
  2316. var dialogButtons = [
  2317. // {
  2318. // label: "确认并查询",
  2319. // className: 'dialog-button-confirm dialog-button-confirm-and-search',
  2320. // action: function (item, e) {
  2321. // }
  2322. // },
  2323. // {
  2324. // label: "确认并导出",
  2325. // className: 'dialog-button-confirm dialog-button-confirm-and-export',
  2326. // action: function (item, e) {
  2327. // }
  2328. // },
  2329. {
  2330. label: "取消",
  2331. className: 'dialog-button-cancel',
  2332. action: function (item, e) {
  2333. }
  2334. }
  2335. ];
  2336. controlDialog.setConfig({
  2337. title: "设置名称",
  2338. titleBackground: paneStyle.paneTitleBackColor,
  2339. titleIcon: '',
  2340. titleColor: paneStyle.paneTitleFontColor,
  2341. //background:'red',
  2342. closable: true, //关闭是否可用
  2343. draggable: true,
  2344. maximizable: false, //设置不可以被最大化
  2345. width: 860,
  2346. height: 600,
  2347. position: { x: ($(window).innerWidth() - 860) / 2, y: ($(window).innerHeight() - 600) / 2 },//对话框的位置
  2348. content: borderPane,
  2349. buttonsAlign: "left",
  2350. buttons: dialogButtons
  2351. });
  2352. controlDialog.setModal(true);
  2353. $(controlDialog.getView()).find('.dialog-overlay').css({
  2354. backgroundColor: 'rgba(20,20,20,0.6)'
  2355. })
  2356. addButtonsToForm(leftPane, deviceArr, 4, 'deviceButton', function () {
  2357. var label = $.trim(this.getLabel());
  2358. var isSelected = this.isSelected();
  2359. if (isSelected) {
  2360. this.setSelectBackground(paneStyle.btnCheckedBackColor);
  2361. this.setLabelSelectColor(paneStyle.btnCheckedFontColor);
  2362. // this.setIcon(imagePath + "DuiHao.png");
  2363. this.setIcon(null);
  2364. this.setLabel(label);
  2365. } else {
  2366. this.setBackground(paneStyle.btnBackColor);
  2367. this.setIcon(null);
  2368. this.setLabel(label);
  2369. this.setLabelColor(paneStyle.btnFontColor);
  2370. }
  2371. var deviceObj;
  2372. for (var i = 0, len = deviceArr.length; i < len; i++) {
  2373. if (deviceArr[i].displayName === label) {
  2374. deviceArr[i].isSelected = isSelected;
  2375. deviceObj = deviceArr[i];
  2376. } else {
  2377. deviceArr[i].isSelected = false;
  2378. }
  2379. }
  2380. for (var j = 0, leng = indicatorArr.length; j < leng; j++) {
  2381. indicatorArr[j].isSelected = false;
  2382. if (deviceObj.inArr) {
  2383. for (var k = 0, lengt = deviceObj.inArr.length; k < lengt; k++) {
  2384. if (deviceObj.inArr[k].name === indicatorArr[j].name) {
  2385. indicatorArr[j].isSelected = true;
  2386. }
  2387. }
  2388. } else {
  2389. indicatorArr[j].isSelected = false;
  2390. }
  2391. }
  2392. deviceObj.type = 'device';
  2393. clearButtonForm(rightPane, indicatorArr);
  2394. refreshButtonFrom(leftPane, deviceArr);
  2395. if (!isSelected) {
  2396. deviceObj.inArr && (deviceObj.inArr.length = 0);
  2397. mergeToTagArr(deviceObj, indicatorArr, tagArr);
  2398. addButtonsToForm(bottomPane, tagArr, 8, 'tagButton', tagButtonClicked);
  2399. } else {
  2400. refreshButtonFrom(rightPane, indicatorArr);
  2401. }
  2402. });
  2403. addButtonsToForm(rightPane, indicatorArr, 4, 'indicatorButton', function () {
  2404. var label = $.trim(this.getLabel());
  2405. var isSelected = this.isSelected();
  2406. var self = this;
  2407. // 设置选择个数限制
  2408. if (tagArr.length >= selectedLimit && isSelected) {
  2409. dialogTip('已选择的指标超过' + selectedLimit + '个了,最多选择' + selectedLimit + '个!');
  2410. this.setSelected(false);
  2411. return;
  2412. }
  2413. if (isSelected) {
  2414. this.setSelectBackground(paneStyle.btnCheckedBackColor);
  2415. this.setLabelSelectColor(paneStyle.btnCheckedFontColor);
  2416. this.setIcon(imagePath + "plus.png");
  2417. this.setLabel(" " + label);
  2418. } else {
  2419. this.setBackground(paneStyle.btnBackColor);
  2420. this.setLabelColor(paneStyle.btnFontColor);
  2421. this.setIcon(null);
  2422. this.setLabel(label);
  2423. }
  2424. var indicatorObj = {};
  2425. for (var i = 0, len = indicatorArr.length; i < len; i++) {
  2426. if (indicatorArr[i].displayName === label) {
  2427. indicatorArr[i].isSelected = isSelected;
  2428. indicatorObj = indicatorArr[i];
  2429. break;
  2430. }
  2431. }
  2432. indicatorObj.type = 'indicator';
  2433. mergeToTagArr(indicatorObj, deviceArr, tagArr);
  2434. addButtonsToForm(bottomPane, tagArr, 8, 'tagButton', tagButtonClicked);
  2435. });
  2436. addButtonsToForm(bottomPane, tagArr, 8, 'tagButton', tagButtonClicked);
  2437. addButtonsToDialogBottom(controlDialog);
  2438. setStyle();
  2439. controlDialog.show();
  2440. $('.dialog-container-buttons').css('background', paneStyle.paneBackColor);
  2441. $('.dialog-button-confirm').css('background', paneStyle.btnBackColor);
  2442. //创建显示按钮,并设置点击事件
  2443. }
  2444. //历史趋势指标列表弹窗
  2445. function createchartSelectDialog(dm, controlDialog, selectedLimit, callback) {
  2446. if (controlDialog.isShowing()) {
  2447. controlDialog.hide();
  2448. }
  2449. var borderPane = new ht.widget.BorderPane();
  2450. // var datas=tags;
  2451. var datas = dm.getDatas()._as;
  2452. var datalength = datas.length;
  2453. var formPane = new ht.widget.FormPane();
  2454. formPane.setHeight(360);
  2455. formPane.addRow([
  2456. '已选择个数:',
  2457. {
  2458. id: "indicatorCount",
  2459. textField: {
  2460. text: '0',
  2461. editable: false,
  2462. width: 100,
  2463. border: 0
  2464. }
  2465. },
  2466. "",
  2467. {
  2468. button: {
  2469. label: '清除',
  2470. labelColor: 'blue',
  2471. borderColor: 'transparent',
  2472. background: '',
  2473. onClicked: function () {
  2474. for (var i = 0; i < datalength; i++) {
  2475. var nameId = datas[i].a("name");
  2476. formPane.getItemById(nameId)["button"].setSelected(false);
  2477. formPane.getItemById(nameId)["button"].setBackground('rgb(255,255,255)');
  2478. formPane.getItemById(nameId)["button"].setIcon(null);
  2479. formPane.getItemById(nameId)["button"].setLabel(datas[i].a("displayName"));
  2480. }
  2481. formPane.setValue("indicatorCount", "0");
  2482. }
  2483. }
  2484. }
  2485. ], [0.1, 0.1, 0.8, 0.05, 0.05, 0.05], 25, {
  2486. index: 1
  2487. });
  2488. formPane.addRow([], [0.1], 1.01, {
  2489. background: 'rgb(243,243,250)',
  2490. index: 2
  2491. });
  2492. var initCount = 0;
  2493. var rowscount = Math.ceil(datas.length / 8);
  2494. for (var m = 0; m < rowscount; m++) {
  2495. var buttonList = [];
  2496. var buttonWidthPercents = [];
  2497. for (var j = m * 8; j < (m + 1) * 8; j++) {
  2498. if (j < datas.length) {
  2499. buttonList.push({
  2500. id: datas[j].a("name"),
  2501. button: createChartButton(datas[j].a("displayName"), datas[j].a("visible"), formPane)
  2502. });
  2503. if (datas[j].a("visible")) {
  2504. initCount = initCount + 1;
  2505. }
  2506. buttonWidthPercents.push(0.1);
  2507. } else {
  2508. buttonList.push(null);
  2509. buttonWidthPercents.push(0.1);
  2510. }
  2511. }
  2512. formPane.addRow(buttonList, buttonWidthPercents, 30, {
  2513. index: m + 2
  2514. });
  2515. formPane.setValue("indicatorCount", initCount);
  2516. }
  2517. borderPane.setTopView(formPane);
  2518. controlDialog.setConfig({
  2519. title: "设置名称",
  2520. titleIcon: '',
  2521. titleColor: "black",
  2522. //background:'red',
  2523. closable: true, //关闭是否可用
  2524. draggable: true,
  2525. maximizable: false, //设置不可以被最大化
  2526. width: 860,
  2527. height: 460,
  2528. position: {
  2529. x: 200,
  2530. y: 100
  2531. }, //对话框的位置
  2532. content: borderPane,
  2533. buttonsAlign: "left",
  2534. buttons: [{
  2535. label: "确认",
  2536. className: 'dialog-button-confirm',
  2537. action: function (item, e) {
  2538. var dictags = {};
  2539. var tagsArray = [];
  2540. var tags = "";
  2541. for (var i = 0; i < datalength; i++) {
  2542. var nameId = datas[i].a("name");
  2543. if (formPane.getItemById(nameId)["button"].isSelected()) {
  2544. datas[i].a("visible", true);
  2545. tagsArray.push(nameId);
  2546. dictags[datas[i].a("name")] = datas[i].a("displayName");
  2547. } else {
  2548. datas[i].a("visible", false);
  2549. }
  2550. }
  2551. controlDialog.hide();
  2552. for (var i = 0; i < tagsArray.length; i++) {
  2553. tags += tagsArray[i] + ",";
  2554. if (i == (tagsArray.length - 1)) {
  2555. tags = tags.substring(0, tags.length - 1);
  2556. }
  2557. }
  2558. callback(tags, dictags);
  2559. }
  2560. }, {
  2561. label: "取消",
  2562. className: 'dialog-button-cancel',
  2563. action: function (item, e) {
  2564. controlDialog.hide();
  2565. }
  2566. }]
  2567. });
  2568. controlDialog.setModal(false);
  2569. controlDialog.show();
  2570. //创建显示按钮,并设置点击事件
  2571. function createChartButton(lable, show, formPane) {
  2572. var button = new ht.widget.Button();
  2573. button.setLabel(lable);
  2574. button.setTogglable(true);
  2575. button.setWidth(100);
  2576. button.setHeight(40);
  2577. if (show) {
  2578. button.setSelected(true);
  2579. button.setSelectBackground('rgb(53,199,122)');
  2580. //button.setBackground('rgb(53,199,122)');
  2581. button.setIcon(imagePath + "DuiHao.png");
  2582. button.setLabel(" " + lable);
  2583. } else {
  2584. button.setBackground('rgb(255,255,255)');
  2585. button.setSelected(false);
  2586. button.setIcon(null);
  2587. button.setLabel(lable);
  2588. }
  2589. button.onClicked = function () {
  2590. // 设置选择个数限制
  2591. if (parseInt(formPane.getValue("indicatorCount")) >= 5 && this.isSelected()) {
  2592. dialogTip('已选择的指标超过' + selectedLimit + '个了,最多选择5个!');
  2593. this.setSelected(false);
  2594. this.setBackground('rgb(255,255,255)');
  2595. this.setIcon(null);
  2596. this.setLabel(lable);
  2597. return button;
  2598. }
  2599. if (this.isSelected()) {
  2600. formPane.setValue("indicatorCount", parseInt(formPane.getValue("indicatorCount")) + 1);
  2601. this.setSelectBackground('rgb(53,199,122)');
  2602. this.setIcon(imagePath + "DuiHao.png");
  2603. this.setLabel(" " + lable);
  2604. } else {
  2605. formPane.setValue("indicatorCount", parseInt(formPane.getValue("indicatorCount")) - 1);
  2606. this.setBackground('rgb(255,255,255)');
  2607. this.setIcon(null);
  2608. this.setLabel(lable);
  2609. }
  2610. }
  2611. return button;
  2612. }
  2613. }
  2614. // 弹出提示框
  2615. function dialogTip(content, callback) {
  2616. GD.createErrorDialog(360, 240, content, callback);
  2617. }
  2618. function createButton(lable, show, formPane, paneStyle, limit) {
  2619. var button = new ht.widget.Button();
  2620. button.setLabel(lable);
  2621. button.setTogglable(true);
  2622. button.setWidth(100);
  2623. button.setHeight(40);
  2624. button.setLabelFont('bold 12px "苹方 粗体"');
  2625. button.setBorderColor('rgba(0,0,0,0)');
  2626. limit = limit || 1000000;
  2627. if (show) {
  2628. button.setSelected(true);
  2629. button.setIcon(imagePath + "DuiHao.png");
  2630. button.setLabel(" " + lable);
  2631. } else {
  2632. button.setSelected(false);
  2633. button.setIcon(null);
  2634. button.setLabel(lable);
  2635. }
  2636. button.setSelectBackground(paneStyle.btnCheckedBackColor);
  2637. button.setBackground(paneStyle.btnBackColor);
  2638. button.setLabelSelectColor(paneStyle.btnCheckedFontColor);
  2639. button.setLabelColor(paneStyle.btnFontColor);
  2640. button.onClicked = function () {
  2641. if (this.isSelected()) {
  2642. if (formPane.getValue("indicatorCount") >= limit) {
  2643. dialogTip('选择的太多啦, 最多可选择' + limit + '个!');
  2644. this.setSelected(false);
  2645. this.setBackground(paneStyle.btnBackColor);
  2646. this.setIcon(null);
  2647. this.setLabel(lable);
  2648. this.setLabelColor(paneStyle.btnFontColor);
  2649. return;
  2650. }
  2651. formPane.setValue("indicatorCount", parseInt(formPane.getValue("indicatorCount")) + 1);
  2652. this.setIcon(imagePath + "DuiHao.png");
  2653. this.setLabel(" " + lable);
  2654. } else {
  2655. formPane.setValue("indicatorCount", parseInt(formPane.getValue("indicatorCount")) - 1);
  2656. this.setIcon(null);
  2657. this.setLabel(lable);
  2658. }
  2659. }
  2660. $(button.getView()).css({
  2661. boxShadow: '1px 1px 4px #000'
  2662. })
  2663. return button;
  2664. }