123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008 |
- <!DOCTYPE html>
- <html class="x-admin-sm">
- <head>
- <meta charset="UTF-8">
- <meta name="renderer" content="webkit">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <meta name="viewport"
- content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
- <link rel="shortcut icon" href="/static/favicon.ico">
- <link rel="bookmark" href="/static/favicon.ico">
- <link rel="stylesheet" href="/static/css/font.css">
- <link rel="stylesheet" href="/static/css/xadmin.css">
- <script src="/static/js/jquery.min.js"></script>
- <script src="/static/js/jquery.cookie.min.js"></script>
- <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
- <script type="text/javascript" src="/static/js/xadmin.js"></script>
- <script src="/static/js/echarts.min.js"></script>
- </head>
- <body>
- <div class="x-nav">
- <span class="layui-breadcrumb">
- <a href="">首页</a>
- <a><cite>数据展示</cite></a>
- </span>
- <a class="layui-btn layui-btn-normal" style="line-height:1.6em;margin-top:3px;float:right"
- onclick="location.reload()" title="刷新">
- <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
- </a>
- </div>
- <div class="layui-fluid">
- <div class="layui-row" style="display: flex;">
- <!-- 传感器 选择 start-->
- <div style="width: 340px;">
- <div class="layui-card">
- <div class="layui-card-body ">
- <form class="layui-form layui-col-space5" οnsubmit="return false;">
- <div class="layui-input-inline layui-show-xs-block">
- <input value="" type="text" id="D_T_sn" name="D_T_sn" placeholder="请输入 SN"
- autocomplete="off"
- class="layui-input"></div>
- <div class="layui-input-inline layui-show-xs-block">
- <input value="" type="text" id="D_Name" name="D_Name" placeholder="请输入 传感器名称"
- autocomplete="off"
- class="layui-input"></div>
- <div class="layui-input-inline layui-show-xs-block" style="width: 168px">
- <select id="Class_1" name="Class_1">
- <option value=0>所有分类</option>
- {{range $index, $elem := .Class_List}}
- <option value={{$elem.Id}}>{{$elem.T_name}}</option>
- {{end}}
- </select>
- </div>
- <div class="layui-input-inline layui-show-xs-block">
- <div class="layui-btn layui-btn-normal"
- onclick="get_DeviceSensor_list(0)">
- <i class="layui-icon"></i></div>
- </div>
- </form>
- <hr>
- </div>
- <div class="layui-card-body " style="margin-top: -20px">
- <!-- <div class="layui-progress " >-->
- <!-- <div id="progress" class="layui-progress-bar layui-bg-blue" lay-percent="80%"></div>-->
- <!-- </div>-->
- <div id="DeviceSensor_list" style="width: 98%; overflow: hidden;max-height: 616px;overflow-y: auto">
- <div style="color: #1E9FFF;text-align: center;font-size: 15px;margin-top: 150px">加载中...</div>
- </div>
- </div>
- <div class="layui-card-body ">
- <div style="height: 70px">
- <div class="layui-card-body " style="text-align: center">
- <div class="layui-input-inline layui-show-xs-block">
- <div class="layui-btn layui-btn-normal"
- onclick="checkAll()">
- <i class="layui-icon">全选择</i>
- </div>
- </div>
- <div class="layui-input-inline layui-show-xs-block">
- <div class="layui-btn layui-btn-normal"
- onclick="checkCancel()">
- <i class="layui-icon">全取消</i>
- </div>
- </div>
- <div class="layui-input-inline layui-show-xs-block">
- <div class="layui-btn layui-btn-normal"
- onclick="checkReverse()">
- <i class="layui-icon">反选</i>
- </div>
- </div>
- <div style="color: #1E9FFF;text-align: center" id="DeviceSensor_list_Pages_x"></div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- 传感器 选择 end-->
- <div style="padding-left: 15px; height: 100%;flex:1;">
- <div class="layui-card">
- <div class="layui-card-body">
- <div class="layui-inline">
- <div class="layui-input-inline">数据时间:</div>
- <div class="layui-input-inline">
- <input type="text" class="layui-input" id="startTime" placeholder="开始时间">
- </div>
- <span style="padding: 5px">~</span>
- <div class="layui-input-inline">
- <input type="text" class="layui-input" id="endTime" placeholder="结束时间">
- </div>
- <div class="layui-input-inline">
- <a class="layui-btn layui-btn-normal" onclick="loadEcharts()" title="刷新">
- <!-- <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>-->
- 加载
- </a>
- </div>
- </div>
- <div class="layui-inline " style="padding-left: 15px">
- <div class="layui-inline">选择时间:</div>
- <div class="layui-input-inline">
- <input type="text" class="layui-input" id="selectStartTime" placeholder="开始时间">
- </div>
- <span style="padding: 5px">~</span>
- <div class="layui-input-inline">
- <input type="text" class="layui-input " id="selectEndTime" placeholder="结束时间">
- </div>
- </div>
- </div>
- <div class="layui-inline">
- <!--按钮-->
- <div class="layui-clear" style="margin-left: 15px">
- <button onclick="offset()" class="layui-btn layui-btn-normal layui-btn-sm">偏移(固定)</button>
- <button onclick="offsetRandom()" class="layui-btn layui-btn-normal layui-btn-sm">偏移(随机)
- </button>
- <!-- <button onclick="copyFrom()" class="layui-btn layui-btn-normal layui-btn-sm">复制到</button>-->
- <button onclick="repair()" class="layui-btn layui-btn-normal layui-btn-sm">补漏</button>
- <button onclick="smooth()" class="layui-btn layui-btn-normal layui-btn-sm">平滑</button>
- <!-- <button onclick="trend()" class="layui-btn layui-btn-normal layui-btn-sm">趋势</button>-->
- <button onclick="Delete()" class="layui-btn layui-btn-normal layui-btn-sm">删除</button>
- <!-- <button onclick="importExcel()" class="layui-btn layui-btn-normal">导入表格</button>-->
- </div>
- </div>
- <hr>
- <div class="layui-card-body" id="echartsBox" style="height: 100%">
- </div>
- </div>
- </div>
- </div>
- </div>
- <!--固定偏移-->
- <div style="display: none;padding: 20px" id="offsetFix">
- <div class="layui-form">
- <div class="layui-form-item">
- 温度:
- <input type="number" class="layui-input" lay-verify="number" placeholder="固定下调温度" id="fixTemperature"
- value="0">
- </div>
- <div class="layui-form-item">
- 湿度:
- <input type="number" class="layui-input" lay-verify="number" placeholder="固定下调湿度" id="fixHumidity"
- value="0">
- </div>
- </div>
- </div>
- <!--随机偏移-->
- <div style="display: none;padding: 20px;justify-content: center" id="offsetRand">
- <div class="layui-form">
- <div class="layui-form-item " style="display: flex;align-items: center">
- 温度:
- <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
- placeholder="温度min"
- id="temperatureStart">
- <span style="padding-right: 10px">~</span>
- <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
- placeholder="温度max"
- id="temperatureEnd">
- </div>
- <div class="layui-form-item" style="display: flex;align-items: center">
- 湿度:
- <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
- placeholder="湿度min"
- id="humidityStart">
- <span style="padding-right: 10px">~</span>
- <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
- placeholder="湿度max"
- id="humidityEnd">
- </div>
- </div>
- </div>
- <!--复制移动-->
- <div id="copyMove" style="display: none;padding: 20px">
- <div class="layui-form" style="display: flex;justify-content: center;flex-direction: column">
- <div id="copyInfo">
- 您选择的了从 2023-01-01 00:00:00 ~ 2023-01-02 23:59:59 共 100条记录
- </div>
- <div>
- <input class="layui-input" type="text" id="copyPosition" placeholder="拷贝到的开始时间">
- </div>
- </div>
- </div>
- <!--数据补漏-->
- <div id="dataRepair" style="padding: 20px;display: none">
- 发现了缺少100条数据,确认需要补充数据吗?
- </div>
- <!--数据补漏-->
- <div id="Delete" style="padding: 20px;display: none">
- 确认删除数据吗?
- </div>
- <div style="display: none;padding: 20px;justify-content: center" id="smoothBox">
- <div class="layui-form">
- <div class="layui-form-item " style="display: flex;align-items: center">
- 温度浮动范围:
- <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
- placeholder="温度浮动范围"
- id="temperatureRange">
- </div>
- <div class="layui-form-item" style="display: flex;align-items: center">
- 湿度浮动范围:
- <input type="number" value="0" class="layui-input layui-input-inline" lay-verify="number"
- placeholder="湿度浮动范围" id="humidityRange">
- </div>
- </div>
- </div>
- <!--数据导入-->
- <div id="importDataBox" style="display: none;padding: 20px;width: 300px">
- <div class="layui-form">
- <button onclick="document.getElementById('excelInput').click()" class="layui-btn layui-btn-danger">
- 选择文件
- </button>
- <span id="fileName"></span>
- <input type="file" id="excelInput" style="display: none" class="layui-input" placeholder="选择上传文件!">
- </div>
- </div>
- <script>
- //温度数据
- let temperatureData = []
- //湿度数据
- let humidityData = []
- //当页面加载完毕后会执行的函数
- $(function () {
- //初始化页面元素
- layui.use(['laydate', 'form', 'element'], function () {
- let laydate = layui.laydate
- laydate.render({
- elem: '#startTime',
- type: 'datetime',
- value: new Date(new Date().setUTCDate(new Date().getDate() - 1))
- })
- laydate.render({
- elem: '#endTime',
- type: 'datetime',
- value: new Date()
- })
- laydate.render({
- elem: '#selectStartTime',
- type: 'datetime',
- done: function(value){
- onTimeRangeChange(value, selectEndTime.value);
- }
- })
- laydate.render({
- elem: '#selectEndTime',
- type: 'datetime',
- done: function(value){
- onTimeRangeChange(selectStartTime.value, value);
- }
- })
- laydate.render({
- elem: '#copyPosition',
- type: 'datetime',
- })
- })
- //添加图
- // addCharts()
- //获取设备探头列表
- get_DeviceSensor_list(0)
- })
- //获取设备探头列表
- function get_DeviceSensor_list(page) {
- T_sn = $("#D_T_sn").val();
- T_name = $("#D_Name").val();
- T_class_id = $("#Class_1").val();
- $.ajax({
- type: 'POST',
- url: '/Data/Device_Sensor_List',//发送请求
- data: {
- User_tokey: $.cookie("User_tokey"),
- T_sn: T_sn,
- T_name: T_name,
- T_class_id: parseInt(T_class_id),
- page: page,
- page_z: 1000,
- },
- success: function (result) {
- console.log(result)
- if (result.Code == 200) {
- if (page == 0)
- $('#DeviceSensor_list').html("")
- // $('#DeviceSensor_list_Pages').html("")
- // $('#DeviceSensor_list_Pages_x').html("")
- DeviceSensor_lite = result.Data.DeviceSensor_lite
- if (DeviceSensor_lite.length == 0) {
- $('#DeviceSensor_list').html("<div style=\"color: #1E9FFF;text-align: center;font-size: 15px;margin-top: 150px\">没有设备</div>")
- return
- }
- Add_DeviceSensor_list(result.Data.DeviceSensor_lite) // 列表
- // Add_DeviceSensor_list_Pages(result.Data.Pages) // 分页
- $('#DeviceSensor_list_Pages_x').html(" 传感器 总数:" + result.Data.Num);
- if (result.Data.Page_size > result.Data.Page) {
- get_DeviceSensor_list(result.Data.Page + 1)
- }
- } else {
- }
- }
- });
- return false
- }
- var T_name = ""
- var T_sn = ""
- var T_class_id = 0
- var T_id = 0
- var T_sn_T_id = ""
- var Time_start = ""
- var Time_end = ""
- //添加设备探头数据
- function Add_DeviceSensor_list(DS_lite) {
- for (let i = 0; i < DS_lite.length; i++) {
- if (T_id == 0) {
- T_id = DS_lite[i].T_id;
- T_sn_T_id = DS_lite[i].T_sn;
- }
- $('#DeviceSensor_list').append(`
- <div style="display: flex; user-select: none;align-items: center;" class="layui-row">
- <input type="checkbox" data-sn="${DS_lite[i].T_sn}" data-id="${DS_lite[i].T_id}" style="width: 18px;height: 18px">
- <img src="/static/images/温湿度传感器-1.png" height="50" width="50" alt="">
- <div style="display: flex;flex-direction: column;margin-left: 10px">
- <div>${DS_lite[i].T_name}</div>
- <div>${DS_lite[i].T_sn}</div>
- </div>
- </div>
- `)
- }
- }
- //修改选择状态
- function changeCheckStatus(event) {
- let check = $(event).find("> input[type='checkbox']");
- check.prop('checked', !check.prop('checked'))
- }
- //全选
- function checkAll() {
- $('#DeviceSensor_list > div > input[type="checkbox"]').each((index, item) => {
- $(item).prop('checked', true)
- })
- }
- //反选
- function checkReverse() {
- $('#DeviceSensor_list > div > input[type="checkbox"]').each((index, item) => {
- $(item).prop('checked', !$(item).prop('checked'))
- })
- }
- //取消全选
- function checkCancel() {
- $('#DeviceSensor_list > div > input[type="checkbox"]').each((index, item) => {
- $(item).prop('checked', false)
- })
- }
- //获取选择的sn
- function getSelectedSn() {
- let sns = []
- $('#DeviceSensor_list > div > input[type="checkbox"]').each((index, item) => {
- let dom = $(item)
- if (dom.prop('checked')) {
- let sn = dom.attr('data-sn')
- let id = dom.attr('data-id')
- sns.push([sn, id])
- }
- })
- return sns
- }
- let chartsData = new Map()
- //加载图
- function loadEcharts() {
- //1.获取选中的设备
- let sns = getSelectedSn()
- //1.1是否选有设备选中
- if (sns.length === 0) {
- layui.layer.msg('没有选中操作设备!')
- return
- }
- let startTime = $('#startTime').val()
- let endTime = $('#endTime').val()
- //2.请求对应设备数据
- let index = loading();
- $.ajax({
- type: "POST",
- url: "/Data/DeviceSensorData",
- data: {
- sns: JSON.stringify(sns),
- startTime: startTime,
- endTime: endTime,
- },
- success: function (rlt) {
- layui.layer.close(index)
- if (rlt.Code === 200) {
- //2.1清空图
- $('#echartsBox').html('');
- //2.2添加图
- /*
- for (let v of rlt.Data) {
- chartsData.set(v.sn.join('|'), v)
- addCharts(v)
- // console.log(v)
- }
- */
- handleEchartData(rlt.Data)
- }
- layui.layer.msg(rlt.Msg)
- }
- })
- }
- //处理图的数据
- let temperatureChar = null
- let humidityChar = null
- function handleEchartData(data) {
- //1.将图中数据分开
- let temperatureList = []
- let humidityList = []
- for (let v of data) {
- let t = []
- let h = []
- if (v.data == null) continue
- for (let val of v.data) {
- t.push([val.t_time, val.t_t])
- h.push([val.t_time, val.t_rh])
- }
- temperatureList.push([v.sn.join(' | '), t])
- humidityList.push([v.sn.join(' | '), h])
- chartsData.set(v.sn.join(' | '), v)
- }
- temperatureChar = addCharts(temperatureList, '温度t_t', 'temperature', true)
- humidityChar = addCharts(humidityList, '湿度t_rh', 'humidity', false)
- }
- var myChar;
- //添加图
- function addCharts(data, name, type, show) {
- //没有数据
- if (data == null || data.length === 0) {
- return null
- }
- //获取容器
- let eChartsBox = $('#echartsBox')[0]
- //设置要放置图的框架
- let eChar = $(`<div class="layui-row" style="width: 100%;height: 500px"></div>`)[0]
- eChartsBox.appendChild(eChar)
- //初始化
- myChar = echarts.init(eChar)
- // myChart=myChar
- //图标配置选项
- let options = {
- title: {
- text: name
- },
- grid: {
- left: '10%',
- right: '10%',
- // containLabel: true,
- // width: '100%',
- // x: '35px',
- // y: '40px'
- },
- xAxis: {
- type: 'time',
- splitLine: {
- show: false
- }
- },
- yAxis: {
- type: 'value',
- splitLine: {
- show: false
- },
- },
- toolbox: {
- feature: {
- restore: {},
- }
- },
- dataZoom: [
- {
- type: 'inside',
- start: 0,
- end: 100
- },
- {
- start: 0,
- end: 100
- }
- ],
- tooltip: {
- trigger: 'axis',
- formatter: function (params) {
- let v = params[0]
- return `${v.seriesName}\n
- 时间:${v.data[0]} 数据:${v.data[1]}`
- },
- // position: function (pt) {
- // return [pt[0], '10%'];
- // }
- },
- brush: {
- xAxisIndex: 0,
- toolbox: ['lineX', 'keep', 'clear'],
- brushMode: 'multiple',
- throttleType: 'debounce',
- throttleDelay: 600
- },
- series: []
- }
- for (let v of data) {
- console.log(v)
- options.series.push({
- name: v[0],
- data: v[1],
- type: 'line',
- })
- }
- if (!show) {
- options.dataZoom[1]["show"] = false
- options.toolbox = null
- options.brush = null
- }
- console.log(options)
- //设置参数
- myChar.setOption(options)
- //设置选中后的函数
- myChar.on('brushSelected', brushSelected)
- myChar.on('dataZoom', brushDataZoom)
- return myChar
- }
- function brushDataZoom(param) {
- console.log(param)
- let option = humidityChar.getOption();
- if (param.start !== undefined) {
- option.dataZoom[0].start = param.start
- option.dataZoom[0].end = param.end
- } else {
- option.dataZoom[0].start = param.batch[0].start
- option.dataZoom[0].end = param.batch[0].end
- }
- humidityChar.setOption(option)
- }
- //图获取选中数据
- let timeRange = []
- function brushSelected(param) {
- if (!param.batch || !param.batch[0] || !param.batch[0].areas || !param.batch[0].areas[0]) {
- return; // 如果参数不完整,直接返回避免错误
- }
- let coordRange = param.batch[0].areas[0].coordRange;
- timeRange = [Math.floor(coordRange[0]), Math.floor(coordRange[1])];
- $("#selectStartTime").val(dateFormat(new Date(timeRange[0])));
- $("#selectEndTime").val(dateFormat(new Date(timeRange[1])));
- }
- function onTimeRangeChange(startTimeStr, endTimeStr) {
- var startTime = new Date(startTimeStr).getTime();
- var endTime = new Date(endTimeStr).getTime();
- console.log("============")
- console.log(startTime, endTime)
- if (startTime > endTime) {
- alert("开始时间不能大于结束时间");
- return;
- }
- // 清除现有的画刷区域(如果存在)
- myChar.dispatchAction({
- type: 'brush',
- areas: [] // 清空画刷区域
- });
- console.log("前:",myChar.getOption())
- // 设置新的画刷区域
- myChar.dispatchAction({
- type: 'brush',
- areas: [{
- brushType: 'lineX',
- range: [startTime, endTime]
- }]
- });
- console.log("后:",myChar.getOption())
- }
- //温湿度偏移
- function offset() {
- if (timeRange.length === 0) {
- layui.layer.msg('请在图中选择要操作数据的区域!')
- return
- }
- //2.layer 打开一个窗口设置要统一设置下移的数据
- layui.layer.open({
- type: 1,
- area: ['300px', '270px'],
- content: $('#offsetFix'),
- btn: '确定',
- btnAlign: 'c',
- yes: function (index, elem) {
- let fixTemperature = $('#fixTemperature').val();
- let fixHumidity = $('#fixHumidity').val();
- if (fixHumidity === "" || fixTemperature === "") {
- //提示消息
- layui.layer.msg("没有设置固定温湿度偏移")
- return
- }
- //3.发送修改数据区域进行循环对值进行统一下调
- let index2 = loading();
- $.ajax({
- type: 'POST',
- url: '/Data/UpdateFix',
- data: JSON.stringify({
- fixTemperature: fixTemperature,
- fixHumidity: fixHumidity,
- sns: getSelectedSn(),
- data: timeRange
- }),
- contentType: 'application/json;charset=utf-8',
- processData: false,
- success: function (rlt) {
- layui.layer.close(index2)
- if (rlt.Code === 200) {
- //3.1判断是否处理成功
- //3.1.1成功更新该设备的数据
- timeRange = []
- loadEcharts()
- layui.layer.close(index)
- }
- //提示消息
- layui.layer.msg(rlt.Msg)
- }
- })
- }
- })
- }
- //删除
- function Delete() {
- if (timeRange.length === 0) {
- layui.layer.msg('请在图中选择要操作数据的区域!')
- return
- }
- //2.layer 打开一个窗口设置要统一设置下移的数据
- layui.layer.open({
- type: 1,
- area: ['300px', '270px'],
- content: $('#Delete'),
- btn: '确定',
- btnAlign: 'c',
- yes: function (index, elem) {
- //3.发送修改数据区域进行循环对值进行统一下调
- let index2 = loading();
- $.ajax({
- type: 'POST',
- url: '/Data/Delete',
- data: JSON.stringify({
- sns: getSelectedSn(),
- data: timeRange
- }),
- contentType: 'application/json;charset=utf-8',
- processData: false,
- success: function (rlt) {
- layui.layer.close(index2)
- if (rlt.Code === 200) {
- //3.1判断是否处理成功
- //3.1.1成功更新该设备的数据
- timeRange = []
- loadEcharts()
- layui.layer.close(index)
- }
- //提示消息
- layui.layer.msg(rlt.Msg)
- }
- })
- }
- })
- }
- //温湿度随机偏移
- function offsetRandom() {
- if (timeRange.length === 0) {
- layui.layer.msg('请在图中选择要操作数据的区域!')
- return
- }
- layui.layer.open({
- type: 1,
- area: ['520px', '240px'],
- content: $('#offsetRand'),
- btn: '确定',
- btnAlign: 'c',
- yes: function (index, elem) {
- let t_s = Number.parseFloat($('#temperatureStart').val()) * 100
- let t_e = Number.parseFloat($('#temperatureEnd').val()) * 100
- let h_s = Number.parseFloat($('#humidityStart').val()) * 100
- let h_e = Number.parseFloat($('#humidityEnd').val()) * 100
- if (!t_s && !t_e && !h_s && !h_e) {
- layui.layer.msg('随机值设置错误!因该从最小到最大!')
- return
- }
- let index2 = loading();
- $.ajax({
- type: 'POST',
- url: '/Data/UpdateRand',
- data: JSON.stringify({
- temperatureMax: Math.max(Math.floor(t_e), Math.floor(t_s)),
- temperatureMin: Math.min(Math.floor(t_e), Math.floor(t_s)),
- humidityMax: Math.max(Math.floor(h_e), Math.floor(h_s)),
- humidityMin: Math.min(Math.floor(h_e), Math.floor(h_s)),
- sns: getSelectedSn(),
- data: timeRange
- }),
- contentType: "application/json;charset=utf-8",
- processData: false,
- success: function (rlt) {
- layui.layer.close(index2)
- if (rlt.Code === 200) {
- //操作成功
- layui.layer.close(index)
- rangeData = []
- loadEcharts()
- }
- layui.layer.msg(rlt.Msg)
- }
- })
- }
- })
- //2.layer 打开一个窗口设置随机值范围,温湿度
- //3.发送修改数据区域进行循环对值进行随机值统一下调(layer点击确定之后)
- //3.1判断是否处理成功
- //3.1.1成功更新该设备的数据
- //3.1.2失败提示
- }
- //复制时间段内的数据到另一个时间段
- function copyFrom() {
- if (timeRange.length === 0) {
- layui.layer.msg('请在图中选择要操作数据的区域!')
- return
- }
- //2.layer 提示选区的内容条目数,选区内的开始时间和结束时间(可以进行修改)(layer点击确定之后),要复制到的区域时间
- $('#copyInfo').html(`<p style="color: red">${dateFormat(new Date(timeRange[0]))} ~ ${dateFormat(new Date(timeRange[1]))}</p>`)
- layui.layer.open({
- type: 1,
- title: '数据复制(指定开始时间)',
- areas: ['300px', '200px'],
- content: $('#copyMove'),
- btn: '确定',
- btnAlign: 'c',
- yes: function (index, elem) {
- let copyPosition = $('#copyPosition').val();
- if (copyPosition === '') {
- layui.layer.msg('复制到时间节点不能为空!', {icon: 6})
- return
- }
- let index2 = loading();
- $.ajax({
- type: "POST",
- url: "/Data/CopyFromPosition",
- data: JSON.stringify({
- copyPosition: copyPosition,
- sns: getSelectedSn(),
- data: timeRange
- }),
- processData: false,
- contentType: "application/json;charset=utf-8",
- success: function (rlt) {
- layui.layer.close(index2)
- if (rlt.Code === 200) {
- layui.layer.close(index)
- }
- layui.layer.msg(rlt.Msg, {icon: 1})
- }
- })
- }
- })
- }
- //补漏数据
- function repair() {
- if (timeRange.length === 0) {
- layui.layer.msg('请在图中选择要操作数据的区域!')
- return
- }
- let index2 = loading();
- layui.layer.confirm(`确认对${dateFormat(new Date(timeRange[0]))}~${dateFormat(new Date(timeRange[1]))} 时间的数据进行查询补漏吗?`, function (index) {
- $.ajax({
- type: "POST",
- url: '/Data/RepairSensorData',
- data: {
- sns: JSON.stringify(getSelectedSn()),
- data: JSON.stringify(timeRange)
- },
- success: function (rlt) {
- layui.layer.close(index2)
- if (rlt.Code === 200) {
- layui.layer.close(index)
- loadEcharts()
- }
- layui.layer.msg(rlt.Msg)
- },
- error: function(xhr, status, error) {
- layui.layer.close(index2); // 确保在AJAX请求失败时也关闭加载提示
- layui.layer.msg('数据补漏请求出错!');
- }
- });
- },function(index) {
- layui.layer.close(index2); // 用户点击取消时,关闭加载提示
- layui.layer.close(index); //
- });
- //3.需要补漏,则将数据处理后生成中间缺失的数据发送到服务
- //4.提示结果,成功刷新
- }
- //选区内做平滑
- function smooth() {
- if (timeRange.length === 0) {
- layui.layer.msg('请在图中选择要操作数据的区域!')
- return
- }
- //2.获取选区内的最开始第一条数据和最后一条数据,中间存在多少条数据,
- if (timeRange.length === 0) {
- layui.layer.msg('请在图中选择要操作数据的区域!')
- return
- }
- layui.layer.open({
- type: 1,
- area: ['300px', '240px'],
- content: $('#smoothBox'),
- btn: '提交',
- btnAlign: 'c',
- yes: function (index, elem) {
- let index2 = loading();
- $.ajax({
- type: "POST",
- url: "/Data/DataSensorDataSmooth",
- data: {
- sns: JSON.stringify(getSelectedSn()),
- data: JSON.stringify(timeRange),
- tRange: Number.parseFloat($('#temperatureRange').val()),
- hRange: Number.parseFloat($('#humidityRange').val()),
- },
- success: function (rlt) {
- layui.layer.close(index2)
- if (rlt.Code === 200) {
- layui.layer.close(index)
- loadEcharts()
- }
- layui.layer.msg(rlt.Msg)
- }
- })
- }
- })
- //count = (time_end -time_start) / time_threshold
- //(temperature_end - temperature_start) / count
- //3.生成数据发送,判断是否发送成功数据
- }
- //趋势
- function trend() {
- if (timeRange.length === 0) {
- layui.layer.msg('请在图中选择要操作数据的区域!')
- return
- }
- layui.layer.confirm("1.确保数据没有存在遗漏!\n2.确定对选区做数据趋势吗?", function (index) {
- let index2 = loading();
- $.ajax({
- type: "POST",
- url: "/Data/DataSensorDataTrend",
- data: {
- sns: JSON.stringify(getSelectedSn()),
- data: JSON.stringify(timeRange),
- },
- success: function (rlt) {
- layui.layer.close(index2)
- if (rlt.Code === 200) {
- layui.layer.close(index)
- loadEcharts()
- }
- layui.layer.msg(rlt.Msg)
- }
- })
- })
- }
- //导入excel
- function importExcel() {
- let sns = getSelectedSn();
- if (sns.length === 0) {
- //没有选择设备
- layui.layer.msg("没有选择设备,请选择设备后再执行导入!")
- return
- }
- $('#excelInput').change(function () {
- let f = this.files[0]
- let suffix = f.name.split(".")[1];
- if (suffix !== 'xlsx' && suffix !== 'xls') {
- layui.layer.msg("上传文件必须为 excel 类型的文件")
- this.files[0] = null
- return
- }
- $('#fileName').text(f.name)
- })
- //1.弹出需要导入的页面
- layui.layer.open({
- type: 1,
- title: '导入数据',
- areas: ['400px', '300px'],
- content: $('#importDataBox'),
- btn: '提交',
- btnAlign: 'c',
- yes: function (index, elem) {
- let data = new FormData()
- let file = $('#excelInput')[0].files[0];
- console.log(file.name)
- data.set("file", file)
- data.set("sn", sns.join("|"))
- let index2 = loading();
- $.ajax({
- type: "POST",
- url: "/Data/ImportSensorData",
- data: data,
- contentType: false,
- processData: false,
- success: function (rlt) {
- layui.layer.close(index2)
- if (rlt.Code === 200) {
- layui.layer.close(index)
- }
- layui.layer.msg(rlt.Msg)
- }
- })
- }
- })
- //判断是否有存在文件,文件后缀是否正确
- //如果正确则上传到服务器处理
- //2.提示处理结果
- }
- function dateFormat(date) {
- date.setHours(date.getHours() + 8);
- let year = date.getUTCFullYear();
- let month = date.getUTCMonth()+1;
- month = month < 10 ? `0${month}` : month
- let day = date.getUTCDate()
- day = day < 10 ? `0${day}` : day
- let hour = date.getUTCHours()
- hour = hour < 10 ? `0${hour}` : hour
- let minute = date.getUTCMinutes()
- minute = minute < 10 ? `0${minute}` : minute
- let second = date.getUTCSeconds()
- second = second < 10 ? `0${second}` : second
- return `${year}-${month}-${day} ${hour}:${minute}:${second}`
- }
- function loading() {
- return layui.layer.load("Loading...", {
- icon: 16,
- shade: 0.2
- })
- }
- </script>
- </body>
- </html>
|