修复生产统计与维修记录用户数据

This commit is contained in:
2026-09-06 21:06:36 +08:00
parent 02c8fb7021
commit 5ca6ef2d5a
41 changed files with 1838 additions and 205 deletions
+438 -40
View File
@@ -5,8 +5,9 @@
<text class="hero-title">扫码工作台</text>
<text class="hero-subtitle">高效完成生产扫码与库存管理</text>
</view>
<view class="hero-action">
<view class="hero-action" @tap="openNotifications">
<u-icon name="bell-fill" color="#1677ff" size="38" />
<text v-if="unreadNotificationCount > 0" class="notification-badge">{{ unreadNotificationText }}</text>
</view>
</view>
@@ -42,23 +43,32 @@
<view class="chart-header">
<view>
<text class="chart-title">今日数据</text>
<text class="chart-subtitle">扫码与异常概览</text>
<text class="chart-subtitle">扫码、异常与维修实时概览</text>
</view>
<view class="chart-badge">实时</view>
<view class="chart-badge">{{ dashboardUpdatedAt }}</view>
</view>
<view class="summary-grid">
<view v-for="item in summaries" :key="item.label" class="summary-card">
<text class="summary-value">{{ item.value }}</text>
<text class="summary-label">{{ item.label }}</text>
<view v-for="item in summaries" :key="item.label" class="summary-card" :class="[item.type, { 'has-details': item.details && item.details.length }]">
<view class="summary-main">
<text class="summary-value" :class="item.type">{{ item.value }}</text>
<text class="summary-label">{{ item.label }}</text>
</view>
<view v-if="item.details && item.details.length" class="summary-detail-list">
<view v-for="detail in item.details" :key="detail.key" class="summary-detail-row">
<text class="summary-detail-name">{{ detail.name }}</text>
<text class="summary-detail-value">{{ detail.quantity }}</text>
</view>
</view>
</view>
</view>
<view class="trend-card">
<view class="chart-section-title">扫码趋势</view>
<view class="bar-chart">
<view v-for="item in trendData" :key="item.label" class="bar-item">
<view class="bar-track">
<view v-for="item in trendData" :key="item.label" class="bar-item">
<text class="bar-value">{{ item.value }}</text>
<view class="bar-track">
<view class="bar-fill" :style="{ height: item.percent + '%', backgroundColor: item.color }"></view>
</view>
<text class="bar-label">{{ item.label }}</text>
@@ -67,16 +77,22 @@
</view>
<view class="progress-card">
<view class="chart-section-title">异常处理</view>
<view v-for="item in exceptionData" :key="item.label" class="progress-row">
<view class="progress-info">
<text class="progress-label">{{ item.label }}</text>
<text class="progress-value">{{ item.value }}%</text>
</view>
<view class="progress-track">
<view class="progress-fill" :style="{ width: item.value + '%', backgroundColor: item.color }"></view>
<view class="responsibility-header">
<view>
<text class="chart-section-title responsibility-title">不良责任订单</text>
<text class="responsibility-subtitle">本月总计 {{ responsibilityOrderTotal }} 次 · 最近 5 条</text>
</view>
</view>
<view v-if="responsibilityOrders.length" class="reporter-list">
<view v-for="item in responsibilityOrders" :key="item.key" class="reporter-row">
<view>
<text class="reporter-name">订单:{{ item.order_no }}</text>
<text class="reporter-code">不良原因:{{ item.exception_reason || '未记录不良原因' }}</text>
</view>
<text class="reporter-count">{{ item.quantity }} 次</text>
</view>
</view>
<text v-else class="breakdown-empty">本月暂无不良责任订单</text>
</view>
</view>
</view>
@@ -84,6 +100,8 @@
<script>
import { getUserInfo } from '@/api/member.js'
import { getUnreadNotificationCount } from '@/api/produce/notification.js'
import { getTodayDashboard } from '@/api/produce/data-entry.js'
export default {
data() {
@@ -94,24 +112,19 @@
levelName: '请先登录',
enabled: true
},
unreadNotificationCount: 0,
responsibilityOrders: [],
responsibilityOrderTotal: 0,
summaries: [
{ label: '订单扫码', value: '128' },
{ label: '整机扫码', value: '86' },
{ label: '异常待处理', value: '12' }
{ label: '订单扫码', value: '0', type: 'primary' },
{ label: '整机记录', value: '0', type: 'success' },
{ label: '异常提报', value: '0', type: 'warning' },
{ label: '维修完成', value: '0', type: 'danger' }
],
trendData: [
{ label: '09', percent: 42, color: '#1677ff' },
{ label: '10', percent: 68, color: '#35bfa3' },
{ label: '11', percent: 52, color: '#1677ff' },
{ label: '12', percent: 76, color: '#35bfa3' },
{ label: '13', percent: 45, color: '#1677ff' },
{ label: '14', percent: 88, color: '#35bfa3' }
],
exceptionData: [
{ label: '已处理', value: 72, color: '#19be6b' },
{ label: '待复核', value: 46, color: '#f7b733' },
{ label: '待处理', value: 28, color: '#e91f3f' }
{ label: '--:--', value: 0, percent: 0, color: '#1677ff' }
],
dashboardUpdatedAt: '等待更新',
sections: [
{
title: '扫码',
@@ -119,7 +132,6 @@
{ title: '订单模式', icon: 'order', bgColor: '#e91f3f', url: '/pages/entry/order' },
{ title: '一单多机', icon: 'grid-fill', bgColor: '#6b70e8', url: '/pages/entry/multi-machine' },
{ title: '整机模式', icon: 'scan', bgColor: '#1e9df2', url: '/pages/entry/machine' },
{ title: 'UTS 扫码原型', icon: 'scan', bgColor: '#1677ff', url: '/pages/scan/prototype' },
{ title: '异常处理', icon: 'warning-fill', bgColor: '#f7b733', url: '/pages/exception/index' },
{ title: '维修处理', icon: 'setting-fill', bgColor: '#35bfa3', url: '/pages/repair/index' }
]
@@ -135,8 +147,15 @@
]
}
},
onShow() {
this.loadMemberInfo()
computed: {
unreadNotificationText() {
return this.unreadNotificationCount > 99 ? '99+' : String(this.unreadNotificationCount)
}
},
onShow() {
this.loadMemberInfo()
this.loadNotificationCount()
this.loadTodayDashboard()
},
methods: {
async loadMemberInfo() {
@@ -163,6 +182,78 @@
console.error('[scanapp] 获取首页会员信息失败', error)
}
},
async loadNotificationCount() {
if (!this.isLoggedIn()) {
this.unreadNotificationCount = 0
return
}
try {
const data = await getUnreadNotificationCount()
this.unreadNotificationCount = Number(data?.unread_count || 0)
} catch (error) {
this.unreadNotificationCount = 0
console.error('[app] 获取未读通知数量失败', error)
}
},
async loadTodayDashboard() {
if (!this.isLoggedIn()) {
this.summaries = [
{ label: '订单扫码', value: '0', type: 'primary' },
{ label: '整机记录', value: '0', type: 'success' },
{ label: '异常提报', value: '0', type: 'warning' },
{ label: '维修完成', value: '0', type: 'danger' }
]
this.responsibilityOrders = []
this.responsibilityOrderTotal = 0
this.trendData = [{ label: '--:--', value: 0, percent: 0, color: '#1677ff' }]
this.dashboardUpdatedAt = '登录后查看'
return
}
try {
const data = await getTodayDashboard()
const summary = data?.summary || {}
this.summaries = [
{ label: '订单扫码', value: String(summary.order_scan || 0), type: 'primary', details: this.createBreakdownDetails([...(data?.order_breakdown || []), ...(data?.repair_breakdown || [])]) },
{ label: '整机记录', value: String(summary.product_scan || 0), type: 'success', details: this.createBreakdownDetails(data?.product_breakdown) },
{ label: '异常提报', value: String(summary.exception || 0), type: 'warning' },
{ label: '维修完成', value: String(summary.repair || 0), type: 'danger' }
]
this.responsibilityOrders = (Array.isArray(data?.responsibility_orders) ? data.responsibility_orders : []).map((item, index) => ({
...item,
key: `${item.order_no || 'unknown'}-${index}`,
quantity: Number(item.quantity || 0)
}))
this.responsibilityOrderTotal = Number(data?.responsibility_order_total || 0)
const trend = Array.isArray(data?.trend) ? data.trend : []
const maxTrend = Math.max(1, ...trend.map((item) => Number(item.value || 0)))
this.trendData = trend.map((item, index) => ({
label: item.label || `时段${index + 1}`,
value: Number(item.value || 0),
percent: Math.round((Number(item.value || 0) / maxTrend) * 100),
color: index % 2 === 0 ? '#1677ff' : '#35bfa3'
}))
this.dashboardUpdatedAt = data?.updated_at ? `更新于 ${this.formatDashboardTime(data.updated_at)}` : '刚刚更新'
} catch (error) {
this.dashboardUpdatedAt = '暂时无法更新'
console.error('[app] 获取首页今日数据失败', error)
}
},
formatDashboardTime(timestamp) {
const date = new Date(Number(timestamp) * 1000)
return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
},
createBreakdownDetails(items) {
const list = Array.isArray(items) ? items : []
const grouped = {}
list.forEach((item) => {
const key = `${item.process_id || 'none'}-${item.step_id || 'none'}`
if (!grouped[key]) grouped[key] = { key, name: `${item.process_name || '未记录工序'} / ${item.step_name || '未记录步骤'}`, quantity: 0 }
grouped[key].quantity += Number(item.quantity || 0)
})
return Object.values(grouped)
},
isLoggedIn() {
return Boolean(uni.getStorageSync('scanapp_token'))
},
@@ -175,7 +266,7 @@
}
uni.showModal({
title: '需要登录',
content: '登录后可访问个人资料',
content: '登录后可使用此功能',
confirmText: '去登录',
success: (res) => {
if (res.confirm) {
@@ -189,6 +280,9 @@
openProfile() {
this.requireLogin('/pages/profile/index')
},
openNotifications() {
this.requireLogin('/pages/notification/index')
},
handleMenuTap(item) {
if (item.url) {
uni.navigateTo({
@@ -240,6 +334,7 @@
}
.hero-action {
position: relative;
display: flex;
align-items: center;
justify-content: center;
@@ -250,6 +345,24 @@
box-shadow: 0 12rpx 32rpx rgba(23, 35, 61, 0.08);
}
.notification-badge {
position: absolute;
top: -10rpx;
right: -12rpx;
min-width: 30rpx;
height: 30rpx;
padding: 0 6rpx;
border: 3rpx solid #ffffff;
border-radius: 999rpx;
box-sizing: border-box;
background: #e91f3f;
color: #ffffff;
font-size: 18rpx;
font-weight: 700;
line-height: 24rpx;
text-align: center;
}
.user-card {
position: relative;
overflow: hidden;
@@ -462,19 +575,52 @@
.summary-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-columns: repeat(2, 1fr);
gap: 16rpx;
margin-bottom: 22rpx;
}
.summary-card {
position: relative;
overflow: hidden;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 112rpx;
min-height: 136rpx;
padding: 18rpx 20rpx;
box-sizing: border-box;
border-radius: 22rpx;
background: #f8fbff;
background: linear-gradient(145deg, #f8fbff 0%, #f3f7fd 100%);
}
.summary-card.has-details {
align-items: stretch;
justify-content: flex-start;
min-height: 188rpx;
}
.summary-card::before {
position: absolute;
top: 20rpx;
bottom: 20rpx;
left: 0;
width: 6rpx;
border-radius: 0 6rpx 6rpx 0;
background: #1677ff;
content: '';
}
.summary-card.success::before {
background: #19be6b;
}
.summary-card.warning::before {
background: #f7a928;
}
.summary-card.danger::before {
background: #e91f3f;
}
.summary-value {
@@ -484,6 +630,30 @@
line-height: 1.3;
}
.summary-main {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.summary-card.has-details .summary-main {
flex-direction: row;
justify-content: space-between;
}
.summary-value.success {
color: #19be6b;
}
.summary-value.warning {
color: #f7a928;
}
.summary-value.danger {
color: #e91f3f;
}
.summary-label {
margin-top: 8rpx;
color: #8a94a6;
@@ -491,6 +661,138 @@
line-height: 1.3;
}
.summary-card.has-details .summary-label {
margin-top: 0;
margin-left: 12rpx;
text-align: right;
}
.summary-detail-list {
width: 100%;
margin-top: 14rpx;
padding-top: 10rpx;
border-top: 1rpx solid #eaf0f8;
}
.summary-detail-row {
display: flex;
align-items: center;
justify-content: space-between;
min-width: 0;
padding: 7rpx 10rpx;
border-radius: 10rpx;
background: rgba(255, 255, 255, 0.72);
}
.summary-detail-row + .summary-detail-row {
margin-top: 6rpx;
}
.summary-detail-name {
min-width: 0;
overflow: hidden;
color: #5f6b7a;
font-size: 18rpx;
line-height: 1.3;
text-overflow: ellipsis;
white-space: nowrap;
}
.summary-detail-value {
margin-left: 8rpx;
color: #17233d;
font-size: 20rpx;
font-weight: 700;
line-height: 1.3;
flex-shrink: 0;
}
.breakdown-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 16rpx;
margin-bottom: 22rpx;
}
.breakdown-card {
min-width: 0;
padding: 20rpx;
border-radius: 22rpx;
background: #f8fbff;
}
.breakdown-header,
.breakdown-row,
.reporter-row,
.responsibility-header {
display: flex;
align-items: center;
justify-content: space-between;
}
.breakdown-title,
.breakdown-name,
.breakdown-value,
.breakdown-total,
.breakdown-empty,
.reporter-name,
.reporter-code,
.reporter-count,
.exception-status-title {
display: block;
}
.breakdown-title {
color: #17233d;
font-size: 22rpx;
font-weight: 700;
line-height: 1.4;
}
.breakdown-total {
margin-left: 8rpx;
color: #1677ff;
font-size: 18rpx;
flex-shrink: 0;
}
.breakdown-list {
margin-top: 12rpx;
}
.breakdown-row {
padding: 10rpx 0;
border-bottom: 1rpx solid #eaf0f8;
}
.breakdown-row:last-child {
border-bottom: 0;
}
.breakdown-name {
overflow: hidden;
color: #5f6b7a;
font-size: 20rpx;
line-height: 1.35;
text-overflow: ellipsis;
white-space: nowrap;
}
.breakdown-value {
margin-left: 10rpx;
color: #17233d;
font-size: 22rpx;
font-weight: 700;
flex-shrink: 0;
}
.breakdown-empty {
margin-top: 16rpx;
color: #9aa4b4;
font-size: 20rpx;
text-align: center;
}
.trend-card,
.progress-card {
padding: 24rpx;
@@ -502,6 +804,45 @@
margin-top: 20rpx;
}
.reporter-list {
margin-bottom: 22rpx;
}
.reporter-row {
padding: 12rpx 0;
border-bottom: 1rpx solid #eaf0f8;
}
.reporter-row:last-child {
border-bottom: 0;
}
.reporter-name {
color: #5f6b7a;
font-size: 22rpx;
line-height: 1.35;
}
.reporter-code {
margin-top: 4rpx;
color: #9aa4b4;
font-size: 18rpx;
line-height: 1.3;
}
.reporter-count {
color: #f7a928;
font-size: 22rpx;
font-weight: 700;
}
.exception-status-title {
margin-bottom: 12rpx;
color: #17233d;
font-size: 22rpx;
font-weight: 700;
}
.chart-section-title {
margin-bottom: 22rpx;
color: #17233d;
@@ -509,6 +850,19 @@
font-weight: 700;
}
.responsibility-title {
margin-bottom: 0;
}
.responsibility-subtitle {
display: block;
margin-top: 6rpx;
margin-bottom: 22rpx;
color: #8a94a6;
font-size: 20rpx;
line-height: 1.4;
}
.bar-chart {
display: flex;
align-items: flex-end;
@@ -523,6 +877,13 @@
flex-direction: column;
}
.bar-value {
margin-bottom: 8rpx;
color: #5f6b7a;
font-size: 18rpx;
line-height: 1.2;
}
.bar-track {
display: flex;
align-items: flex-end;
@@ -609,11 +970,20 @@
.theme-dark .menu-item--active,
.theme-dark .summary-card,
.theme-dark .breakdown-card,
.theme-dark .trend-card,
.theme-dark .progress-card {
background: #1c2431;
}
.theme-dark .summary-detail-list {
border-color: #364152;
}
.theme-dark .summary-detail-row {
background: #222936;
}
.theme-dark .user-account,
.theme-dark .menu-title,
.theme-dark .workspace-title,
@@ -624,15 +994,43 @@
color: #f2f5fa;
}
.theme-dark .hero-subtitle,
.theme-dark .hero-subtitle,
.theme-dark .user-name,
.theme-dark .menu-desc,
.theme-dark .chart-subtitle,
.theme-dark .responsibility-subtitle,
.theme-dark .summary-label,
.theme-dark .bar-label,
.theme-dark .progress-label {
color: #aeb9ca;
}
color: #aeb9ca;
}
.theme-dark .breakdown-title,
.theme-dark .exception-status-title {
color: #f2f5fa;
}
.theme-dark .breakdown-name,
.theme-dark .reporter-name {
color: #aeb9ca;
}
.theme-dark .breakdown-value {
color: #f2f5fa;
}
.theme-dark .summary-detail-name {
color: #aeb9ca;
}
.theme-dark .summary-detail-value {
color: #f2f5fa;
}
.theme-dark .breakdown-row,
.theme-dark .reporter-row {
border-color: #364152;
}
.theme-dark .bar-track,
.theme-dark .progress-track {