Files
WMS/HHWMS.Web/Views/Home/FrontPage.cshtml
T
zhougf c38199268f feat: 添加SignalR登录状态管理功能
- 在Program.cs中注册LoginHub
- 在HomeController中传递用户ID以支持SignalR连接
- 在Index.cshtml中实现SignalR连接和心跳机制,处理强制登出和注册成功事件
- 移除旧的登录状态检查逻辑,优化页面加载时的连接管理
2025-12-05 21:36:47 +08:00

417 lines
12 KiB
Plaintext

@model WalkingTec.Mvvm.Core.BaseVM
@using System.Text.Json
<div class="layui-row layui-col-space15" id="frontpage">
<div class="layui-col-md12">
<div class="layui-row layui-col-space15">
<!-- 一周内出入库任务统计柱状图 -->
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-header">一周内出入库任务统计</div>
<div class="layui-card-body">
<div id="taskHistoryChart" style="width: 100%; height: 300px;"></div>
</div>
</div>
</div>
<!-- 库内库位统计南丁格尔图 -->
<div class="layui-col-md6">
<div class="layui-card">
<div class="layui-card-header">库内库位统计</div>
<div class="layui-card-body">
<div id="locationChart" style="width: 100%; height: 300px;"></div>
</div>
</div>
</div>
<!-- 当前任务统计仪表盘 -->
<div class="layui-col-md6">
<div class="layui-card">
<div class="layui-card-header">未完成任务统计</div>
<div class="layui-card-body">
<div id="currentTaskChart" style="width: 100%; height: 300px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$("#frontpage").parent().css("background-color", "#eee");
// 初始化所有图表
layui.use(['admin', 'carousel'], function () {
var $ = layui.$
, admin = layui.admin
, carousel = layui.carousel
, element = layui.element
, device = layui.device();
element.render('progress');
// 初始化图表
initTaskHistoryChart();
initLocationChart();
initCurrentTaskChart();
});
//console.log(echarts);
// 一周内出入库任务统计柱状图
function initTaskHistoryChart() {
var taskHistoryChart = echarts.init(document.getElementById('taskHistoryChart'));
// 显示加载动画
taskHistoryChart.showLoading();
// 获取数据
$.ajax({
url: '/Home/GetTaskHistoryChart',
type: 'GET',
success: function(res) {
taskHistoryChart.hideLoading();
// 处理数据
var categories = [];
var inData = [];
var outData = [];
var moveData = [];
if (res) {
try {
// 解析后端返回的JSON字符串
var dataset = JSON.parse(res.dataset);
var series = JSON.parse(res.series);
var legend = JSON.parse(res.legend);
// 从dataset中提取数据
if (dataset && dataset.source && dataset.source.length > 1) {
// 第一行是表头,获取日期列表
var headers = dataset.source[0];
var dateIndex = 0; // 假设第一列是日期
// 找到各个任务类型的索引
var inIndex = headers.indexOf('入库任务');
var outIndex = headers.indexOf('出库任务');
var moveIndex = headers.indexOf('移库任务');
// 提取日期列表(跳过表头行)
for (var i = 1; i < dataset.source.length; i++) {
categories.push(dataset.source[i][dateIndex]);
}
// 提取各类任务数据
for (var i = 1; i < dataset.source.length; i++) {
var row = dataset.source[i];
inData.push(inIndex > 0 ? parseInt(row[inIndex]) || 0 : 0);
outData.push(outIndex > 0 ? parseInt(row[outIndex]) || 0 : 0);
moveData.push(moveIndex > 0 ? parseInt(row[moveIndex]) || 0 : 0);
}
}
} catch (e) {
console.error('解析数据失败:', e);
}
}
// 设置图表选项
var option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
data: ['入库任务', '出库任务', '移库任务']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
data: categories
},
yAxis: {
type: 'value',
minInterval: 1,
},
series: [
{
name: '入库任务',
type: 'bar',
label: {
show: true,
position: 'top'
},
emphasis: {
focus: 'series'
},
data: inData
},
{
name: '出库任务',
type: 'bar',
label: {
show: true,
position: 'top'
},
emphasis: {
focus: 'series'
},
data: outData
},
{
name: '移库任务',
label: {
show: true,
position: 'top'
},
type: 'bar',
emphasis: {
focus: 'series'
},
data: moveData
}
]
};
// 设置图表选项并渲染
taskHistoryChart.setOption(option);
},
error: function() {
taskHistoryChart.hideLoading();
layer.msg('获取任务历史数据失败');
}
});
// 窗口大小变化时,重新调整图表大小
window.addEventListener('resize', function() {
taskHistoryChart.resize();
});
}
// 库内库位统计南丁格尔图
function initLocationChart() {
var locationChart = echarts.init(document.getElementById('locationChart'));
// 显示加载动画
locationChart.showLoading();
// 获取数据
$.ajax({
url: '/Home/GetLocationChart',
type: 'GET',
success: function(res) {
locationChart.hideLoading();
// 处理数据
var data = [];
if (res) {
try {
// 解析后端返回的JSON字符串
var dataset = JSON.parse(res.dataset);
var series = JSON.parse(res.series);
var legend = JSON.parse(res.legend);
// 从dataset中提取数据
if (dataset && dataset.source && dataset.source.length > 1) {
// 跳过表头行
for (var i = 1; i < dataset.source.length; i++) {
var row = dataset.source[i];
data.push({
name: row[0],
value: row[1]
});
}
}
} catch (e) {
console.error('解析数据失败:', e);
}
}
// 设置图表选项
var option = {
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left',
data: data.map(item => item.name)
},
series: [
{
name: '库位状态',
type: 'pie',
radius: ['30%', '70%'],
center: ['50%', '50%'],
roseType: 'area', // 南丁格尔图
itemStyle: {
borderRadius: 8
},
data: data,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
// 设置图表选项并渲染
locationChart.setOption(option);
},
error: function() {
locationChart.hideLoading();
layer.msg('获取库位统计数据失败');
}
});
// 窗口大小变化时,重新调整图表大小
window.addEventListener('resize', function() {
locationChart.resize();
});
}
// 当前任务统计仪表盘
function initCurrentTaskChart() {
var currentTaskChart = echarts.init(document.getElementById('currentTaskChart'));
// 显示加载动画
currentTaskChart.showLoading();
// 获取数据
$.ajax({
url: '/Home/GetCurrentTaskChart',
type: 'GET',
success: function(res) {
currentTaskChart.hideLoading();
// 处理数据
var data = [];
var maxValue = 0;
if (res) {
try {
// 解析后端返回的JSON字符串
var dataset = JSON.parse(res.dataset);
var series = JSON.parse(res.series);
var legend = JSON.parse(res.legend);
// 从dataset中提取数据
if (dataset && dataset.source && dataset.source.length > 1) {
// 跳过表头行
for (var i = 1; i < dataset.source.length; i++) {
var row = dataset.source[i];
data.push({
name: row[0],
value: parseInt(row[1]) || 0
});
}
// 计算最大值,用于仪表盘刻度
maxValue = Math.max(...data.map(item => item.value), 10);
}
} catch (e) {
console.error('解析数据失败:', e);
}
}
// 设置仪表盘的位置和大小
var gaugeWidth = 100 / (data.length || 1);
var gauges = [];
data.forEach(function(item, index) {
gauges.push({
name: item.name,
type: 'gauge',
center: [(index + 0.5) * gaugeWidth + '%', '55%'],
radius: '70%',
min: 0,
max: maxValue,
splitNumber: 5,
axisLine: {
lineStyle: {
width: 8,
color: [
[0.3, '#67e0e3'],
[0.7, '#37a2da'],
[1, '#fd666d']
]
}
},
pointer: {
itemStyle: {
color: 'auto'
}
},
axisTick: {
distance: -30,
length: 8,
lineStyle: {
color: '#fff',
width: 2
}
},
splitLine: {
distance: -30,
length: 30,
lineStyle: {
color: '#fff',
width: 4
}
},
axisLabel: {
color: 'auto',
distance: 40,
fontSize: 10
},
detail: {
valueAnimation: true,
formatter: '{value}',
color: 'auto',
fontSize: 16
},
title: {
offsetCenter: [0, '80%'],
fontSize: 12
},
data: [{
value: item.value,
name: item.name
}]
});
});
// 设置图表选项
var option = {
tooltip: {
formatter: '{a} <br/>{b} : {c}'
},
series: gauges
};
// 设置图表选项并渲染
currentTaskChart.setOption(option);
},
error: function() {
currentTaskChart.hideLoading();
layer.msg('获取当前任务统计数据失败');
}
});
// 窗口大小变化时,重新调整图表大小
window.addEventListener('resize', function() {
currentTaskChart.resize();
});
}
</script>