This commit is contained in:
liuwu 2023-10-20 10:52:35 +08:00
parent 2918751662
commit 7aa66d199e
7 changed files with 119 additions and 37695 deletions

View File

@ -1,724 +0,0 @@
<!-- <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../script/echarts.js"></script>
<script src="../script/api.js"></script>
</head>
<style>
.echarts_wrap {
width: 100%;
height: 96vh;
/* background-color: black; */
display: flex;
justify-content: center;
align-items: center;
}
.echarts_item {
width: 35%;
height: 96vh;
}
.echarts_item1 {
width: 30%;
height: 96vh;
}
.header_btn {
background-color: #407ae6;
color: #ffffff;
font-size: 20px;
height: 50px;
font-weight: 900;
width: 100%;
}
</style>
<body>
<div class="echarts_wrap">
<div class="echarts_item" id="echarts_main_one"></div>
<div class="echarts_item" id="echarts_main_two"></div>
<div class="echarts_item1" >
<div class="header_led_text" id="beforeWeight"></div>
<div class="header_led_text" id="nowWeight">称实时重量:</div>
<button type="button" class="header_btn" onclick="weightFix()">校准装料前重量</button>
<text style="color: red;font-size: 14px;">请在装料前校准,装料过程中禁止校准</text>
</div>
</div>
<script type="text/javascript">
// 初始化echarts Dom
var weightChartDom = document.getElementById('echarts_main_two');
var weightMyChart = echarts.init(weightChartDom);
var feedChartDom = document.getElementById('echarts_main_one');
var feedMyChart = echarts.init(feedChartDom);
// 语言播报路径 讯飞语言引擎appid
var android_appid = '3cbf130a';
var audioPath = 'fs://speechRecogniser/read.mp3';
// 字符卡通信配置
var zifukaHost = '';
var zifukaPort = null;
// 称重通信配置
var weightHost = '';
var weightPort = null;
// 称重通信连接id
var sid;
// 装料状态还是卸料状态
var load = true;
// 是否是该车次第一个料
var isFirst = getUrlParam("isFirst")
//之前总重量,车次计划总量:计划量,实时总重量,已装量,剩余量,允许误差
var beforeWeight = getUrlParam('beforeWeight');
$api.html($api.byId("beforeWeight"),"装料前重量:"+(beforeWeight?beforeWeight:''));
var _weightSum = getUrlParam('total');
var _planSum = getUrlParam('plan');
var nowWeight = 0;
var _feedNum = 0;
var allow = getUrlParam("allow")
// 定义语言引擎,字符卡
var tts;
var zfk;
// 定义称重稳定滤波数组
var weightArray = [];
//echarts公共参数
var ROOT_PATH = 'https://echarts.apache.org/examples';
var _panelImageURL = ROOT_PATH + '/data/asset/img/custom-gauge-panel.png';
var _outerRadius = 220;
var _innerRadius = 170;
var zfkList = [];
var feedName;
var _pointerInnerRadius = 20;
var _insidePanelRadius = 160;
var fontsize = 70;
var lastZfkMsg = ''
apiready = function () {
lastZfkMsg = ''
api.setGlobalData({ key: 'wendin', value: false });
// 判断是装料还是卸料
if (getUrlParam('type') == 1) {
load = true;
} else {
load = false;
}
// console.log(allow);
weightArray = []
resizeWindow()
var feedJson = { plan: _planSum, feed: _feedNum, id: getUrlParam('id'), beforeWeight: nowWeight, type: getUrlParam('type') }
api.setGlobalData({ key: 'feedJson', value: feedJson });
// 渲染装料echarts
renderUnload()
// 渲染总重量echarts
renderLoad()
// 称重通信服务初始化
startWeightService()
clearInterval(interv)
var interv = setInterval(function () {
// console.log("监听消息"+ api.getGlobalData({ key: 'feedName' }) + Number(_planSum - _feedNum).toFixed(0));
// 判断字符卡服务和饲料名称都存在且上次字符卡消息不等于当前要发的消息
if(zfk!=undefined && feedName!='' && lastZfkMsg != api.getGlobalData({ key: 'feedName' }) + Number(_planSum - _feedNum).toFixed(0)){
lastZfkMsg = api.getGlobalData({ key: 'feedName' }) + Number(_planSum - _feedNum).toFixed(0);
var param={
start:"78 ",
ver:'34 ',
addr:'01 00 ',
cmd:'29 ',
ident:'BC FD 00 00 ',
frame:'00 00 00 00 ',
end:'A5',
msg: lastZfkMsg,
diskId:'01 00 ',
encode:'01 ',
show:'02 ',
color:'01 '
}
if(zfkList && zfkList.length >0 ){
var sourceCow = api.getPrefs({sync: true,key: 'sourceCow'});
var LedType = api.getPrefs({sync: true,key: 'LedType'});
zfkList.forEach(e => {
// 奶二版本
if(sourceCow == 2){
param.addr = e+" ";
zfk.send(param, function (ret, err) {
// console.log(JSON.stringify(ret));
api.setGlobalData({ key: 'sendMsg', value: ret.sendMsg });
console.log(ret.sendMsg);
if (!ret.status) {
console.warn("字符卡发送失败");
}
})
}
})
}
}
}, 1000);
}
function startWeightService() {
// console.log('http://192.168.0.107:8088/app/tmr/appService?deviceId=' + api.deviceId + '&sbId='+api.getGlobalData({ key: 'sbId' }));
// 查询称重服务配置并启动
api.ajax({
// url: 'http://192.168.0.107:8088/app/tmr/appService?sbId='+api.getGlobalData({ key: 'sbId' }),
url: 'https://tmr.nxcyx.com/api/app/tmr/appService?sbId='+api.getGlobalData({ key: 'sbId' }),
method: 'get',
}, function (ret, err) {
ret.data.forEach(e => {
if (e.serviceName == 'weight') {
weightHost = e.param.host;
weightPort = e.param.port;
api.setGlobalData({ key: 'weightTcp', value: weightHost + ':' + weightPort });
// console.log('*****************************'+e.serviceName+" "+e.param.host+':'+e.param.port+'*****************************');
} else if (e.serviceName == 'zfk') {
zfkList = e.param.addrList;
zifukaHost = e.param.host;
zifukaPort = Number(e.param.port);
api.setGlobalData({ key: 'zfkTcp', value: zifukaHost + ':' + zifukaPort });
api.setGlobalData({ key: 'addrList', value: e.param.addrList});
initReadStrAndLedSend()
setTimeout(() => {
initWeightService()
}, 1000);
}
})
})
// 定时语言播报误差值并发送给LED屏
// setInterval(function () {
// var err = _planSum - _feedNum;
// var feedName = api.getGlobalData({
// key: 'feedName'
// });
// var str = feedName + "差" + err + "kg";
// // readStr(str)
// zfk.send({ msg: feedName + "差" + err + "kg" }, function (ret, err) {
// if (!ret.status) {
// console.warn("字符卡发送失败");
// }
// })
// }, 6000)
}
// 之前重量矫正,抓取实时重量并赋值
function weightFix(){
api.confirm({
title: '提醒',
msg: '确认重新校准装料前称总重量么?',
buttons: ['确认', '取消']
}, function (ret, err) {
if (1 == ret.buttonIndex) {
beforeWeight = nowWeight;
// console.log("校准完重量为"+beforeWeight);
api.setGlobalData({ key: 'beforeWeight', value: beforeWeight });
$api.html($api.byId("beforeWeight"),"装料前重量:"+beforeWeight);
}
});
}
function initWeightService() {
var s = api.require('socketManager');
var sssid = api.getGlobalData({ key: 'sid' });
// console.log(sssid);
if (sssid) {
s.closeSocket({ sid: sssid }, function (ret, err) {
// console.log(JSON.stringify(ret));
});
}
s.createSocket({ host: weightHost, port: weightPort }, function (ret, err) {
if (ret.state == 101) {
// console.log("192.168.0.107连接中");
} else if (ret.state == 102) {
// console.log("192.168.0.107连接成功");
sid = ret.sid;
// console.log(sid);
api.setGlobalData({ key: 'sid', value: ret.sid });
} else if (ret.state == 103) {
// 如果是手动清零需要刷新页面
// 实时获取回传重量信息
nowWeight = Number(ret.data)
// 第一次装料当前重量即等于之前重量,不一定为0
if (undefined == beforeWeight && isFirst) {
readStr("开始装料" + api.getGlobalData({ key: 'feedName' }) + _planSum + "kg")
// console.log("*********************装料前车总重量"+nowWeight+"*********************");
beforeWeight = nowWeight
// 设置装料前车次基础重量
api.setGlobalData({ key: 'beforeWeight', value: beforeWeight });
}
$api.html($api.byId("beforeWeight"),"装料前重量:"+beforeWeight);
// 设置卸料完后车次基础重量
api.setGlobalData({ key: 'totalWeight', value: nowWeight });
// 计算装料卸料已装重量
if (load) {
_feedNum = nowWeight - beforeWeight;
} else {
_feedNum = beforeWeight - nowWeight;
}
// 计算计划和实际误差值
var err = _planSum - _feedNum;
// 获取饲料名称
var feedName = api.getGlobalData({
key: 'feedName'
});
ifWeightWendin(err)
// 实时更新饲料计划量,装载量,饲料id,之前重量,装料类型
var feedJson = { plan: _planSum, feed: _feedNum, id: getUrlParam('id'), beforeWeight: nowWeight, type: getUrlParam('type') }
api.setGlobalData({ key: 'feedJson', value: feedJson });
if(zfkList && zfkList.length >0 ){
var sourceCow = api.getPrefs({sync: true,key: 'sourceCow'});
if(sourceCow != 2){
zfkList.forEach(e => {
var param1={
SF:"AA A5 ",
LEN:'1A 00 ',
DES:'01 01 ',
SRC:'12 34 ',
TID:'B0 A1 ',
CMD1:'38 02 ',
X:'00 00 ',
Y:'00 00 ',
WIDTH:'40 00 ',
HEIGHT:'20 00 ',
FORMAT:'00 00 01 00 ',
CNT:'04 00 ',
CRC:'00 00 ',
EF:'5A 55 ',
msg:''
}
var newmsg = api.getGlobalData({ key: 'feedName' });
if(newmsg.length == 1){
newmsg = newmsg+":还"
}else if(newmsg.length == 2){
newmsg = newmsg+""
}
param1.DES = e+" ";
param1.msg = newmsg.substr(0,4) +"差"+ Number(_planSum - _feedNum).toFixed(0)
zfk.send1(param1, function (ret, err) {
console.log(ret.sendMsg);
if (!ret.status) {
console.warn("字符卡发送失败");
}
})
// // 奶二版本
// if(sourceCow == 2){
// }else{
// }
})
}
}
// 实时渲染echarts图
feedMyChart.setOption({
dataset: {
// source: [[1, err]]
source: [[1, _feedNum]]
}
})
weightMyChart.setOption({
dataset: {
source: [[1, nowWeight]]
}
})
} else {
console.warn("*********************称重连接失败*********************")
api.alert({ msg: '称服务连接失败,请检查配置' });
}
})
}
function ifWeightWendin(err) {
// 重量稳定判断
var countSize = 30;
if (Math.abs(err) <= allow) {
weightArray.push(nowWeight);
} else {
weightArray = []
}
weightArray.push(nowWeight);
if (weightArray.length > countSize && Math.abs(err) <= allow) {
weightArray.splice(0, 1)
var arr = weightArray;
var count = 0
for (var i = 0; i < arr.length - 1; i++) {
if (arr[i] != 0) {
count += arr[i + 1] - arr[i]
}
}
// console.log(Math.abs(err) / _planSum);
// 判断最近30条数据平均值是否小于允许误差,并且误差在5%以下
// console.log(err+"/"+Math.abs(err) / _planSum + "/"+ allow);
if (nowWeight && (count / countSize) <= allow && (Math.abs(err) / _planSum < 0.05)) {
// console.log("*********************重量已经稳定,且在误差允许范围内*********************");
api.setGlobalData({ key: 'wendin', value: true });
weightArray = [];
} else {
weightArray = [];
// console.log("重量未稳定,请等待");
api.setGlobalData({ key: 'wendin', value: false });
}
}
}
function initReadStrAndLedSend() {
// 初始化讯飞语言引擎和字符卡通信
tts = api.require('iflyRecognition');
zfk = api.require("moduleDemo");
var param = {
host:zifukaHost,
port:zifukaPort,
};
// console.log(JSON.stringify(param));
zfk.createTcp(param, function (ret, err) {
if (!ret.status) {
console.log("字符卡连接异常");
api.alert({ msg: '字符卡连接异常,请检查配置' });
}
})
tts.createUtility({
android_appid: android_appid
}, function (ret, err) {
if (!ret.status) {
console.warn("语音引擎创建失败");
}
});
}
//语言播报指定内容
function readStr(str) {
tts.read({
readStr: str,
speed: 0,
volume: 100,
voice: "xiaoyan",
rate: 16000,
audioPath: audioPath
}, function (ret, err) {
if (ret.status) {
ret.speakProgress
} else {
console.warn("语言播报异常");
}
});
}
function resizeWindow() {
// 获取当前屏幕宽度,高度
var winWidth = api.winWidth;
var winHeight = api.winHeight;
if (winWidth < 800) {
_outerRadius = 82
_innerRadius = 70
_insidePanelRadius = 65
fontsize = 25
} else if (winWidth < 1200) {
_outerRadius = 105
_innerRadius = 80
_insidePanelRadius = 75
fontsize = 30
}
}
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]); return null; //返回参数值
}
function convertToPolarPoint(renderItemParams, radius, radian) {
return [
Math.cos(radian) * radius + renderItemParams.coordSys.cx,
-Math.sin(radian) * radius + renderItemParams.coordSys.cy
];
}
function makePionterPoints(renderItemParams, polarEndRadian) {
return [
convertToPolarPoint(renderItemParams, _outerRadius, polarEndRadian),
convertToPolarPoint(
renderItemParams,
_outerRadius,
polarEndRadian + Math.PI * 0.03
),
convertToPolarPoint(renderItemParams, _pointerInnerRadius, polarEndRadian)
];
}
//计划量/已装量echarts参数
function renderItemFeed(params, api) {
var valOnRadian = api.value(1);
var coords = api.coord([api.value(0), valOnRadian]);
var polarEndRadian = coords[3];
var imageStyle = {
image: _panelImageURL,
x: params.coordSys.cx - _outerRadius,
y: params.coordSys.cy - _outerRadius,
width: _outerRadius * 2,
height: _outerRadius * 2
};
return {
type: 'group',
children: [
{
type: 'image',
style: imageStyle,
clipPath: {
type: 'sector',
shape: {
cx: params.coordSys.cx,
cy: params.coordSys.cy,
r: _outerRadius,
r0: _innerRadius,
startAngle: 0,
endAngle: -polarEndRadian,
transition: 'endAngle',
enterFrom: { endAngle: 0 }
}
}
},
{
type: 'image',
style: imageStyle,
clipPath: {
type: 'polygon',
shape: {
points: makePionterPoints(params, polarEndRadian)
},
extra: {
polarEndRadian: polarEndRadian,
transition: 'polarEndRadian',
enterFrom: { polarEndRadian: 0 }
},
during: function (apiDuring) {
apiDuring.setShape(
'points',
makePionterPoints(params, apiDuring.getExtra('polarEndRadian'))
);
}
}
},
{
type: 'circle',
shape: {
cx: params.coordSys.cx,
cy: params.coordSys.cy,
r: _insidePanelRadius
},
style: {
fill: '#fff',
shadowBlur: 25,
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowColor: 'rgba(76,107,167,0.4)'
}
},
{
type: 'text',
extra: {
valOnRadian: valOnRadian,
transition: 'valOnRadian',
enterFrom: { valOnRadian: 0 }
},
style: {
text: makeTextFeed(valOnRadian),
fontSize: fontsize,
fontWeight: 900,
x: params.coordSys.cx,
y: params.coordSys.cy,
fill: 'rgb(255, 0, 0)',
align: 'center',
verticalAlign: 'middle',
enterFrom: { opacity: 0 }
},
during: function (apiDuring) {
apiDuring.setStyle(
'text',
makeTextFeed(apiDuring.getExtra('valOnRadian'))
);
}
}
]
};
}
function makeTextFeed(valOnRadian) {
if (load) {
// return '剩余应装\n' + valOnRadian.toFixed(1) + 'kg';
return api.getGlobalData({ key: 'feedName' }) + '差\n' + (_planSum - _feedNum).toFixed(0) + 'kg';
} else {
// return '剩余应卸\n' + valOnRadian.toFixed(1) + 'kg';
return api.getGlobalData({ key: 'feedName' }) + '差\n' + (_planSum - _feedNum).toFixed(0) + 'kg';
}
}
function renderLoad(title) {
var weightOption = {
animation: false,
dataset: {
source: [[1, nowWeight]]
},
title: {
// text:'总重量/剩余量'
// text:title
},
tooltip: {},
angleAxis: {
type: 'value',
startAngle: 0,
show: false,
min: 0,
max: _weightSum
},
radiusAxis: {
type: 'value',
show: false
},
polar: {},
series: [
{
type: 'custom',
coordinateSystem: 'polar',
renderItem: renderItemWeight
}
]
};
weightOption && weightMyChart.setOption(weightOption);
}
function renderUnload() {
var feedOption = {
animation: false,
dataset: {
// source: [[1, _planSum]]
source: [[1, _feedNum]]
},
tooltip: {},
angleAxis: {
type: 'value',
startAngle: 0,
show: false,
min: 0,
max: _planSum
},
radiusAxis: {
type: 'value',
show: false
},
polar: {},
series: [
{
type: 'custom',
coordinateSystem: 'polar',
renderItem: renderItemFeed
}
]
};
feedOption && feedMyChart.setOption(feedOption);
}
//总重量/剩余量echarts参数
function renderItemWeight(params, api) {
var valOnRadian = api.value(1);
var coords = api.coord([api.value(0), valOnRadian]);
var polarEndRadian = coords[3];
var imageStyle = {
image: _panelImageURL,
x: params.coordSys.cx - _outerRadius,
y: params.coordSys.cy - _outerRadius,
width: _outerRadius * 2,
height: _outerRadius * 2
};
return {
type: 'group',
children: [
{
type: 'image',
style: imageStyle,
clipPath: {
type: 'sector',
shape: {
cx: params.coordSys.cx,
cy: params.coordSys.cy,
r: _outerRadius,
r0: _innerRadius,
startAngle: 0,
endAngle: -polarEndRadian,
transition: 'endAngle',
enterFrom: { endAngle: 0 }
}
}
},
{
type: 'image',
style: imageStyle,
clipPath: {
type: 'polygon',
shape: {
points: makePionterPoints(params, polarEndRadian)
},
extra: {
polarEndRadian: polarEndRadian,
transition: 'polarEndRadian',
enterFrom: { polarEndRadian: 0 }
},
during: function (apiDuring) {
apiDuring.setShape(
'points',
makePionterPoints(params, apiDuring.getExtra('polarEndRadian'))
);
}
}
},
{
type: 'circle',
shape: {
cx: params.coordSys.cx,
cy: params.coordSys.cy,
r: _insidePanelRadius
},
style: {
fill: '#fff',
shadowBlur: 25,
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowColor: 'rgba(76,107,167,0.4)'
}
},
{
type: 'text',
extra: {
valOnRadian: valOnRadian,
transition: 'valOnRadian',
enterFrom: { valOnRadian: 0 }
},
style: {
text: makeTextWeight(valOnRadian),
fontSize: fontsize,
fontWeight: 900,
x: params.coordSys.cx,
y: params.coordSys.cy,
fill: 'rgb(0, 0, 0)',
align: 'center',
verticalAlign: 'middle',
enterFrom: { opacity: 0 }
},
during: function (apiDuring) {
apiDuring.setStyle(
'text',
makeTextWeight(apiDuring.getExtra('valOnRadian'))
);
}
}
]
};
}
function makeTextWeight(valOnRadian) {
return '总装料重\n' + valOnRadian.toFixed(0) + 'kg';
}
</script>
</body>
</html> -->

