足底健康分析服务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

621 lines
17 KiB

3 years ago
var device_list = [];
const app = {
data() {
return {
device_list: [],
show_category1:false,
show_category2:true,
menu_selected:1,
compare:{
compare1:true,
compare2:false,
compare3:false,
compare4:false,
compare5:false,
},
}
},
mounted() {
var _this = this;
axios
.get('/loraDeviceList')
.then(function (response) {
device_list = response.data
_this.device_list = device_list;
})
.catch(function (error) { // 请求失败处理
console.log(error);
});
3 years ago
3 years ago
// 每隔5分钟定时刷新
this.timer = setInterval(() => {
this.getFxItemlist();
}, 1000 * 3)
},
beforeDestroy() {
clearInterval(this.timer);
},
methods: {
toggleCompare(click_compare) {
if (click_compare == 1){
this.show_category = true
} else {
this.show_category = false
3 years ago
}
3 years ago
this.menu_selected = click_compare;
for(key in this.compare){
this.compare[key] = false
this.compare['compare' + click_compare] = true
3 years ago
}
3 years ago
},
toggleDevice(device_mac){
console.log(device_mac)
},
//定时刷新设备在线状态
getFxItemlist() {
this.device_list = device_list
this.$forceUpdate();
}
},
computed: {
menuSelected(menu_selected_num) {
return {
'menu-button-selected': true,
}
}
}
}
Vue.createApp(app).mount('#app')
var mac = '616162626363';
var clear = 0;
//默认显示各项对比
var show_type = 1;
//1血氧
var compare_type = 1;
var dom1 = document.getElementById('container1');
var dom2 = document.getElementById('container2');
var dom4 = document.getElementById('container4');
var data_blood = [];
var data_temperature = [];
var data_heart = [];
var data_humidity = [];
var data_total = [];
buildCompare(dom1);
buildRadar(dom2);
buildDevice(dom4);
function hideDiv() {
$("#container1").toggle();
$("#container2").toggle();
$("#container3").toggle();
clear = 1
show_type = (show_type == 1) ? 2 : 1;
}
/**
* 各项对比
* @param dom
*/
function buildCompare(dom) {
var myChart = echarts.init(dom, 'dark', {
renderer: 'canvas',
useDirtyRect: false
3 years ago
});
3 years ago
var option = {
color: ['#2ec7c9', '#5ab1ef', '#f5994e', '#c05050', '#c14089', '#9a7fd1'],
backgroundColor:'',
grid: {
left: '25%'
},
3 years ago
tooltip: {
trigger: 'axis'
},
3 years ago
legend: {
data: [
{
name: '血氧',
textStyle: {
color: 'auto'
}
},
{
name: '温度',
textStyle: {
color: 'auto'
}
},
{
name: '心率',
textStyle: {
color: 'auto'
}
},
{
name: '湿度',
textStyle: {
color: 'auto'
}
},
{
name: '总体',
textStyle: {
color: 'auto'
}
}
],
textStyle: {
fontSize: 20
}
},
3 years ago
xAxis: {
3 years ago
type: 'time',
name: '时间(/s)',
axisLabel: {
fontSize: 16,
formatter: function (value) {
return echarts.format.formatTime('mm:ss', new Date(value));
}
},
nameTextStyle: {
fontSize: 16
}
3 years ago
},
yAxis: [
{
3 years ago
name: '血氧',
min: 0,
max: 100,
position: 'left',
nameTextStyle: {
align: 'right',
color: '#2ec7c9',
fontSize: 16
},
axisLine: {
show: true,
lineStyle: {
color: '#2ec7c9'
}
},
axisLabel: {
formatter: '{value}%',
color: '#2ec7c9',
fontSize: 16
},
},
{
type: 'value',
name: '温度',
3 years ago
min: 30,
3 years ago
max: 45,
position: 'left',
offset: 50,
nameTextStyle: {
align: 'right',
color: '#5ab1ef',
fontSize: 16
},
axisLine: {
show: true,
lineStyle: {
color: '#5ab1ef'
}
},
axisLabel: {
formatter: '{value}°C',
color: '#5ab1ef',
fontSize: 16
},
3 years ago
},
{
type: 'value',
3 years ago
name: '心率',
min: 0,
max: 150,
position: 'left',
offset: 100,
nameTextStyle: {
align: 'right',
color: '#f5994e',
fontSize: 16
},
axisLine: {
show: true,
lineStyle: {
color: '#f5994e'
}
},
axisLabel: {
formatter: '{value}次',
color: '#f5994e',
fontSize: 16
},
},
{
type: 'value',
name: '湿度',
3 years ago
min: 0,
max: 100,
position: 'left',
3 years ago
offset: 150,
nameTextStyle: {
align: 'right',
color: '#c05050',
fontSize: 16
},
axisLine: {
show: true,
lineStyle: {
color: '#c05050'
}
},
3 years ago
axisLabel: {
3 years ago
formatter: '{value}%',
color: '#c05050',
fontSize: 16
},
},
{
type: 'value',
name: '总体',
min: 0,
max: 100,
position: 'left',
offset: 200,
nameTextStyle: {
align: 'right',
color: '#c14089',
fontSize: 16
},
axisLine: {
show: true,
lineStyle: {
color: '#c14089'
}
},
axisLabel: {
formatter: '{value}%',
color: '#c14089',
fontSize: 16
},
3 years ago
}
],
3 years ago
series: [
{
name: '血氧',
type: 'scatter',
symbolSize: 10,
yAxisIndex: 0,
tooltip: {
valueFormatter: (value) => value.toFixed(2) + ' %'
}
},
{
name: '温度',
type: 'scatter',
symbolSize: 10,
yAxisIndex: 1,
tooltip: {
valueFormatter: (value) => value.toFixed(2) + ' ℃'
}
},
{
name: '心率',
type: 'scatter',
symbolSize: 10,
yAxisIndex: 2,
tooltip: {
valueFormatter: (value) => value.toFixed(2) + ' 次'
}
},
{
name: '湿度',
type: 'scatter',
symbolSize: 10,
yAxisIndex: 3,
tooltip: {
valueFormatter: (value) => value.toFixed(2) + ' %'
}
},
{
name: '总体',
type: 'line',
smooth: true,
tooltip: {
valueFormatter: (value) => value.toFixed(2) + ' %'
}
3 years ago
}
3 years ago
],
3 years ago
3 years ago
};
3 years ago
3 years ago
if (option && typeof option === 'object') {
myChart.setOption(option);
}
3 years ago
3 years ago
window.addEventListener('resize', myChart.resize);
3 years ago
3 years ago
setInterval(function () {
if (show_type != 1) {
if (clear == 1) {
data_blood = []
data_temperature = [];
data_heart = [];
data_humidity = [];
data_total = [];
clear = 0;
}
3 years ago
3 years ago
return;
3 years ago
}
3 years ago
$.get('/loraData2?mac=' + mac).done(function (rawData) {
if (!rawData || rawData.length == 0){
return;
}
3 years ago
3 years ago
let limit = 5
if (data_blood.length >= limit) {
data_blood.shift();
}
if (data_temperature.length >= limit) {
data_temperature.shift();
}
if (data_heart.length >= limit) {
data_heart.shift();
}
if (data_humidity.length >= limit) {
data_humidity.shift();
}
if (data_total.length >= 10 * limit) {
data_total.splice(0, 10);
}
rawData.blood.forEach(value => data_blood.push(value));
rawData.temperature.forEach(value => data_temperature.push(value));
rawData.heart.forEach(value => data_heart.push(value));
rawData.humidity.forEach(value => data_humidity.push(value));
// rawData.total_data.forEach(value => data_total.push(value));
3 years ago
3 years ago
myChart.setOption({
series: [
{
name: '血氧',
data: data_blood
}, {
name: '温度',
data: data_temperature
}, {
name: '心率',
data: data_heart
}, {
name: '湿度',
data: data_humidity
},
// {
// name: '总体',
// data: data_total
// }
]
});
});
3 years ago
3 years ago
}, 2000);
3 years ago
}
3 years ago
/**
* 雷达图
* @param dom
*/
function buildRadar(dom) {
3 years ago
var myChart = echarts.init(dom, null, {
renderer: 'canvas',
3 years ago
useDirtyRect: false,
3 years ago
});
3 years ago
// window.onresize = function() {
// myChart.resize();
// };
var option = {
color: ['#2ec7c9', '#5ab1ef', '#f5994e', '#c05050', '#c14089', '#9a7fd1'],
backgroundColor:'',
radar: {
// shape: 'circle',
indicator: [
{name: '血氧', max: 100},
{name: '温度', max: 45},
{name: '心率', max: 150},
{name: '湿度', max: 100},
3 years ago
],
3 years ago
axisName: {
fontSize: 18,
color: '#2ec7c9',
3 years ago
},
3 years ago
},
series: [
{
type: 'radar',
}
]
};
if (option && typeof option === 'object') {
3 years ago
myChart.setOption(option);
}
3 years ago
window.addEventListener('resize', myChart.resize);
3 years ago
3 years ago
setInterval(buildData, 1000 * 5);
3 years ago
3 years ago
function buildData() {
if (show_type != 1 || data_blood.length == 0) {
return;
}
3 years ago
3 years ago
let blood = data_blood.slice(-1)[0][1];
let temperature = data_temperature.slice(-1)[0][1];
let heart = data_temperature.slice(-1)[0][1];
let humidity = data_humidity.slice(-1)[0][1];
3 years ago
3 years ago
myChart.setOption({
series: [
{
data: [
3 years ago
{
3 years ago
value: [blood, temperature, heart, humidity],
areaStyle: {
color: 'rgba(255, 228, 52, 0.6)'
},
label: {
show: true,
textStyle: {
color: '#2ec7c9',
fontSize: 16,
},
formatter: function (params) {
return params.value;
}
}
3 years ago
}
3 years ago
]
}
]
});
}
}
3 years ago
3 years ago
function buildDevice(dom) {
var myChart = echarts.init(dom, 'dark', {
renderer: 'canvas',
useDirtyRect: false
});
3 years ago
3 years ago
var option = {
backgroundColor:'',
tooltip: {
trigger: 'axis'
},
legend: {
data: ['设备1', '设备2', '设备3',],
textStyle: {
fontSize: 20
3 years ago
}
3 years ago
},
xAxis: {
type: 'time',
name: '时间(/s)',
axisLabel: {
fontSize: 16,
formatter: function (value) {
return echarts.format.formatTime('mm:ss', new Date(value));
}
},
nameTextStyle: {
fontSize: 16
}
},
yAxis: [
{
type: 'value',
min: 0,
max: 100,
nameTextStyle: {
align: 'right',
fontSize: 16
},
axisLine: {
show: true,
},
axisLabel: {
formatter: '{value}%',
fontSize: 16
},
}
],
3 years ago
3 years ago
};
3 years ago
if (option && typeof option === 'object') {
myChart.setOption(option);
}
window.addEventListener('resize', myChart.resize);
3 years ago
let special_compare_data = [];
setInterval(function () {
// if (show_type != 2) {
// if (clear == 1) {
// special_compare_data = [];
// clear = 0;
// }
//
// return;
// }
let chart_data = [];
let expire = 0;
$.get('/getSpecialCompare?compare_type=' + compare_type).done(function (rawData) {
//追加数据
device_list.forEach(function (item, key) {
let name = item.name;
let device_data = rawData[name];
if (device_data) {
device_list[key].online = 1
if (special_compare_data[name]) {
device_data.forEach(value => special_compare_data[name].push(value));
} else {
device_data.forEach(function (value) {
special_compare_data[name] = [value]
});
}
if (special_compare_data[name].length > 5) {
if (special_compare_data[name][0][0] > expire) {
expire = special_compare_data[name][0][0];
}
3 years ago
3 years ago
}
} else {
device_list[key].online = 0
}
})
//删除过期时间,构建图表数据
for (key in special_compare_data) {
if (special_compare_data[key]
&& special_compare_data[key].length > 0
&& special_compare_data[key][0][0] <= expire) {
special_compare_data[key].shift()
}
chart_data.push({
name: key,
data: special_compare_data[key],
type: 'line',
smooth: true,
})
}
myChart.setOption({
series: chart_data
});
});
}, 1000 * 2);
}