GeneratorData2.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. <!DOCTYPE html>
  2. <html class="x-admin-sm">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="renderer" content="webkit">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <meta name="viewport"
  8. content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
  9. <link rel="shortcut icon" href="/static/favicon.ico">
  10. <link rel="bookmark" href="/static/favicon.ico">
  11. <link rel="stylesheet" href="/static/css/font.css">
  12. <link rel="stylesheet" href="/static/css/xadmin.css">
  13. <script src="/static/js/jquery.min.js"></script>
  14. <script src="/static/js/jquery.cookie.min.js"></script>
  15. <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
  16. <script type="text/javascript" src="/static/js/xadmin.js"></script>
  17. <script src="/static/js/echarts.min.js"></script>
  18. </head>
  19. <body>
  20. <div class="x-nav">
  21. <span class="layui-breadcrumb">
  22. <a href="">首页</a>
  23. <a><cite>数据展示</cite></a>
  24. </span>
  25. <a class="layui-btn layui-btn-normal" style="line-height:1.6em;margin-top:3px;float:right"
  26. onclick="location.reload()" title="刷新">
  27. <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
  28. </a>
  29. </div>
  30. <div class="layui-fluid">
  31. <div class="layui-row" style="display: flex;">
  32. <!-- 传感器 选择 start-->
  33. <div style="width: 340px;">
  34. <div class="layui-card">
  35. <div class="layui-card-body ">
  36. <form class="layui-form layui-col-space5" οnsubmit="return false;">
  37. <div class="layui-input-inline layui-show-xs-block">
  38. <input value="" type="text" id="D_T_sn" name="D_T_sn" placeholder="请输入 SN"
  39. autocomplete="off"
  40. class="layui-input"></div>
  41. <div class="layui-input-inline layui-show-xs-block">
  42. <input value="" type="text" id="D_Name" name="D_Name" placeholder="请输入 传感器名称"
  43. autocomplete="off"
  44. class="layui-input"></div>
  45. <div class="layui-input-inline layui-show-xs-block" style="width: 168px">
  46. <select id="Class_1" name="Class_1">
  47. <option value=0>所有分类</option>
  48. {{range $index, $elem := .Class_List}}
  49. <option value={{$elem.Id}}>{{$elem.T_name}}</option>
  50. {{end}}
  51. </select>
  52. </div>
  53. <div class="layui-input-inline layui-show-xs-block">
  54. <div class="layui-btn layui-btn-normal"
  55. onclick="get_DeviceSensor_list(0)">
  56. <i class="layui-icon">&#xe615;</i></div>
  57. </div>
  58. </form>
  59. <hr>
  60. </div>
  61. <div class="layui-card-body " style="margin-top: -20px">
  62. <!-- <div class="layui-progress " >-->
  63. <!-- <div id="progress" class="layui-progress-bar layui-bg-blue" lay-percent="80%"></div>-->
  64. <!-- </div>-->
  65. <div id="DeviceSensor_list" style="width: 98%; overflow: hidden;max-height: 616px;overflow-y: auto">
  66. <div style="color: #1E9FFF;text-align: center;font-size: 15px;margin-top: 150px">加载中...</div>
  67. </div>
  68. </div>
  69. <div class="layui-card-body ">
  70. <div style="height: 70px">
  71. <div class="layui-card-body " style="text-align: center">
  72. <div class="layui-input-inline layui-show-xs-block">
  73. <div class="layui-btn layui-btn-normal"
  74. onclick="checkAll()">
  75. <i class="layui-icon">全选择</i>
  76. </div>
  77. </div>
  78. <div class="layui-input-inline layui-show-xs-block">
  79. <div class="layui-btn layui-btn-normal"
  80. onclick="checkCancel()">
  81. <i class="layui-icon">全取消</i>
  82. </div>
  83. </div>
  84. <div class="layui-input-inline layui-show-xs-block">
  85. <div class="layui-btn layui-btn-normal"
  86. onclick="checkReverse()">
  87. <i class="layui-icon">反选</i>
  88. </div>
  89. </div>
  90. <div style="color: #1E9FFF;text-align: center" id="DeviceSensor_list_Pages_x"></div>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. <!-- 传感器 选择 end-->
  97. <div style="padding-left: 15px; height: 100%;flex:1;">
  98. <div class="layui-card">
  99. <div class="layui-card-body">
  100. <div class="layui-inline">
  101. <div class="layui-input-inline">数据时间:</div>
  102. <div class="layui-input-inline">
  103. <input type="text" class="layui-input" id="startTime" placeholder="开始时间">
  104. </div>
  105. <span style="padding: 5px">~</span>
  106. <div class="layui-input-inline">
  107. <input type="text" class="layui-input" id="endTime" placeholder="结束时间">
  108. </div>
  109. <div class="layui-input-inline">
  110. <a class="layui-btn layui-btn-normal" onclick="loadEcharts()" title="刷新">
  111. <!-- <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>-->
  112. 加载
  113. </a>
  114. </div>
  115. </div>
  116. <div class="layui-inline " style="padding-left: 15px">
  117. <div class="layui-inline">选择时间:</div>
  118. <div class="layui-input-inline">
  119. <input type="text" class="layui-input" id="selectStartTime" placeholder="开始时间">
  120. </div>
  121. <span style="padding: 5px">~</span>
  122. <div class="layui-input-inline">
  123. <input type="text" class="layui-input " id="selectEndTime" placeholder="结束时间">
  124. </div>
  125. </div>
  126. </div>
  127. <div class="layui-inline">
  128. <!--按钮-->
  129. <div class="layui-clear" style="margin-left: 15px">
  130. <button onclick="offset()" class="layui-btn layui-btn-normal layui-btn-sm">偏移(固定)</button>
  131. <button onclick="offsetRandom()" class="layui-btn layui-btn-normal layui-btn-sm">偏移(随机)
  132. </button>
  133. <!-- <button onclick="copyFrom()" class="layui-btn layui-btn-normal layui-btn-sm">复制到</button>-->
  134. <button onclick="repair()" class="layui-btn layui-btn-normal layui-btn-sm">补漏</button>
  135. <button onclick="smooth()" class="layui-btn layui-btn-normal layui-btn-sm">平滑</button>
  136. <!-- <button onclick="trend()" class="layui-btn layui-btn-normal layui-btn-sm">趋势</button>-->
  137. <button onclick="Delete()" class="layui-btn layui-btn-normal layui-btn-sm">删除</button>
  138. <!-- <button onclick="importExcel()" class="layui-btn layui-btn-normal">导入表格</button>-->
  139. </div>
  140. </div>
  141. <hr>
  142. <div class="layui-card-body" id="echartsBox" style="height: 100%">
  143. </div>
  144. </div>
  145. </div>
  146. </div>
  147. </div>
  148. <!--固定偏移-->
  149. <div style="display: none;padding: 20px" id="offsetFix">
  150. <div class="layui-form">
  151. <div class="layui-form-item">
  152. 温度:
  153. <input type="number" class="layui-input" lay-verify="number" placeholder="固定下调温度" id="fixTemperature"
  154. value="0">
  155. </div>
  156. <div class="layui-form-item">
  157. 湿度:
  158. <input type="number" class="layui-input" lay-verify="number" placeholder="固定下调湿度" id="fixHumidity"
  159. value="0">
  160. </div>
  161. </div>
  162. </div>
  163. <!--随机偏移-->
  164. <div style="display: none;padding: 20px;justify-content: center" id="offsetRand">
  165. <div class="layui-form">
  166. <div class="layui-form-item " style="display: flex;align-items: center">
  167. 温度:
  168. <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
  169. placeholder="温度min"
  170. id="temperatureStart">
  171. <span style="padding-right: 10px">~</span>
  172. <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
  173. placeholder="温度max"
  174. id="temperatureEnd">
  175. </div>
  176. <div class="layui-form-item" style="display: flex;align-items: center">
  177. 湿度:
  178. <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
  179. placeholder="湿度min"
  180. id="humidityStart">
  181. <span style="padding-right: 10px">~</span>
  182. <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
  183. placeholder="湿度max"
  184. id="humidityEnd">
  185. </div>
  186. </div>
  187. </div>
  188. <!--复制移动-->
  189. <div id="copyMove" style="display: none;padding: 20px">
  190. <div class="layui-form" style="display: flex;justify-content: center;flex-direction: column">
  191. <div id="copyInfo">
  192. 您选择的了从 2023-01-01 00:00:00 ~ 2023-01-02 23:59:59 共 100条记录
  193. </div>
  194. <div>
  195. <input class="layui-input" type="text" id="copyPosition" placeholder="拷贝到的开始时间">
  196. </div>
  197. </div>
  198. </div>
  199. <!--数据补漏-->
  200. <div id="dataRepair" style="padding: 20px;display: none">
  201. 发现了缺少100条数据,确认需要补充数据吗?
  202. </div>
  203. <!--数据补漏-->
  204. <div id="Delete" style="padding: 20px;display: none">
  205. 确认删除数据吗?
  206. </div>
  207. <div style="display: none;padding: 20px;justify-content: center" id="smoothBox">
  208. <div class="layui-form">
  209. <div class="layui-form-item " style="display: flex;align-items: center">
  210. 温度浮动范围:
  211. <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
  212. placeholder="温度浮动范围"
  213. id="temperatureRange">
  214. </div>
  215. <div class="layui-form-item" style="display: flex;align-items: center">
  216. 湿度浮动范围:
  217. <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
  218. placeholder="湿度浮动范围" id="humidityRange">
  219. </div>
  220. </div>
  221. </div>
  222. <!--数据导入-->
  223. <div id="importDataBox" style="display: none;padding: 20px;width: 300px">
  224. <div class="layui-form">
  225. <button onclick="document.getElementById('excelInput').click()" class="layui-btn layui-btn-danger">
  226. 选择文件
  227. </button>
  228. <span id="fileName"></span>
  229. <input type="file" id="excelInput" style="display: none" class="layui-input" placeholder="选择上传文件!">
  230. </div>
  231. </div>
  232. <script>
  233. //温度数据
  234. let temperatureData = []
  235. //湿度数据
  236. let humidityData = []
  237. //当页面加载完毕后会执行的函数
  238. $(function () {
  239. //初始化页面元素
  240. layui.use(['laydate', 'form', 'element'], function () {
  241. let laydate = layui.laydate
  242. laydate.render({
  243. elem: '#startTime',
  244. type: 'datetime',
  245. value: new Date(new Date().setUTCDate(new Date().getDate() - 1))
  246. })
  247. laydate.render({
  248. elem: '#endTime',
  249. type: 'datetime',
  250. value: new Date()
  251. })
  252. laydate.render({
  253. elem: '#selectStartTime',
  254. type: 'datetime',
  255. done: function(value){
  256. onTimeRangeChange(value, selectEndTime.value);
  257. }
  258. })
  259. laydate.render({
  260. elem: '#selectEndTime',
  261. type: 'datetime',
  262. done: function(value){
  263. onTimeRangeChange(selectStartTime.value, value);
  264. }
  265. })
  266. laydate.render({
  267. elem: '#copyPosition',
  268. type: 'datetime',
  269. })
  270. })
  271. //添加图
  272. // addCharts()
  273. //获取设备探头列表
  274. get_DeviceSensor_list(0)
  275. })
  276. //获取设备探头列表
  277. function get_DeviceSensor_list(page) {
  278. T_sn = $("#D_T_sn").val();
  279. T_name = $("#D_Name").val();
  280. T_class_id = $("#Class_1").val();
  281. $.ajax({
  282. type: 'POST',
  283. url: '/Data/Device_Sensor_List',//发送请求
  284. data: {
  285. User_tokey: $.cookie("User_tokey"),
  286. T_sn: T_sn,
  287. T_name: T_name,
  288. T_class_id: parseInt(T_class_id),
  289. page: page,
  290. page_z: 1000,
  291. },
  292. success: function (result) {
  293. console.log(result)
  294. if (result.Code == 200) {
  295. if (page == 0)
  296. $('#DeviceSensor_list').html("")
  297. // $('#DeviceSensor_list_Pages').html("")
  298. // $('#DeviceSensor_list_Pages_x').html("")
  299. DeviceSensor_lite = result.Data.DeviceSensor_lite
  300. if (DeviceSensor_lite.length == 0) {
  301. $('#DeviceSensor_list').html("<div style=\"color: #1E9FFF;text-align: center;font-size: 15px;margin-top: 150px\">没有设备</div>")
  302. return
  303. }
  304. Add_DeviceSensor_list(result.Data.DeviceSensor_lite) // 列表
  305. // Add_DeviceSensor_list_Pages(result.Data.Pages) // 分页
  306. $('#DeviceSensor_list_Pages_x').html(" 传感器 总数:" + result.Data.Num);
  307. if (result.Data.Page_size > result.Data.Page) {
  308. get_DeviceSensor_list(result.Data.Page + 1)
  309. }
  310. } else {
  311. }
  312. }
  313. });
  314. return false
  315. }
  316. var T_name = ""
  317. var T_sn = ""
  318. var T_class_id = 0
  319. var T_id = 0
  320. var T_sn_T_id = ""
  321. var Time_start = ""
  322. var Time_end = ""
  323. //添加设备探头数据
  324. function Add_DeviceSensor_list(DS_lite) {
  325. for (let i = 0; i < DS_lite.length; i++) {
  326. if (T_id == 0) {
  327. T_id = DS_lite[i].T_id;
  328. T_sn_T_id = DS_lite[i].T_sn;
  329. }
  330. $('#DeviceSensor_list').append(`
  331. <div style="display: flex; user-select: none;align-items: center;" class="layui-row">
  332. <input type="checkbox" data-sn="${DS_lite[i].T_sn}" data-id="${DS_lite[i].T_id}" style="width: 18px;height: 18px">
  333. <img src="/static/images/温湿度传感器-1.png" height="50" width="50" alt="">
  334. <div style="display: flex;flex-direction: column;margin-left: 10px">
  335. <div>${DS_lite[i].T_name}</div>
  336. <div>${DS_lite[i].T_sn}</div>
  337. </div>
  338. </div>
  339. `)
  340. }
  341. }
  342. //修改选择状态
  343. function changeCheckStatus(event) {
  344. let check = $(event).find("> input[type='checkbox']");
  345. check.prop('checked', !check.prop('checked'))
  346. }
  347. //全选
  348. function checkAll() {
  349. $('#DeviceSensor_list > div > input[type="checkbox"]').each((index, item) => {
  350. $(item).prop('checked', true)
  351. })
  352. }
  353. //反选
  354. function checkReverse() {
  355. $('#DeviceSensor_list > div > input[type="checkbox"]').each((index, item) => {
  356. $(item).prop('checked', !$(item).prop('checked'))
  357. })
  358. }
  359. //取消全选
  360. function checkCancel() {
  361. $('#DeviceSensor_list > div > input[type="checkbox"]').each((index, item) => {
  362. $(item).prop('checked', false)
  363. })
  364. }
  365. //获取选择的sn
  366. function getSelectedSn() {
  367. let sns = []
  368. $('#DeviceSensor_list > div > input[type="checkbox"]').each((index, item) => {
  369. let dom = $(item)
  370. if (dom.prop('checked')) {
  371. let sn = dom.attr('data-sn')
  372. let id = dom.attr('data-id')
  373. sns.push([sn, id])
  374. }
  375. })
  376. return sns
  377. }
  378. let chartsData = new Map()
  379. //加载图
  380. function loadEcharts() {
  381. //1.获取选中的设备
  382. let sns = getSelectedSn()
  383. //1.1是否选有设备选中
  384. if (sns.length === 0) {
  385. layui.layer.msg('没有选中操作设备!')
  386. return
  387. }
  388. let startTime = $('#startTime').val()
  389. let endTime = $('#endTime').val()
  390. //2.请求对应设备数据
  391. let index = loading();
  392. $.ajax({
  393. type: "POST",
  394. url: "/Data/DeviceSensorData",
  395. data: {
  396. sns: JSON.stringify(sns),
  397. startTime: startTime,
  398. endTime: endTime,
  399. },
  400. success: function (rlt) {
  401. layui.layer.close(index)
  402. if (rlt.Code === 200) {
  403. //2.1清空图
  404. $('#echartsBox').html('');
  405. //2.2添加图
  406. /*
  407. for (let v of rlt.Data) {
  408. chartsData.set(v.sn.join('|'), v)
  409. addCharts(v)
  410. // console.log(v)
  411. }
  412. */
  413. handleEchartData(rlt.Data)
  414. }
  415. layui.layer.msg(rlt.Msg)
  416. }
  417. })
  418. }
  419. //处理图的数据
  420. let temperatureChar = null
  421. let humidityChar = null
  422. function handleEchartData(data) {
  423. //1.将图中数据分开
  424. let temperatureList = []
  425. let humidityList = []
  426. for (let v of data) {
  427. let t = []
  428. let h = []
  429. if (v.data == null) continue
  430. for (let val of v.data) {
  431. t.push([val.t_time, val.t_t])
  432. h.push([val.t_time, val.t_rh])
  433. }
  434. temperatureList.push([v.sn.join(' | '), t])
  435. humidityList.push([v.sn.join(' | '), h])
  436. chartsData.set(v.sn.join(' | '), v)
  437. }
  438. temperatureChar = addCharts(temperatureList, '温度t_t', 'temperature', true)
  439. humidityChar = addCharts(humidityList, '湿度t_rh', 'humidity', false)
  440. }
  441. var myChar;
  442. //添加图
  443. function addCharts(data, name, type, show) {
  444. //没有数据
  445. if (data == null || data.length === 0) {
  446. return null
  447. }
  448. //获取容器
  449. let eChartsBox = $('#echartsBox')[0]
  450. //设置要放置图的框架
  451. let eChar = $(`<div class="layui-row" style="width: 100%;height: 500px"></div>`)[0]
  452. eChartsBox.appendChild(eChar)
  453. //初始化
  454. myChar = echarts.init(eChar)
  455. // myChart=myChar
  456. //图标配置选项
  457. let options = {
  458. title: {
  459. text: name
  460. },
  461. grid: {
  462. left: '10%',
  463. right: '10%',
  464. // containLabel: true,
  465. // width: '100%',
  466. // x: '35px',
  467. // y: '40px'
  468. },
  469. xAxis: {
  470. type: 'time',
  471. splitLine: {
  472. show: false
  473. }
  474. },
  475. yAxis: {
  476. type: 'value',
  477. splitLine: {
  478. show: false
  479. },
  480. },
  481. toolbox: {
  482. feature: {
  483. restore: {},
  484. }
  485. },
  486. dataZoom: [
  487. {
  488. type: 'inside',
  489. start: 0,
  490. end: 100
  491. },
  492. {
  493. start: 0,
  494. end: 100
  495. }
  496. ],
  497. tooltip: {
  498. trigger: 'axis',
  499. formatter: function (params) {
  500. let v = params[0]
  501. return `${v.seriesName}\n
  502. 时间:${v.data[0]} 数据:${v.data[1]}`
  503. },
  504. // position: function (pt) {
  505. // return [pt[0], '10%'];
  506. // }
  507. },
  508. brush: {
  509. xAxisIndex: 0,
  510. toolbox: ['lineX', 'keep', 'clear'],
  511. brushMode: 'multiple',
  512. throttleType: 'debounce',
  513. throttleDelay: 600
  514. },
  515. series: []
  516. }
  517. for (let v of data) {
  518. console.log(v)
  519. options.series.push({
  520. name: v[0],
  521. data: v[1],
  522. type: 'line',
  523. })
  524. }
  525. if (!show) {
  526. options.dataZoom[1]["show"] = false
  527. options.toolbox = null
  528. options.brush = null
  529. }
  530. console.log(options)
  531. //设置参数
  532. myChar.setOption(options)
  533. //设置选中后的函数
  534. myChar.on('brushSelected', brushSelected)
  535. myChar.on('dataZoom', brushDataZoom)
  536. return myChar
  537. }
  538. function brushDataZoom(param) {
  539. console.log(param)
  540. let option = humidityChar.getOption();
  541. if (param.start !== undefined) {
  542. option.dataZoom[0].start = param.start
  543. option.dataZoom[0].end = param.end
  544. } else {
  545. option.dataZoom[0].start = param.batch[0].start
  546. option.dataZoom[0].end = param.batch[0].end
  547. }
  548. humidityChar.setOption(option)
  549. }
  550. //图获取选中数据
  551. let timeRange = []
  552. function brushSelected(param) {
  553. if (!param.batch || !param.batch[0] || !param.batch[0].areas || !param.batch[0].areas[0]) {
  554. return; // 如果参数不完整,直接返回避免错误
  555. }
  556. let coordRange = param.batch[0].areas[0].coordRange;
  557. timeRange = [Math.floor(coordRange[0]), Math.floor(coordRange[1])];
  558. $("#selectStartTime").val(dateFormat(new Date(timeRange[0])));
  559. $("#selectEndTime").val(dateFormat(new Date(timeRange[1])));
  560. }
  561. function onTimeRangeChange(startTimeStr, endTimeStr) {
  562. var startTime = new Date(startTimeStr).getTime();
  563. var endTime = new Date(endTimeStr).getTime();
  564. console.log("============")
  565. console.log(startTime, endTime)
  566. if (startTime > endTime) {
  567. alert("开始时间不能大于结束时间");
  568. return;
  569. }
  570. // 清除现有的画刷区域(如果存在)
  571. myChar.dispatchAction({
  572. type: 'brush',
  573. areas: [] // 清空画刷区域
  574. });
  575. console.log("前:",myChar.getOption())
  576. // 设置新的画刷区域
  577. myChar.dispatchAction({
  578. type: 'brush',
  579. areas: [{
  580. brushType: 'lineX',
  581. range: [startTime, endTime]
  582. }]
  583. });
  584. console.log("后:",myChar.getOption())
  585. }
  586. //温湿度偏移
  587. function offset() {
  588. if (timeRange.length === 0) {
  589. layui.layer.msg('请在图中选择要操作数据的区域!')
  590. return
  591. }
  592. //2.layer 打开一个窗口设置要统一设置下移的数据
  593. layui.layer.open({
  594. type: 1,
  595. area: ['300px', '270px'],
  596. content: $('#offsetFix'),
  597. btn: '确定',
  598. btnAlign: 'c',
  599. yes: function (index, elem) {
  600. let fixTemperature = $('#fixTemperature').val();
  601. let fixHumidity = $('#fixHumidity').val();
  602. if (fixHumidity === "" || fixTemperature === "") {
  603. //提示消息
  604. layui.layer.msg("没有设置固定温湿度偏移")
  605. return
  606. }
  607. //3.发送修改数据区域进行循环对值进行统一下调
  608. let index2 = loading();
  609. $.ajax({
  610. type: 'POST',
  611. url: '/Data/UpdateFix',
  612. data: JSON.stringify({
  613. fixTemperature: fixTemperature,
  614. fixHumidity: fixHumidity,
  615. sns: getSelectedSn(),
  616. data: timeRange
  617. }),
  618. contentType: 'application/json;charset=utf-8',
  619. processData: false,
  620. success: function (rlt) {
  621. layui.layer.close(index2)
  622. if (rlt.Code === 200) {
  623. //3.1判断是否处理成功
  624. //3.1.1成功更新该设备的数据
  625. timeRange = []
  626. loadEcharts()
  627. layui.layer.close(index)
  628. }
  629. //提示消息
  630. layui.layer.msg(rlt.Msg)
  631. }
  632. })
  633. }
  634. })
  635. }
  636. //删除
  637. function Delete() {
  638. if (timeRange.length === 0) {
  639. layui.layer.msg('请在图中选择要操作数据的区域!')
  640. return
  641. }
  642. //2.layer 打开一个窗口设置要统一设置下移的数据
  643. layui.layer.open({
  644. type: 1,
  645. area: ['300px', '270px'],
  646. content: $('#Delete'),
  647. btn: '确定',
  648. btnAlign: 'c',
  649. yes: function (index, elem) {
  650. //3.发送修改数据区域进行循环对值进行统一下调
  651. let index2 = loading();
  652. $.ajax({
  653. type: 'POST',
  654. url: '/Data/Delete',
  655. data: JSON.stringify({
  656. sns: getSelectedSn(),
  657. data: timeRange
  658. }),
  659. contentType: 'application/json;charset=utf-8',
  660. processData: false,
  661. success: function (rlt) {
  662. layui.layer.close(index2)
  663. if (rlt.Code === 200) {
  664. //3.1判断是否处理成功
  665. //3.1.1成功更新该设备的数据
  666. timeRange = []
  667. loadEcharts()
  668. layui.layer.close(index)
  669. }
  670. //提示消息
  671. layui.layer.msg(rlt.Msg)
  672. }
  673. })
  674. }
  675. })
  676. }
  677. //温湿度随机偏移
  678. function offsetRandom() {
  679. if (timeRange.length === 0) {
  680. layui.layer.msg('请在图中选择要操作数据的区域!')
  681. return
  682. }
  683. layui.layer.open({
  684. type: 1,
  685. area: ['520px', '240px'],
  686. content: $('#offsetRand'),
  687. btn: '确定',
  688. btnAlign: 'c',
  689. yes: function (index, elem) {
  690. let t_s = Number.parseFloat($('#temperatureStart').val()) * 100
  691. let t_e = Number.parseFloat($('#temperatureEnd').val()) * 100
  692. let h_s = Number.parseFloat($('#humidityStart').val()) * 100
  693. let h_e = Number.parseFloat($('#humidityEnd').val()) * 100
  694. if (!t_s && !t_e && !h_s && !h_e) {
  695. layui.layer.msg('随机值设置错误!因该从最小到最大!')
  696. return
  697. }
  698. let index2 = loading();
  699. $.ajax({
  700. type: 'POST',
  701. url: '/Data/UpdateRand',
  702. data: JSON.stringify({
  703. temperatureMax: Math.max(Math.floor(t_e), Math.floor(t_s)),
  704. temperatureMin: Math.min(Math.floor(t_e), Math.floor(t_s)),
  705. humidityMax: Math.max(Math.floor(h_e), Math.floor(h_s)),
  706. humidityMin: Math.min(Math.floor(h_e), Math.floor(h_s)),
  707. sns: getSelectedSn(),
  708. data: timeRange
  709. }),
  710. contentType: "application/json;charset=utf-8",
  711. processData: false,
  712. success: function (rlt) {
  713. layui.layer.close(index2)
  714. if (rlt.Code === 200) {
  715. //操作成功
  716. layui.layer.close(index)
  717. rangeData = []
  718. loadEcharts()
  719. }
  720. layui.layer.msg(rlt.Msg)
  721. }
  722. })
  723. }
  724. })
  725. //2.layer 打开一个窗口设置随机值范围,温湿度
  726. //3.发送修改数据区域进行循环对值进行随机值统一下调(layer点击确定之后)
  727. //3.1判断是否处理成功
  728. //3.1.1成功更新该设备的数据
  729. //3.1.2失败提示
  730. }
  731. //复制时间段内的数据到另一个时间段
  732. function copyFrom() {
  733. if (timeRange.length === 0) {
  734. layui.layer.msg('请在图中选择要操作数据的区域!')
  735. return
  736. }
  737. //2.layer 提示选区的内容条目数,选区内的开始时间和结束时间(可以进行修改)(layer点击确定之后),要复制到的区域时间
  738. $('#copyInfo').html(`<p style="color: red">${dateFormat(new Date(timeRange[0]))} ~ ${dateFormat(new Date(timeRange[1]))}</p>`)
  739. layui.layer.open({
  740. type: 1,
  741. title: '数据复制(指定开始时间)',
  742. areas: ['300px', '200px'],
  743. content: $('#copyMove'),
  744. btn: '确定',
  745. btnAlign: 'c',
  746. yes: function (index, elem) {
  747. let copyPosition = $('#copyPosition').val();
  748. if (copyPosition === '') {
  749. layui.layer.msg('复制到时间节点不能为空!', {icon: 6})
  750. return
  751. }
  752. let index2 = loading();
  753. $.ajax({
  754. type: "POST",
  755. url: "/Data/CopyFromPosition",
  756. data: JSON.stringify({
  757. copyPosition: copyPosition,
  758. sns: getSelectedSn(),
  759. data: timeRange
  760. }),
  761. processData: false,
  762. contentType: "application/json;charset=utf-8",
  763. success: function (rlt) {
  764. layui.layer.close(index2)
  765. if (rlt.Code === 200) {
  766. layui.layer.close(index)
  767. }
  768. layui.layer.msg(rlt.Msg, {icon: 1})
  769. }
  770. })
  771. }
  772. })
  773. }
  774. //补漏数据
  775. function repair() {
  776. if (timeRange.length === 0) {
  777. layui.layer.msg('请在图中选择要操作数据的区域!')
  778. return
  779. }
  780. let index2 = loading();
  781. layui.layer.confirm(`确认对${dateFormat(new Date(timeRange[0]))}~${dateFormat(new Date(timeRange[1]))} 时间的数据进行查询补漏吗?`, function (index) {
  782. $.ajax({
  783. type: "POST",
  784. url: '/Data/RepairSensorData',
  785. data: {
  786. sns: JSON.stringify(getSelectedSn()),
  787. data: JSON.stringify(timeRange)
  788. },
  789. success: function (rlt) {
  790. layui.layer.close(index2)
  791. if (rlt.Code === 200) {
  792. layui.layer.close(index)
  793. loadEcharts()
  794. }
  795. layui.layer.msg(rlt.Msg)
  796. },
  797. error: function(xhr, status, error) {
  798. layui.layer.close(index2); // 确保在AJAX请求失败时也关闭加载提示
  799. layui.layer.msg('数据补漏请求出错!');
  800. }
  801. });
  802. },function(index) {
  803. layui.layer.close(index2); // 用户点击取消时,关闭加载提示
  804. layui.layer.close(index); //
  805. });
  806. //3.需要补漏,则将数据处理后生成中间缺失的数据发送到服务
  807. //4.提示结果,成功刷新
  808. }
  809. //选区内做平滑
  810. function smooth() {
  811. if (timeRange.length === 0) {
  812. layui.layer.msg('请在图中选择要操作数据的区域!')
  813. return
  814. }
  815. //2.获取选区内的最开始第一条数据和最后一条数据,中间存在多少条数据,
  816. if (timeRange.length === 0) {
  817. layui.layer.msg('请在图中选择要操作数据的区域!')
  818. return
  819. }
  820. layui.layer.open({
  821. type: 1,
  822. area: ['300px', '240px'],
  823. content: $('#smoothBox'),
  824. btn: '提交',
  825. btnAlign: 'c',
  826. yes: function (index, elem) {
  827. let index2 = loading();
  828. $.ajax({
  829. type: "POST",
  830. url: "/Data/DataSensorDataSmooth",
  831. data: {
  832. sns: JSON.stringify(getSelectedSn()),
  833. data: JSON.stringify(timeRange),
  834. tRange: Number.parseFloat($('#temperatureRange').val()),
  835. hRange: Number.parseFloat($('#humidityRange').val()),
  836. },
  837. success: function (rlt) {
  838. layui.layer.close(index2)
  839. if (rlt.Code === 200) {
  840. layui.layer.close(index)
  841. loadEcharts()
  842. }
  843. layui.layer.msg(rlt.Msg)
  844. }
  845. })
  846. }
  847. })
  848. //count = (time_end -time_start) / time_threshold
  849. //(temperature_end - temperature_start) / count
  850. //3.生成数据发送,判断是否发送成功数据
  851. }
  852. //趋势
  853. function trend() {
  854. if (timeRange.length === 0) {
  855. layui.layer.msg('请在图中选择要操作数据的区域!')
  856. return
  857. }
  858. layui.layer.confirm("1.确保数据没有存在遗漏!\n2.确定对选区做数据趋势吗?", function (index) {
  859. let index2 = loading();
  860. $.ajax({
  861. type: "POST",
  862. url: "/Data/DataSensorDataTrend",
  863. data: {
  864. sns: JSON.stringify(getSelectedSn()),
  865. data: JSON.stringify(timeRange),
  866. },
  867. success: function (rlt) {
  868. layui.layer.close(index2)
  869. if (rlt.Code === 200) {
  870. layui.layer.close(index)
  871. loadEcharts()
  872. }
  873. layui.layer.msg(rlt.Msg)
  874. }
  875. })
  876. })
  877. }
  878. //导入excel
  879. function importExcel() {
  880. let sns = getSelectedSn();
  881. if (sns.length === 0) {
  882. //没有选择设备
  883. layui.layer.msg("没有选择设备,请选择设备后再执行导入!")
  884. return
  885. }
  886. $('#excelInput').change(function () {
  887. let f = this.files[0]
  888. let suffix = f.name.split(".")[1];
  889. if (suffix !== 'xlsx' && suffix !== 'xls') {
  890. layui.layer.msg("上传文件必须为 excel 类型的文件")
  891. this.files[0] = null
  892. return
  893. }
  894. $('#fileName').text(f.name)
  895. })
  896. //1.弹出需要导入的页面
  897. layui.layer.open({
  898. type: 1,
  899. title: '导入数据',
  900. areas: ['400px', '300px'],
  901. content: $('#importDataBox'),
  902. btn: '提交',
  903. btnAlign: 'c',
  904. yes: function (index, elem) {
  905. let data = new FormData()
  906. let file = $('#excelInput')[0].files[0];
  907. console.log(file.name)
  908. data.set("file", file)
  909. data.set("sn", sns.join("|"))
  910. let index2 = loading();
  911. $.ajax({
  912. type: "POST",
  913. url: "/Data/ImportSensorData",
  914. data: data,
  915. contentType: false,
  916. processData: false,
  917. success: function (rlt) {
  918. layui.layer.close(index2)
  919. if (rlt.Code === 200) {
  920. layui.layer.close(index)
  921. }
  922. layui.layer.msg(rlt.Msg)
  923. }
  924. })
  925. }
  926. })
  927. //判断是否有存在文件,文件后缀是否正确
  928. //如果正确则上传到服务器处理
  929. //2.提示处理结果
  930. }
  931. function dateFormat(date) {
  932. date.setHours(date.getHours() + 8);
  933. let year = date.getUTCFullYear();
  934. let month = date.getUTCMonth()+1;
  935. month = month < 10 ? `0${month}` : month
  936. let day = date.getUTCDate()
  937. day = day < 10 ? `0${day}` : day
  938. let hour = date.getUTCHours()
  939. hour = hour < 10 ? `0${hour}` : hour
  940. let minute = date.getUTCMinutes()
  941. minute = minute < 10 ? `0${minute}` : minute
  942. let second = date.getUTCSeconds()
  943. second = second < 10 ? `0${second}` : second
  944. return `${year}-${month}-${day} ${hour}:${minute}:${second}`
  945. }
  946. function loading() {
  947. return layui.layer.load("Loading...", {
  948. icon: 16,
  949. shade: 0.2
  950. })
  951. }
  952. </script>
  953. </body>
  954. </html>