Files
bj_power/bj_power_workstation/frontend/src/views/Login.vue
T
SunYF 756d978900 feat: 实现工位终端滑动续签机制,强化安全与身份追溯
- 新增滑动续签功能:人工触屏触发本地心跳 + 30秒节流刷新JWT,避免作业中令牌过期
- 拆分质量检验权限:过程检/完工检使用不同权限码,细化权限粒度
- 新增操作人用户ID字段:报工、拧紧记录落库时携带可信用户ID,解决身份追溯问题
- 移除编译期默认密钥,启动期校验所有必要密钥非空,防止密钥泄露风险
- 修复WMS附件越权遍历问题:使用UUID文件名替代顺序ID访问附件
- 实现登录态过期数据隔离:仅返回当前操作人的待同步数据,避免身份混淆
2026-10-06 19:36:22 +08:00

196 lines
4.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="login-page">
<div class="login-card">
<h1 class="title">工位终端</h1>
<p class="subtitle">产线触屏终端(端口 8892)</p>
<div class="field">
<span class="lab">账号</span>
<el-input
v-model.trim="username"
size="large"
placeholder="请输入账号"
clearable
@keyup.enter="submit"
/>
</div>
<div class="field">
<span class="lab">密码</span>
<el-input
v-model="password"
size="large"
type="password"
show-password
placeholder="请输入密码"
@keyup.enter="submit"
/>
</div>
<div class="field">
<span class="lab">工位</span>
<span class="station-fixed">{{ fixedStation != null ? '工位 ' + fixedStation : '工位加载中…' }}</span>
</div>
<el-button class="btn-login" type="primary" size="large" :loading="loading" @click="submit">
登 录
</el-button>
<p class="hint">账号由 MES 统一管理</p>
</div>
</div>
</template>
<script setup>
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { getConfig, getSyncStats, login } from '../api'
import { setAuth } from '../utils/request'
const router = useRouter()
const username = ref('')
const password = ref('')
// null=未加载;0=上线位是合法工位,不能用 falsy 判断
const fixedStation = ref(null)
const loading = ref(false)
// 工位由服务端配置文件固定,一个工位一个终端,终端不允许修改工位
onMounted(async () => {
try {
const cfg = await getConfig()
// 0=上线位、13=下线位为合法虚拟工位,>=0 都算加载成功
if (typeof cfg?.stationNo === 'number' && cfg.stationNo >= 0) fixedStation.value = cfg.stationNo
} catch {
// 网络异常时保留 0,登录会提示配置未加载
}
})
async function submit() {
if (!username.value || !password.value) {
ElMessage.warning('请输入账号和密码')
return
}
if (fixedStation.value == null) {
ElMessage.warning('工位配置未加载,请检查服务端配置文件后重启')
return
}
loading.value = true
try {
const data = await login({
username: username.value,
password: password.value,
stationNo: fixedStation.value
})
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 {
loading.value = false
}
}
</script>
<style scoped>
.login-page {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #0f2b4c 0%, #14385f 60%, #1a4a7a 100%);
}
.login-card {
width: 480px;
padding: 48px 56px;
background: #fff;
border-radius: 16px;
box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35);
}
.title {
margin: 0 0 8px;
font-size: 34px;
text-align: center;
color: #16324f;
}
.subtitle {
margin: 0 0 32px;
text-align: center;
font-size: 16px;
color: #7a8aa0;
}
.field {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 22px;
}
.lab {
width: 64px;
font-size: 20px;
font-weight: bold;
color: #16324f;
text-align: right;
}
.field :deep(.el-input__inner) {
height: 52px;
font-size: 20px;
}
.station-el {
flex: 1;
}
.station-el :deep(.el-input__inner) {
height: 52px;
font-size: 20px;
font-weight: bold;
color: #16324f;
}
.station-fixed {
flex: 1;
font-size: 22px;
font-weight: bold;
color: #16324f;
line-height: 52px;
background: #f2f6fb;
border-radius: 8px;
padding: 0 16px;
}
.btn-login {
width: calc(100% - 80px);
margin-left: 80px;
height: 54px;
font-size: 24px;
letter-spacing: 12px;
}
.hint {
margin-top: 26px;
text-align: center;
font-size: 14px;
color: #9aa7b8;
}
</style>