template.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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>
  72. <div class="all">
  73. <div class="c t1">
  74. <button type="button" class="layui-btn layui-btn-sm" onclick="addTemplate()">添加指标模板</button>
  75. <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" onclick="deleteTemplate()">删除指标模板</button>
  76. <div id="allArea"></div>
  77. <div id="indicatorTemplate"></div>
  78. <div id="add-template" style="display: none;">
  79. <form class="layui-form" action="">
  80. <div class="layui-form-item" style="margin-top: 20px">
  81. <label class="layui-form-label">模板名称</label>
  82. <div class="layui-input-block" style="width: 400px">
  83. <input id="templateName" type="text" name="templateName" required lay-verify="required"
  84. placeholder="请输入模板名称" autocomplete="off" class="layui-input">
  85. </div>
  86. </div>
  87. </form>
  88. <div id="allIndicator"></div>
  89. </div>
  90. </div>
  91. <!-- <div class="c t2">
  92. <form class="layui-form" action="">
  93. <div class="column" id="searchType">
  94. <input type="radio" name="where" value="eci" title="按eci查询" lay-filter="where" checked>
  95. <input type="radio" name="where" value="all" title="全网选择" lay-filter="where">
  96. </div>
  97. <textarea id="condition" cols="14" rows="19"
  98. style="border-width:1px;border-style: solid;border-color: #eee;"></textarea>
  99. </form>
  100. </div> -->
  101. <div class="c view">
  102. <div class="row layui-form row2">
  103. <div style="width:100%;float: left;">
  104. <div class="c1 label"> 粒度:</div>
  105. <div class="timeTypeDiv c1" style="width: 10%;">
  106. <select name="timeType" id="timeType">
  107. <option value="quater">15分钟</option>
  108. <option value="hour">小时</option>
  109. <option value="day">天</option>
  110. <!--<option value="week">星期</option>-->
  111. <!--<option value="month">月</option>-->
  112. </select>
  113. </div>
  114. <div class="c1 label" style="margin-left: 120px;">时间:</div>
  115. <input type="text" class="layui-input c1" style="width: 300px;" id="time1">
  116. <button class="layui-btn btn c1" style="margin-left: 20px;" onclick="search()">查询</button>
  117. <!-- <button class="layui-btn btn c1" style="margin-left: 20px;" onclick="conditionSearch()">条件查询</button>-->
  118. </div>
  119. </br>
  120. <div style="width:100%;float: left;">
  121. <div class="column" id="searchType" style="width:auto;float: left;">
  122. <input type="radio" name="where" value="eci" title="按eci查询" lay-filter="where" checked>
  123. <input type="radio" name="where" value="area" title="按地市查询" lay-filter="where">
  124. </div>
  125. <div style="width:70%;float: left;">
  126. <input id="condition" class="layui-input" placeholder="如多个eci查询请用英文逗号隔开"
  127. style="border-width:1px;border-style: solid;border-color: #eee;"></input>
  128. </div>
  129. </div>
  130. </div>
  131. <div>
  132. <table id="demo" lay-filter="test" style="width: 200px;"></table>
  133. </div>
  134. </div>
  135. </div>
  136. <script src="./js/jquery-3.5.1.min.js"></script>
  137. <script src="./js/layui/layui.js"></script>
  138. <script>
  139. var dataA;
  140. var layer;
  141. var tree;
  142. var table;
  143. layui.use(['layer', 'tree', 'form', 'laydate', 'table'], function () {
  144. tree = layui.tree;
  145. layer = layui.layer;
  146. table = layui.table;
  147. var form = layui.form, laydate = layui.laydate;
  148. // layer.msg('Hello Zhou')
  149. table.render({
  150. elem: '#demo',
  151. height: 320,
  152. // url: 'https://www.layui.com/demo/table/user/' , //数据接口
  153. page: true, //开启分页
  154. toolbar: true,
  155. defaultToolbar: [{
  156. title: '导出' //标题
  157. ,
  158. layEvent: 'export' //事件名,用于 toolbar 事件中使用
  159. ,
  160. icon: 'layui-icon-export' //图标类名
  161. }],
  162. limit: 50,
  163. limits: [50, 200, 500],
  164. cols: [
  165. ],
  166. data: []
  167. });
  168. //工具条事件
  169. table.on('toolbar(test)', function (obj) { //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
  170. var data = obj.data; //获得当前行数据
  171. var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
  172. if (layEvent === 'export') {
  173. // layer.alert('Hi,头部工具栏扩展的右侧图标。');
  174. var tableData = table.cache['demo']
  175. obj.config.title = "地市指标"
  176. // console.log(JSON.stringify(dataA))
  177. table.exportFile(obj.config.id, dataA.datas, 'csv')
  178. }
  179. });
  180. laydate.render({
  181. elem: '#time1',
  182. type: 'datetime',
  183. range: true,
  184. });
  185. initTreeCity(tree)
  186. initTreeIndicator(tree)
  187. initTreeIndicatorTemplate(tree)
  188. })
  189. var treeCity;
  190. function initTreeCity(tree) {
  191. console.log('initTreeCity')
  192. $.ajax({
  193. type: "GET",
  194. // url: './json/citys.json',
  195. url: './initTreeCitys',
  196. data: {
  197. "spread": false
  198. },
  199. success: function (r) {
  200. // console.log(r)
  201. let o = r instanceof Object
  202. if (!o) {
  203. r = JSON.parse(r)
  204. }
  205. treeCity = tree.render({
  206. elem: '#allArea',
  207. showCheckbox: true,
  208. accordion: true,
  209. id: 'Id1',
  210. data: r
  211. });
  212. return false;
  213. }
  214. });
  215. }
  216. var treeIn;
  217. // 渲染指标模板
  218. function initTreeIndicatorTemplate(tree) {
  219. console.log('initTreeIndicatorTemplate')
  220. $.ajax({
  221. type: "GET",
  222. url: './initTreeIndicatorTemplate',
  223. data: {
  224. "spread": false
  225. },
  226. success: function (r) {
  227. let o = r instanceof Object
  228. if (!o) {
  229. r = JSON.parse(r)
  230. }
  231. treeIn = tree.render({
  232. elem: '#indicatorTemplate',
  233. showCheckbox: true,
  234. accordion: true,
  235. id: 'Id3',
  236. data: r
  237. });
  238. return false;
  239. }
  240. });
  241. }
  242. function initTreeIndicator(tree) {
  243. console.log('initTreeIndicator')
  244. $.ajax({
  245. type: "GET",
  246. url: './initTreeIndicator',
  247. data: {
  248. "spread": false
  249. },
  250. success: function (r) {
  251. // console.log(r)
  252. let o = r instanceof Object
  253. if (!o) {
  254. r = JSON.parse(r)
  255. }
  256. treeIn = tree.render({
  257. elem: '#allIndicator',
  258. showCheckbox: true,
  259. accordion: true,
  260. id: 'Id2',
  261. data: r
  262. });
  263. return false;
  264. }
  265. });
  266. }
  267. function renderTable(condition, searchType, table, citys, quxians, indicators, ttype, sdate) {
  268. console.log('renderTable')
  269. $.ajax({
  270. type: "POST",
  271. url: './renderTable',
  272. async: false,
  273. data: {
  274. "condition": condition,
  275. "searchType": searchType,
  276. "citys": citys,
  277. "quxians": quxians,
  278. "indicators": indicators,
  279. "ttype": ttype,
  280. "sdate": sdate
  281. },
  282. success: function (r) {
  283. dataA = r;
  284. // 没有权限提示
  285. if (r?.msg && r.msg.length > 0) {
  286. alert(r.msg);
  287. return;
  288. }
  289. let o = r instanceof Object
  290. if (!o) {
  291. r = JSON.parse(r)
  292. }
  293. table.render({
  294. elem: '#demo',
  295. height: 320,
  296. // url: 'https://www.layui.com/demo/table/user/' , //数据接口
  297. page: true, //开启分页
  298. toolbar: true,
  299. defaultToolbar: [{
  300. title: '提示' //标题
  301. ,
  302. layEvent: 'export' //事件名,用于 toolbar 事件中使用
  303. ,
  304. icon: 'layui-icon-export' //图标类名
  305. }],
  306. limit: 50,
  307. limits: [50, 200, 500],
  308. cols: [
  309. r.cols
  310. ],
  311. data: r.datas
  312. });
  313. return false;
  314. }
  315. });
  316. }
  317. // function conditionRenderTable(table, condition, searchType, indicators, ttype, sdate) {
  318. // console.log('conditionRenderTable')
  319. // $.ajax({
  320. // type: "POST",
  321. // url: './conditionRenderTable',
  322. // async: false,
  323. // data: {
  324. // "condition": condition,
  325. // "searchType": searchType,
  326. // "indicators": indicators,
  327. // "ttype": ttype,
  328. // "sdate": sdate
  329. // },
  330. // success: function (r) {
  331. // dataA = r;
  332. // // console.log(r)
  333. // let o = r instanceof Object
  334. // if (!o) {
  335. // r = JSON.parse(r)
  336. // }
  337. // table.render({
  338. // elem: '#demo',
  339. // height: 320,
  340. // // url: 'https://www.layui.com/demo/table/user/' , //数据接口
  341. // page: true, //开启分页
  342. // toolbar: true,
  343. // defaultToolbar: [{
  344. // title: '提示' //标题
  345. // ,
  346. // layEvent: 'export' //事件名,用于 toolbar 事件中使用
  347. // ,
  348. // icon: 'layui-icon-export' //图标类名
  349. // }],
  350. // limit: 50,
  351. // limits: [50, 200, 500],
  352. // cols: [
  353. // r.cols
  354. // ],
  355. // data: r.datas
  356. // });
  357. // return false;
  358. // }
  359. // });
  360. // }
  361. function search() {
  362. // form.on('submit(formDemo)', function (data) {
  363. if ($('#time1').val() === 0) {
  364. alert('填选择时间')
  365. return;
  366. }
  367. if (tree.getChecked('Id1').length === 0) {
  368. alert('请选择地市')
  369. return;
  370. }
  371. if (tree.getChecked('Id3').length === 0) {
  372. alert('请选择指标')
  373. return;
  374. }
  375. let condition = $('#condition').val();
  376. let searchType = $('#searchType').find('input:checked').val()
  377. if (searchType === 'eci' && $('#condition').val().length === 0) {
  378. alert('请填写eci')
  379. return;
  380. }
  381. console.log(`searchType: ${searchType}`)
  382. console.log(`condition: ${condition}`)
  383. alert('开始查询')
  384. // layer.msg(JSON.stringify(data.field));
  385. console.log(JSON.stringify(tree.getChecked('Id1')))
  386. let checkData1 = tree.getChecked('Id1')[0].children;
  387. let checkData2 = tree.getChecked('Id3')[0].children;
  388. console.log(checkData1)
  389. console.log(checkData2)
  390. const quxianA = new Set();
  391. var citysA = [];
  392. checkData1.forEach(eee => {
  393. citysA.push("'" + eee.title + "'")
  394. eee.children.forEach(ee => {
  395. quxianA.add("'" + ee.title + "'")
  396. })
  397. });
  398. const quxians = Array.from(quxianA).join(',')
  399. citys = citysA.join(',')
  400. console.log(`citys: ${citys}`)
  401. console.log(`quxians: ${quxians}`)
  402. const indicatorsA = new Set();
  403. checkData2.forEach(eee => {
  404. eee.children.forEach(ee => {
  405. indicatorsA.add(ee.id)
  406. })
  407. });
  408. indicatorsA.add('eci')
  409. const indicators = Array.from(indicatorsA).join(',')
  410. console.log(`indicators: ${JSON.stringify(indicators)}`)
  411. let ttype = $('#timeType').val()
  412. let sdate = $('#time1').val()
  413. console.log(`sdate: ${sdate}`)
  414. renderTable(condition, searchType, table, citys, quxians,indicators, ttype, sdate)
  415. return false;
  416. }
  417. // function conditionSearch() {
  418. // let sdate = $('#time1').val()
  419. // if (sdate.length === 0) {
  420. // alert('请选择时间')
  421. // return;
  422. // }
  423. //
  424. // if (tree.getChecked('Id3').length == 0) {
  425. // alert('请选择指标')
  426. // return;
  427. // }
  428. // let condition = $('#condition').val();
  429. // let ttype = $('#timeType').val()
  430. // let searchType = $('#searchType').find('input:checked').val()
  431. // if (searchType === 'eci' && $('#condition').val().length === 0) {
  432. // alert('请填写查询条件')
  433. // return;
  434. // }
  435. // console.log(`searchType: ${searchType}`)
  436. // console.log(`condition: ${condition}`)
  437. // // layer.msg(JSON.stringify(data.field));
  438. // // let checkData1 = tree.getChecked('Id1')[0].children;
  439. // let checkData2 = tree.getChecked('Id3')[0].children;
  440. // const indicatorsA = new Set();
  441. // checkData2.forEach(eee => {
  442. // eee.children.forEach(ee => {
  443. // indicatorsA.add(ee.id)
  444. // })
  445. // });
  446. // indicatorsA.add('eci')
  447. // const indicatorsB = [...indicatorsA]
  448. // const indicators = indicatorsB.join(',')
  449. // console.log(`indicators: ${indicators}`)
  450. // conditionRenderTable(table, condition, searchType, indicators, ttype, sdate)
  451. // return false;
  452. // }
  453. // 添加指标模板
  454. function addTemplate() {
  455. layer.open({
  456. type: 1,
  457. title:"添加指标模板",
  458. content: $("#add-template"),
  459. area: ['600px', '1000px'],
  460. btn: ['确定'],
  461. shadeClose: true,
  462. yes: function(index, layero){
  463. const templateName = $('#templateName').val()
  464. if (!templateName || templateName.length <= 0) {
  465. alert('请输入模板名称!')
  466. return
  467. }
  468. const checkedData = tree?.getChecked('Id2')?.[0]?.children
  469. if (!checkedData || checkedData.length <= 0) {
  470. alert('请选择指标!')
  471. return
  472. }
  473. console.log(`templateName: ${templateName}`)
  474. console.log(`checkedData: ${JSON.stringify(checkedData)}`)
  475. const indicatorsA = []
  476. checkedData.forEach(eee => {
  477. eee.children.forEach(ee => {
  478. indicatorsA.push(ee.id)
  479. })
  480. });
  481. const indicators = indicatorsA.join(',')
  482. console.log(`indicators: ${indicators}`)
  483. $.ajax({
  484. type: "POST",
  485. url: './addTemplate',
  486. async: false,
  487. data: {
  488. "templateName": templateName,
  489. "indicators": indicators,
  490. },
  491. success: function (r) {
  492. console.log(`response: ${JSON.stringify(r)}`)
  493. if (r) {
  494. alert('添加失败!')
  495. } else {
  496. initTreeIndicatorTemplate(tree)
  497. layer.msg('添加成功')
  498. layer.close(index)
  499. }
  500. }
  501. });
  502. },
  503. });
  504. }
  505. // 删除指标模板
  506. function deleteTemplate() {
  507. const checkedData = tree?.getChecked('Id3')?.[0]?.children
  508. const idArray = []
  509. checkedData.forEach(t => {
  510. idArray.push(t.id)
  511. });
  512. if (!checkedData || checkedData.length <= 0) {
  513. alert('请选择要删除的指标模板!')
  514. return
  515. }
  516. layer.confirm('确认删除?', {icon: 3, title:'删除模板'}, function(index){
  517. const ids = idArray.join(',')
  518. console.log(`deleteTemplate: ${JSON.stringify(idArray)}`)
  519. $.ajax({
  520. type: "POST",
  521. url: './deleteTemplate',
  522. async: false,
  523. data: {
  524. "ids": ids,
  525. },
  526. success: function (r) {
  527. console.log(`response: ${JSON.stringify(r)}`)
  528. if (r) {
  529. alert('删除失败!')
  530. } else {
  531. initTreeIndicatorTemplate(tree)
  532. layer.msg('删除成功')
  533. layer.close(index)
  534. }
  535. }
  536. });
  537. });
  538. }
  539. //
  540. $(document).ready(function(){
  541. setTimeout(()=>{
  542. $(".layui-tree-txt").mouseenter(function(){
  543. // console.log('this',this)
  544. $(this).attr("title",$(this).text());
  545. // console.log('this.text(): ', $(this).text());
  546. });
  547. },1000)
  548. });
  549. </script>
  550. </body>
  551. </html>