template.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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. <div id="allArea"></div>
  85. <div id="indicatorTemplate"></div>
  86. <div id="add-template" style="display: none;">
  87. <form class="layui-form" action="">
  88. <div class="layui-form-item" style="margin-top: 20px">
  89. <label class="layui-form-label">模板名称</label>
  90. <div class="layui-input-block" style="width: 400px">
  91. <input id="templateName" type="text" name="templateName" required lay-verify="required"
  92. placeholder="请输入模板名称" autocomplete="off" class="layui-input">
  93. </div>
  94. </div>
  95. </form>
  96. <div id="allIndicator"></div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <!-- <div class="c t2">
  102. <form class="layui-form" action="">
  103. <div class="column" id="searchType">
  104. <input type="radio" name="where" value="eci" title="按eci查询" lay-filter="where" checked>
  105. <input type="radio" name="where" value="all" title="全网选择" lay-filter="where">
  106. </div>
  107. <textarea id="condition" cols="14" rows="19"
  108. style="border-width:1px;border-style: solid;border-color: #eee;"></textarea>
  109. </form>
  110. </div> -->
  111. <div class="c view layui-col-md10">
  112. <div class="grid-demo">
  113. <div class="row layui-form row2">
  114. <div style="width:100%;float: left;">
  115. <div class="c1 label"> 粒度:</div>
  116. <div class="timeTypeDiv c1" style="width: 10%;">
  117. <select name="timeType" id="timeType">
  118. <option value="QUATER">15分钟</option>
  119. <option value="HOUR">小时</option>
  120. <option value="DAY">天</option>
  121. <!--<option value="week">星期</option>-->
  122. <!--<option value="month">月</option>-->
  123. </select>
  124. </div>
  125. <div class="c1 label" style="margin-left: 120px;">时间:</div>
  126. <input type="text" class="layui-input c1" style="width: 300px;" id="time1">
  127. <button class="layui-btn btn c1" style="margin-left: 20px;" onclick="search()">查询</button>
  128. <!-- <button class="layui-btn btn c1" style="margin-left: 20px;" onclick="conditionSearch()">条件查询</button>-->
  129. </div>
  130. </br>
  131. <div style="width:100%;float: left;">
  132. <div class="column" id="searchType" style="width:auto;float: left;">
  133. <input type="radio" name="where" value="AREA" title="按地市查询" lay-filter="where" checked>
  134. <input type="radio" name="where" value="ECI" title="按eci查询" lay-filter="where" >
  135. </div>
  136. <div style="width:70%;float: left;">
  137. <input id="condition" class="layui-input" placeholder="如多个eci查询请用英文逗号隔开"
  138. style="border-width:1px;border-style: solid;border-color: #eee;"></input>
  139. </div>
  140. </div>
  141. </div>
  142. <div>
  143. <table id="demo" lay-filter="test" style="width: 200px;"></table>
  144. </div>
  145. </div>
  146. </div>
  147. </div>
  148. <script src="./js/jquery-3.5.1.min.js"></script>
  149. <script src="./js/layui/layui.js"></script>
  150. <script>
  151. var dataA;
  152. var layer;
  153. var tree;
  154. var table;
  155. layui.use(['layer', 'tree', 'form', 'laydate', 'table'], function () {
  156. tree = layui.tree;
  157. layer = layui.layer;
  158. table = layui.table;
  159. var form = layui.form, laydate = layui.laydate;
  160. // layer.msg('Hello Zhou')
  161. table.render({
  162. elem: '#demo',
  163. height: 480,
  164. // url: 'https://www.layui.com/demo/table/user/' , //数据接口
  165. page: true, //开启分页
  166. toolbar: true,
  167. defaultToolbar: [{
  168. title: '导出' //标题
  169. ,
  170. layEvent: 'export' //事件名,用于 toolbar 事件中使用
  171. ,
  172. icon: 'layui-icon-export' //图标类名
  173. }],
  174. limit: 50,
  175. limits: [50, 200, 500],
  176. cols: [],
  177. data: []
  178. });
  179. //工具条事件
  180. table.on('toolbar(test)', function (obj) { //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
  181. var data = obj.data; //获得当前行数据
  182. var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
  183. if (layEvent === 'export') {
  184. // layer.alert('Hi,头部工具栏扩展的右侧图标。');
  185. var tableData = table.cache['demo']
  186. obj.config.title = "地市指标"
  187. table.exportFile(obj.config.id, dataA, 'csv')
  188. }
  189. });
  190. laydate.render({
  191. elem: '#time1',
  192. type: 'datetime',
  193. range: true,
  194. });
  195. initTreeCity(tree)
  196. initTreeIndicator(tree)
  197. initTreeIndicatorTemplate(tree)
  198. // console.log(window.sessionStorage.getItem('userName'))
  199. $("#userName").text(window.sessionStorage.getItem('userName'))
  200. if(!window.sessionStorage.getItem('userName')){
  201. setTimeout(() => window.location.href = '/login', 1000)
  202. }
  203. })
  204. var treeCity;
  205. function initTreeCity(tree) {
  206. $.ajax({
  207. type: "POST",
  208. // url: '/api/json/citys.json',
  209. url: '/api/initTreeCitys',
  210. success: function (r) {
  211. if (r?.success) {
  212. treeCity = tree.render({
  213. elem: '#allArea',
  214. showCheckbox: true,
  215. accordion: true,
  216. id: 'Id1',
  217. data: r?.data
  218. });
  219. return
  220. }
  221. alert(r?.message ?? '发生错误了');
  222. }
  223. });
  224. }
  225. var treeIn;
  226. // 渲染指标模板
  227. function initTreeIndicatorTemplate(tree) {
  228. $.ajax({
  229. type: "POST",
  230. url: '/api/initTreeIndicatorTemplate',
  231. success: function (r) {
  232. if (r?.success) {
  233. treeIn = tree.render({
  234. elem: '#indicatorTemplate',
  235. showCheckbox: true,
  236. accordion: true,
  237. id: 'Id3',
  238. data: r?.data
  239. });
  240. return
  241. }
  242. alert(r?.message ?? '发生错误了');
  243. }
  244. });
  245. }
  246. function initTreeIndicator(tree) {
  247. $.ajax({
  248. type: "POST",
  249. url: '/api/initTreeIndicator',
  250. success: function (r) {
  251. if (r?.success) {
  252. treeIn = tree.render({
  253. elem: '#allIndicator',
  254. showCheckbox: true,
  255. accordion: true,
  256. id: 'Id2',
  257. data: r?.data
  258. });
  259. return
  260. }
  261. alert(r?.message ?? '发生错误了');
  262. }
  263. });
  264. }
  265. function renderTable(condition, searchType, table, citys, quxians, indicators, timeType, startTime, endTime) {
  266. var tishi = layer.load(1, {
  267. shadeClose: false,
  268. title: '加载中..',
  269. shade: [0.5,'#000'] //0.1透明度的白色背景
  270. });
  271. // setTimeout(()=>{
  272. // layer.close(tishi);
  273. // },5000)
  274. const dataJson = JSON.stringify({
  275. "condition": condition,
  276. "searchType": searchType,
  277. "citys": [...citys],
  278. "quxians": [...quxians],
  279. "indicators": [...indicators],
  280. "timeType": timeType,
  281. "startTime": startTime,
  282. "endTime": endTime
  283. })
  284. $.ajax({
  285. type: "POST",
  286. contentType: "application/json;charset=UTF-8",
  287. url: '/api/renderTable',
  288. data: dataJson,
  289. success: function (r) {
  290. layer.close(tishi);
  291. if (r?.success) {
  292. dataA = r?.data?.datas
  293. table.render({
  294. elem: '#demo',
  295. height: 480,
  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?.data?.cols ?? []
  310. ],
  311. data: r?.data?.datas ?? []
  312. });
  313. return
  314. }
  315. alert(r?.message ?? '发生错误了');
  316. },
  317. error: function(err){
  318. layer.close(tishi);
  319. }
  320. });
  321. }
  322. function search() {
  323. if ($('#time1').val() === 0) {
  324. alert('填选择时间')
  325. return;
  326. }
  327. if (tree.getChecked('Id3').length === 0) {
  328. alert('请选择指标')
  329. return;
  330. }
  331. let condition = $('#condition').val();
  332. let searchType = $('#searchType').find('input:checked').val()
  333. if (searchType === 'ECI' && $('#condition').val().length === 0) {
  334. alert('请填写eci')
  335. return;
  336. }
  337. if (searchType === 'AREA' && tree.getChecked('Id1').length === 0) {
  338. alert('请选择地市')
  339. return;
  340. }
  341. let checkData1 = tree?.getChecked('Id1')?.[0]?.children;
  342. let quxians = new Set()
  343. let citys = new Set()
  344. if (checkData1) {
  345. checkData1.forEach(eee => {
  346. citys.add(eee.title)
  347. eee?.children?.forEach(ee => {
  348. quxians.add(ee.title)
  349. })
  350. });
  351. }
  352. let checkData2 = tree.getChecked('Id3')[0].children;
  353. const indicators = new Set();
  354. checkData2.forEach(eee => {
  355. eee.children.forEach(ee => {
  356. indicators.add(ee.id)
  357. })
  358. });
  359. indicators.add('eci')
  360. let timeType = $('#timeType').val()
  361. let sdate = $('#time1').val()
  362. const [startTime, endTime] = sdate.split(' - ')
  363. renderTable(condition, searchType, table, citys, quxians, indicators, timeType, startTime, endTime)
  364. return false;
  365. }
  366. // 添加指标模板
  367. function addTemplate() {
  368. layer.open({
  369. type: 1,
  370. title:"添加指标模板",
  371. content: $("#add-template"),
  372. area: ['600px', '600px'],
  373. btn: ['确定'],
  374. shadeClose: true,
  375. yes: function(index, layero){
  376. const templateName = $('#templateName').val()
  377. if (!templateName || templateName.length <= 0) {
  378. alert('请输入模板名称!')
  379. return
  380. }
  381. const checkedData = tree?.getChecked('Id2')?.[0]?.children
  382. if (!checkedData || checkedData.length <= 0) {
  383. alert('请选择指标!')
  384. return
  385. }
  386. const indicators = new Set()
  387. checkedData.forEach(eee => {
  388. eee.children.forEach(ee => {
  389. indicators.add(ee.id)
  390. })
  391. });
  392. const dataJson = JSON.stringify({
  393. "templateName": templateName,
  394. "indicators": [...indicators],
  395. })
  396. $.ajax({
  397. type: "POST",
  398. contentType: "application/json;charset=UTF-8",
  399. url: '/api/addTemplate',
  400. data: dataJson,
  401. success: function (r) {
  402. if (r?.success) {
  403. initTreeIndicatorTemplate(tree)
  404. layer.msg('添加成功')
  405. layer.close(index)
  406. return
  407. }
  408. alert(r?.message ?? '发生错误了');
  409. }
  410. });
  411. },
  412. });
  413. }
  414. // 删除指标模板
  415. function deleteTemplate() {
  416. const checkedData = tree?.getChecked('Id3')?.[0]?.children
  417. if (!checkedData || checkedData.length <= 0) {
  418. alert('请选择要删除的指标模板!')
  419. return
  420. }
  421. const ids = new Set()
  422. checkedData.forEach(t => {
  423. ids.add(t.id)
  424. });
  425. const dataJson = JSON.stringify({
  426. "ids": [...ids],
  427. })
  428. layer.confirm('确认删除?', {icon: 3, title:'删除模板'}, function(index){
  429. $.ajax({
  430. type: "POST",
  431. contentType: "application/json;charset=UTF-8",
  432. url: '/api/deleteTemplate',
  433. // async: false,
  434. data: dataJson,
  435. success: function (r) {
  436. if (r?.success) {
  437. initTreeIndicatorTemplate(tree)
  438. layer.msg('删除成功')
  439. layer.close(index)
  440. return
  441. }
  442. alert(r?.message ?? '发生错误了')
  443. }
  444. });
  445. });
  446. }
  447. // 获取登录用户信息
  448. // 退出登录
  449. function logOutFun() {
  450. console.log('tuichu')
  451. $.ajax({
  452. type: "POST",
  453. // url: '/api/json/citys.json',
  454. url: '/api/logout',
  455. success: function (r) {
  456. console.log('r: ', r);
  457. if (r?.success) {
  458. layer.msg('退出登录成功');
  459. setTimeout(() => window.location.href = '/login', 1000)
  460. }else{
  461. alert('退出登录失败');
  462. }
  463. }
  464. });
  465. }
  466. //
  467. $(document).ready(function(){
  468. setTimeout(()=>{
  469. $(".layui-tree-txt").mouseenter(function(){
  470. // console.log('this',this)
  471. $(this).attr("title",$(this).text());
  472. // console.log('this.text(): ', $(this).text());
  473. });
  474. },1000)
  475. });
  476. window.onbeforeunload=function(e){
  477. logOutFun()
  478. }
  479. // window.addEventListener('unload',logOutFun());
  480. </script>
  481. </body>
  482. </html>