template.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Template</title>
  8. <link rel="stylesheet" href="./js/layui/css/layui.css">
  9. <link rel="stylesheet" href="./js/layui/css/modules/index.css">
  10. <style>
  11. .all {
  12. padding-top: 10px;
  13. padding-left: 30px;
  14. padding-right: 30px;
  15. }
  16. .c {
  17. float: left;
  18. background-color: #fff;
  19. padding: 10px;
  20. }
  21. .c1 {
  22. margin: 10px;
  23. float: left;
  24. }
  25. .t1 {
  26. /* width: 18%; */
  27. /* margin-right: 10px; */
  28. -webkit-box-sizing:border-box;
  29. -moz-box-sizing:border-box;
  30. -ms-box-sizing:border-box;
  31. box-sizing:border-box
  32. }
  33. .row {
  34. height: 50px;
  35. }
  36. .row2 {
  37. height: 130px;
  38. }
  39. .t2 {
  40. width: 10%;
  41. }
  42. .view {
  43. /* width: 79%; */
  44. }
  45. #timeType {
  46. float: left;
  47. width: 10%;
  48. }
  49. #time1 {
  50. float: left;
  51. width: 10%;
  52. }
  53. .btn {
  54. float: left;
  55. width: 10%;
  56. }
  57. .label {
  58. height: 50px;
  59. line-height: 32px;
  60. }
  61. #column{
  62. width: 100%;
  63. }
  64. </style>
  65. </head>
  66. <body>
  67. <div class="banner">
  68. <!-- <img src="../static/js/layui/css/modules/layer/default/nokiaLogo.png" alt="" width="150px" height="50px"> -->
  69. <div class="logo"></div>
  70. <div class="name">KPI-Analyser</div>
  71. <div class="userinfo">
  72. <!-- <i class="layui-icon layui-icon-username"></i> -->
  73. <span>你好,</span>
  74. <span id="userName"></span>
  75. <span class="logOut" onclick="logOutFun()">退出登录</span>
  76. </div>
  77. </div>
  78. <div class="all layui-row">
  79. <div class=" t1 layui-col-md2 " >
  80. <div class="c" style="width:90%;height: 85vh;overflow: auto;">
  81. <div class="grid-demo grid-demo-bg1">
  82. <button type="button" class="layui-btn layui-btn-sm" onclick="addTemplate()">添加指标模板</button>
  83. <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" onclick="deleteTemplate()">删除指标模板</button>
  84. <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="editTemplate()" style="margin-left: 0px;margin-top: 10px;">修改指标模板</button>
  85. <div id="allArea"></div>
  86. <div id="allMetrics"></div>
  87. <div id="indicatorTemplate"></div>
  88. <div id="add-template" style="display: none;">
  89. <form class="layui-form" action="">
  90. <div class="layui-form-item" style="margin-top: 20px">
  91. <label class="layui-form-label">模板名称</label>
  92. <div class="layui-input-block" style="width: 400px">
  93. <input id="templateName" type="text" name="templateName" required lay-verify="required"
  94. placeholder="请输入模板名称" autocomplete="off" class="layui-input">
  95. </div>
  96. </div>
  97. </form>
  98. <div id="allIndicator"></div>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. <!-- <div class="c t2">
  104. <form class="layui-form" action="">
  105. <div class="column" id="searchType">
  106. <input type="radio" name="where" value="eci" title="按eci查询" lay-filter="where" checked>
  107. <input type="radio" name="where" value="all" title="全网选择" lay-filter="where">
  108. </div>
  109. <textarea id="condition" cols="14" rows="19"
  110. style="border-width:1px;border-style: solid;border-color: #eee;"></textarea>
  111. </form>
  112. </div> -->
  113. <div class="c view layui-col-md10">
  114. <div class="grid-demo">
  115. <div class="row layui-form row2">
  116. <div style="width:100%;float: left;">
  117. <div class="c1 label"> 粒度:</div>
  118. <div class="timeTypeDiv c1" style="width: 10%;">
  119. <select name="timeType" id="timeType" lay-filter="timeType" onchange="console.log('555555555555555555')">
  120. <option value="QUATER" selected>15分钟</option>
  121. <option value="HOUR">小时</option>
  122. <option value="DAY">天</option>
  123. <!--<option value="week">星期</option>-->
  124. <!--<option value="month">月</option>-->
  125. </select>
  126. </div>
  127. <div class="c1 label" style="margin-left: 120px;">时间:</div>
  128. <input type="text" class="layui-input c1" style="width: 300px;" id="time1">
  129. <button class="layui-btn btn c1" style="margin-left: 20px;" onclick="search()">查询</button>
  130. <!-- <button class="layui-btn btn c1" style="margin-left: 20px;" onclick="conditionSearch()">条件查询</button>-->
  131. </div>
  132. </br>
  133. <div style="width:100%;float: left;">
  134. <div class="column" id="searchType" style="width:auto;float: left;">
  135. <input type="radio" name="where" value="AREA" title="按地市查询" lay-filter="where" checked>
  136. <input type="radio" name="where" value="ECI" title="按eci查询" lay-filter="where" >
  137. </div>
  138. <div style="width:70%;float: left;">
  139. <input id="condition" class="layui-input" placeholder="如多个eci查询请用英文逗号隔开"
  140. style="border-width:1px;border-style: solid;border-color: #eee;"></input>
  141. </div>
  142. </div>
  143. </div>
  144. <div>
  145. <table id="demo" lay-filter="test" style="width: 200px;"></table>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. <script src="./js/jquery-3.5.1.min.js"></script>
  151. <script src="./js/layui/layui.js"></script>
  152. <script>
  153. const host = window.location.host
  154. const username = window.sessionStorage.getItem('userName')
  155. const socket = new WebSocket(`ws://${host}/ws?username=${username}`);
  156. socket.onopen = (event) => {
  157. console.log(event)
  158. }
  159. socket.onclose = (event) => {
  160. console.log(event)
  161. logout()
  162. }
  163. socket.onerror = (event) => {
  164. console.log(event)
  165. logout()
  166. }
  167. const logout = () => {
  168. alert('websocket连接异常,请重新登录')
  169. setTimeout(() => window.location.href = '/login', 1000)
  170. }
  171. var dataA;
  172. var layer;
  173. var tree;
  174. var table;
  175. layui.use(['layer', 'tree', 'form', 'laydate', 'table'], function () {
  176. tree = layui.tree;
  177. layer = layui.layer;
  178. table = layui.table;
  179. var form = layui.form, laydate = layui.laydate;
  180. // layer.msg('Hello Zhou')
  181. table.render({
  182. elem: '#demo',
  183. height: 480,
  184. // url: 'https://www.layui.com/demo/table/user/' , //数据接口
  185. page: true, //开启分页
  186. toolbar: true,
  187. defaultToolbar: [{
  188. title: '下载' //标题
  189. ,
  190. layEvent: 'export' //事件名,用于 toolbar 事件中使用
  191. ,
  192. icon: 'layui-icon-export' //图标类名
  193. }],
  194. limit: 50,
  195. limits: [50, 200, 500],
  196. cols: [],
  197. data: []
  198. });
  199. //工具条事件
  200. table.on('toolbar(test)', function (obj) { //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
  201. var data = obj.data; //获得当前行数据
  202. var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
  203. if (layEvent === 'export') {
  204. // layer.alert('Hi,头部工具栏扩展的右侧图标。');
  205. var tableData = table.cache['demo']
  206. obj.config.title = "地市指标"
  207. table.exportFile(obj.config.id, dataA, 'csv')
  208. }
  209. });
  210. let dateArray = '';
  211. let timeType = $('#timeType').val()
  212. console.log('timeType: ', timeType);
  213. let date = new Date();
  214. if(timeType == 'QUATER'){
  215. dateArray= formatDate(date) + ' ' + '00:00:00' + ' - ' + formatDate(date) + ' ' + '00:15:00';
  216. console.log('dateArray: ', dateArray);
  217. }
  218. initTreeCity(tree)
  219. initTreeIndicator(tree)
  220. initAllIndicator(tree)
  221. initTreeIndicatorTemplate(tree)
  222. // console.log(window.sessionStorage.getItem('userName'))
  223. $("#userName").text(window.sessionStorage.getItem('userName'))
  224. form.on('select(timeType)', function(data){
  225. // console.log('data: ', data);
  226. // console.log('ooooo')
  227. // handleChange(data.value)
  228. form.render('select'); // 渲染select,固定写法
  229. if(data.value == 'QUATER'){
  230. dateArray= formatDate(date) + ' ' + '00:00:00' + ' - ' + formatDate(date) + ' ' + '00:15:00';
  231. // console.log('dateArray: ', dateArray);
  232. laydate.render({
  233. elem: '#time1',
  234. type: 'datetime',
  235. range: true,
  236. value: dateArray,
  237. ready: function(date){
  238. console.log(date); //得到初始的日期时间对象:{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
  239. },
  240. });
  241. }
  242. if(data.value == 'HOUR'){
  243. // console.log('xiaoshi')
  244. dateArray= formatDate(date) + ' ' + '00:00:00' + ' - ' + formatDate(date) + ' ' + '01:00:00';
  245. // console.log('dateArray: ', dateArray);
  246. laydate.render({
  247. elem: '#time1',
  248. type: 'datetime',
  249. range: true,
  250. value: dateArray,
  251. ready: function(date){
  252. console.log(date); //得到初始的日期时间对象:{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
  253. },
  254. });
  255. }
  256. if(data.value == 'DAY'){
  257. // console.log('xiaoshi')
  258. dateArray= formatDate(date) + ' ' + '00:00:00' + ' - ' + formatDate(date) + ' ' + '23:59:59';
  259. // console.log('dateArray: ', dateArray);
  260. laydate.render({
  261. elem: '#time1',
  262. type: 'datetime',
  263. range: true,
  264. value: dateArray,
  265. ready: function(date){
  266. console.log(date); //得到初始的日期时间对象:{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
  267. },
  268. });
  269. }
  270. });
  271. laydate.render({
  272. elem: '#time1',
  273. type: 'datetime',
  274. range: true,
  275. value: dateArray,
  276. ready: function(date){
  277. console.log(date); //得到初始的日期时间对象:{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
  278. },
  279. change: function(value, date){
  280. console.log('date: ', date);
  281. }
  282. });
  283. })
  284. // function handleChange(val){
  285. // console.log('val: ', val);
  286. // let date = new Date();
  287. // if(val == 'QUATER'){
  288. // dateArray= formatDate(date) + ' ' + '00:00:00' + ' - ' + formatDate(date) + ' ' + '00:15:00';
  289. // // console.log('dateArray: ', dateArray);
  290. // }
  291. // if(val == 'HOUR'){
  292. // console.log('xiaoshi')
  293. // dateArray= formatDate(date) + ' ' + '00:00:00' + ' - ' + formatDate(date) + ' ' + '01:00:00';
  294. // // console.log('dateArray: ', dateArray);
  295. // }
  296. // if(val == 'DAY'){
  297. // console.log('xiaoshi')
  298. // dateArray= formatDate(date) + ' ' + '00:00:00' + ' - ' + formatDate(date) + ' ' + '23:59:59';
  299. // // console.log('dateArray: ', dateArray);
  300. // }
  301. // }
  302. function formatDate (date) {
  303. var y = date.getFullYear();
  304. var m = date.getMonth() + 1;
  305. m = m < 10 ? '0' + m : m;
  306. var d = date.getDate();
  307. d = d < 10 ? ('0' + d) : d;
  308. return y + '-' + m + '-' + d;
  309. };
  310. var treeCity;
  311. function initTreeCity(tree) {
  312. $.ajax({
  313. type: "POST",
  314. // url: '/api/json/citys.json',
  315. url: '/api/initTreeCitys',
  316. success: function (r) {
  317. if (r?.success) {
  318. treeCity = tree.render({
  319. elem: '#allArea',
  320. showCheckbox: true,
  321. accordion: true,
  322. id: 'Id1',
  323. data: r?.data
  324. });
  325. return
  326. }
  327. alert(r?.message ?? '发生错误了');
  328. }
  329. });
  330. }
  331. var treeIn;
  332. // 渲染指标模板
  333. function initTreeIndicatorTemplate(tree) {
  334. $.ajax({
  335. type: "POST",
  336. url: '/api/initTreeIndicatorTemplate',
  337. success: function (r) {
  338. if (r?.success) {
  339. treeIn = tree.render({
  340. elem: '#indicatorTemplate',
  341. showCheckbox: true,
  342. accordion: true,
  343. id: 'Id3',
  344. // edit: ['update'],
  345. data: r?.data,
  346. // customOperate: true,
  347. // operate:function(obj){
  348. // console.log('obj: ', obj);
  349. // $('.layui-tree-editInput').remove();
  350. // if(obj.type == "update"){
  351. // // addTemplate()
  352. // }
  353. // },
  354. oncheck: function(obj){
  355. // console.log(obj);
  356. if(obj.checked) {
  357. // console.log('tree.getChecked("Id4"): ', tree.getChecked('Id4'));
  358. tree.getChecked('Id4').length = 0
  359. tree.setChecked('Id4', [])
  360. tree.reload('Id4', {
  361. //新的参数
  362. });
  363. // console.log(' ----++++ ', tree.getChecked('Id4'));
  364. }
  365. }
  366. });
  367. return
  368. }
  369. alert(r?.message ?? '发生错误了');
  370. }
  371. });
  372. }
  373. // 全部指标
  374. function initAllIndicator(tree) {
  375. $.ajax({
  376. type: "POST",
  377. url: '/api/allIndicator',
  378. success: function (r) {
  379. if (r?.success) {
  380. treeIn = tree.render({
  381. elem: '#allMetrics',
  382. showCheckbox: true,
  383. accordion: true,
  384. id: 'Id4',
  385. data: r?.data,
  386. oncheck: function(obj){
  387. // console.log(obj);
  388. if(obj.checked) {
  389. // console.log('tree.getChecked("Id3"): ', tree.getChecked('Id3'));
  390. tree.getChecked('Id3').length = 0
  391. tree.setChecked('Id3', [])
  392. tree.reload('Id3', {
  393. //新的参数
  394. });
  395. // console.log(' ---- ', tree.getChecked('Id3'));
  396. }
  397. }
  398. });
  399. return
  400. }
  401. alert(r?.message ?? '发生错误了');
  402. }
  403. });
  404. }
  405. function initTreeIndicator(tree) {
  406. $.ajax({
  407. type: "POST",
  408. url: '/api/initTreeIndicator',
  409. success: function (r) {
  410. if (r?.success) {
  411. treeIn = tree.render({
  412. elem: '#allIndicator',
  413. showCheckbox: true,
  414. accordion: true,
  415. id: 'Id2',
  416. data: r?.data,
  417. });
  418. return
  419. }
  420. alert(r?.message ?? '发生错误了');
  421. }
  422. });
  423. }
  424. function renderTable(includeOther, condition, searchType, table, lteCitys, lteQuxians, nblteCitys, nblteQuxians,
  425. indicators, timeType, startTime, endTime) {
  426. var tishi = layer.load(1, {
  427. shadeClose: false,
  428. title: '加载中..',
  429. shade: [0.5,'#000'] //0.1透明度的白色背景
  430. });
  431. // setTimeout(()=>{
  432. // layer.close(tishi);
  433. // },5000)
  434. const dataJson = JSON.stringify({
  435. "includeOther": includeOther,
  436. "condition": condition,
  437. "searchType": searchType,
  438. "lteCitys": [...lteCitys],
  439. "lteQuxians": [...lteQuxians],
  440. "nblteCitys": [...nblteCitys],
  441. "nblteQuxians": [...nblteQuxians],
  442. "indicators": [...indicators],
  443. "timeType": timeType,
  444. "startTime": startTime,
  445. "endTime": endTime
  446. })
  447. $.ajax({
  448. type: "POST",
  449. contentType: "application/json;charset=UTF-8",
  450. url: '/api/renderTable',
  451. data: dataJson,
  452. success: function (r) {
  453. layer.close(tishi);
  454. if (r?.success) {
  455. dataA = r?.data?.datas
  456. table.render({
  457. elem: '#demo',
  458. height: 480,
  459. // url: 'https://www.layui.com/demo/table/user/' , //数据接口
  460. page: true, //开启分页
  461. toolbar: true,
  462. defaultToolbar: [{
  463. title: '下载' //标题
  464. ,
  465. layEvent: 'export' //事件名,用于 toolbar 事件中使用
  466. ,
  467. icon: 'layui-icon-export' //图标类名
  468. }],
  469. limit: 50,
  470. limits: [50, 200, 500],
  471. cols: [
  472. r?.data?.cols ?? []
  473. ],
  474. data: r?.data?.datas ?? []
  475. });
  476. return
  477. }
  478. alert(r?.message ?? '发生错误了');
  479. },
  480. error: function(err){
  481. layer.close(tishi);
  482. }
  483. });
  484. }
  485. function search() {
  486. if ($('#time1').val() === 0) {
  487. alert('填选择时间')
  488. return;
  489. }
  490. if (tree.getChecked('Id3').length === 0 && tree.getChecked('Id4').length === 0) {
  491. alert('请选择指标')
  492. return;
  493. }
  494. let condition = $('#condition').val();
  495. let searchType = $('#searchType').find('input:checked').val()
  496. if (searchType === 'ECI' && $('#condition').val().length === 0) {
  497. alert('请填写eci')
  498. return;
  499. }
  500. if (searchType === 'AREA' && tree.getChecked('Id1').length === 0) {
  501. alert('请选择地市')
  502. return;
  503. }
  504. const checkData1 = tree.getChecked('Id1')?.[0]?.children;
  505. let lte
  506. let nblte
  507. let includeOther = false
  508. checkData1.forEach?.(t => {
  509. if (t?.id === 'LTE') {
  510. lte = t
  511. }
  512. if (t?.id === 'NBLTE') {
  513. nblte = t
  514. }
  515. if (t?.id === 'OTHER') {
  516. includeOther = true
  517. }
  518. })
  519. console.log(lte)
  520. console.log(nblte)
  521. const lteQuxians = new Set()
  522. let lteCitys = new Set()
  523. lte?.children.forEach?.(eee => {
  524. lteCitys.add(eee.title)
  525. eee?.children.forEach?.(ee => {
  526. lteQuxians.add(ee.title)
  527. })
  528. })
  529. const nblteQuxians = new Set()
  530. let nblteCitys = new Set()
  531. nblte?.children.forEach?.(eee => {
  532. nblteCitys.add(eee.title)
  533. eee?.children.forEach?.(ee => {
  534. nblteQuxians.add(ee.title)
  535. })
  536. })
  537. let checkData2 ;
  538. // console.log('3333 ', tree.getChecked('Id3')[0]?.children);
  539. // console.log('4444 ', tree.getChecked('Id4')[0]?.children);
  540. if(tree.getChecked('Id3')?.[0]?.children){
  541. checkData2= tree.getChecked('Id3')?.[0]?.children ;
  542. }
  543. if(tree.getChecked('Id4')?.[0]?.children){
  544. checkData2= tree.getChecked('Id4')?.[0]?.children ;
  545. }
  546. const indicators = new Set();
  547. checkData2.forEach(eee => {
  548. eee.children.forEach(ee => {
  549. indicators.add(ee.id)
  550. })
  551. });
  552. let timeType = $('#timeType').val()
  553. let sdate = $('#time1').val()
  554. const [startTime, endTime] = sdate.split(' - ')
  555. renderTable(includeOther, condition, searchType, table, lteCitys, lteQuxians, nblteCitys, nblteQuxians,
  556. indicators, timeType, startTime, endTime)
  557. return false;
  558. }
  559. // 添加指标模板
  560. function addTemplate() {
  561. layer.open({
  562. type: 1,
  563. title:"添加指标模板",
  564. content: $("#add-template"),
  565. area: ['600px', '600px'],
  566. btn: ['确定'],
  567. shadeClose: true,
  568. success: function(layero, index){
  569. $('#templateName').val('');
  570. tree.reload('Id2', {
  571. //新的参数
  572. });
  573. },
  574. yes: function(index, layero){
  575. const templateName = $('#templateName').val()
  576. if (!templateName || templateName.length <= 0) {
  577. alert('请输入模板名称!')
  578. return
  579. }
  580. const checkedData = tree?.getChecked('Id2')?.[0]?.children
  581. if (!checkedData || checkedData.length <= 0) {
  582. alert('请选择指标!')
  583. return
  584. }
  585. const indicators = new Set()
  586. checkedData.forEach(eee => {
  587. eee.children.forEach(ee => {
  588. indicators.add(ee.id)
  589. })
  590. });
  591. const dataJson = JSON.stringify({
  592. "templateName": templateName,
  593. "indicators": [...indicators],
  594. })
  595. $.ajax({
  596. type: "POST",
  597. contentType: "application/json;charset=UTF-8",
  598. url: '/api/addTemplate',
  599. data: dataJson,
  600. success: function (r) {
  601. if (r?.success) {
  602. initTreeIndicatorTemplate(tree)
  603. layer.msg('添加成功')
  604. layer.close(index)
  605. return
  606. }
  607. alert(r?.message ?? '发生错误了');
  608. }
  609. });
  610. },
  611. });
  612. }
  613. // 修改指标模板
  614. var templateId;
  615. function editTemplate() {
  616. console.log('xiugai')
  617. const checkedData = tree?.getChecked('Id3')?.[0]?.children
  618. console.log('checkedData: ', checkedData);
  619. if(!checkedData || checkedData.length <= 0){
  620. alert('请选择要修改的指标模板!')
  621. return
  622. }else if(checkedData.length > 1){
  623. alert('请选择一个要修改的指标模板!')
  624. return
  625. }else{
  626. layer.open({
  627. type: 1,
  628. title:"修改指标模板",
  629. content: $("#add-template"),
  630. area: ['600px', '600px'],
  631. btn: ['确定'],
  632. shadeClose: true,
  633. success: function(layero, index){
  634. let data = checkedData[0].id;
  635. $.ajax({
  636. type: "POST",
  637. contentType: "application/json;charset=UTF-8",
  638. url: '/api/getTemplateDetail',
  639. data: data,
  640. success: function (r) {
  641. if (r?.success) {
  642. templateId = r.data.id;
  643. $('#templateName').val(r.data.templateName);
  644. let arr = [];
  645. r.data.list.map(item=>{
  646. arr.push(item.id)
  647. })
  648. console.log('arr: ', arr);
  649. tree.setChecked('Id2', arr)
  650. return
  651. }
  652. alert(r?.message ?? '发生错误了');
  653. }
  654. });
  655. },
  656. yes: function(index, layero){
  657. const templateName = $('#templateName').val()
  658. if (!templateName || templateName.length <= 0) {
  659. alert('请输入模板名称!')
  660. return
  661. }
  662. const checkedData = tree?.getChecked('Id2')?.[0]?.children
  663. if (!checkedData || checkedData.length <= 0) {
  664. alert('请选择指标!')
  665. return
  666. }
  667. const indicators = new Set()
  668. checkedData.forEach(eee => {
  669. eee.children.forEach(ee => {
  670. indicators.add(ee.id)
  671. })
  672. });
  673. const dataJson = JSON.stringify({
  674. "id": templateId,
  675. "templateName": templateName,
  676. "indicators": [...indicators],
  677. })
  678. $.ajax({
  679. type: "POST",
  680. contentType: "application/json;charset=UTF-8",
  681. url: '/api/updateTemplate',
  682. data: dataJson,
  683. success: function (r) {
  684. if (r?.success) {
  685. initTreeIndicatorTemplate(tree)
  686. layer.msg('修改成功')
  687. layer.close(index)
  688. return
  689. }
  690. alert(r?.message ?? '发生错误了');
  691. }
  692. });
  693. },
  694. });
  695. }
  696. }
  697. // 删除指标模板
  698. function deleteTemplate() {
  699. const checkedData = tree.getChecked('Id3')?.[0]?.children
  700. if (!checkedData || checkedData.length <= 0) {
  701. alert('请选择要删除的指标模板!')
  702. return
  703. }
  704. const ids = new Set()
  705. checkedData.forEach(t => {
  706. ids.add(t.id)
  707. });
  708. const dataJson = JSON.stringify({
  709. "ids": [...ids],
  710. })
  711. layer.confirm('确认删除?', {icon: 3, title:'删除模板'}, function(index){
  712. $.ajax({
  713. type: "POST",
  714. contentType: "application/json;charset=UTF-8",
  715. url: '/api/deleteTemplate',
  716. // async: false,
  717. data: dataJson,
  718. success: function (r) {
  719. if (r?.success) {
  720. initTreeIndicatorTemplate(tree)
  721. layer.msg('删除成功')
  722. layer.close(index)
  723. return
  724. }
  725. alert(r?.message ?? '发生错误了')
  726. }
  727. });
  728. });
  729. }
  730. // 获取登录用户信息
  731. // 退出登录
  732. function logOutFun() {
  733. $.ajax({
  734. type: "POST",
  735. // url: '/api/json/citys.json',
  736. url: '/api/logout',
  737. success: function (r) {
  738. window.sessionStorage.clear()
  739. layer.msg('退出登录成功');
  740. setTimeout(() => window.location.href = '/login', 1000)
  741. }
  742. });
  743. }
  744. //
  745. $(document).ready(function(){
  746. setTimeout(()=>{
  747. $(".layui-tree-txt").mouseenter(function(){
  748. // console.log('this',this)
  749. $(this).attr("title",$(this).text());
  750. // console.log('this.text(): ', $(this).text());
  751. });
  752. },1000)
  753. });
  754. window.onbeforeunload=function(e){
  755. if (window.sessionStorage.getItem('userName')) {
  756. logOutFun()
  757. }
  758. }
  759. // window.addEventListener('unload',logOutFun());
  760. </script>
  761. </body>
  762. </html>