修改移动端内容,后端添加了所有查询接口

This commit is contained in:
2025-10-31 17:18:30 +08:00
parent 9800a37055
commit ac541472c2
9 changed files with 2530 additions and 1262 deletions

View File

@@ -1,147 +1,141 @@
<template>
<view class="container">
<!-- 日月年汇总单选 -->
<view class="tab-container">
<view
v-for="item in timeTabs"
<view class="page-container">
<!-- 时间维度切换 -->
<view class="time-tab-bar">
<view
v-for="item in timeTabs"
:key="item.value"
class="tab-item"
:class="{ active: activeTab === item.value }"
class="time-tab-item"
:class="{ 'time-tab-active': activeTab === item.value }"
@click="handleTabChange(item.value)"
>
{{ item.label }}
</view>
</view>
<!-- 日期选择 -->
<view class="date-picker">
<!-- 日期选择 -->
<view class="date-selector">
<!-- 日模式 -->
<view v-if="activeTab === 'day'" class="date-item">
<picker
mode="date"
:value="startDate"
@change="handleDateChange"
>
<view class="picker-text">选择日期{{ startDate }}</view>
<picker v-if="activeTab === 'day'" mode="date" :value="startDate" @change="handleDateChange">
<view class="date-input">
<text class="date-label">日期</text>
<text class="date-value">{{ startDate }}</text>
</view>
</picker>
<!-- 月模式 -->
<view v-else-if="activeTab === 'month'" class="date-range-group">
<picker mode="date" fields="month" :value="startDate" @change="handleStartMonthChange">
<view class="date-input">
<text class="date-label"></text>
<text class="date-value">{{ startDate }}</text>
</view>
</picker>
<view class="date-separator"></view>
<picker mode="date" fields="month" :value="endDate" :start="startDate" :end="maxMonthEnd" @change="handleEndMonthChange">
<view class="date-input">
<text class="date-label"></text>
<text class="date-value">{{ endDate }}</text>
</view>
</picker>
</view>
<!-- 月模式 -->
<view v-else-if="activeTab === 'month'" class="date-range">
<view class="date-item">
<picker
mode="date"
fields="month"
:value="startDate"
@change="handleStartMonthChange"
>
<view class="picker-text">开始月份{{ startDate }}</view>
</picker>
</view>
<view class="date-item">
<picker
mode="date"
fields="month"
:value="endDate"
:start="startDate"
:end="maxMonthEnd"
@change="handleEndMonthChange"
>
<view class="picker-text">结束月份{{ endDate }}</view>
</picker>
</view>
</view>
<!-- 年模式 -->
<view v-else class="date-range">
<view class="date-item">
<picker
mode="date"
fields="year"
:value="startDate"
@change="handleStartYearChange"
>
<view class="picker-text">开始年份{{ startDate }}</view>
<view v-else class="date-range-group">
<picker mode="date" fields="year" :value="startDate" @change="handleStartYearChange">
<view class="date-input">
<text class="date-label"></text>
<text class="date-value">{{ startDate }}</text>
</view>
</picker>
<view class="date-separator"></view>
<picker mode="date" fields="year" :value="endDate" @change="handleEndYearChange">
<view class="date-input">
<text class="date-label"></text>
<text class="date-value">{{ endDate }}</text>
</view>
</picker>
</view>
<view class="date-item">
<picker
mode="date"
fields="year"
:value="endDate"
@change="handleEndYearChange"
>
<view class="picker-text">结束年份{{ endDate }}</view>
</picker>
</view>
<!-- 生产汇总数据 -->
<view class="summary-section">
<view class="section-header">
<text class="section-title">生产汇总</text>
<text class="section-date">{{ displayDateRange }}</text>
</view>
<view class="summary-grid">
<view class="summary-card" v-for="(item, index) in summaryData" :key="index">
<text class="summary-label">{{ item.label }}</text>
<view class="summary-value-box">
<text class="summary-value">{{ item.value }}</text>
<text v-if="item.unit" class="summary-unit">{{ item.unit }}</text>
</view>
</view>
</view>
</view>
<!-- 统计图轮播产量相关 -->
<view class="chart-container">
<swiper
class="chart-swiper"
:current="currentSwiperIndex"
@change="onSwiperChange"
:autoplay="false"
:circular="false"
:indicator-dots="true"
indicator-active-color="#1a73e8"
indicator-color="#e5e5e5"
>
<swiper-item v-for="(item, index) in chanLiangChartConfig" :key="index">
<qiun-data-charts :type="item.type" :chartData="item.chartData" :title="item.title"/>
</swiper-item>
</swiper>
<!-- 产量趋势图 -->
<view class="chart-section">
<view class="section-header">
<text class="section-title">产量趋势</text>
</view>
<view class="chart-wrapper">
<qiun-data-charts type="mix" :chartData="productionChartData" :opts="productionChartOpts"/>
</view>
</view>
<!-- 日期范围汇总 -->
<klp-collapse-panel :title="'汇总(' + displayDateRange + ''">
<k-metric-card
:items="summaryData"
:columns="3"
/>
<!-- 班组产量对比 -->
<view class="chart-section">
<view class="section-header">
<text class="section-title">班组产量对比</text>
</view>
<view class="chart-wrapper">
<qiun-data-charts type="column" :chartData="crewChartData" :opts="columnChartOpts"/>
</view>
</view>
<!-- 汇总饼图轮播 -->
<swiper
class="chart-swiper"
:autoplay="false"
:circular="false"
:indicator-dots="true"
indicator-active-color="#1a73e8"
indicator-color="#e5e5e5"
>
<swiper-item v-for="(item, index) in summaryChartConfig" :key="index">
<qiun-data-charts type="pie" :opts="item.opts" :chartData="item.chartData" :title="item.title"/>
</swiper-item>
</swiper>
</klp-collapse-panel>
<!-- 规格分布 -->
<view class="chart-section">
<view class="section-header">
<text class="section-title">规格分布</text>
</view>
<view class="pie-charts-row">
<view class="pie-chart-item">
<text class="pie-title">厚度分布</text>
<qiun-data-charts type="pie" :chartData="thicknessPieData" :opts="pieChartOpts"/>
</view>
</view>
<view class="pie-charts-row">
<view class="pie-chart-item">
<text class="pie-title">宽度分布</text>
<qiun-data-charts type="pie" :chartData="widthPieData" :opts="pieChartOpts"/>
</view>
</view>
</view>
</view>
</template>
<script>
// 2. 独立工具函数避免Vue2 data初始化时调用this.methods的问题
/**
* 获取默认日期(根据视图类型)
* @param {string} type - 视图类型day/month/year
* @returns {string} 格式化后的日期
*/
import {
getProductionSummary,
getCrewProduction,
getThicknessDistribution,
getWidthDistribution
} from '@/api/pocket/plantState'
// 工具函数
function getDefaultDate(type = "day") {
const date = new Date();
return formatDate(date, type);
}
/**
* 格式化日期
* @param {Date} date - 日期对象
* @param {string} type - 视图类型day/month/year
* @returns {string} 格式化后的日期
*/
function formatDate(date, type) {
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = date.getDate().toString().padStart(2, "0");
switch (type) {
case "day": return `${year}-${month}-${day}`;
case "month": return `${year}-${month}`;
@@ -151,128 +145,97 @@ function formatDate(date, type) {
}
export default {
// 4. 响应式数据(替代 Vue3 的 ref
data() {
return {
// 激活的视图类型(日/月/年)
activeTab: "day",
// 开始/结束日期(月份/年份)
startDate: getDefaultDate(),
endDate: getDefaultDate(),
// 视图切换选项
timeTabs: [
{ label: "日视图", value: "day" },
{ label: "月视图", value: "month" },
{ label: "年视图", value: "year" }
{ label: "日", value: "day" },
{ label: "月", value: "month" },
{ label: "年", value: "year" }
],
// 产量相关图表配置(轮播)
chanLiangChartConfig: [
{
title: "规格曲线",
type: "column",
chartData: {} // 初始空对象,后续加载数据
},
{
title: "超产-欠产统计",
type: "line",
chartData: {} // 初始空对象,后续加载数据
},
{
title: "产量-成材率统计",
type: "column",
chartData: {
categories: ["2016", "2017", "2018", "2019", "2020", "2021"],
series: [
{ name: "目标值", data: [35, 36, 31, 33, 13, 34] },
{ name: "完成量", data: [18, 27, 21, 24, 6, 28] }
]
} // 固定初始数据
}
],
// 汇总饼图配置(轮播)
summaryChartConfig: [
{
title: "成品厚度统计(mm)",
opts: {
color: ["#1890FF","#91CB74","#FAC858","#EE6666","#73C0DE","#3CA272","#FC8452","#9A60B4","#ea7ccc"],
padding: [5,5,5,5],
enableScroll: false,
position: "left",
float: "left",
extra: {
pie: {
activeOpacity: 0.5,
activeRadius: 10,
offsetAngle: 0,
labelWidth: 15,
border: false,
borderWidth: 3,
borderColor: "#FFFFFF"
}
}
},
chartData: JSON.parse(JSON.stringify({
series: [{ data: [{"name":"一班","value":50},{"name":"二班","value":30},{"name":"三班","value":20},{"name":"四班","value":18},{"name":"五班","value":8}] }]
}))
},
{
title: "钢种统计",
opts: {
color: ["#1890FF","#91CB74","#FAC858","#EE6666","#73C0DE","#3CA272","#FC8452","#9A60B4","#ea7ccc"],
padding: [5,5,5,5],
enableScroll: false,
extra: {
pie: {
activeOpacity: 0.5,
activeRadius: 10,
offsetAngle: 0,
labelWidth: 15,
border: false,
borderWidth: 3,
borderColor: "#FFFFFF"
}
}
},
chartData: JSON.parse(JSON.stringify({
series: [{ data: [{"name":"一班","value":50},{"name":"二班","value":30},{"name":"三班","value":20},{"name":"四班","value":18},{"name":"五班","value":8}] }]
}))
},
{
title: "班组统计",
opts: {
color: ["#1890FF","#91CB74","#FAC858","#EE6666","#73C0DE","#3CA272","#FC8452","#9A60B4","#ea7ccc"],
padding: [5,5,5,5],
enableScroll: false,
extra: {
pie: {
activeOpacity: 0.5,
activeRadius: 10,
offsetAngle: 0,
labelWidth: 15,
border: false,
borderWidth: 3,
borderColor: "#FFFFFF"
}
}
},
chartData: JSON.parse(JSON.stringify({
series: [{ data: [{"name":"一班","value":50},{"name":"二班","value":30},{"name":"三班","value":20},{"name":"四班","value":18},{"name":"五班","value":8}] }]
}))
}
],
// 轮播图当前索引
currentSwiperIndex: 0,
// 服务器加载的图表基础数据
chartData: {},
// 汇总指标卡数据
// 汇总数据
summaryData: [
{ label: "生产钢卷数", value: 186 },
{ label: "平均宽度", value: 1054, unit: "mm" },
{ label: "平均厚度", value: 0.93, unit: "mm" },
{ label: "原料总量", value: 3396.47, unit: "t" },
{ label: "成品总量", value: 4360.18, unit: "t" },
{ label: "成材率", value: 95.99, unit: "%" } // 原代码unit写t推测是笔误修正为%
]
{ label: "生产钢卷数", value: 0, unit: "卷" },
{ label: "平均宽度", value: 0, unit: "mm" },
{ label: "平均厚度", value: 0, unit: "mm" },
{ label: "原料总量", value: 0, unit: "t" },
{ label: "成品总量", value: 0, unit: "t" },
{ label: "成材率", value: 0, unit: "%" }
],
// 产量趋势图(柱状+折线)
productionChartData: {},
productionChartOpts: {
color: ["#0066cc", "#00b96b"],
padding: [15, 15, 0, 15],
enableScroll: false,
legend: { position: "top" },
xAxis: { disableGrid: true },
yAxis: {
gridType: "dash",
dashLength: 4,
gridColor: "#e4e7ed",
data: [
{ position: "left", title: "产量(t)" },
{ position: "right", title: "成材率(%)" }
]
},
extra: {
mix: {
column: { width: 20 }
}
}
},
// 班组产量对比
crewChartData: {},
columnChartOpts: {
color: ["#0066cc", "#409eff", "#66b1ff"],
padding: [15, 15, 0, 15],
enableScroll: false,
legend: {},
xAxis: { disableGrid: true },
yAxis: {
gridType: "dash",
dashLength: 4,
gridColor: "#e4e7ed",
data: [{ title: "产量(t)" }]
}
},
// 饼图配置
pieChartOpts: {
color: ["#0066cc", "#409eff", "#66b1ff", "#a0cfff", "#d9ecff"],
padding: [15, 15, 15, 15],
enableScroll: false,
legend: {
show: true,
position: "bottom",
lineHeight: 16,
fontSize: 10,
fontColor: "#666",
margin: 5,
itemGap: 8
},
extra: {
pie: {
activeOpacity: 0.5,
activeRadius: 10,
labelWidth: 15,
border: false,
ringWidth: 0,
offsetAngle: 0,
disablePieStroke: true,
linearType: "none",
customRadius: 0
}
}
},
thicknessPieData: {
series: [{ data: [] }]
},
widthPieData: {
series: [{ data: [] }]
}
};
},
// 5. 计算属性(替代 Vue3 的 computed 函数)
@@ -298,168 +261,427 @@ export default {
}
}
},
// 6. 生命周期钩子(替代 Vue3 的 onMounted
mounted() {
this.getServerData(); // 页面挂载后加载图表数据
this.loadProductionData();
},
// 7. 方法定义(所有交互逻辑与数据处理)
methods: {
// 切换视图(日/月/年)
// 切换时间维度
handleTabChange(tab) {
this.activeTab = tab;
// 重置日期:日视图首尾一致,月/年视图首尾默认当前
const defaultDate = getDefaultDate();
this.startDate = defaultDate;
this.endDate = tab === "day" ? defaultDate : getDefaultDate(tab);
this.loadProductionData();
},
// 日模式:日期选择器变更
// 日期选择变更
handleDateChange(e) {
this.startDate = e.detail.value;
this.endDate = e.detail.value; // 日视图首尾日期同步
this.endDate = e.detail.value;
this.loadProductionData();
},
// 月模式:开始月份变更
handleStartMonthChange(e) {
this.startDate = e.detail.value;
// 自动调整结束月份:不超过开始月份+1年
const maxEndDate = new Date(this.startDate);
maxEndDate.setFullYear(maxEndDate.getFullYear() + 1);
const maxEndStr = formatDate(maxEndDate, "month");
if (new Date(this.endDate) > maxEndDate) {
this.endDate = maxEndStr;
}
this.loadProductionData();
},
// 月模式:结束月份变更
handleEndMonthChange(e) {
this.endDate = e.detail.value;
this.loadProductionData();
},
// 年模式:开始年份变更
handleStartYearChange(e) {
this.startDate = e.detail.value;
this.loadProductionData();
},
// 年模式:结束年份变更
handleEndYearChange(e) {
this.endDate = e.detail.value;
this.loadProductionData();
},
// 轮播图切换回调(更新当前索引)
onSwiperChange(e) {
this.currentSwiperIndex = e.detail.current;
// 加载生产数据
loadProductionData() {
uni.showLoading({ title: '加载中' })
// 并行请求所有数据
Promise.all([
this.loadSummaryData(),
this.loadCrewProductionData(),
this.loadSpecDistribution()
]).finally(() => {
uni.hideLoading()
})
},
// 模拟从服务器加载图表数据
getServerData() {
setTimeout(() => {
// 模拟服务器返回数据
const serverRes = {
categories: ["2016", "2017", "2018", "2019", "2020", "2021"],
series: [
{ name: "目标值", data: [35, 36, 31, 33, 13, 34] },
{ name: "完成量", data: [18, 27, 21, 24, 6, 28] }
// 加载汇总数据
loadSummaryData() {
// 转换为完整日期格式
const start = this.formatFullDate(this.startDate, true)
const end = this.formatFullDate(this.endDate, false)
return getProductionSummary(start, end).then(response => {
if (response.code === 200 && response.data) {
const data = response.data
this.summaryData = [
{ label: "生产钢卷数", value: data.coilCount || 0, unit: "卷" },
{ label: "平均宽度", value: data.avgWidth || 0, unit: "mm" },
{ label: "平均厚度", value: data.avgThick || 0, unit: "mm" },
{ label: "原料总量", value: data.totalEntryWeight || 0, unit: "t" },
{ label: "成品总量", value: data.totalExitWeight || 0, unit: "t" },
{ label: "成材率", value: data.yieldRate || 0, unit: "%" }
]
};
// 深拷贝避免引用问题确保Vue2响应式
this.chartData = JSON.parse(JSON.stringify(serverRes));
// 更新产量图表配置的前两个图表数据(第三个固定)
this.chanLiangChartConfig.forEach((item, index) => {
if (index < 2) { // 仅前两个图表用服务器数据
item.chartData = JSON.parse(JSON.stringify(this.chartData));
}
}).catch(error => {
console.error('加载汇总数据失败:', error)
})
},
// 加载班组产量数据
loadCrewProductionData() {
const start = this.formatFullDate(this.startDate, true)
const end = this.formatFullDate(this.endDate, false)
return getCrewProduction(start, end).then(response => {
if (response.code === 200 && response.data && response.data.length > 0) {
const crewData = response.data
// 按班组和班次分组
const categories = []
const crewMap = {}
crewData.forEach(item => {
const label = `${item.crew}-${item.shift}`
categories.push(label)
if (!crewMap[item.shift]) {
crewMap[item.shift] = []
}
crewMap[item.shift].push(Number(item.totalWeight) || 0)
})
// 构建班组产量对比图
const series = Object.keys(crewMap).map(shift => ({
name: shift,
data: crewMap[shift]
}))
this.crewChartData = {
categories: categories,
series: series
}
});
}, 500);
// 构建产量趋势图(使用班组数据)
this.productionChartData = {
categories: categories,
series: [
{
name: "产量",
type: "column",
index: 0,
data: crewData.map(item => Number(item.totalWeight) || 0)
},
{
name: "平均厚度",
type: "line",
index: 1,
style: "curve",
data: crewData.map(item => Number(item.avgThick) || 0)
}
]
}
}
}).catch(error => {
console.error('加载班组产量失败:', error)
})
},
// 加载规格分布
loadSpecDistribution() {
const start = this.formatFullDate(this.startDate, true)
const end = this.formatFullDate(this.endDate, false)
return Promise.all([
getThicknessDistribution(start, end),
getWidthDistribution(start, end)
]).then(([thicknessRes, widthRes]) => {
// 厚度分布
if (thicknessRes.code === 200 && thicknessRes.data) {
this.thicknessPieData = {
series: [{
data: thicknessRes.data.map(item => ({
name: item.category,
value: item.count
}))
}]
}
}
// 宽度分布
if (widthRes.code === 200 && widthRes.data) {
this.widthPieData = {
series: [{
data: widthRes.data.map(item => ({
name: item.category,
value: item.count
}))
}]
}
}
}).catch(error => {
console.error('加载规格分布失败:', error)
})
},
// 格式化为完整日期(用于查询)
formatFullDate(dateStr, isStart) {
if (!dateStr) return ''
// 如果已经是完整日期格式 yyyy-MM-dd直接返回
if (dateStr.length === 10) {
return dateStr
}
// 月份格式 yyyy-MM
if (dateStr.length === 7) {
if (isStart) {
// 开始日期:该月第一天
return `${dateStr}-01`
} else {
// 结束日期:该月最后一天
const [year, month] = dateStr.split('-')
const lastDay = new Date(year, month, 0).getDate()
return `${dateStr}-${String(lastDay).padStart(2, '0')}`
}
}
// 年份格式 yyyy
if (dateStr.length === 4) {
if (isStart) {
// 开始日期:该年第一天
return `${dateStr}-01-01`
} else {
// 结束日期:该年最后一天
return `${dateStr}-12-31`
}
}
return dateStr
}
}
};
</script>
<style scoped>
.container {
padding: 20rpx;
<style scoped lang="scss">
/* 页面容器 */
.page-container {
background: #f5f7fa;
padding: 24rpx;
}
/* 简洁Tab容器 */
.tab-container {
/* 时间维度切换 */
.time-tab-bar {
display: flex;
box-sizing: border-box;
background: #fff;
margin-bottom: 20rpx;
border-radius: 12rpx;
overflow: hidden;
border: 1rpx solid #e8e8e8;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
border-radius: 8rpx;
padding: 8rpx;
margin-bottom: 24rpx;
border: 1rpx solid #e4e7ed;
}
.tab-item {
.time-tab-item {
flex: 1;
text-align: center;
padding: 24rpx 20rpx;
color: #666;
font-size: 28rpx;
font-weight: 500;
transition: all 0.3s ease;
position: relative;
&:not(:last-child)::after {
content: '';
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
width: 1rpx;
height: 40rpx;
background: #e8e8e8;
}
padding: 16rpx 0;
font-size: 26rpx;
color: #606266;
border-radius: 6rpx;
transition: all 0.2s;
}
.tab-item.active {
.time-tab-active {
background: #0066cc;
color: #fff;
background: #1a73e8;
font-weight: 600;
font-weight: 500;
}
/* 日期选择 */
.date-picker {
padding: 20rpx;
/* 日期选择 */
.date-selector {
background: #fff;
border-radius: 12rpx;
margin-bottom: 20rpx;
border: 1rpx solid #e8e8e8;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
border-radius: 8rpx;
padding: 24rpx;
margin-bottom: 24rpx;
border: 1rpx solid #e4e7ed;
}
.date-range {
.date-range-group {
display: flex;
gap: 20rpx;
align-items: stretch;
gap: 0;
}
.date-item {
.date-input {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 32rpx;
background: #f5f7fa;
border: 1rpx solid #e4e7ed;
&:first-child {
border-radius: 6rpx 0 0 6rpx;
border-right: none;
}
&:last-child {
border-radius: 0 6rpx 6rpx 0;
border-left: none;
}
}
.picker-text {
padding: 20rpx;
background: #f8f9fa;
border-radius: 10rpx;
color: #333;
.date-label {
font-size: 26rpx;
color: #909399;
margin-right: 16rpx;
}
.date-value {
font-size: 28rpx;
border: 1rpx solid #e8e8e8;
transition: all 0.2s ease;
&:active {
background: #f0f2f5;
}
color: #303133;
font-weight: 500;
flex: 1;
text-align: right;
}
.date-separator {
font-size: 28rpx;
color: #fff;
background: #0066cc;
padding: 24rpx 20rpx;
display: flex;
align-items: center;
justify-content: center;
min-width: 80rpx;
}
/* 区块样式 */
.summary-section,
.chart-section {
margin-bottom: 24rpx;
}
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20rpx;
padding-left: 16rpx;
border-left: 4rpx solid #0066cc;
}
.section-title {
font-size: 30rpx;
font-weight: 500;
color: #303133;
}
.section-date {
font-size: 24rpx;
color: #909399;
}
/* 汇总卡片网格 */
.summary-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16rpx;
}
.summary-card {
background: #fff;
border: 1rpx solid #e4e7ed;
border-radius: 8rpx;
padding: 28rpx 20rpx;
text-align: center;
}
.summary-label {
display: block;
font-size: 24rpx;
color: #909399;
margin-bottom: 16rpx;
}
.summary-value-box {
display: flex;
align-items: baseline;
justify-content: center;
}
.summary-value {
font-size: 40rpx;
font-weight: 600;
color: #0066cc;
line-height: 1;
}
.summary-unit {
font-size: 22rpx;
color: #909399;
margin-left: 6rpx;
}
/* 图表容器 */
.chart-container {
margin-bottom: 20rpx;
.chart-wrapper {
background: #fff;
border-radius: 16rpx;
padding: 30rpx;
border: 1rpx solid #e8e8e8;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
border: 1rpx solid #e4e7ed;
border-radius: 8rpx;
padding: 24rpx 16rpx;
min-height: 450rpx;
}
.chart-swiper {
height: 500rpx;
box-sizing: border-box;
/* 饼图行布局 */
.pie-charts-row {
display: flex;
gap: 16rpx;
}
</style>
.pie-chart-item {
flex: 1;
background: #fff;
border: 1rpx solid #e4e7ed;
border-radius: 8rpx;
padding: 24rpx 0 32rpx 0;
min-height: 520rpx;
display: flex;
flex-direction: column;
}
.pie-title {
display: block;
text-align: center;
font-size: 26rpx;
color: #606266;
font-weight: 500;
margin-bottom: 16rpx;
padding: 0 16rpx;
flex-shrink: 0;
}
.pie-chart-wrapper {
flex: 1;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
</style>

View File

@@ -1,54 +1,90 @@
<template>
<view>
<view class="month-picker">
<picker
mode="date"
fields="month"
:value="selectedMonth"
:start="startDate"
:end="endDate"
@change="handleMonthChange"
>
<view class="picker-content">
<!-- 左箭头 -->
<view
class="arrow"
@click.stop="changeMonth(-1)"
:class="{ disabled: isMinMonth }"
>
</view>
<view class="month-display">
<text class="label">选择月份</text>
<text class="month-text">{{ formattedMonth }}</text>
</view>
<!-- 右箭头 -->
<view
class="arrow"
@click.stop="changeMonth(1)"
:class="{ disabled: isMaxMonth }"
>
</view>
<text class="icon"></text>
<view class="page-container">
<!-- 月份选择器 -->
<view class="month-selector">
<view class="month-arrow" @click="changeMonth(-1)" :class="{ disabled: isMinMonth }">
<text></text>
</view>
<picker mode="date" fields="month" :value="selectedMonth" :start="startDate" :end="endDate" @change="handleMonthChange">
<view class="month-display">
<text class="month-text">{{ formattedMonth }}</text>
<text class="picker-icon"></text>
</view>
</picker>
<view class="month-arrow" @click="changeMonth(1)" :class="{ disabled: isMaxMonth }">
<text></text>
</view>
</view>
<view>
<k-table :columns="columns" :data="tableData"></k-table>
<!-- 班组绩效排名 -->
<view class="ranking-section">
<view class="section-header">
<text class="section-title">绩效排名</text>
</view>
<view class="ranking-list">
<view
class="ranking-item"
v-for="(item, index) in teamRankingData"
:key="index"
:class="'rank-' + (index + 1)"
>
<view class="rank-badge">{{ index + 1 }}</view>
<view class="rank-info">
<text class="team-name">{{ item.team }}</text>
<text class="team-shift">{{ item.shift }}</text>
</view>
<view class="rank-score">
<text class="score-value">{{ item.score }}</text>
<text class="score-label"></text>
</view>
</view>
</view>
</view>
<!-- 班组产量对比 -->
<view class="chart-section">
<view class="section-header">
<text class="section-title">产量对比</text>
</view>
<view class="chart-wrapper">
<qiun-data-charts type="column" :chartData="outputChartData" :opts="columnChartOpts"/>
</view>
</view>
<!-- 质量指标对比 -->
<view class="chart-section">
<view class="section-header">
<text class="section-title">质量指标</text>
</view>
<view class="chart-wrapper">
<qiun-data-charts type="radar" :chartData="qualityRadarData" :opts="radarChartOpts"/>
</view>
</view>
<!-- 班组详细数据 -->
<view class="detail-section">
<view class="section-header">
<text class="section-title">详细数据</text>
</view>
<view class="detail-table">
<view class="table-header">
<text class="table-cell header-cell" v-for="col in columns" :key="col.key">{{ col.title }}</text>
</view>
<view class="table-row" v-for="(row, index) in tableData" :key="index">
<text class="table-cell" v-for="col in columns" :key="col.key">{{ row[col.key] }}</text>
</view>
<view v-if="tableData.length === 0" class="empty-state">
<text class="empty-text">暂无数据</text>
</view>
</view>
</view>
</view>
</template>
<script>
// 1. 导入组件(路径需根据实际项目结构调整)
import klpTable from "../klp-ui/k-table/k-table.vue";
import { getTeamPerformance } from '@/api/pocket/plantState'
// 2. 独立工具函数避免data初始化时调用this.methods的问题
// 工具函数
function getCurrentMonth() {
const date = new Date();
const year = date.getFullYear();
@@ -56,104 +92,215 @@ function getCurrentMonth() {
return `${year}-${month}`;
}
function getDefaultMonth() {
return getCurrentMonth();
}
export default {
// 3. 显式注册局部组件Vue 2 必需)
components: {
klpTable
},
// 4. 响应式数据(替代 Vue 3 的 ref
data() {
return {
// 默认选中当前月份
selectedMonth: getDefaultMonth(),
// 可选月份范围2020年1月 - 当前月
selectedMonth: getCurrentMonth(),
startDate: "2020-01",
endDate: getCurrentMonth(),
// 表格列配置
columns: [
{ title: '班组', key: 'team' },
{ title: '作业次数', key: 'workCount' },
{ title: '原始产量', key: 'originalOutput' },
{ title: '产量(t)', key: 'output' },
{ title: '成材率', key: 'yieldRate' },
{ title: '厚度合格率', key: 'thicknessPassRate' }
{ title: '合格率', key: 'passRate' },
{ title: '综合评分', key: 'score' }
],
// 表格数据
tableData: [
{ team: '班组1', workCount: 100, originalOutput: 1000, yieldRate: '95%', thicknessPassRate: '90%' },
{ team: '班组2', workCount: 120, originalOutput: 1200, yieldRate: '92%', thicknessPassRate: '88%' },
{ team: '班组3', workCount: 90, originalOutput: 900, yieldRate: '93%', thicknessPassRate: '91%' },
{ team: '班组4', workCount: 110, originalOutput: 1100, yieldRate: '94%', thicknessPassRate: '89%' }
]
tableData: [],
// 班组排名数据
teamRankingData: [
{ team: '班', shift: '早班', score: 96.8 },
{ team: '班', shift: '中班', score: 95.5 },
{ team: '丙班', shift: '晚班', score: 94.2 },
{ team: '丁班', shift: '早班', score: 93.6 }
],
// 产量对比图
outputChartData: {},
columnChartOpts: {
color: ["#0066cc"],
padding: [15, 15, 0, 15],
enableScroll: false,
xAxis: { disableGrid: true },
yAxis: {
gridType: "dash",
dashLength: 4,
gridColor: "#e4e7ed",
data: [{ title: "产量(t)" }]
}
},
// 质量指标雷达图
qualityRadarData: {
categories: [],
series: []
},
radarChartOpts: {
color: ["#0066cc", "#409eff", "#66b1ff", "#a0cfff"],
padding: [15, 15, 15, 15],
enableScroll: false,
legend: {
show: true,
position: "bottom",
lineHeight: 16,
fontSize: 10,
fontColor: "#666"
},
extra: {
radar: {
gridType: "radar",
gridColor: "#e4e7ed",
gridCount: 5,
opacity: 0.2,
labelShow: true,
max: 100,
labelColor: "#666666",
labelFontSize: 10
}
}
}
};
},
// 5. 计算属性(替代 Vue 3 的 computed 函数)
computed: {
// 是否为最小可选月份2020-01
isMinMonth() {
return this.selectedMonth === this.startDate;
},
// 是否为最大可选月份(当前月)
isMaxMonth() {
return this.selectedMonth === this.endDate;
},
// 格式化月份显示2024年05月
formattedMonth() {
const [year, month] = this.selectedMonth.split("-");
return `${year}${month}`;
}
},
// 6. 方法定义(所有函数需放在 methods 中)
mounted() {
this.loadTeamPerformance();
},
methods: {
// 选择器切换月份picker组件自带事件
handleMonthChange(e) {
this.selectedMonth = e.detail.value;
this.loadTeamPerformance();
},
// 箭头切换月份左减1右加1
changeMonth(step) {
// 解析当前选中的年月
const [year, month] = this.selectedMonth.split("-").map(Number);
// 计算目标月份month从0开始需-1后+step
const targetDate = new Date(year, month - 1 + step);
// 格式化目标月份为 YYYY-MM
const targetMonth = `${targetDate.getFullYear()}-${(targetDate.getMonth() + 1).toString().padStart(2, "0")}`;
// 边界校验:不能小于最小月,不能大于最大月
if (this.compareMonths(targetMonth, this.startDate) < 0) return;
if (this.compareMonths(targetMonth, this.endDate) > 0) return;
// 更新选中月份
this.selectedMonth = targetMonth;
this.loadTeamPerformance();
},
// 比较两个月份a > b 返回1a = b 返回0a < b 返回-1
compareMonths(a, b) {
const [aYear, aMonth] = a.split("-").map(Number);
const [bYear, bMonth] = b.split("-").map(Number);
if (aYear !== bYear) return aYear - bYear;
return aMonth - bMonth;
},
// 加载班组绩效数据
loadTeamPerformance() {
uni.showLoading({ title: '加载中' })
// 转换月份为完整日期范围
const startDate = `${this.selectedMonth}-01`
const [year, month] = this.selectedMonth.split('-')
const lastDay = new Date(year, month, 0).getDate()
const endDate = `${this.selectedMonth}-${String(lastDay).padStart(2, '0')}`
console.log('查询班组绩效:', startDate, endDate)
getTeamPerformance(startDate, endDate).then(response => {
uni.hideLoading()
if (response.code === 200 && response.data && response.data.length > 0) {
const teamData = response.data
console.log('班组绩效数据:', teamData)
// 排名数据取前4名
this.teamRankingData = teamData.slice(0, 4).map(item => ({
team: item.crew,
shift: item.shift,
score: Number(item.score) || 0
}))
// 表格数据
this.tableData = teamData.map(item => ({
team: item.teamName,
output: Number(item.output) || 0,
yieldRate: `${Number(item.yieldRate) || 0}%`,
passRate: `${Number(item.passRate) || 0}%`,
score: Number(item.score) || 0
}))
// 产量对比柱状图
this.outputChartData = {
categories: teamData.map(item => item.teamName),
series: [
{ name: '产量', data: teamData.map(item => Number(item.output) || 0) }
]
}
// 质量指标雷达图
this.qualityRadarData = {
categories: ['产量指标', '成材率', '合格率', '厚度质量', '板形质量'],
series: teamData.map(item => ({
name: item.teamName,
data: [
Number(this.normalizeValue(item.output, 1500)), // 产量归一化到100
Number(item.yieldRate) || 0,
Number(item.passRate) || 0,
Number(item.avgThickQuality) || 0,
Number(item.avgShapeQuality) || 0
]
}))
}
} else {
console.log('暂无班组绩效数据')
}
}).catch(error => {
uni.hideLoading()
console.error('加载班组绩效失败:', error)
})
},
// 数值归一化到100用于雷达图
normalizeValue(value, max) {
return Math.min(100, (Number(value) / max) * 100).toFixed(2)
}
}
};
</script>
<style scoped>
/* 月份选择器 */
.month-picker {
padding: 20rpx;
<style scoped lang="scss">
/* 页面容器 */
.page-container {
background: #f5f7fa;
padding: 24rpx;
}
.picker-content {
/* 月份选择器 */
.month-selector {
display: flex;
align-items: center;
padding: 24rpx 20rpx;
background: #fff;
border-radius: 12rpx;
border: 1rpx solid #e8e8e8;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
border-radius: 8rpx;
padding: 20rpx 24rpx;
margin-bottom: 24rpx;
border: 1rpx solid #e4e7ed;
}
.month-arrow {
padding: 12rpx 20rpx;
font-size: 28rpx;
color: #0066cc;
font-weight: 600;
&.disabled {
color: #dcdfe6;
}
}
.month-display {
@@ -161,42 +308,176 @@ export default {
display: flex;
align-items: center;
justify-content: center;
}
.arrow {
padding: 0 24rpx;
font-size: 32rpx;
color: #1a73e8;
cursor: pointer;
transition: all 0.2s ease;
font-weight: 600;
&:active {
opacity: 0.7;
transform: scale(0.9);
}
&.disabled {
color: #ccc;
pointer-events: none;
}
}
.label {
color: #666;
font-size: 28rpx;
gap: 12rpx;
}
.month-text {
color: #1a73e8;
font-size: 32rpx;
color: #0066cc;
font-weight: 600;
font-size: 30rpx;
margin: 0 20rpx;
}
.icon {
color: #999;
font-size: 24rpx;
margin-left: 20rpx;
.picker-icon {
font-size: 20rpx;
color: #909399;
}
</style>
/* 区块样式 */
.ranking-section,
.chart-section,
.detail-section {
margin-bottom: 24rpx;
}
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20rpx;
padding-left: 16rpx;
border-left: 4rpx solid #0066cc;
}
.section-title {
font-size: 30rpx;
font-weight: 500;
color: #303133;
}
/* 排名列表 */
.ranking-list {
background: #fff;
border-radius: 8rpx;
border: 1rpx solid #e4e7ed;
overflow: hidden;
}
.ranking-item {
display: flex;
align-items: center;
padding: 24rpx;
border-bottom: 1rpx solid #f5f7fa;
&:last-child {
border-bottom: none;
}
&.rank-1 .rank-badge {
background: #0066cc;
}
&.rank-2 .rank-badge {
background: #409eff;
}
&.rank-3 .rank-badge {
background: #66b1ff;
}
}
.rank-badge {
width: 56rpx;
height: 56rpx;
border-radius: 50%;
background: #a0cfff;
color: #fff;
font-size: 28rpx;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
margin-right: 24rpx;
}
.rank-info {
flex: 1;
display: flex;
flex-direction: column;
gap: 8rpx;
}
.team-name {
font-size: 30rpx;
color: #303133;
font-weight: 500;
}
.team-shift {
font-size: 24rpx;
color: #909399;
}
.rank-score {
display: flex;
align-items: baseline;
gap: 4rpx;
}
.score-value {
font-size: 48rpx;
color: #0066cc;
font-weight: 600;
line-height: 1;
}
.score-label {
font-size: 22rpx;
color: #909399;
}
/* 图表容器 */
.chart-wrapper {
background: #fff;
border: 1rpx solid #e4e7ed;
border-radius: 8rpx;
padding: 24rpx 16rpx;
min-height: 450rpx;
}
/* 详细数据表格 */
.detail-table {
background: #fff;
border-radius: 8rpx;
border: 1rpx solid #e4e7ed;
overflow: hidden;
}
.table-header {
display: flex;
background: #0066cc;
color: #fff;
}
.header-cell {
color: #fff !important;
font-weight: 500;
}
.table-row {
display: flex;
border-bottom: 1rpx solid #f5f7fa;
&:last-child {
border-bottom: none;
}
}
.table-cell {
flex: 1;
padding: 24rpx 12rpx;
text-align: center;
font-size: 26rpx;
color: #303133;
}
/* 空状态 */
.empty-state {
padding: 100rpx 0;
text-align: center;
}
.empty-text {
font-size: 28rpx;
color: #909399;
}
</style>

File diff suppressed because it is too large Load Diff

View File

@@ -1,141 +1,5 @@
<template>
<view>
<!-- 简洁标签栏 -->
<view class="tab-container">
<view
v-for="item in tabData"
:key="item.value"
@click="currentTab = item.value"
class="tab-item"
:class="{ 'tab-active': currentTab === item.value }"
>
<text class="tab-label">{{ item.text }}</text>
<view class="tab-indicator" v-if="currentTab === item.value"></view>
</view>
</view>
<scroll-view scroll-y v-if="currentTab === 1">
<view class="content-card">
<k-metric-card
:items="status"
:columns="2"
></k-metric-card>
</view>
<view class="content-card">
<klp-collapse-panel title="状态统计">
<qiun-data-charts type="line" :chartData="chartData" />
</klp-collapse-panel>
</view>
<view class="content-card">
<klp-collapse-panel title="轧机状态">
<qiun-data-charts type="column" :chartData="chartData" />
</klp-collapse-panel>
</view>
<view class="content-card">
<klp-collapse-panel title="机组跟踪">
<view style="padding: 30rpx; display: flex; flex-direction: column; align-items: stretch; justify-content: center; gap: 20rpx;">
<view style="display: flex; justify-content: space-between; align-items: center; padding: 20rpx; background-color: #d9edf6; border-radius: 10rpx;">
<text>轧机</text>
<text>6390000</text>
</view>
<view style="border-radius: 10rpx; overflow: hidden;">
<view style="display: flex; justify-content: space-between; align-items: center; padding: 20rpx; background-color: #d9edf6; border: 1px solid #d9edf6;">
<text>圆剪盘</text>
<text>6390000</text>
</view>
<view class="info-container">
<view class="info-row">
<view class="info-item">
<text class="info-label">设备编号</text>
<text class="info-value">M-001</text>
</view>
<view class="info-item">
<text class="info-label">运行状态</text>
<text class="info-value">正常</text>
</view>
</view>
<view class="info-row">
<view class="info-item">
<text class="info-label">当前产量</text>
<text class="info-value">2580 </text>
</view>
<view class="info-item">
<text class="info-label">合格率</text>
<text class="info-value">98.5%</text>
</view>
</view>
</view>
</view>
<view style="display: flex; justify-content: space-between; align-items: center; padding: 20rpx; background-color: #d9edf6; border-radius: 10rpx;">
<text>酸洗</text>
<text>6390000</text>
</view>
<view style="border-radius: 10rpx; overflow: hidden;">
<view style="display: flex; justify-content: space-between; align-items: center; padding: 20rpx; background-color: #d9edf6; border: 1px solid #d9edf6;">
<text>入口活套</text>
<text>6390000</text>
</view>
<view class="info-container">
<view class="info-row">
<view class="info-item">
<text class="info-label">设备编号</text>
<text class="info-value">M-001</text>
</view>
<view class="info-item">
<text class="info-label">运行状态</text>
<text class="info-value">正常</text>
</view>
</view>
<view class="info-row">
<view class="info-item">
<text class="info-label">当前产量</text>
<text class="info-value">2580 </text>
</view>
<view class="info-item">
<text class="info-label">合格率</text>
<text class="info-value">98.5%</text>
</view>
</view>
</view>
</view>
</view>
</klp-collapse-panel>
</view>
<view class="content-card">
<klp-collapse-panel title="能耗">
<view class="metric-container">
<!-- 网络状态指标 -->
<view class="metric-item">
<view class="metric-value">
9.9
</view>
<view class="metric-label">
工艺缎带钢线速度
</view>
</view>
<!-- 班组指标 -->
<view class="metric-item">
<view class="metric-value team-number">
126.0
</view>
<view class="metric-label">
轧机出口带钢线速度
</view>
</view>
</view>
</klp-collapse-panel>
</view>
</scroll-view>
<scroll-view scroll-y v-if="currentTab == 2">
<klp-product-statistic></klp-product-statistic>
@@ -152,7 +16,8 @@
</template>
<script>
import { listPlantStateCurrent, listPlantStateHistory } from '@/api/pocket/plantState'
import { getAllPlantStateDefines, listPlantStateHistory } from '@/api/pocket/plantState'
import config from '@/config'
export default {
// 响应式数据(替代 Vue 3 的 ref
@@ -166,91 +31,77 @@ export default {
{ text: "班组绩效", value: 4 }
],
status: [ // 状态指标数据(供 k-metric-card 使用)
{ label: '网络状态', value: '正常' },
{ label: '当前班组', value: '乙 / 中' }
{ label: '网络状态', value: '检测中...' },
{ label: '当前班组', value: '' }
],
chartData: {} // 图表数据(初始化空对象)
plantStateDefines: [] // 缓存所有的状态定义
}
},
// 生命周期钩子(替代 Vue 3 的 onMounted
mounted() {
this.getServerData() // 页面挂载后加载数据
this.loadCurrentState() // 加载当前状态
this.checkNetworkStatus() // 检测网络状态
this.initPlantStateDefines() // 加载所有定义
},
// 方法定义(所有函数需放在 methods 中)
methods: {
// 加载当前设备状态
loadCurrentState() {
uni.showLoading({ title: '加载中' })
listPlantStateCurrent({ pageNum: 1, pageSize: 10 }).then(response => {
uni.hideLoading()
if (response.code === 200 && response.rows) {
// 处理当前状态数据
console.log('当前状态数据:', response.rows)
// 可以根据实际需求更新status数据
}
}).catch(error => {
uni.hideLoading()
console.error('加载设备状态失败:', error)
})
},
// 从服务器获取历史数据用于图表
getServerData() {
uni.showLoading({ title: '加载中' })
listPlantStateHistory({ pageNum: 1, pageSize: 20 }).then(response => {
uni.hideLoading()
if (response.code === 200 && response.rows && response.rows.length > 0) {
// 处理历史数据,转换为图表需要的格式
const categories = []
const targetData = []
const completeData = []
response.rows.forEach(item => {
// 根据实际数据结构调整
const dateStr = this.formatDate(item.insdate)
categories.push(dateStr)
// 这里使用value1和value2作为示例实际应根据业务需求调整
targetData.push(item.value1 || 0)
completeData.push(item.value2 || 0)
})
const res = {
categories: categories,
series: [
{ name: '目标值', data: targetData },
{ name: '完成量', data: completeData }
]
// 检测网络状态
checkNetworkStatus() {
const startTime = Date.now()
// 使用uni.request测试网络连接速度
uni.request({
url: config.baseUrl + '/pocket/proPlantStateDefine/allWithValues',
method: 'GET',
timeout: 5000,
success: (res) => {
const responseTime = Date.now() - startTime
// 根据响应时间判断网络状态
if (responseTime < 500) {
this.status[0].value = '通畅'
} else if (responseTime < 2000) {
this.status[0].value = '卡顿'
} else {
this.status[0].value = '异常'
}
this.chartData = JSON.parse(JSON.stringify(res))
},
fail: () => {
this.status[0].value = '异常'
}
})
},
// 初始化:加载所有状态定义及其当前值
initPlantStateDefines() {
uni.showLoading({ title: '加载中' })
getAllPlantStateDefines().then(response => {
if (response.code === 200 && response.data) {
// 缓存所有定义
this.plantStateDefines = response.data
console.log('状态定义已加载:', this.plantStateDefines)
uni.hideLoading()
// 这里可以根据 plantStateDefines 来处理首页数据
// 例如this.initHomePageData()
} else {
// 如果没有数据,使用默认数据
this.loadDefaultChartData()
uni.hideLoading()
}
}).catch(error => {
uni.hideLoading()
console.error('加载历史数据失败:', error)
// 加载失败时使用默认数据
this.loadDefaultChartData()
console.error('加载状态定义失败:', error)
})
},
// 加载默认图表数据
loadDefaultChartData() {
const res = {
categories: ['2016', '2017', '2018', '2019', '2020', '2021'],
series: [
{ name: '目标值', data: [35, 36, 31, 33, 13, 34] },
{ name: '完成量', data: [18, 27, 21, 24, 6, 28] }
]
}
this.chartData = JSON.parse(JSON.stringify(res))
// 根据define ID获取对应的值工具方法
getValueByDefineId(dataRow, defineId) {
const fieldName = `value${defineId}`
return dataRow[fieldName] || null
},
// 格式化日期
// 格式化日期(工具方法)
formatDate(dateStr) {
if (!dateStr) return ''
const date = new Date(dateStr)
@@ -287,21 +138,21 @@ page {
align-items: center;
justify-content: center;
transition: all 0.3s ease;
.tab-label {
font-size: 28rpx;
color: #666;
font-weight: 400;
transition: all 0.3s ease;
}
&.tab-active {
.tab-label {
color: #1a73e8;
font-weight: 600;
}
}
.tab-indicator {
position: absolute;
bottom: 0;
@@ -320,6 +171,17 @@ page {
margin-bottom: 20rpx;
}
/* 空状态占位 */
.empty-placeholder {
padding: 100rpx 40rpx;
text-align: center;
.empty-text {
font-size: 28rpx;
color: #999;
}
}
/* 指标容器 */
.metric-container {
display: flex;
@@ -348,6 +210,12 @@ page {
font-size: 28rpx;
color: #666;
letter-spacing: 1rpx;
.metric-unit {
font-size: 24rpx;
color: #999;
margin-left: 4rpx;
}
}
/* 信息容器 */
@@ -377,7 +245,7 @@ page {
border-radius: 10rpx;
border: 1rpx solid #e8e8e8;
transition: all 0.2s ease;
&:active {
background: #f0f2f5;
}
@@ -396,4 +264,4 @@ page {
font-weight: 500;
word-break: break-all;
}
</style>
</style>