| New file |
| | |
| | | var pageCurr; |
| | | layui.use(['table', 'laydate', 'form', 'layer'], function(){ |
| | | var table = layui.table; |
| | | var $ = layui.jquery; |
| | | var layer = layui.layer; |
| | | var layDate = layui.laydate; |
| | | var form = layui.form; |
| | | |
| | | // 记录时间范围选择器(单个输入框显示范围) |
| | | layDate.render({ |
| | | elem: '#recordTime', |
| | | type: 'datetime', |
| | | range: true, // 范围选择,使用默认分隔符 " - " |
| | | format: 'yyyy-MM-dd HH:mm:ss' |
| | | }); |
| | | |
| | | // 数据渲染 |
| | | tableIns = table.render({ |
| | | elem: '#crnTiltRecord', |
| | | headers: {token: localStorage.getItem('token')}, |
| | | url: baseUrl+'/crnTiltRecord/list/auth', |
| | | page: true, |
| | | limit: 16, |
| | | limits: [16, 30, 50, 100, 200, 500], |
| | | toolbar: '#toolbar', |
| | | cellMinWidth: 50, |
| | | cols: [[ |
| | | {field: 'id', title: 'ID', sort: true, align: 'center', width: 80} |
| | | ,{field: 'crnNo', align: 'center', title: '堆垛机编号', sort: true, width: 120} |
| | | ,{field: 'tiltValue', align: 'center', title: '倾斜度值', sort: true, width: 120, templet: function(d){ |
| | | return d.tiltValue != null ? d.tiltValue.toFixed(4) + '°' : '-'; |
| | | }} |
| | | ,{field: 'tiltX', align: 'center', title: 'X方向倾斜度', sort: true, width: 140, templet: function(d){ |
| | | return d.tiltX != null ? d.tiltX.toFixed(4) + '°' : '-'; |
| | | }} |
| | | ,{field: 'tiltY', align: 'center', title: 'Y方向倾斜度', sort: true, width: 140, templet: function(d){ |
| | | return d.tiltY != null ? d.tiltY.toFixed(4) + '°' : '-'; |
| | | }} |
| | | // ,{field: 'tiltZ', align: 'center', title: 'Z方向倾斜度', sort: true, width: 140, templet: function(d){ |
| | | // return d.tiltZ != null ? d.tiltZ.toFixed(4) + '°' : '-'; |
| | | // }} |
| | | ,{field: 'recordTime$', align: 'center', title: '记录时间', sort: true, width: 180} |
| | | ,{field: 'prevTiltValue', align: 'center', title: '上次倾斜度', sort: true, width: 120, templet: function(d){ |
| | | return d.prevTiltValue != null ? d.prevTiltValue.toFixed(4) + '°' : '-'; |
| | | }} |
| | | ,{field: 'tiltChange', align: 'center', title: '变化量', sort: true, width: 120, templet: function(d){ |
| | | if (d.tiltChange == null) return '-'; |
| | | var change = d.tiltChange.toFixed(4); |
| | | var color = d.tiltChange > 0 ? 'red' : (d.tiltChange < 0 ? 'green' : 'black'); |
| | | return '<span style="color: ' + color + '">' + change + '°</span>'; |
| | | }} |
| | | ,{field: 'recordType$', align: 'center', title: '记录类型', sort: true, width: 100} |
| | | ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 100} |
| | | ]], |
| | | request: { |
| | | pageName: 'curr', |
| | | pageSize: 'limit' |
| | | }, |
| | | parseData: function (res) { |
| | | return { |
| | | 'code': res.code, |
| | | 'msg': res.msg, |
| | | 'count': res.data.total, |
| | | 'data': res.data.records |
| | | } |
| | | }, |
| | | response: { |
| | | statusCode: 200 |
| | | }, |
| | | done: function(res, curr, count) { |
| | | if (res.code === 403) { |
| | | top.location.href = baseUrl+"/"; |
| | | } |
| | | pageCurr = curr; |
| | | } |
| | | }); |
| | | |
| | | // 监听排序事件 |
| | | table.on('sort(crnTiltRecord)', function (obj) { |
| | | var searchData = {}; |
| | | $.each($('#search-box [name]').serializeArray(), function() { |
| | | if (this.value) { |
| | | searchData[this.name] = this.value; |
| | | } |
| | | }); |
| | | searchData['orderByField'] = obj.field; |
| | | searchData['orderByType'] = obj.type; |
| | | tableIns.reload({ |
| | | where: searchData, |
| | | page: { |
| | | curr: pageCurr |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | // 监听工具条 |
| | | table.on('toolbar(crnTiltRecord)', function(obj){ |
| | | var checkStatus = table.checkStatus(obj.config.id); |
| | | switch(obj.event){ |
| | | case 'manualRecord': |
| | | manualRecord(); |
| | | break; |
| | | case 'exportData': |
| | | exportData(); |
| | | break; |
| | | } |
| | | }); |
| | | |
| | | // 监听行工具事件 |
| | | table.on('tool(crnTiltRecord)', function(obj){ |
| | | var data = obj.data; |
| | | switch(obj.event){ |
| | | case 'detail': |
| | | showDetail(data); |
| | | break; |
| | | } |
| | | }); |
| | | |
| | | // 搜索 |
| | | form.on('submit(search)', function(data){ |
| | | pageCurr = 1; |
| | | tableReload(false); |
| | | return false; |
| | | }); |
| | | |
| | | // 重置(完全套用月结管理的重置逻辑) |
| | | form.on('submit(reset)', function (data) { |
| | | pageCurr = 1; |
| | | clearFormVal($('#search-box')); |
| | | // 手动清空日期范围选择器 |
| | | $('#recordTime').val(''); |
| | | // 显式清空表格配置中的 where 参数 |
| | | if (tableIns && tableIns.config) { |
| | | tableIns.config.where = {}; |
| | | } |
| | | // 使用 setTimeout 确保表单值被完全清空后再重新加载表格 |
| | | setTimeout(function() { |
| | | tableReload(false); |
| | | }, 0); |
| | | return false; |
| | | }); |
| | | |
| | | // tableReload 函数(完全套用月结管理的逻辑) |
| | | function tableReload(child) { |
| | | var searchData = {}; |
| | | $.each($('#search-box [name]').serializeArray(), function() { |
| | | var value = this.value; |
| | | // 只处理非空值 |
| | | if (value && value.trim() !== '') { |
| | | searchData[this.name] = value; |
| | | } |
| | | }); |
| | | |
| | | // 获取 table 实例 |
| | | var tableInstance = child ? parent.tableIns : tableIns; |
| | | |
| | | // 如果 searchData 为空对象,需要显式传入覆盖所有可能参数的对象 |
| | | // 因为 layui table 可能会合并旧的参数,即使传入空对象也可能保留旧值 |
| | | if (Object.keys(searchData).length === 0) { |
| | | if (tableInstance && tableInstance.config) { |
| | | // 先保存旧的 where 中可能存在的所有键 |
| | | var oldWhereKeys = []; |
| | | if (tableInstance.config.where) { |
| | | for (var key in tableInstance.config.where) { |
| | | if (tableInstance.config.where.hasOwnProperty(key)) { |
| | | oldWhereKeys.push(key); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 完全替换 where 对象 |
| | | tableInstance.config.where = {}; |
| | | |
| | | // 如果之前有参数,创建一个明确覆盖的对象,将所有旧参数设置为空字符串 |
| | | // 使用空字符串而不是 null,因为 layui 可能会过滤 null 值 |
| | | if (oldWhereKeys.length > 0) { |
| | | var overrideWhere = {}; |
| | | oldWhereKeys.forEach(function(key) { |
| | | overrideWhere[key] = ''; // 设置为空字符串来覆盖旧值 |
| | | }); |
| | | searchData = overrideWhere; |
| | | } else { |
| | | // 即使没有旧参数,也创建一个包含所有可能参数的空对象 |
| | | // 这样可以确保覆盖任何可能的旧参数 |
| | | searchData = { |
| | | crnNo: '', |
| | | recordTime: '' |
| | | }; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 构建 reload 参数 |
| | | var reloadOptions = { |
| | | where: searchData, |
| | | page: { |
| | | curr: pageCurr |
| | | }, |
| | | done: function (res, curr, count) { |
| | | if (res.code === 403) { |
| | | top.location.href = baseUrl+"/"; |
| | | } |
| | | pageCurr = curr; |
| | | if (res.data.length === 0 && count !== 0) { |
| | | var reloadTableInstance = child ? parent.tableIns : tableIns; |
| | | // 如果 searchData 为空,也完全替换 where 对象 |
| | | if (Object.keys(searchData).length === 0 && reloadTableInstance && reloadTableInstance.config) { |
| | | reloadTableInstance.config.where = {}; |
| | | } |
| | | reloadTableInstance.reload({ |
| | | where: searchData, |
| | | page: { |
| | | curr: pageCurr-1 |
| | | } |
| | | }); |
| | | pageCurr -= 1; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | tableInstance.reload(reloadOptions); |
| | | } |
| | | |
| | | // 显示详情 |
| | | function showDetail(data) { |
| | | var content = '<div style="padding: 20px;">' + |
| | | '<table class="layui-table" lay-skin="line">' + |
| | | '<tr><td style="width: 150px;">ID:</td><td>' + (data.id || '-') + '</td></tr>' + |
| | | '<tr><td>堆垛机编号:</td><td>' + (data.crnNo || '-') + '</td></tr>' + |
| | | '<tr><td>倾斜度值:</td><td>' + (data.tiltValue != null ? data.tiltValue.toFixed(4) + '°' : '-') + '</td></tr>' + |
| | | '<tr><td>X方向倾斜度:</td><td>' + (data.tiltX != null ? data.tiltX.toFixed(4) + '°' : '-') + '</td></tr>' + |
| | | '<tr><td>Y方向倾斜度:</td><td>' + (data.tiltY != null ? data.tiltY.toFixed(4) + '°' : '-') + '</td></tr>' + |
| | | // '<tr><td>Z方向倾斜度:</td><td>' + (data.tiltZ != null ? data.tiltZ.toFixed(4) + '°' : '-') + '</td></tr>' + |
| | | '<tr><td>上次倾斜度:</td><td>' + (data.prevTiltValue != null ? data.prevTiltValue.toFixed(4) + '°' : '-') + '</td></tr>' + |
| | | '<tr><td>变化量:</td><td>' + (data.tiltChange != null ? data.tiltChange.toFixed(4) + '°' : '-') + '</td></tr>' + |
| | | '<tr><td>记录时间:</td><td>' + (data.recordTime$ || '-') + '</td></tr>' + |
| | | '<tr><td>记录类型:</td><td>' + (data.recordType$ || '-') + '</td></tr>' + |
| | | '</table>' + |
| | | '</div>'; |
| | | |
| | | layer.open({ |
| | | type: 1, |
| | | title: '倾斜度记录详情', |
| | | area: ['600px', '500px'], |
| | | content: content, |
| | | btn: ['关闭'], |
| | | yes: function(index) { |
| | | layer.close(index); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 手动触发记录 |
| | | function manualRecord() { |
| | | layer.confirm('确定要手动触发倾斜度记录吗?', { |
| | | icon: 3, |
| | | title: '提示' |
| | | }, function(index) { |
| | | layer.close(index); |
| | | var loadIndex = layer.load(2); |
| | | $.ajax({ |
| | | url: baseUrl + '/crn/tiltRecord/manual', |
| | | type: 'POST', |
| | | headers: {token: localStorage.getItem('token')}, |
| | | data: {}, |
| | | success: function(res) { |
| | | layer.close(loadIndex); |
| | | if (res.code === 200) { |
| | | layer.msg('手动触发记录成功', {icon: 1}); |
| | | tableIns.reload(); |
| | | } else { |
| | | layer.msg(res.msg || '手动触发失败', {icon: 2}); |
| | | } |
| | | }, |
| | | error: function() { |
| | | layer.close(loadIndex); |
| | | layer.msg('请求失败', {icon: 2}); |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | // 导出数据 |
| | | function exportData() { |
| | | var searchData = {}; |
| | | $.each($('#search-box [name]').serializeArray(), function() { |
| | | if (this.value) { |
| | | searchData[this.name] = this.value; |
| | | } |
| | | }); |
| | | |
| | | var params = []; |
| | | for (var key in searchData) { |
| | | params.push(key + '=' + encodeURIComponent(searchData[key])); |
| | | } |
| | | var url = baseUrl + '/crnTiltRecord/export/auth?' + params.join('&'); |
| | | window.open(url); |
| | | } |
| | | }); |