feat: 实现工位终端滑动续签机制,强化安全与身份追溯
- 新增滑动续签功能:人工触屏触发本地心跳 + 30秒节流刷新JWT,避免作业中令牌过期 - 拆分质量检验权限:过程检/完工检使用不同权限码,细化权限粒度 - 新增操作人用户ID字段:报工、拧紧记录落库时携带可信用户ID,解决身份追溯问题 - 移除编译期默认密钥,启动期校验所有必要密钥非空,防止密钥泄露风险 - 修复WMS附件越权遍历问题:使用UUID文件名替代顺序ID访问附件 - 实现登录态过期数据隔离:仅返回当前操作人的待同步数据,避免身份混淆
This commit is contained in:
@@ -3,6 +3,12 @@ import request from '../utils/request'
|
||||
// 登录
|
||||
export const login = (data) => request.post('/api/auth/login', data)
|
||||
|
||||
// 滑动续签心跳(本地空闲计时):任何人工触屏触发,立即刷新服务端登录态空闲计时
|
||||
export const touchSession = () => request.post('/api/auth/touch')
|
||||
|
||||
// 滑动续签 Bearer(前端节流 30 秒一次):用当前登录态换新 JWT,作业中令牌不过期
|
||||
export const refreshToken = () => request.post('/api/auth/refresh-token')
|
||||
|
||||
// 工位配置(固定工位号)
|
||||
export const getConfig = () => request.get('/api/config')
|
||||
|
||||
|
||||
@@ -3,5 +3,14 @@ import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import { touch } from './store/station'
|
||||
|
||||
// 滑动续签全局监听(修订需求):任何人工触屏行为(点击/触摸/键盘/滚轮/滚动)都触发续签。
|
||||
// 捕获阶段监听,弹窗/遮罩/任何组件拦截不了;程序化行为(轮询、WS 保活、定时刷新)
|
||||
// 不派发真实用户事件,不算触发。具体节流在 store.touch() 内部(本地立即 + Bearer 30 秒)。
|
||||
const ACTIVITY_EVENTS = ['click', 'touchstart', 'keydown', 'wheel', 'scroll']
|
||||
for (const evt of ACTIVITY_EVENTS) {
|
||||
window.addEventListener(evt, () => touch(), { capture: true, passive: true })
|
||||
}
|
||||
|
||||
createApp(App).use(router).use(ElementPlus).mount('#app')
|
||||
@@ -13,9 +13,11 @@ import {
|
||||
getWip,
|
||||
occupyLinePoint,
|
||||
pauseStation,
|
||||
submitTorque
|
||||
refreshToken,
|
||||
submitTorque,
|
||||
touchSession
|
||||
} from '../api'
|
||||
import { getUser } from '../utils/request'
|
||||
import { getUser, getToken } from '../utils/request'
|
||||
|
||||
export const state = reactive({
|
||||
stationNo: 0,
|
||||
@@ -374,6 +376,22 @@ export async function moveOut() {
|
||||
|
||||
export const operatorName = () => user.name || user.username || ''
|
||||
|
||||
// ---------- 滑动续签(修订需求:触发点 = 任何人工触屏行为) ----------
|
||||
// 双层机制:
|
||||
// ① 本地空闲计时:每次触摸立即调用 /api/auth/touch(零成本本地写 last_active_at),防作业中误登出;
|
||||
// ② MES Bearer 续签:节流 30 秒一次 /api/auth/refresh-token,作业中令牌不因固定有效期过期。
|
||||
// 未登录(无自身 JWT,如登录页)时静默跳过;系统后台行为(轮询/WS 保活)不会派发人工事件,
|
||||
// 不会进入本函数,不算触发。
|
||||
let lastBearerRefreshAt = 0
|
||||
export function touch() {
|
||||
if (!getToken()) return
|
||||
touchSession().catch(() => { /* 本地心跳失败静默,下一触摸重试 */ })
|
||||
const now = Date.now()
|
||||
if (now - lastBearerRefreshAt < 30_000) return
|
||||
lastBearerRefreshAt = now
|
||||
refreshToken().catch(() => { /* MES 不可达时静默,下个节流窗口重试 */ })
|
||||
}
|
||||
|
||||
// flowId 随任务到达后再触发一次绑定加载(上线位/首次拉到任务时 flowId 才有值)
|
||||
watch(flowId, (v) => {
|
||||
if (v > 0 && state.currentSn && !state.bindPanel) loadBind()
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { getConfig, login } from '../api'
|
||||
import { getConfig, getSyncStats, login } from '../api'
|
||||
import { setAuth } from '../utils/request'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -83,6 +83,20 @@ async function submit() {
|
||||
setAuth(data.accessToken, data.user)
|
||||
ElMessage.success('登录成功')
|
||||
router.push('/main')
|
||||
// 仅提示本人上次发送失败、仍留在本机的数据条数(不自动打开任何页面);
|
||||
// 他人登录时后端按操作人隔离,不会返回、也不会代发这些数据。
|
||||
try {
|
||||
const stats = await getSyncStats()
|
||||
const n = Number(stats?.pendingTotal || 0)
|
||||
if (n > 0) {
|
||||
ElMessage({
|
||||
type: 'info',
|
||||
message: `您上次有 ${n} 条报工数据发送失败,仍保留在本机;留意顶部「待同步」即可,系统会自动重发`,
|
||||
duration: 8000,
|
||||
showClose: true
|
||||
})
|
||||
}
|
||||
} catch { /* 统计不可达时静默,不阻断登录 */ }
|
||||
} catch (e) {
|
||||
// 错误提示已由 request 封装统一弹出
|
||||
} finally {
|
||||
|
||||
@@ -166,10 +166,23 @@ async function manualFlush() {
|
||||
} catch (e) { /* 统一错误提示 */ }
|
||||
}
|
||||
|
||||
function logout() {
|
||||
stationLogout({ username: user?.username || '', stationNo: stationNo.value || 0 }).catch(() => {})
|
||||
async function logout() {
|
||||
// 退出前先本地退出(服务端登出失败也照样退),再按响应提醒本人未发送成功的条数
|
||||
let data = null
|
||||
try {
|
||||
data = await stationLogout({ username: user?.username || '', stationNo: stationNo.value || 0 })
|
||||
} catch { /* MES 不可达也继续本地退出 */ }
|
||||
clearAuth()
|
||||
router.push('/login')
|
||||
const n = Number(data?.pendingTotal || 0)
|
||||
if (n > 0) {
|
||||
ElMessage({
|
||||
type: 'warning',
|
||||
message: `您有 ${n} 条报工数据发送失败,仍保留在本机(只有您本人登录可见/可发送),下次登录后请留意「待同步」`,
|
||||
duration: 8000,
|
||||
showClose: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
Reference in New Issue
Block a user