File diff suppressed because it is too large Load Diff

View File

@ -1,725 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>Document</title>
<link rel="stylesheet" href="../css/mui_min.css">
<link href="../css/mui_picker_min.css" rel="stylesheet" />
<link href="../css/mui_poppicker_css" rel="stylesheet" />
<script src="../script/ble.js"></script>
<script src="../script/index.js"></script>
<script src="../script/electric.js"></script>
<script src="../script/api.js"></script>
<script src="../script/mui.min.js"></script>
<script src="../script/mui.picker.min.js"></script>
<script src="../script/mui.poppicker.js"></script>
<script src="../script/echarts.js"></script>
</head>
<style>
.content {
width: 100%;
}
.head {
height: 9vh;
padding: 4px 0;
}
.btnc {
margin-left: 5px;
font-weight: 900;
border-radius: 20px;
}
.btnWIFI {
color: seagreen;
margin-left: 20px;
font-weight: 900;
}
.echarts_wrap {
background-color: brown;
width: 100%;
height: 72vh;
margin-top: 9vh;
display: flex;
justify-content: center;
align-items: center;
}
.echarts_item {
width: 35%;
height: 79vh;
}
.echarts_item1 {
width: 30%;
height: 79vh;
font-size: medium;
font-weight: 900;
}
.header_btn {
background-color: #407ae6;
color: #ffffff;
font-size: 25px;
height: 40px;
font-weight: 900;
width: 100%;
}
.feedShow {
margin: 10px;
}
.trains {
background-color: #407ae6
}
.dis {
display: none;
font-size: 30px;
}
/*toast信息提示*/
.mui-toast-container {
bottom: 50% !important;
}
.mui-toast-message {
/* background: url(/app/themes/default/images/toast.png) no-repeat center 10px #407ae6; */
opacity: 1;
/* color: #fff; */
width: 100%;
padding: 10px 5px 10px 5px;
}
</style>
<body>
<header class="mui-bar mui-bar-nav" style="height: 8vh;">
<div class="mui-row">
<div class="mui-col-xs-6" style="display:flex;align-items: center;">
<button id='showUserPicker' class="btnc mui-btn-inline mui-btn-primary" type='button'>请选择设备</button>
<text id='batchName' style="font-size: 14px;font-weight: 900;"></text>
<button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="refreshDayPlan()">更新计划</button>
<button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="reloadPage()">刷新页面</button>
</div>
<div class="mui-col-xs-6" style="display:flex;justify-content: flex-end;">
<button class="btnc mui-btn-inline mui-btn-danger" onclick="closeApp()" type='button'>关闭系统</button>
<button id="driveName" class="btnc mui-btn-info" type="button" onclick="handleBackSys()">机车手</button>
<button id='wifiDom' onclick="showZifuka()" class="btnc mui-btn-inline mui-btn-info"
style="color: seagreen !important;" type='button'>暂无设备</button>
</div>
</div>
</header>
<div class="mui-row" style="height: 83vh;margin-top: 9vh;">
<div class="mui-col-xs-2" style="height: 100%;box-sizing: border-box; border: 1px solid #a3caef;overflow: auto;">
<ul class="mui-table-view" id="train"
style="text-align: center;line-height: 30px;font-size: 12px;font-weight: 900;">
</ul>
</div>
<div class="mui-col-xs-10">
<div class="mui-scroll-wrapper"
style="width:100%;white-space: nowrap !important;overflow-x: scroll;" id="feedList">
</div>
<div>
<div id="echarts_main_one"></div>
<div id="echarts_main_two"></div>
<div >
<button class="btnc mui-btn-primary" type="button" id="fix" onclick="weightFix()">校准计划</button>
<div class="feedShow" id="nowFeed"></div>
<div class="feedShow" id="feedNum"></div>
<button class="btnc mui-btn-primary" id="startLoad" style="font-size: x-large;width: 80%;;"
onclick="startLoad()">开始装料</button>
<button class="btnc mui-btn-primary dis" id="submitData" style="font-size: x-large;width: 90%;"
onclick="submitData()">下一步</button>
</div>
</div>
</div>
</div>
<div class="mui-row" style="box-sizing: border-box; border: 1px solid #a3caef;">
<div class="mui-col-xs-2">
<text id="text" style="margin-left: 20px;line-height:10vh;font-weight: 900;" onclick="updateApp()"></text>
</div>
<div class="mui-col-xs-10" id="timeList">
</div>
</div>
<script type="text/javascript">
'use strict';
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var networkStatus = true;
var driverName = '';
var pickData = [];
var btnArray = ['取消', '<b style="font-weight:900">确认</b>'];
var sbId = null;
// 初始化echarts Dom
var weightChartDom = document.getElementById('echarts_main_two');
var weightMyChart = echarts.init(weightChartDom);
var feedChartDom = document.getElementById('echarts_main_one');
var feedMyChart = echarts.init(feedChartDom);
var _outerRadius = 105;
var _innerRadius = 85;
var feedName;
var templateName;
var templetType;
var _pointerInnerRadius = 20;
var _insidePanelRadius = 80;
var fontsize = 25;
var feedList = [];
var feedIndex = 0;
var classCode = 1;
var trainNumber = 1;
var templateName = '';
var trainIndex = 0;
var trainArr = [];
var batchName = '';
// 装料状态还是卸料状态
var load = true;
var beforeWeight = 0;
var _weightSum = 0;
var _planSum = 0;
var nowWeight = 0;
var _feedNum = 0;
var allow = 0;
var first = true;
var carListener = null;
var resultInterval = null;
var totalInterval = null;
var textInterval = null;
var echartsType = '';
var weightStatus = true;
var IFlyVoice = null;
var text = '';
var speed = '30';
var zfk;
var UNICODE_CHARS = {
1: "①",
2: "②",
3: "③",
4: "④",
5: "⑤",
6: "⑥",
7: "⑦",
8: "⑧",
9: "⑨",
10: "⑩",
11: "⑪",
12: "⑫",
13: "⑬",
14: "⑭",
15: "⑮",
16: "⑯",
17: "⑰",
18: "⑱",
19: "⑲",
20: "⑳",
21: "㉑",
22: "㉒",
23: "㉓",
24: "㉔",
25: "㉕",
26: "㉖",
27: "㉗",
28: "㉘",
29: "㉙",
30: "㉚"
}
var ble;
var apiready = function apiready() {
ble = api.require('ble');
zfk = api.require("moduleDemo");
clearInterval(resultInterval);
clearInterval(totalInterval);
clearInterval(textInterval);
IFlyVoice = api.require('IFlyVoice');
IFlyVoice.initSpeechSynthesizer(function (ret) {
// textInterval = setInterval(function () {
// console.log(text);
// if (text.length > 0) {
// speakTest(text, speed);
// text = '';
// speed = '30';
// }
// }, 2000);
});
initPage();
setTimeout(function(){
initService()
},1000)
api.addEventListener({
name: 'keyback'
}, function (ret, err) {
mui.confirm('确认关闭TMR饲喂系统', '提示', btnArray, function (e) {
if (e.index == 0) {} else {
api.closeWidget({
id: api.appId, //应用ID
retData: { name: 'closeWidget' },
silent: true
});
}
});
});
};
var value = 0;
var value1 = 0;
var data = [value, value1];
var option = {
backgroundColor: '#0F224C',
title: [{
text: batchName,
subtext: '',
x: '65%',
y: '70%',
textStyle: {
fontSize: 14,
fontWeight: '100',
color: '#5dc3ea',
lineHeight: 16,
textAlign: 'center'
}
}, {
text: feedName,
subtext: '',
x: '15%',
y: '70%',
textStyle: {
fontSize: 14,
fontWeight: '100',
color: '#5dc3ea',
lineHeight: 16,
textAlign: 'center'
}
}],
series: [{ //第二个球的填充
type: 'liquidFill',
radius: '60%',
center: ['75%', '35%'],
color: [{
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [{
offset: 0,
color: '#2aa1e3'
}, {
offset: 1,
color: '#08bbc9'
}],
globalCoord: false
}],
data: [value1, value1], // data个数代表波浪数
backgroundStyle: {
borderWidth: 1,
color: 'RGBA(51, 66, 127, 0.7)'
// color: '#0F224C',
},
label: {
normal: {
textStyle: {
fontSize: 28,
color: '#fff'
}
}
},
outline: {
// show: false
borderDistance: 0,
itemStyle: {
borderWidth: 2,
borderColor: '#112165'
}
}
}, {
type: 'liquidFill',
radius: '60%',
center: ['25%', '35%'],
color: [{
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [{
offset: 0,
color: '#446bf5'
}, {
offset: 1,
color: '#2ca3e2'
}],
globalCoord: false
}],
data: [value, value], // data个数代表波浪数
backgroundStyle: {
borderWidth: 1,
color: 'RGBA(51, 66, 127, 0.7)'
// color: '#0F224C',
},
label: {
normal: {
textStyle: {
fontSize: 28,
color: '#fff'
}
}
},
outline: {
// show: false
borderDistance: 0,
itemStyle: {
borderWidth: 2,
borderColor: '#112165'
}
}
}]
};
// 初始化页面
function initPage() {
getWifiInfo();
}
String.prototype.getByteLen = function () {
var len = 0;
for (var i = 0; i < this.length; i++) {
this.charCodeAt(i) < 256 ? len += 1 : len += 2;
}
return len;
};
var userPicker;
// 初始化设备下拉
function muiInit() {
(function ($, doc) {
$.init();
$.ready(function () {
/**
* 获取对象属性的值
* 主要用于过滤三级联动中,可能出现的最低级的数据不存在的情况,实际开发中需要注意这一点;
* @param {Object} obj 对象
* @param {String} param 属性名
*/
var _getParam = function _getParam(obj, param) {
return obj[param] || '';
};
if (userPicker) {} else {
userPicker = new $.PopPicker();
var showUserPickerButton = doc.getElementById('showUserPicker');
carListener = null;
carListener = showUserPickerButton.addEventListener('tap', function (event) {
userPicker.show(function (items) {
console.log('设备切换');
sbId = items[0].value;
showUserPickerButton.innerHTML = items[0].text;
initTime();
});
}, false);
}
userPicker.setData(pickData);
});
})(mui, document);
}
// 初始化班次信息
function initTime() {
api.ajax({
url: 'https://tmr.nxcyx.com/api/app/tmr/time?sourceCow=' + api.getPrefs({ sync: true, key: 'sourceCow' }),
method: 'get'
}, function (ret, err) {
if (ret) {
if (ret.data.length > 0) {
document.getElementById('text').innerHTML = '班次初始化';
} else {
document.getElementById('text').innerHTML = '当前暂无班次';
}
var html = '';
ret.data.forEach(function (e, index) {
if (index == 0) {
html += '<button class="btnc classes mui-btn-inline mui-btn-primary" type="button" onclick="handleClassClick(this,' + '\'' + e.batch + '\')">' + e.name + '(' + e.start + '-' + e.end + ')</button>';
} else {
html += '<button class="btnc classes mui-btn-inline" type="button" onclick="handleClassClick(this,' + '\'' + e.batch + '\')">' + e.name + '(' + e.start + '-' + e.end + ')</button>';
}
});
document.getElementById('timeList').innerHTML = html;
var param = {
classCode: ret.data[0].batch,
sbId: sbId,
sourceCow: api.getPrefs({ sync: true, key: 'sourceCow' }),
dateOf: getDateStr(new Date())
};
initTrain(param);
} else {
document.getElementById('text').innerHTML = '<font style="color:red">班次加载失败</font>';
}
});
}
// 初始化当前班次所有车次
function initTrain(param) {
document.getElementById('train').innerHTML = '暂无车次';
api.ajax({
url: 'https://tmr.nxcyx.com/api/app/tmr/planDay',
headers: {
'Content-Type': 'application/json;charset=utf-8' //建议key使用首字母大写的形式如 User-Agent
},
method: 'post',
data: {
body: param
}
}, function (ret, err) {
if (ret) {
if (ret.data.length > 0) {
document.getElementById('text').innerHTML = '车次初始化';
} else {
document.getElementById('feedList').innerHTML = '';
feedList = [];
document.getElementById('text').innerHTML = '当前暂无计划';
}
if (ret.data.length == 0) {
mui.toast("该班次暂无车次信息");
} else if (ret.data.length > 0) {
var html = '';
trainArr = [];
ret.data.forEach(function (e, index) {
trainArr.push(e.trainNumber);
if (index == 0) {
html += '<li id="classeCode_' + e.classCode + 'train_' + index + '" class="mui-table-view-cell trains" onclick="handleCarClick(this,' + '\'' + e.classCode + '\',\'' + e.trainNumber + '\')">第' + e.trainNumber + '车(' + e.templetName + ')</li>';
} else {
html += '<li id="classeCode_' + e.classCode + 'train_' + index + '" class="mui-table-view-cell" onclick="handleCarClick(this,' + '\'' + e.classCode + '\',\'' + e.trainNumber + '\')">第' + e.trainNumber + '车(' + e.templetName + ')</li>';
}
});
document.getElementById('train').innerHTML = html;
trainIndex = 0;
classCode = ret.data[0].classCode;
var param = {
classCode: ret.data[0].classCode,
sbId: sbId,
trainNumber: ret.data[0].trainNumber,
sourceCow: api.getPrefs({ sync: true, key: 'sourceCow' }),
dateOf: getDateStr(new Date())
};
initOne(param);
}
} else {
document.getElementById('text').innerHTML = '<font style="color:red">车次加载失败</font>';
}
});
}
// 初始化当前车次饲料信息
function initOne(param) {
if (sid) {
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-primary');
}
api.ajax({
url: 'https://tmr.nxcyx.com/api/app/tmr/planDay',
headers: {
'Content-Type': 'application/json;charset=utf-8' //建议key使用首字母大写的形式如 User-Agent
},
method: 'post',
data: {
body: param
}
}, function (ret, err) {
if (ret) {
first = true;
document.getElementById('text').innerHTML = '装料信息初始化成功';
var html = '';
ret.data.forEach(function (e) {
load = true;
trainNumber = e.trainNumber;
_weightSum = e.total.toFixed(0);
// 饲料
var feedJson = e.feedJson;
// 合并饲料和圈舍圈舍存入步骤stepsList
var json = [].concat(_toConsumableArray(e.feedJson), _toConsumableArray(e.cowshedJson));
feedList = json;
json.forEach(function (j, index) {
if (index == 0) {
html += '<span id="feed_' + index + '" class="mui-badge mui-badge-purple" style="font-size: 14px;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
} else {
html += '<span id="feed_' + index + '" class="mui-badge" style="font-size: 14px;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
}
});
document.getElementById('feedList').innerHTML = html;
// 根据步骤下标取stepsList的值
document.getElementById('batchName').innerHTML = e.className + e.trainNumber + '(' + e.total.toFixed(0) + 'kg)';
feedIndex = 0;
_feedNum = 0;
feedName = json[0].name;
// document.getElementById("upload").innerHTML = '上传'+json[0].name
document.getElementById('submitData').innerHTML = '上传' + json[0].name;
document.getElementById('fix').innerHTML = '装料前校准' + json[0].name;
document.querySelector('#feed_0').scrollIntoView(true);
allow = json[0].allow;
// 计划
_planSum = json[0].weight.toFixed(0);
document.getElementById('feedNum').innerHTML = '<font style="color:blue">计划:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
text = feedName + _planSum;
batchName = e.className + e.trainNumber;
templateName = e.templetName;
templetType = e.templetType;
document.getElementById('nowFeed').innerHTML = '<font style="color:blue">' + e.className + e.trainNumber + ',' + feedName + '</font>';
document.getElementById('text').innerHTML = 'V' + api.appVersion;
});
} else {
document.getElementById('text').innerHTML = '<font style="color:red">装料信息加载失败</font>';
}
});
}
//班次点击事件
function handleClassClick(obj, batch) {
document.getElementById('batchName').innerHTML = '';
document.getElementById('nowFeed').innerHTML = '';
// document.getElementById('beforeWeight').innerHTML = ''
document.getElementById('feedNum').innerHTML = '';
var doms = document.getElementsByClassName('classes');
if (doms.length > 0) {
for (var i = 0; i < doms.length; i++) {
doms[i].setAttribute("class", 'btnc classes mui-btn-inline');
}
}
obj.setAttribute("class", 'btnc classes mui-btn-inline mui-btn-primary');
var param = {
classCode: batch,
sbId: sbId,
sourceCow: api.getPrefs({ sync: true, key: 'sourceCow' }),
dateOf: getDateStr(new Date())
};
initTrain(param);
}
//左侧车次点击事件
function handleCarClick(obj, classCode, trainNumber) {
trainIndex = Number(trainNumber) - 1;
var doms = document.getElementsByClassName('trains');
if (doms.length > 0) {
for (var i = 0; i < doms.length; i++) {
doms[i].setAttribute("class", 'mui-table-view-cell');
}
}
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 = '设备初始化成功';
sbId = ret.data[0].sbId;
document.getElementById('showUserPicker').innerHTML = ret.data[0].name;
ret.data.forEach(function (e) {
var json = { value: e.sbId, text: e.name };
pickData.push(json);
});
muiInit();
initTime();
} else {
networkStatus = false;
api.hideProgress();
mui.alert("sbList:" + err.msg);
document.getElementById('text').innerHTML = '<font style="color:red">' + '服务器异常' + '</font>';
}
});
}
// 刷新页面
function reloadPage() {
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("清除完成");
});
}
});
}
</script>
</body>
</html>

