template.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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.localStorage.getItem('userName'))
  199. $("#userName").text(window.localStorage.getItem('userName'))
  200. })
  201. var treeCity;
  202. function initTreeCity(tree) {
  203. $.ajax({
  204. type: "POST",
  205. // url: '/api/json/citys.json',
  206. url: '/api/initTreeCitys',
  207. success: function (r) {
  208. if (r?.success) {
  209. treeCity = tree.render({
  210. elem: '#allArea',
  211. showCheckbox: true,
  212. accordion: true,
  213. id: 'Id1',
  214. data: r?.data
  215. });
  216. return
  217. }
  218. alert(r?.message ?? '发生错误了');
  219. }
  220. });
  221. }
  222. var treeIn;
  223. // 渲染指标模板
  224. function initTreeIndicatorTemplate(tree) {
  225. $.ajax({
  226. type: "POST",
  227. url: '/api/initTreeIndicatorTemplate',
  228. success: function (r) {
  229. if (r?.success) {
  230. treeIn = tree.render({
  231. elem: '#indicatorTemplate',
  232. showCheckbox: true,
  233. accordion: true,
  234. id: 'Id3',
  235. data: r?.data
  236. });
  237. return
  238. }
  239. alert(r?.message ?? '发生错误了');
  240. }
  241. });
  242. }
  243. function initTreeIndicator(tree) {
  244. $.ajax({
  245. type: "POST",
  246. url: '/api/initTreeIndicator',
  247. success: function (r) {
  248. if (r?.success) {
  249. treeIn = tree.render({
  250. elem: '#allIndicator',
  251. showCheckbox: true,
  252. accordion: true,
  253. id: 'Id2',
  254. data: r?.data
  255. });
  256. return
  257. }
  258. alert(r?.message ?? '发生错误了');
  259. }
  260. });
  261. }
  262. function renderTable(condition, searchType, table, citys, quxians, indicators, timeType, startTime, endTime) {
  263. var tishi = layer.load(1, {
  264. shadeClose: false,
  265. title: '加载中..',
  266. shade: [0.5,'#000'] //0.1透明度的白色背景
  267. });
  268. // setTimeout(()=>{
  269. // layer.close(tishi);
  270. // },5000)
  271. const dataJson = JSON.stringify({
  272. "condition": condition,
  273. "searchType": searchType,
  274. "citys": [...citys],
  275. "quxians": [...quxians],
  276. "indicators": [...indicators],
  277. "timeType": timeType,
  278. "startTime": startTime,
  279. "endTime": endTime
  280. })
  281. $.ajax({
  282. type: "POST",
  283. contentType: "application/json;charset=UTF-8",
  284. url: '/api/renderTable',
  285. data: dataJson,
  286. success: function (r) {
  287. layer.close(tishi);
  288. if (r?.success) {
  289. dataA = r?.data?.datas
  290. table.render({
  291. elem: '#demo',
  292. height: 480,
  293. // url: 'https://www.layui.com/demo/table/user/' , //数据接口
  294. page: true, //开启分页
  295. toolbar: true,
  296. defaultToolbar: [{
  297. title: '提示' //标题
  298. ,
  299. layEvent: 'export' //事件名,用于 toolbar 事件中使用
  300. ,
  301. icon: 'layui-icon-export' //图标类名
  302. }],
  303. limit: 50,
  304. limits: [50, 200, 500],
  305. cols: [
  306. r?.data?.cols ?? []
  307. ],
  308. data: r?.data?.datas ?? []
  309. });
  310. return
  311. }
  312. alert(r?.message ?? '发生错误了');
  313. },
  314. error: function(err){
  315. layer.close(tishi);
  316. }
  317. });
  318. }
  319. function search() {
  320. if ($('#time1').val() === 0) {
  321. alert('填选择时间')
  322. return;
  323. }
  324. if (tree.getChecked('Id3').length === 0) {
  325. alert('请选择指标')
  326. return;
  327. }
  328. let condition = $('#condition').val();
  329. let searchType = $('#searchType').find('input:checked').val()
  330. if (searchType === 'ECI' && $('#condition').val().length === 0) {
  331. alert('请填写eci')
  332. return;
  333. }
  334. if (searchType === 'AREA' && tree.getChecked('Id1').length === 0) {
  335. alert('请选择地市')
  336. return;
  337. }
  338. let checkData1 = tree?.getChecked('Id1')?.[0]?.children;
  339. let quxians = new Set()
  340. let citys = new Set()
  341. if (checkData1) {
  342. checkData1.forEach(eee => {
  343. citys.add(eee.title)
  344. eee?.children?.forEach(ee => {
  345. quxians.add(ee.title)
  346. })
  347. });
  348. }
  349. let checkData2 = tree.getChecked('Id3')[0].children;
  350. const indicators = new Set();
  351. checkData2.forEach(eee => {
  352. eee.children.forEach(ee => {
  353. indicators.add(ee.id)
  354. })
  355. });
  356. indicators.add('eci')
  357. let timeType = $('#timeType').val()
  358. let sdate = $('#time1').val()
  359. const [startTime, endTime] = sdate.split(' - ')
  360. renderTable(condition, searchType, table, citys, quxians, indicators, timeType, startTime, endTime)
  361. return false;
  362. }
  363. // 添加指标模板
  364. function addTemplate() {
  365. layer.open({
  366. type: 1,
  367. title:"添加指标模板",
  368. content: $("#add-template"),
  369. area: ['600px', '600px'],
  370. btn: ['确定'],
  371. shadeClose: true,
  372. yes: function(index, layero){
  373. const templateName = $('#templateName').val()
  374. if (!templateName || templateName.length <= 0) {
  375. alert('请输入模板名称!')
  376. return
  377. }
  378. const checkedData = tree?.getChecked('Id2')?.[0]?.children
  379. if (!checkedData || checkedData.length <= 0) {
  380. alert('请选择指标!')
  381. return
  382. }
  383. const indicators = new Set()
  384. checkedData.forEach(eee => {
  385. eee.children.forEach(ee => {
  386. indicators.add(ee.id)
  387. })
  388. });
  389. const dataJson = JSON.stringify({
  390. "templateName": templateName,
  391. "indicators": [...indicators],
  392. })
  393. $.ajax({
  394. type: "POST",
  395. contentType: "application/json;charset=UTF-8",
  396. url: '/api/addTemplate',
  397. data: dataJson,
  398. success: function (r) {
  399. if (r?.success) {
  400. initTreeIndicatorTemplate(tree)
  401. layer.msg('添加成功')
  402. layer.close(index)
  403. return
  404. }
  405. alert(r?.message ?? '发生错误了');
  406. }
  407. });
  408. },
  409. });
  410. }
  411. // 删除指标模板
  412. function deleteTemplate() {
  413. const checkedData = tree?.getChecked('Id3')?.[0]?.children
  414. if (!checkedData || checkedData.length <= 0) {
  415. alert('请选择要删除的指标模板!')
  416. return
  417. }
  418. const ids = new Set()
  419. checkedData.forEach(t => {
  420. ids.add(t.id)
  421. });
  422. const dataJson = JSON.stringify({
  423. "ids": [...ids],
  424. })
  425. layer.confirm('确认删除?', {icon: 3, title:'删除模板'}, function(index){
  426. $.ajax({
  427. type: "POST",
  428. contentType: "application/json;charset=UTF-8",
  429. url: '/api/deleteTemplate',
  430. // async: false,
  431. data: dataJson,
  432. success: function (r) {
  433. if (r?.success) {
  434. initTreeIndicatorTemplate(tree)
  435. layer.msg('删除成功')
  436. layer.close(index)
  437. return
  438. }
  439. alert(r?.message ?? '发生错误了')
  440. }
  441. });
  442. });
  443. }
  444. // 获取登录用户信息
  445. // 退出登录
  446. function logOutFun() {
  447. console.log('tuichu')
  448. $.ajax({
  449. type: "POST",
  450. // url: '/api/json/citys.json',
  451. url: '/api/logout',
  452. success: function (r) {
  453. console.log('r: ', r);
  454. if (r?.success) {
  455. layer.msg('退出登录成功');
  456. setTimeout(() => window.location.href = '/login', 1000)
  457. }else{
  458. alert('退出登录失败');
  459. }
  460. }
  461. });
  462. }
  463. //
  464. $(document).ready(function(){
  465. setTimeout(()=>{
  466. $(".layui-tree-txt").mouseenter(function(){
  467. // console.log('this',this)
  468. $(this).attr("title",$(this).text());
  469. // console.log('this.text(): ', $(this).text());
  470. });
  471. },1000)
  472. });
  473. </script>
  474. </body>
  475. </html>