@@ -25,19 +25,12 @@
\ No newline at end of file
diff --git a/src/locales/zh-CN/L4Data.json b/src/locales/zh-CN/L4Data.json
new file mode 100644
index 0000000..b801378
--- /dev/null
+++ b/src/locales/zh-CN/L4Data.json
@@ -0,0 +1,37 @@
+{
+ "id": "主键",
+ "processInfoId": "加工信息ID",
+ "pltNo": "PLT No",
+ "processF1": "加工F1",
+ "processF2": "加工F2",
+ "goodProductF1": "良品F1",
+ "goodProductF2": "良品F2",
+ "electricalResult": "电气检测结果",
+ "engraveResult": "印字检测结果",
+ "qrCode": "二维码",
+ "qrCodeLevel": "二维码等级",
+ "pressure15Riveting": "压力1_5#_铆接",
+ "height15Riveting": "高度1_5#_铆接",
+ "pressure25Magnet1": "压力2_5#_磁石1",
+ "height25Magnet1": "高度2_5#_磁石1",
+ "pressure36Magnet2": "压力3_6#_磁石2",
+ "height36Magnet2": "高度3_6#_磁石2",
+ "torque47AxisInsert": "扭矩4_7#_轴旋入",
+ "height47AxisInsert": "高度4_7#_轴旋入",
+ "pressure58LowerCase": "压力5_8#_下壳装入",
+ "height58LowerCase": "高度5_8#_下壳装入",
+ "pressure69UpperCase": "压力6_9#_上壳装入",
+ "height69UpperCase": "高度6_9#_上壳装入",
+ "height79HeightCheck": "高度7_9#_高度检测",
+ "pressure79Laser": "压力7_9#_激光",
+ "height89Laser": "高度8_9#_激光",
+ "value19DcrUpper": "数値1_9#_DCR(上)",
+ "value29DcrLower": "数値2_9#_DCR(下)",
+ "value39LcrUpperLs": "数値3_9#_LCR(上)LS",
+ "value49LcrLowerQ": "数値4_9#_LCR(下)Q",
+ "value59LcrLowerLs": "数値5_9#_LCR(下)LS",
+ "value69LcrLowerQ": "数値6_9#_LCR(下)Q",
+ "value79IrR": "数値7_9#_IR R",
+ "value89IrI": "数値8_9#_IR I",
+ "createTime": "创建时间"
+}
diff --git a/src/router/index.ts b/src/router/index.ts
index 79186cf..12fa9f7 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -3,23 +3,18 @@ import { createRouter, createWebHistory } from 'vue-router';
const routes = [
{
path: '/',
- name: 'IndexV2',
- component: () => import('@/views/index_v2.vue')
- },
- {
- path: '/index',
name: 'Index',
component: () => import('@/views/index.vue')
},
{
- path: '/package-station',
- name: 'PackageStation',
- component: () => import('@/views/PackageStation.vue')
+ path: '/login',
+ name: 'Login',
+ component: () => import('@/views/login.vue')
},
{
- path: '/sse-test',
- name: 'SSETest',
- component: () => import('@/views/sse/sse-test.vue')
+ path: '/package-station',
+ name: 'PackageStation',
+ component: () => import('@/views/package-station/index.vue')
}
];
diff --git a/src/utils/auth.ts b/src/utils/auth.ts
new file mode 100644
index 0000000..1ddb068
--- /dev/null
+++ b/src/utils/auth.ts
@@ -0,0 +1,15 @@
+import Cookies from 'js-cookie';
+
+const TokenKey = 'Admin-Token'
+
+export function getToken() {
+ return Cookies.get(TokenKey)
+}
+
+export function setToken(token: string) {
+ return Cookies.set(TokenKey, token)
+}
+
+export function removeToken() {
+ return Cookies.remove(TokenKey)
+}
diff --git a/src/utils/dateUtils.ts b/src/utils/dateUtils.ts
index 5102736..2e6552e 100644
--- a/src/utils/dateUtils.ts
+++ b/src/utils/dateUtils.ts
@@ -1,6 +1,4 @@
-/**
- * 时间格式化工具函数
- */
+import { ref, onMounted, onBeforeUnmount } from 'vue';
/**
* 格式化日期时间
@@ -40,8 +38,6 @@ export function getCurrentTime(format = 'YYYY-MM-DD HH:mm:ss'): string {
return formatDateTime(new Date(), format);
}
-import { ref, onMounted, onBeforeUnmount } from 'vue';
-
/**
* 获取实时时间(用于显示)
* @param format 格式字符串
diff --git a/src/utils/useSSE.ts b/src/utils/useSSE.ts
index 02b7895..92bad13 100644
--- a/src/utils/useSSE.ts
+++ b/src/utils/useSSE.ts
@@ -1,17 +1,27 @@
-import { ref, computed, onMounted, onUnmounted } from 'vue';
+import { ref, computed } from 'vue';
+import { EventSourcePolyfill } from 'event-source-polyfill';
import { generateUUID } from './uuidUtils';
+import { getToken } from '@/utils/auth';
-const defaultServerUrl = 'http://192.168.1.100:18081/sse';
+const defaultServerUrl = 'http://192.168.1.38:18081/sse';
+
+interface EventData {
+ timestamp: string;
+ message: string;
+ data: any;
+ code: 200 | 201 | 300 | 400 | 500;
+}
+
+interface logItem {
+ message: string;
+ type?: "success" | "error" | "log";
+}
export interface SSEOptions {
/** SSE服务器地址 */
serverUrl?: string;
- /** 自动连接 */
- autoConnect?: boolean;
/** 连接超时时间(毫秒) */
timeout?: number;
- /** 是否使用凭证 */
- withCredentials?: boolean;
/** 客户端ID,不传则自动生成 */
clientId?: string;
/** 消息处理函数 */
@@ -20,10 +30,12 @@ export interface SSEOptions {
onConnect?: () => void;
/** 连接错误回调 */
onError?: (error: Event | Error) => void;
- /** 是否在组件挂载时自动连接 */
- connectOnMount?: boolean;
- /** 是否在组件卸载时自动断开连接 */
- disconnectOnUnmount?: boolean;
+ /** L1事件处理回调 */
+ onL1Event?: (data: EventData) => void;
+ /** L4事件处理回调 */
+ onL4Event?: (data: EventData) => void;
+ /** MES事件处理回调 */
+ onMesEvent?: (data: EventData) => void;
}
function addSSEListener(eventSource: EventSource, type: string, handler: (data: any, event: MessageEvent) => void) {
@@ -42,32 +54,16 @@ function addSSEListener(eventSource: EventSource, type: string, handler: (data:
* @param options SSE连接选项
*/
export function useSSE(options: SSEOptions) {
- // 默认选项
- const defaultOptions: SSEOptions = {
- serverUrl: defaultServerUrl,
- autoConnect: true,
- timeout: 10000,
- withCredentials: false,
- connectOnMount: true,
- disconnectOnUnmount: true,
- clientId: generateUUID()
- };
-
- // 合并选项
- const mergedOptions = { ...defaultOptions, ...options };
// 状态变量
- const logs = ref
([]);
+ const logs = ref([]);
const isConnecting = ref(false);
const isConnected = ref(false);
- const clientId = ref(mergedOptions.clientId || generateUUID());
- const serverUrl = ref(mergedOptions.serverUrl);
- const isInCooldown = ref(false); // 连接冷却状态
- const cooldownRemaining = ref(0); // 剩余冷却时间
+ const clientId = ref(options.clientId || generateUUID());
+ const serverUrl = ref(options.serverUrl || defaultServerUrl);
// 存储EventSource实例
let eventSource: EventSource | null = null;
let connectionTimeout: number | null = null;
- let cooldownTimer: number | null = null;
// 计算属性
const sseStatusText = computed(() => {
@@ -82,32 +78,16 @@ export function useSSE(options: SSEOptions) {
return 'disconnected error';
});
- // 构建包含clientId的连接URL
- const getConnectUrl = () => {
- return `${serverUrl.value}/connect`;
- };
-
// 添加日志
- const addLog = (message: string) => {
+ const addLog = (message: string, type: 'success' | 'error' | 'log' = 'log') => {
const timestamp = new Date().toLocaleTimeString('zh-CN', { hour12: false });
const logEntry = `${timestamp} - ${message}`;
- logs.value.push(logEntry);
+ logs.value.push({ message: logEntry, type });
return logEntry;
};
- // 清空日志
- const clearLogs = () => {
- logs.value = [];
- };
-
// 连接SSE
- const connect = () => {
- // 检查是否在冷却期间
- if (isInCooldown.value) {
- addLog(`连接冷却中,请等待 ${cooldownRemaining.value} 秒后重试`);
- return;
- }
-
+ const connect = () => {
// 先断开可能存在的连接
if (eventSource) {
disconnect();
@@ -121,7 +101,7 @@ export function useSSE(options: SSEOptions) {
throw new Error('SSE服务器地址不能为空');
}
- const connectUrl = getConnectUrl();
+ const connectUrl = `${serverUrl.value}/connect`;
addLog(`开始连接到 ${connectUrl}...`);
// 设置连接超时
@@ -131,7 +111,7 @@ export function useSSE(options: SSEOptions) {
connectionTimeout = window.setTimeout(() => {
if (isConnecting.value) {
- addLog('连接超时,请检查服务器地址或网络连接');
+ addLog('连接超时,请检查服务器地址或网络连接', 'error');
isConnecting.value = false;
if (eventSource) {
eventSource.close();
@@ -139,15 +119,19 @@ export function useSSE(options: SSEOptions) {
}
// 调用错误回调
- if (mergedOptions.onError) {
- mergedOptions.onError(new Error('连接超时'));
+ if (options.onError) {
+ options.onError(new Error('连接超时'));
}
}
- }, mergedOptions.timeout || 10000); // 默认10秒超时
+ }, options.timeout || 10000); // 默认10秒超时
// 创建EventSource
- const eventSourceOptions = { withCredentials: mergedOptions.withCredentials || false };
- eventSource = new EventSource(connectUrl, eventSourceOptions);
+ const eventSourceOptions = {
+ headers: {
+ 'Authorization': `Bearer ${getToken()}`,
+ }
+ };
+ eventSource = new EventSourcePolyfill(connectUrl, eventSourceOptions);
eventSource.onopen = () => {
if (connectionTimeout) {
@@ -157,27 +141,42 @@ export function useSSE(options: SSEOptions) {
isConnected.value = true;
isConnecting.value = false;
- addLog('SSE 连接已建立');
+ addLog('SSE 连接已建立', 'success');
// 调用连接成功回调
- if (mergedOptions.onConnect) {
- mergedOptions.onConnect();
+ if (options.onConnect) {
+ options.onConnect();
}
};
eventSource.onmessage = (event) => {
- addLog(`收到消息: ${JSON.parse(event.data).message}`);
+ addLog(`收到消息: ${ JSON.parse(event.data).message }`);
console.log(event)
// 调用消息处理回调
- if (mergedOptions.onMessage) {
- mergedOptions.onMessage(event.data);
+ if (options.onMessage) {
+ options.onMessage(event.data);
}
};
- // 改为以下格式
+ // 添加事件监听器
+ addSSEListener(eventSource, 'L1_EVENT', (data) => {
+ console.log('收到 L1_EVENT:', data);
+ if (options.onL1Event) {
+ options.onL1Event(data);
+ }
+ });
addSSEListener(eventSource, 'L4_EVENT', (data) => {
- console.log('收到 L4_EVENT:', data);
+ console.log('收到 L4_EVENT:', data);
+ if (options.onL4Event) {
+ options.onL4Event(data);
+ }
+ });
+ addSSEListener(eventSource, 'MES_EVENT', (data) => {
+ console.log('收到 MES_EVENT:', data);
+ if (options.onMesEvent) {
+ options.onMesEvent(data);
+ }
});
eventSource.onerror = (err) => {
@@ -186,7 +185,7 @@ export function useSSE(options: SSEOptions) {
connectionTimeout = null;
}
- addLog('SSE 连接错误,请检查服务器地址或网络连接');
+ addLog('SSE 连接错误,请检查服务器地址或网络连接', 'error');
isConnected.value = false;
isConnecting.value = false;
@@ -196,17 +195,17 @@ export function useSSE(options: SSEOptions) {
}
// 调用错误回调
- if (mergedOptions.onError) {
- mergedOptions.onError(err);
+ if (options.onError) {
+ options.onError(err);
}
};
} catch (error) {
- addLog(`连接失败: ${error}`);
+ addLog(`连接失败: ${error}`, 'error');
isConnecting.value = false;
// 调用错误回调
- if (mergedOptions.onError && error instanceof Error) {
- mergedOptions.onError(error);
+ if (options.onError && error instanceof Error) {
+ options.onError(error);
}
}
};
@@ -223,89 +222,11 @@ export function useSSE(options: SSEOptions) {
eventSource = null;
}
- addLog('已断开连接');
+ addLog('已断开连接', 'log');
isConnected.value = false;
-
- // 启动5秒冷却时间
- startCooldown();
};
- // 启动连接冷却时间
- const startCooldown = () => {
- isInCooldown.value = true;
- cooldownRemaining.value = 5;
-
- const updateCooldown = () => {
- if (cooldownRemaining.value > 0) {
- cooldownRemaining.value--;
- cooldownTimer = window.setTimeout(updateCooldown, 1000);
- } else {
- isInCooldown.value = false;
- cooldownTimer = null;
- }
- };
-
- updateCooldown();
- };
-
- // 生命周期钩子
- onMounted(() => {
- if (mergedOptions.connectOnMount && mergedOptions.autoConnect) {
- connect();
- }
- });
-
- onUnmounted(() => {
- if (mergedOptions.disconnectOnUnmount) {
- disconnect();
- }
- });
-
- // 清理函数(兼容旧版本)
- const cleanup = () => {
- if (connectionTimeout) {
- clearTimeout(connectionTimeout);
- connectionTimeout = null;
- }
-
- if (cooldownTimer) {
- clearTimeout(cooldownTimer);
- cooldownTimer = null;
- }
-
- if (eventSource) {
- eventSource.close();
- eventSource = null;
- }
-
- isConnected.value = false;
- isConnecting.value = false;
- isInCooldown.value = false;
- cooldownRemaining.value = 0;
- };
-
- // 消息分类处理函数
- const processMessage = (data: string) => {
- try {
- // 尝试解析JSON消息
- const message = JSON.parse(data);
- // 根据消息类型分类
- return {
- type: message.type || 'system',
- content: message.content || data,
- raw: data,
- timestamp: new Date().toLocaleTimeString('zh-CN', { hour12: false })
- };
- } catch (error) {
- // 非JSON格式消息,视为系统消息
- return {
- type: 'system',
- content: data,
- raw: data,
- timestamp: new Date().toLocaleTimeString('zh-CN', { hour12: false })
- };
- }
- };
+
return {
logs,
@@ -315,13 +236,8 @@ export function useSSE(options: SSEOptions) {
serverUrl,
sseStatusText,
sseStatusClass,
- isInCooldown,
- cooldownRemaining,
connect,
disconnect,
- addLog, // SSE内部日志记录
- clearLogs,
- cleanup,
- processMessage // 消息分类处理
+ addLog
};
}
\ No newline at end of file
diff --git a/src/views/L1-data-list/index.vue b/src/views/L1-data-list/index.vue
new file mode 100644
index 0000000..e69de29
diff --git a/src/views/L4-data-list/index.vue b/src/views/L4-data-list/index.vue
new file mode 100644
index 0000000..e69de29
diff --git a/src/views/index.vue b/src/views/index.vue
new file mode 100644
index 0000000..39d3d92
--- /dev/null
+++ b/src/views/index.vue
@@ -0,0 +1,975 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 单号检查
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 序号检查
+ 复检序号检查
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 正常
+ 异常
+ 待检
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/views/login.vue b/src/views/login.vue
new file mode 100644
index 0000000..f668a2d
--- /dev/null
+++ b/src/views/login.vue
@@ -0,0 +1,527 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 点击刷新
+
+
+
+
+
+
+
+
+ {{ loading ? '登录中...' : '登录' }}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/views/package-station/index.vue b/src/views/package-station/index.vue
new file mode 100644
index 0000000..97a2d56
--- /dev/null
+++ b/src/views/package-station/index.vue
@@ -0,0 +1,684 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
本箱累计
+
{{ totalCount }}
+
+
+
+
+
+
+
+
+
+
+ 打印箱签
+
+
+
+
+
+ 提交装箱
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/vite.config.ts b/vite.config.ts
index 38269d9..18143d3 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -36,7 +36,7 @@ export default defineConfig({
server: {
proxy: {
'/api': {
- target: 'http://localhost:3000',
+ target: 'http://192.168.1.38:18081',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}