View File

@ -72,8 +72,9 @@
margin:0 auto;
}
.btnc {
margin-left: 5px;
font-size: x-large;
margin-left: 15px;
/* margin-right: 15px; */
font-size: larger;
font-weight: 900;
border-radius: 20px;
}
@ -107,17 +108,17 @@
<div class="mui-row">
<!--头部信息开始-->
<div class="head flex mui-row">
<div class="mui-col-xs-6" style="display:flex;align-items: center;">
<div class="mui-col-xs-7" style="display:flex;align-items: center;">
<button id='showUserPicker' class="btnc mui-btn-inline mui-btn-primary" type='button'>请选择设备</button>
<text id='batchName' style="font-size: x-large;font-weight: 900;"></text>
<text id='batchName' style="font-size: larger;margin-left:15px;font-weight: 900;"></text>
<button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="refreshDayPlan()">更新计划</button>
<button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="reloadPage()">刷新页面</button>
</div>
<div class="mui-col-xs-6" style="display:flex;justify-content: flex-end;">
<div class="mui-col-xs-5" style="display:flex;justify-content: flex-end;">
<button class="btnc mui-btn-inline mui-btn-danger" onclick="closeApp()" type='button'>关闭系统</button>
<button id="driveName" class="btnc mui-btn-info" type="button" onclick="handleBackSys()">机车手</button>
<button id='wifiDom' onclick="showZifuka()" class="btnc mui-btn-inline mui-btn-info"
style="color: seagreen !important;" type='button'>暂无设备</button>
<button id='wifiDom' class="btnc mui-btn-inline mui-btn-info"
style="color: seagreen !important;" type='button'>暂未连接</button>
</div>
</div>
<!--中间内容开始-->
@ -125,24 +126,24 @@
<!--中间左边开始-->
<div class="mui-col-xs-3 centerLeft">
<ul class="mui-table-view" id="train"
style="text-align: left;line-height: 40px;font-size: x-large;font-weight: 900;">
style="text-align: left;line-height: 40px;font-size: larger;font-weight: 900;">
</ul>
</div>
<!--中间右边开始-->
<div class="mui-col-xs-9 centerRight mui-row">
<div class="mui-scroll-wrapper mui-col-sm-12 flex"
<div class="mui-scroll-wrapper mui-col-sm-12 "
style="width:100%;height:5vh;white-space: nowrap !important;overflow-x: scroll;" id="feedList">
</div>
<div class="mui-row mui-col-sm-12" >
<div id="echarts_main_one" class="mui-col-sm-6 echarts_item"></div>
<div id="echarts_main_two" class="mui-col-sm-6 echarts_item"></div>
<div class="mui-col-sm-12 flex2">
<button class="btnc mui-btn-primary" type="button" id="fix" onclick="weightFix()">校准计划</button>
<text id='nowFeed' style="font-size: x-large;font-weight: 900;"></text>
<button class="btnc mui-btn-success" style="font-size: x-large;" type="button" id="fix" onclick="weightFix()">校准计划</button>
<text id='nowFeed' style="font-size:x-large;font-weight: 900;margin-left:10px; "></text>
<text id='feedNum' style="font-size: x-large;font-weight: 900;"></text>
<button class="btnc mui-btn-primary" id="startLoad" style="font-size: x-large;width: 20%;;"
<button class="btnc mui-btn-success" id="startLoad" style="font-size: x-large;width: 20%;;"
onclick="startLoad()">开始装料</button>
<button class="btnc mui-btn-primary dis" id="submitData" style="font-size: x-large;width: 20%;"
<button class="btnc mui-btn-success dis" id="submitData" style="font-size: x-large;"
onclick="submitData()">上传</button>
</div>
@ -152,7 +153,7 @@
<!--尾部信息开始-->
<div class="footer flex mui-row">
<div class="mui-col-xs-2" >
<text id="text" style="margin-left: 20px;font-weight: 900;font-size: x-large;" onclick="updateApp()"></text>
<text id="text" style="margin-left: 20px;font-weight: 900;font-size: larger;" onclick="updateApp()"></text>
</div>
<div class="mui-col-xs-10" id="timeList" >
@ -278,6 +279,26 @@
});
};
function initService() {
initManager({single: true});
}
// 获取当前日期字符串
function getDateStr(date) {
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
return currentdate;
}
var value = 0;
var value1 = 0;
var data = [value, value1];
@ -524,7 +545,7 @@
// 初始化当前车次饲料信息
function initOne(param) {
if (sid) {
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-primary');
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-success');
}
api.ajax({
url: 'https://tmr.nxcyx.com/api/app/tmr/planDay',
@ -551,9 +572,9 @@
feedList = json;
json.forEach(function (j, index) {
if (index == 0) {
html += '<span id="feed_' + index + '" class="mui-badge mui-badge-purple" style="font-size: larger;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
html += '<span id="feed_' + index + '" class="mui-badge mui-badge-purple" style="font-size: large;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
} else {
html += '<span id="feed_' + index + '" class="mui-badge" style="font-size: larger;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
html += '<span id="feed_' + index + '" class="mui-badge" style="font-size: large;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
}
});
document.getElementById('feedList').innerHTML = html;
@ -564,7 +585,8 @@
feedName = json[0].name;
// document.getElementById("upload").innerHTML = '上传'+json[0].name
document.getElementById('submitData').innerHTML = '上传' + json[0].name;
document.getElementById('fix').innerHTML = '装料前校准' + json[0].name;
// document.getElementById('fix').innerHTML = '装料前校准' + json[0].name;
document.getElementById('fix').innerHTML = '装料前校准';
document.querySelector('#feed_0').scrollIntoView(true);
allow = json[0].allow;
// 计划
@ -574,7 +596,7 @@
batchName = e.className + e.trainNumber;
templateName = e.templetName;
templetType = e.templetType;
document.getElementById('nowFeed').innerHTML = '<font style="color:blue">' + e.className + e.trainNumber + ',' + feedName + '</font>';
document.getElementById('nowFeed').innerHTML = '<font style="color:blue;margin-left:10px; ">' + e.className + e.trainNumber + ',' + feedName + '</font>';
document.getElementById('text').innerHTML = 'V' + api.appVersion+'Ble';
});
} else {

View File

@ -1,67 +0,0 @@
const http = require('http')
const url = require('url')
const fs = require('fs')
const path = require('path')
// const mime = require('mime')
const mime = {
map: {
'html': 'text/html',
'xhtml': 'application/xhtml+xml',
'xml': 'text/xml',
'js': 'application/javascript',
'wasm': 'application/wasm',
'map': 'magnus-internal/imagemap',
'css': 'text/css',
'png': 'image/png',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'gif': 'image/gif',
'ico': 'image/vnd.microsoft.icon'
},
getType: function (ext) {
let conType = this.map[ext]
return conType || 'text/plain'
}
}
const httpServer = http.createServer()
httpServer.on('request', (req, res) => {
console.log(`[receive request] ${req.method} ${req.url}`)
const urlJson = url.parse(req.url)
let { pathname } = urlJson
let ext = pathname.split('.').pop()
// all
// res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
// res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
// just page file
if (ext === 'html' || ext === 'xhtml'|| ext === 'js') {
//跨域隔离
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
res.setHeader('Access-Control-Allow-Origin', 'https://resource.eziot.com')
//影响报告
//res.setHeader('Cross-Origin-Embedder-Policy-Report-Only', 'require-corp')
//res.setHeader('Cross-Origin-Opener-Policy-Report-Only', 'same-origin')
}
let contentType = mime.getType(ext)
res.setHeader('Content-Type', contentType)
fs.readFile(path.resolve(__dirname, pathname.substr(1)), (err, data) => {
if (err) {
res.writeHead(404)
res.end('Not found.')
} else {
res.writeHead(200)
res.end(data)
}
})
})
const PORT = 9090
httpServer.listen(9090, () => {
console.log(`Server running at http://localhost:${PORT}`)
})

View File

@ -3,9 +3,6 @@ function initManager(param) {
ble.initManager(param, function (ret) {
if (ret.state === "poweredOn") {
// console.log("初始化成功");
if (uuid){
disconnect({peripheralUUID: uuid});
}
scan({clean: true});
} else if (ret.state === 'poweredOff') {
api.hideProgress();
@ -20,6 +17,17 @@ var sta = true;
var scanInter;
function scan(param) {
if (!uuid){
uuid = api.getPrefs({
sync: true,
key: 'uuid'
});
}
if (uuid){
disconnect({peripheralUUID: uuid});
connect({peripheralUUID: uuid});
return false
}
sta = true
clearInterval(scanInter)
times = 5;
@ -38,7 +46,6 @@ function scan(param) {
getPeripheral();
sta = false;
}
}
},1000)
}
@ -54,6 +61,10 @@ function getPeripheral() {
console.log(p.name);
if (p.name.indexOf("BLUE2USART") !== -1) {
uuid = p.uuid;
api.setPrefs({
key: 'uuid',
value: uuid
});
ret2 = p;
if (ret2 !== {}) {
var wifiDom = document.getElementById('wifiDom');
@ -83,10 +94,17 @@ function getPeripheral() {
var connectTimes=0;
function connect(param) {
var wifiDom = document.getElementById('wifiDom');
wifiDom.innerHTML = "暂未连接";
api.showProgress({
title: '蓝牙连接中...',
modal: true
});
ble.connect(param, function (ret, err) {
if (ret.status) {
connetcedStatus = true
connectTimes = 0;
wifiDom.innerHTML = '已连接';
document.getElementById('text').innerHTML = '设备已连接';
text = '设备已连接';
console.log('连接成功')
@ -136,7 +154,7 @@ function discoverService(param) {
var msg = msgList[0];
msgList.splice(0, 1);
// console.log(msg+ ' ' +new Date().getSeconds()*1000+ new Date().getMilliseconds())
console.log('设备'+sbId + '班次' + classCode + '车次' + trainNumber +' '+ nowWeight + '/' + _weightSum + ' ' + feedName + _feedNum + '/' + _planSum);
// console.log('设备'+sbId + '班次' + classCode + '车次' + trainNumber +' '+ nowWeight + '/' + _weightSum + ' ' + feedName + _feedNum + '/' + _planSum);
var param1 = {
peripheralUUID: param.peripheralUUID,
serviceUUID: ret4,
@ -284,10 +302,10 @@ function discoverService(param) {
ledStatus = true;
}, 500);
setTimeout(() => {
setTimeout(function() {
console.log("开始长鸣")
control("40", "02");
setTimeout(() => {
setTimeout(function() {
ledStatus = true;
}, 500)
}, 500)
@ -295,7 +313,7 @@ function discoverService(param) {
}
if (feedErr <= allow) {
var filteredValue = weightDataFilter.filter(nowWeight);
if (weightDataFilter.dataBuffer.length == 80) {
if (weightDataFilter.dataBuffer.length === 80) {
console.log("重量稳定", currTimeFn(new Date()));
weightDataFilter.dataBuffer = [];
// document.getElementById('submitData').click();
@ -335,7 +353,7 @@ function setNotify(param, callback) {
ble.setNotify(param, function (ret) {
// console.log(JSON.stringify(ret))
var value = ret.characteristic.value;
if (ret && value.indexOf('ff01') != -1) {
if (ret && value.indexOf('ff01') !== -1) {
var wei = value.substr(12, 12);
wei = Math.round(Number(hex2a(wei)));
}
@ -406,6 +424,7 @@ function getMess(param, callback) {
count ++;
if (count >= 5){
msgList.push(param.value);
// console.log(param.value + ' '+ new Date().getSeconds() + ' '+new Date().getMilliseconds())
renderUnload();
renderLoad();
feedMyChart.setOption({
@ -418,12 +437,16 @@ function getMess(param, callback) {
source: [[1, nowWeight]]
}
});
// console.log(param.value + ' '+ _feedNum + ' '+nowWeight)
count = 0 ;
}
});
}
function initWeight() {
api.showProgress({
title: '图表数据加装中...',
modal: true
});
weightStatus = true;
weightDataFilter = new WeightDataFilter(80, _weightSum);
renderUnload();
@ -446,8 +469,8 @@ function initWeight() {
totalInterval = setInterval(function () {
totalWeightUpload();
}, 3000);
document.getElementById('startLoad').setAttribute("class", 'btnc mui-btn-primary dis');
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-primary');
document.getElementById('startLoad').setAttribute("class", 'btnc mui-btn-success dis');
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-success');
document.getElementById('text').innerHTML = 'V' + api.appVersion;
api.setGlobalData({key: 'startTime', value: currTimeFn(new Date())});
}

View File

@ -27,6 +27,10 @@ function startLoad() {
mui.toast("没有装料信息");
return false;
}
api.showProgress({
title: '初始化服务中...',
modal: true
});
// 初始化查询称和字符卡配置信息
initService();
}
@ -78,7 +82,7 @@ function submitData() {
// 没有下一个车次,饲喂完成
if (trainIndex > trainArr.length - 1) {
mui.toast('本班次饲喂完成');
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-primary dis');
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-success dis');
return false;
}
// 自动点击下一车,并定位,同时刷新下一个开始装料时间
@ -107,12 +111,13 @@ function submitData() {
feedName = feedList[feedIndex].name;
// document.getElementById("upload").innerHTML = '上传'+json[0].name
document.getElementById('submitData').innerHTML = '上传' + feedName;
document.getElementById('fix').innerHTML = '装料前校准' + feedName;
// document.getElementById('fix').innerHTML = '装料前校准' + feedName;
document.getElementById('fix').innerHTML = '装料前校准';
document.querySelector('#feed_' + feedIndex).scrollIntoView(true);
allow = feedList[feedIndex].allow;
_planSum = feedList[feedIndex].weight.toFixed(0);
text = feedName + _planSum;
document.getElementById('nowFeed').innerHTML = '<font style="color:blue">' + batchName + ',' + feedName + '</font>';
document.getElementById('nowFeed').innerHTML = '<font style="color:blue;margin-left:10px;">' + batchName + ',' + feedName + '</font>';
ledStatus = false;
// setTimeout(() => {
console.log("停止蜂鸣");
@ -153,25 +158,7 @@ var connetcedStatus = false;
// }, 1000)
// 初始化所有服务
function initService() {
initManager({single: true});
}
// 获取当前日期字符串
function getDateStr(date) {
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
return currentdate;
}
// 获取当前时间字符串
function currTimeFn(_date) {
@ -585,20 +572,30 @@ function closeApp() {
// let filteredValue = weightDataFilter.filter(measurementValue);
// 其中10是窗口大小0.5是最大的偏差值可以根据实际需求进行调整。measurementValue是当前的测量值。
class WeightDataFilter {
constructor(windowSize, maxDeviation) {
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var WeightDataFilter = function () {
function WeightDataFilter(windowSize, maxDeviation) {
_classCallCheck(this, WeightDataFilter);
this.windowSize = windowSize;
this.maxDeviation = maxDeviation;
this.dataBuffer = [];
this.lastValidValue = NaN;
}
filter(value) {
_createClass(WeightDataFilter, [{
key: "filter",
value: function filter(value) {
this.dataBuffer.push(value);
if (this.dataBuffer.length > this.windowSize) {
this.dataBuffer.shift();
}
let filteredValue = this.getAverageValue();
var filteredValue = this.getAverageValue();
// console.log(filteredValue,Math.abs(filteredValue - this.lastValidValue),this.maxDeviation);
if (isNaN(this.lastValidValue) || Math.abs(filteredValue - this.lastValidValue) <= this.maxDeviation) {
this.lastValidValue = filteredValue;
@ -607,10 +604,15 @@ class WeightDataFilter {
return this.lastValidValue;
}
}
getAverageValue() {
let sum = this.dataBuffer.reduce((total, value) => total + value, 0);
}, {
key: "getAverageValue",
value: function getAverageValue() {
var sum = this.dataBuffer.reduce(function (total, value) {
return total + value;
}, 0);
return sum / this.dataBuffer.length;
}
}]);
}
return WeightDataFilter;
}();