Files
bj_power/bj_power_workstation/frontend/src/views/Login.vue
T
SunYF 1e92b2a596 feat: 核心业务实体扩充(混产模板/产品BOM/试制记录)、WMS 库存检验增强与前端通用能力
- MES 新增实体:混产模板、产品BOM、产品工艺物料、试制记录(schema + ent 生成码 + logic/handler/前端页)
- WMS 实体增强:检验记录、库存、半成品重构;新增序列号库存与短缺代报
- AGV 与产能:AGV 手动点位与链路、物料守卫、短缺预测、原因字典
- 前端通用能力:新增下一步引导组件 NextStepBar,统一帮助文档/布局/请求拦截与操作列
- 工位终端:界面与各 handler 调整(api/store/绑定/PLC/拧紧/上报等)
- 配置与文档:更新 mes-api.yaml、WMS README 及案例/产线API/问题记录/项目说明/流程说明
2026-11-15 12:17:39 +08:00

222 lines
6.2 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>
<!-- 固定模式:服务端配置了工位(stationNo>0),不允许选择 -->
<span v-if="fixedStation" class="station-fixed">工位 {{ fixedStation }}</span>
<!-- 选择模式(2026-11-11 多会话拍板):终端未配置工位=虚拟工位专用机,只允许选虚拟工位 -->
<el-select v-else v-model="pickedStation" class="station-el" :placeholder="stationGroups.OFFLINE.length ? '请选择虚拟工位' : '未查到可用的虚拟工位,请先在 MES 工位管理中配置'" size="large">
<el-option-group v-if="stationGroups.OFFLINE.length" label="虚拟工位">
<el-option v-for="s in stationGroups.OFFLINE" :key="s.stationNo" :label="stationLabel(s)" :value="s.stationNo" />
</el-option-group>
</el-select>
</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 { computed, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { getConfig, getStationOptions, login } from '../api'
import { setAuth } from '../utils/request'
const router = useRouter()
const username = ref('')
const password = ref('')
// null=未加载;>0=固定工位模式;<=0=选择模式(终端未配置工位)
const fixedStation = ref(null)
const pickedStation = ref(null)
const stationList = ref([])
const loading = ref(false)
const stationGroups = computed(() => ({
// 只列工位号为正整数的虚拟工位(0/负数不是合法工位号)
OFFLINE: stationList.value.filter((s) => s.stationType === 'OFFLINE' && Number.isInteger(Number(s.stationNo)) && Number(s.stationNo) > 0)
}))
const stationLabel = (s) => {
const tip = s.stationType === 'OFFLINE' ? '(虚拟)' : ''
return s.name ? `工位 ${s.stationNo} ${s.name}${tip}` : `工位 ${s.stationNo}${tip}`
}
// 2026-11-09 拍板:配置了工位(stationNo>0)登录页不允许选择。
// 2026-11-11 多会话拍板:未配置工位(<=0)的终端实例=虚拟工位专用机,登录页只显示虚拟工位
//(后端登录接口同样硬校验 stationType=OFFLINE,防前端绕过)。固定模式下不显示接驳台。
onMounted(async () => {
try {
const cfg = await getConfig()
if (typeof cfg?.stationNo === 'number' && cfg.stationNo > 0) {
fixedStation.value = cfg.stationNo
return
}
const list = await getStationOptions()
stationList.value = Array.isArray(list) ? list : []
// 默认选中首个可选虚拟工位(只列正整数工位号)
pickedStation.value = stationGroups.value.OFFLINE[0]?.stationNo ?? null
} catch {
// 网络异常:固定模式保持 null(提交时提示),选择模式保持空清单(提交时提示)
}
})
async function submit() {
if (!username.value || !password.value) {
ElMessage.warning('请输入账号和密码')
return
}
let stationNo
if (fixedStation.value) {
stationNo = fixedStation.value
} else {
if (pickedStation.value === null || pickedStation.value === undefined) {
ElMessage.warning(stationGroups.value.OFFLINE.length
? '请选择虚拟工位'
: '未查到可用的虚拟工位,请先在 MES 工位管理中配置')
return
}
stationNo = pickedStation.value
}
loading.value = true
try {
const data = await login({
username: username.value,
password: password.value,
stationNo
})
// 选择模式:记住本班次实际登录工位与工位类型(供主界面判定虚拟工位)
if (!fixedStation.value) {
sessionStorage.setItem('stationNo', String(stationNo))
const picked = stationList.value.find((s) => String(s.stationNo) === String(stationNo))
sessionStorage.setItem('stationType', picked?.stationType || '')
}
setAuth(data.accessToken, data.user)
ElMessage.success('登录成功')
router.push('/main')
} 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>