feat: 五项目业务实现并对接完成
- MES(B): 工单/BOM/备料/工序字典/PLC下发/拧紧/扫码报工/半成品/AGV/追溯逻辑,WMS与海康RCS客户端,看板Redis缓存API(概览/设备/进度/报警/趋势)+SSE - WMS(C): JWT滑动续签、Excel导入、盘点、内部API、种子数据、独立Postgres配置 - WMS客户端(E): Go网关8891反向代理+内嵌Vue3十页 - 工位终端(D): SQLite本地缓存+模拟拧紧源+内嵌Vue3页面 - Dashboard(A): 看板数据改接MES内部缓存API,SSE实时刷新+vite代理 - 清理各项目球形磨遗留代码,新增部署手册.md
This commit is contained in:
@@ -28,6 +28,15 @@ export default function App() {
|
||||
return () => clearInterval(intervalRef.current);
|
||||
}, [fetchAll, refresh]);
|
||||
|
||||
// 订阅 MES SSE:看板相关事件(dashboard_update)实时触发刷新
|
||||
// 断线时浏览器会自动重连,轮询(10s)作为兜底
|
||||
useEffect(() => {
|
||||
const es = new EventSource('/sse');
|
||||
const onUpdate = () => refresh();
|
||||
es.addEventListener('dashboard_update', onUpdate);
|
||||
return () => es.close();
|
||||
}, [refresh]);
|
||||
|
||||
// 产线概览 / 设备监控 每 30s 自动轮播切换
|
||||
// 依赖 page:用户手动切页后计时从 0 重新开始,避免刚切完立刻被自动切走
|
||||
useEffect(() => {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import axios from 'axios';
|
||||
|
||||
// MES(B) 内部 API:X-API-TOKEN 写死 token(值与 MES etc 配置 Internal.Token 一致)
|
||||
export const MES_TOKEN =
|
||||
(import.meta as any).env?.VITE_MES_TOKEN || 'bj-power-internal-2026';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api/v1/dashboard',
|
||||
timeout: 10000,
|
||||
@@ -13,4 +17,19 @@ api.interceptors.response.use(
|
||||
},
|
||||
);
|
||||
|
||||
export default api;
|
||||
// 走 MES 内部接口(经 vite proxy 或 nginx 反代到 MES :8888)
|
||||
const mesApi = axios.create({
|
||||
baseURL: '/api/internal',
|
||||
timeout: 10000,
|
||||
headers: { 'X-API-TOKEN': MES_TOKEN },
|
||||
});
|
||||
|
||||
mesApi.interceptors.response.use(
|
||||
(res) => res,
|
||||
(err) => {
|
||||
console.error(`[MES API] ${err.message}`);
|
||||
return Promise.reject(err);
|
||||
},
|
||||
);
|
||||
|
||||
export { api as default, mesApi };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { create } from 'zustand';
|
||||
import api from '../api/client';
|
||||
import api, { mesApi } from '../api/client';
|
||||
import type {
|
||||
OverviewData, EquipmentItem, ProgressItem,
|
||||
AlarmItem, TrendItem, SamplingOverview, SamplingTrendItem,
|
||||
@@ -8,6 +8,55 @@ import type {
|
||||
CncOeeItem, WasherOeeItem,
|
||||
} from '../types';
|
||||
|
||||
// MES /api/internal/dashboard/overview 响应结构
|
||||
interface MesOverviewReply {
|
||||
activeOrderCount: number;
|
||||
activeJobCount: number;
|
||||
completedToday: number;
|
||||
scrappedToday: number;
|
||||
stationFaultCount: number;
|
||||
}
|
||||
|
||||
/** MES 返回(camelCase,包在 Body.data 里)→ 看板 OverviewData(snake_case) */
|
||||
function mapMesOverview(body: { data?: MesOverviewReply } | MesOverviewReply): OverviewData {
|
||||
const d = (body as any)?.data ?? body;
|
||||
return {
|
||||
active_work_orders: d.activeOrderCount ?? 0,
|
||||
completed_today: d.completedToday ?? 0,
|
||||
yield_rate: d.completedToday + d.scrappedToday > 0
|
||||
? Math.round((d.completedToday / (d.completedToday + d.scrappedToday)) * 1000) / 10
|
||||
: 100,
|
||||
equipment_util_rate: d.activeJobCount ?? 0,
|
||||
active_alarms: d.stationFaultCount ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchOverview(): Promise<OverviewData> {
|
||||
try {
|
||||
const r = await mesApi.get('/dashboard/overview');
|
||||
return mapMesOverview(r.data);
|
||||
} catch {
|
||||
// 回退旧接口(保留兼容)
|
||||
return api.get('/overview').then(r => r.data);
|
||||
}
|
||||
}
|
||||
|
||||
// MES 内部 API 优先,失败回退旧接口(本地兜底服务 :3001)
|
||||
async function fromMes<T>(path: string, fallbackPath?: string): Promise<T | null> {
|
||||
try {
|
||||
const r = await mesApi.get(`/dashboard/${path}`);
|
||||
return r.data as T;
|
||||
} catch {
|
||||
if (!fallbackPath) return null;
|
||||
try {
|
||||
const r = await api.get(fallbackPath);
|
||||
return r.data as T;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface DashboardState {
|
||||
// Page 1: Overview
|
||||
overview: OverviewData | null;
|
||||
@@ -63,16 +112,16 @@ export const useStore = create<DashboardState>((set) => ({
|
||||
try {
|
||||
const [overview, equipment, progress, alarms, trends, cncLatest, samplingOverview, samplingTrends, inspectionOverview, inspectionTrends] =
|
||||
await Promise.all([
|
||||
api.get('/overview').then(r => r.data),
|
||||
api.get('/equipment-status').then(r => r.data),
|
||||
api.get('/production-progress').then(r => r.data),
|
||||
api.get('/alarms').then(r => r.data),
|
||||
api.get('/trends').then(r => r.data),
|
||||
api.get('/cnc-latest').then(r => r.data),
|
||||
api.get('/sampling-overview').then(r => r.data),
|
||||
api.get('/sampling-trends').then(r => r.data),
|
||||
api.get('/inspection-overview').then(r => r.data),
|
||||
api.get('/inspection-trends').then(r => r.data),
|
||||
fetchOverview(),
|
||||
fromMes<EquipmentItem[]>('equipment', '/equipment-status').then(v => v ?? []),
|
||||
fromMes<ProgressItem[]>('progress', '/production-progress').then(v => v ?? []),
|
||||
fromMes<AlarmItem[]>('alarms', '/alarms').then(v => v ?? []),
|
||||
fromMes<TrendItem[]>('trends', '/trends').then(v => v ?? []),
|
||||
api.get('/cnc-latest').then(r => r.data).catch(() => []),
|
||||
api.get('/sampling-overview').then(r => r.data).catch(() => null),
|
||||
api.get('/sampling-trends').then(r => r.data).catch(() => []),
|
||||
api.get('/inspection-overview').then(r => r.data).catch(() => null),
|
||||
api.get('/inspection-trends').then(r => r.data).catch(() => []),
|
||||
]);
|
||||
set({ overview, equipment, progress, alarms, trends, cncLatest, samplingOverview, samplingTrends, inspectionOverview, inspectionTrends, loading: false });
|
||||
} catch {
|
||||
@@ -82,15 +131,24 @@ export const useStore = create<DashboardState>((set) => ({
|
||||
|
||||
refresh: async () => {
|
||||
try {
|
||||
const [overview, equipment, alarms, cncLatest, samplingOverview, inspectionOverview] = await Promise.all([
|
||||
api.get('/overview').then(r => r.data),
|
||||
api.get('/equipment-status').then(r => r.data),
|
||||
api.get('/alarms').then(r => r.data),
|
||||
api.get('/cnc-latest').then(r => r.data),
|
||||
api.get('/sampling-overview').then(r => r.data),
|
||||
api.get('/inspection-overview').then(r => r.data),
|
||||
const [overview, equipment, alarms, trends, cncLatest, samplingOverview, inspectionOverview] = await Promise.all([
|
||||
fetchOverview(),
|
||||
fromMes<EquipmentItem[]>('equipment', '/equipment-status'),
|
||||
fromMes<AlarmItem[]>('alarms', '/alarms'),
|
||||
fromMes<TrendItem[]>('trends', '/trends'),
|
||||
api.get('/cnc-latest').then(r => r.data).catch(() => undefined),
|
||||
api.get('/sampling-overview').then(r => r.data).catch(() => undefined),
|
||||
api.get('/inspection-overview').then(r => r.data).catch(() => undefined),
|
||||
]);
|
||||
set({ overview, equipment, alarms, cncLatest, samplingOverview, inspectionOverview });
|
||||
set((prev) => ({
|
||||
overview,
|
||||
...(equipment !== null ? { equipment } : {}),
|
||||
...(alarms !== null ? { alarms } : {}),
|
||||
...(trends !== null ? { trends } : {}),
|
||||
...(cncLatest !== undefined ? { cncLatest } : {}),
|
||||
...(samplingOverview !== undefined ? { samplingOverview } : {}),
|
||||
...(inspectionOverview !== undefined ? { inspectionOverview } : {}),
|
||||
}));
|
||||
} catch { /* ignore */ }
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user