From 4bb9f8ba3cd0a96324f7652158cddce0184085df Mon Sep 17 00:00:00 2001 From: liuwu <975499773@qq.com> Date: Mon, 6 Nov 2023 10:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=A0=B7=E5=BC=8F=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E5=A2=9E=E5=8A=A0=E5=85=B3=E9=97=ADapp=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=A0=A1=E5=87=86=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=B7=B3=E8=BD=AC=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/config.html | 173 ++++++- html/index.html | 39 +- html/index1.html | 1293 +++++++++++++++++++++++----------------------- script/ble.js | 46 +- script/index.js | 7 +- 5 files changed, 860 insertions(+), 698 deletions(-) diff --git a/html/config.html b/html/config.html index d7af084..c4a3c4d 100644 --- a/html/config.html +++ b/html/config.html @@ -71,6 +71,14 @@ text-align: justify; width: 100%; } + .save{ + display: flex; + /*实现垂直居中*/ + align-items: center; + /*实现水平居中*/ + justify-content: flex-end; + text-align: justify; + }
@@ -84,37 +92,52 @@
-
-
- - - +
+
+
+ 绑定设备: + +
+
+ +
-
- - - - +
+
+ 默认页面: + + +
+
+ +
-
- - - +
+
+ 装料校准: + + +
+
+ +
+
+
+
+ 跳转数据: + +
+
+ +
-
+
@@ -122,16 +145,33 @@ var carListener = null; var pageListener = null; + var fixListener = null; + var weiListener = null; var userPicker; var pagePicker; + var fixPicker; + var weiPicker; var pickData = []; var btnArray = ['取消', '确认']; var pageData = [] + var fixData = [] + var weiData = [] + fixData.push({value: 0, text: "需要"}) + fixData.push({value: 1, text: "不需要"}) + pageData.push({value: "index", text: "首页"}) pageData.push({value: "index1", text: "装料页面"}) pageData.push({value: "collection", text: "剩料收集页面"}) pageData.push({value: "config", text: "设置页面"}) + weiData.push({value: "20", text: "20"}) + weiData.push({value: "30", text: "30"}) + weiData.push({value: "40", text: "40"}) + weiData.push({value: "50", text: "50"}) + weiData.push({value: "60", text: "60"}) + weiData.push({value: "70", text: "70"}) + weiData.push({value: "80", text: "80"}) + function init() { } @@ -139,6 +179,8 @@ initSbList() init() muiInitPage() + muiInitFix() + muiInitWeightSize() var indexPage = api.getPrefs({ sync: true, key: 'initpage' @@ -227,6 +269,9 @@ userPicker.show(function (items) { console.log('设备切换'); showUserPickerButton.innerHTML = items[0].text; + if (items[0].text){ + initsb() + } }); }, false); } @@ -255,9 +300,11 @@ pageListener = null; pageListener = showPagePickerButton.addEventListener('tap', function (event) { pagePicker.show(function (items) { - console.log('设备切换'); document.getElementById('indexPage').value = items[0].value; showPagePickerButton.innerHTML = items[0].text; + if (items[0].text){ + initpage() + } }); }, false); } @@ -266,6 +313,71 @@ })(mui, document); } + function muiInitFix() { + (function ($, doc) { + $.init(); + $.ready(function () { + /** + * 获取对象属性的值 + * 主要用于过滤三级联动中,可能出现的最低级的数据不存在的情况,实际开发中需要注意这一点; + * @param {Object} obj 对象 + * @param {String} param 属性名 + */ + var _getParam = function _getParam(obj, param) { + return obj[param] || ''; + }; + if (fixPicker) { + } else { + fixPicker = new $.PopPicker(); + var showFixPickerButton = doc.getElementById('fixbeforeload'); + fixListener = null; + fixListener = showFixPickerButton.addEventListener('tap', function (event) { + fixPicker.show(function (items) { + document.getElementById('isfix').value = items[0].value; + showFixPickerButton.innerHTML = items[0].text; + if (items[0].text){ + fixbeforeload() + } + }); + }, false); + } + fixPicker.setData(fixData); + }); + })(mui, document); + } + + function muiInitWeightSize() { + (function ($, doc) { + $.init(); + $.ready(function () { + /** + * 获取对象属性的值 + * 主要用于过滤三级联动中,可能出现的最低级的数据不存在的情况,实际开发中需要注意这一点; + * @param {Object} obj 对象 + * @param {String} param 属性名 + */ + var _getParam = function _getParam(obj, param) { + return obj[param] || ''; + }; + if (weiPicker) { + } else { + weiPicker = new $.PopPicker(); + var showWeiPickerButton = doc.getElementById('weightSize'); + weiListener = null; + weiListener = showWeiPickerButton.addEventListener('tap', function (event) { + weiPicker.show(function (items) { + showWeiPickerButton.innerHTML = items[0].text; + if (items[0].text){ + weightSizeSave() + } + }); + }, false); + } + weiPicker.setData(weiData); + }); + })(mui, document); + } + function initsb() { // var value = document.getElementById('initsb').value; var value = document.getElementById('initsb').innerHTML @@ -291,7 +403,7 @@ } function weightSizeSave(){ - var value = document.getElementById('weightSize').value; + var value = document.getElementById('weightSize').innerHTML; if (value) { api.setPrefs({ key: 'weightSize', @@ -300,6 +412,17 @@ mui.alert('自动跳转数据包"' + value + '"成功'); } } + function fixbeforeload(){ + var value = document.getElementById('isfix').value; + if (value) { + api.setPrefs({ + key: 'fixbeforeload', + value: value + }); + var name = document.getElementById('fixbeforeload').innerHTML; + mui.alert('装料前校准"' + name + '"设置成功'); + } + } \ No newline at end of file diff --git a/html/index.html b/html/index.html index 44828c4..f5833a9 100644 --- a/html/index.html +++ b/html/index.html @@ -20,6 +20,13 @@ box-sizing: border-box; border: 1px solid #a3caef; } + .btnc { + margin-left: 15px; + /* margin-right: 15px; */ + font-size: x-large; + font-weight: 900; + border-radius: 20px; + } .flex{ /*flex 布局*/ display: flex; @@ -29,15 +36,25 @@ /*实现水平居中*/ justify-content: center; text-align: justify; - /* width:33%; */ - height: 100vh; - /* - margin: 5px 5px; - padding: 5px 5px; */ + height: 90vh; + } + .flex1{ + /*flex 布局*/ + display: flex; + background-color: #007aff; + /*实现垂直居中*/ + align-items: center; + /*实现水平居中*/ + justify-content: flex-end; + text-align: justify; + height: 10vh; }
+
+ +
@@ -49,6 +66,18 @@
+ obj.setAttribute("class", 'mui-table-view-cell trains'); + var param = { + classCode: classCode, + sbId: sbId, + trainNumber: trainNumber, + sourceCow: api.getPrefs({ sync: true, key: 'sourceCow' }), + dateOf: getDateStr(new Date()) + }; + initOne(param); + } + // 初始化设备查询 + function initSbList() { + document.getElementById('text').innerHTML = '初始化设备'; + api.showProgress({ + title: '初始化设备...', + modal: true + }); + pickData = []; + api.ajax({ + url: 'https://tmr.nxcyx.com/api/app/tmr/sbList?sourceCow=' + api.getPrefs({ sync: true, key: 'sourceCow' }), + // url: 'http://192.168.0.107:8088/app/tmr/sbList?sourceCow=' + api.getPrefs({ sync: true, key: 'sourceCow' }), + method: 'get', + timeout: 5 + }, function (ret, err) { + if (ret) { + networkStatus = true; + api.hideProgress(); + document.getElementById('text').innerHTML = '设备初始化成功'; + var initsb = api.getPrefs({ + sync: true, + key: 'initsb' + }); + ret.data.forEach(function (e) { + if (initsb === e.name){ + var json = { value: e.sbId, text: e.name }; + pickData.push(json); + } + }); + ret.data.forEach(function (e) { + if (initsb !== e.name){ + var json = { value: e.sbId, text: e.name }; + pickData.push(json); + } + }); + // sbId = ret.data[0].sbId; + // document.getElementById('showUserPicker').innerHTML = ret.data[0].name; + sbId = pickData[0].value; + document.getElementById('showUserPicker').innerHTML = pickData[0].text; + muiInit(); + initTime(); + } else { + networkStatus = false; + api.hideProgress(); + mui.alert("sbList:" + err.msg); + document.getElementById('text').innerHTML = '' + '服务器异常' + ''; + } + }); + } + // 刷新页面 + function reloadPage() { + api.openWin({ + name: 'collection', + reload:true, + url:'../html/collection.html' + }) + // mui.confirm('确认重新初始化页面么?', '提示', btnArray, function (e) { + // if (e.index == 0) {} else { + // getWifiInfo(); + // } + // }); + } + var sid; + // 获取WiFi信息,并刷新页面数据 + function getWifiInfo() { + // sid = '' + // document.getElementById('text').innerHTML = '正在连接服务器' + var loginUser = api.getPrefs({ sync: true, key: 'loginUser' }); + var obj = JSON.parse(loginUser); + driverName = obj.nickName; + document.getElementById('driveName').innerHTML = '用户:' + obj.nickName; + pickData = []; + document.getElementById('train').innerHTML = ''; + document.getElementById('timeList').innerHTML = ''; + document.getElementById('feedList').innerHTML = ''; + initSbList(); + } + // 更新获取最新配方 + function refreshDayPlan() { + mui.confirm('确认更新计划么?', '提示', btnArray, function (e) { + if (e.index == 0) {} else { + var param = { + sourceCow: api.getPrefs({ sync: true, key: 'sourceCow' }), + dateOf: getDateStr(new Date()) + }; + api.ajax({ + url: 'https://tmr.nxcyx.com/api/app/tmr/planDayInit', + headers: { + 'Content-Type': 'application/json;charset=utf-8' //建议key使用首字母大写的形式,如 User-Agent + }, + method: 'post', + data: { + body: param + } + }, function (ret, err) { + if (ret) { + mui.toast("计划更新成功"); + getWifiInfo(); + } else { + mui.toast("计划更新失败"); + } + }); + } + }); + } + //退出登录 + function handleBackSys() { + mui.confirm('退出当前登录用户?', JSON.parse(api.getPrefs({ sync: true, key: 'loginUser' })).name + '(' + driverName + ')', btnArray, function (e) { + if (e.index == 0) {} else { + //跳转到login.stml + // api.closeWin(); + api.removePrefs({ + key: 'token' + }); + api.removePrefs({ + key: 'loginUser' + }); + api.removePrefs({ + key: 'sourceCow' + }); + api.clearCache(function () { + console.log("清除完成"); + }); + api.openWin({ + name: 'login', + reload:true, + url:'../pages/login.stml' + }) + } + }); + } + diff --git a/script/ble.js b/script/ble.js index b66ca79..6f1b6c2 100644 --- a/script/ble.js +++ b/script/ble.js @@ -54,6 +54,8 @@ function scan(param) { }); } +var weightBeforefix = '1'; + function stopScan(){ ble.stopScan() } @@ -83,7 +85,7 @@ function getPeripheral() { }); } if (uuid && uuid === p.uuid){ - document.getElementById('showBlePicker').innerHTML = p.name + document.getElementById('showBlePicker').innerHTML = p.name isConnected({peripheralUUID: uuid},function(ret){ console.log("isConnected"+ret); if(ret){ @@ -256,7 +258,7 @@ function discoverService(param) { }, function (ret7) { }); // 装料状态 - if(feedStatus && allowAuto){ + if((feedStatus && allowAuto) || weightBeforefix ==='1' ){ if (first) { first = false; beforeWeight = nowWeight; @@ -276,33 +278,21 @@ function discoverService(param) { } document.getElementById('feedNum').innerHTML = ':' + _planSum + '/已装:' + _feedNum + ''; } - serviceUUID = ret4; - characteristicUUID = ret5; - // // 组装led报文 - // if (ledStatus && !isNaN(nowWeight)) { - // // getMess({ - // // peripheralUUID: param.peripheralUUID, - // // serviceUUID: ret4, - // // characteristicUUID: ret5, - // // value: ret6 - // // }, function (ret7) { - // // }); - // } // 装料状态 - if(feedStatus && allowAuto){ + if((feedStatus && allowAuto) || weightBeforefix === '1'){ // 计划-饲喂 var feedErr = _planSum-_feedNum; if (isNaN(feedErr)) { return false } - // 蜂鸣器校验基础值,大于500的饲料,取500为标准 + // 蜂鸣器校验基础值,大于500的饲料,取500为标准 var count; if (_planSum >= 500) { count = 500 } else { count = _planSum } - // 计算饲料装料量与基础值的误差比例 + // 计算饲料装料量与基础值的误差比例 var ration = feedErr / count; // console.log("ration" + ration.toFixed(2)); // 误差分为100%-20%(停止蜂鸣),10%-20%(间隔05),5%-10%(间隔03),2%-5%(间隔01),-100%-2%(长鸣) @@ -384,7 +374,7 @@ function discoverService(param) { } // console.log(weightStabilization("weightStabilization"+nowWeight)) // 在误差范围内 - if (feedErr <= allow && allowAuto) { + if (feedErr <= allow && (allowAuto || weightBeforefix === '1')) { // 重量稳定计数 var filteredValue = weightDataFilter.filter(nowWeight); // 重量稳定自动跳转 @@ -533,7 +523,7 @@ function getMess(param, callback) { param1.msg = newmsg + Math.abs(Number(_planSum - _feedNum)).toFixed(0) + 'kg'; } // param1.msg = newmsg + Math.abs(Number(param.value)).toFixed(0) + 'kg' - // console.log(param1.msg) + console.log(param1.msg) //组装字符卡LED报文 zfk.getMsg(param1, function (ret, err) { var str = ret.sendMsg; @@ -548,7 +538,7 @@ function getMess(param, callback) { // var num1 = ms.length / 2; // 同步刷新图表 // 饲喂状态刷新实时状态,否则不刷新装料信息 - if(feedStatus && allowAuto){ + if(feedStatus && (allowAuto || weightBeforefix ==='1')){ renderUnload(); feedMyChart.setOption({ dataset: { @@ -620,13 +610,13 @@ function weightStabilization(weight) { var diff = weight - lastWeight; // 如果差值在一定范围内,则认为重量是稳定的 if (Math.abs(diff) < 2) { - weight = weight; - lastWeight = weight; - return true; + weight = weight; + lastWeight = weight; + return true; } else { - // 如果差值超过一定范围,则认为重量是不稳定的,重新开始计算 - weight = 0; - lastWeight = weight; - return false; + // 如果差值超过一定范围,则认为重量是不稳定的,重新开始计算 + weight = 0; + lastWeight = weight; + return false; } - } \ No newline at end of file +} \ No newline at end of file diff --git a/script/index.js b/script/index.js index 9d802a2..efaa9b8 100644 --- a/script/index.js +++ b/script/index.js @@ -3,7 +3,6 @@ function updateApp() { mui.toast(document.getElementById('text').innerHTML); } - // 重量校准 function weightFix() { if (!feedList.length > 0) { @@ -17,6 +16,7 @@ function weightFix() { } else { beforeWeight = nowWeight; allowAuto = true + document.getElementById('isfix').innerHTML = '已校准' mui.toast("校准完成"); } }); @@ -127,7 +127,7 @@ function submitData() { newmsg = feedName + ttr; } param1.msg = newmsg + '饲喂完成'; - + // console.log(param1.msg) zfk.getMsg(param1, function (ret, err) { var str = ret.sendMsg; str = str.replace(/\s+/g, ""); @@ -136,6 +136,7 @@ function submitData() { msgList.push(param.value); }) document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-success dis'); + document.getElementById('feedNum').innerHTML = param1.msg; setTimeout(function(){ console.log("停止蜂鸣"); control("00", "00"); @@ -181,8 +182,10 @@ function submitData() { }); // 误差小于100必须校准才能自动跳转 allowAuto = false; + document.getElementById('isfix').innerHTML = '未校准' text = feedName + _planSum; document.getElementById('nowFeed').innerHTML = '' + batchName + ',' + feedName + ''; + document.getElementById('feedNum').innerHTML = ':' + _planSum + '/已装:' + _feedNum + ''; ledStatus = false; // setTimeout(() => { console.log("停止蜂鸣");