Files
bj_power/bj_power_mes/frontend/src/pages/Station.vue
T

375 lines
17 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>
<el-card>
<el-alert type="info" :closable="false" style="margin-bottom:12px"
title="工位数以数据库为准。新增/停用/绑定工艺在此完成;虚拟工位(线下位)可在「工位名称」列直接点选重命名;内置工位名称锁定不可改、不可删除。" />
<div style="margin-bottom:12px">
<el-button v-if="can('produce.station:add')" type="primary" @click="openAdd">新增工位</el-button>
<span style="margin-left:12px;color:#909399;font-size:12px">虚拟工位类型选「线下位」,不连 PLC、仅记录上下线。</span>
</div>
<el-form inline style="margin-bottom:10px">
<el-form-item label="绑定工艺">
<el-select v-model="filterFlow" clearable filterable placeholder="全部" style="width:180px">
<el-option v-for="f in flows" :key="f.id" :value="f.id" :label="f.name" />
</el-select>
</el-form-item>
<el-form-item label="产品工艺">
<el-select v-model="filterPP" clearable filterable placeholder="全部" style="width:190px">
<el-option v-for="p in ppOptions" :key="p.id" :value="p.name" :label="p.name" />
</el-select>
</el-form-item>
<el-form-item label="状态">
<el-select v-model="filterStatus" clearable placeholder="全部" style="width:110px">
<el-option label="启用" value="ENABLED" />
<el-option label="停用" value="DISABLED" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="load">查询</el-button>
<el-button @click="resetFilter">重置</el-button>
</el-form-item>
</el-form>
<el-table :data="rows" border size="small">
<el-table-column prop="stationNo" label="工位号" width="90" align="center" />
<el-table-column label="工位名称" min-width="170">
<template #default="{ row }">
<el-input v-if="row.stationType === 'OFFLINE' && renamingId === row.id" v-model="renameVal" size="small"
@blur="commitRename(row)" @keyup.enter="commitRename(row)" />
<span v-else-if="row.stationType === 'OFFLINE'" style="cursor:pointer;color:#409eff"
@click="startRename(row)">{{ row.name }} ✎</span>
<span v-else>{{ row.name }}</span>
</template>
</el-table-column>
<el-table-column label="类型" width="90" align="center">
<template #default="{ row }">
<el-tag size="small" :type="row.stationType === 'OFFLINE' ? 'info' : 'success'">
{{ row.stationType === 'OFFLINE' ? '线下位' : '线上位' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="来源" width="90" align="center">
<template #default="{ row }">
<el-tag size="small" :type="row.isBuiltin ? 'warning' : 'info'">
{{ row.isBuiltin ? '内置' : '自定义' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="接驳台(实体)" width="100" align="center">
<template #default="{ row }">
<el-tag size="small" :type="hasDockOf(row.stationNo) ? 'success' : 'info'">{{ hasDockOf(row.stationNo) ? '有' : '无' }}</el-tag>
</template>
</el-table-column>
<el-table-column label="接驳台编码" min-width="170">
<template #default="{ row }">
<span v-if="dockCodesOf(row.stationNo)">{{ dockCodesOf(row.stationNo) }}</span>
<span v-else style="color:#909399">未绑定</span>
</template>
</el-table-column>
<el-table-column label="状态" width="80" align="center">
<template #default="{ row }">
<el-tag size="small" :type="row.status === 'ENABLED' ? 'success' : 'warning'">{{ row.status === 'ENABLED' ? '启用' : '停用' }}</el-tag>
</template>
</el-table-column>
<el-table-column label="绑定工艺" min-width="240">
<template #default="{ row }">
<el-select :model-value="row.flowId" size="small" placeholder="未绑定" @change="(v) => bindFlow(row, v)" style="width:100%">
<el-option :value="0" label="未绑定" />
<el-option v-for="f in flows" :key="f.id" :value="f.id" :label="f.name + (f.status === 'ACTIVE' ? '' : '(停用)')" />
</el-select>
</template>
</el-table-column>
<el-table-column label="产品工艺(反查)" min-width="180" show-overflow-tooltip>
<template #default="{ row }">
<span v-if="row.productProcesses && row.productProcesses.length">{{ row.productProcesses.join('、') }}</span>
<span v-else style="color:#909399">-</span>
</template>
</el-table-column>
<el-table-column label="终端可见页签" min-width="200">
<template #default="{ row }">
<template v-if="row.visibleTabs && row.visibleTabs.length">
<el-tag v-for="t in row.visibleTabs" :key="t" size="small" style="margin-right:4px">{{ tabLabel(t) }}</el-tag>
</template>
<span v-else style="color:#909399">全部显示</span>
</template>
</el-table-column>
<el-table-column label="操作" width="168" align="center" fixed="right">
<template #default="{ row }">
<div style="display:flex;align-items:center;justify-content:center;gap:4px;flex-wrap:nowrap">
<el-button v-if="can('produce.station:edit') && !row.isBuiltin && row.stationType !== 'OFFLINE'" link type="primary" size="small" @click="openName(row)">编辑</el-button>
<el-button link type="primary" size="small" @click="openTabs(row)">页签</el-button>
<el-button v-if="can('produce.station:edit')" link size="small" :type="row.status === 'ENABLED' ? 'warning' : 'success'" @click="toggleStationStatus(row)">{{ row.status === 'ENABLED' ? '停用' : '启用' }}</el-button>
<el-button v-if="can('produce.station:delete') && !row.isBuiltin" link type="danger" size="small" @click="remove(row)">删除</el-button>
</div>
</template>
</el-table-column>
</el-table>
<el-dialog v-model="dlg.show" :title="dlg.title" width="440px">
<el-form :model="dlg" label-width="90px">
<el-form-item label="工位号" required>
<el-input-number v-model="dlg.stationNo" :min="-999" :max="999" :disabled="!dlg.isAdd" style="width:100%" />
<div v-if="dlg.isAdd && dlg.stationNo >= 1 && dlg.stationNo <= 12" style="color:#F56C6C;font-size:12px;line-height:1.5;margin-top:4px">
物理工位 1~12 为硬件锁定,不可新增
</div>
<div v-if="dlg.isAdd" style="color:#909399;font-size:12px;line-height:1.5;margin-top:4px">
1~12 为物理产线工位(已锁定,中间连续、不可插入虚拟工位);负数(-1、-2…)为产线前段虚拟工位(排在工位1之前);≥13 为扩展工位。创建后不可修改。
</div>
</el-form-item>
<el-form-item label="工位名称" required>
<el-input v-model="dlg.name" placeholder="如 一号装配工位" />
</el-form-item>
<el-form-item label="工位类型">
<el-select v-if="!dlg.isBuiltin && !dlg.isAdd" v-model="dlg.stationType" style="width:100%">
<el-option value="OFFLINE" label="线下位(虚拟,不连 PLC,仅记录)" />
<el-option value="LINE" label="线上位(连 PLC)" />
</el-select>
<span v-else>线下位(虚拟,不连 PLC,仅记录)</span>
<div style="color:#909399;font-size:12px;line-height:1.5;margin-top:4px">
<template v-if="dlg.isAdd">新增工位均为虚拟工位(线下位),不连 PLC、仅记录上下线,类型不可选。</template>
<template v-else-if="dlg.isBuiltin">内置工位类型由产线初始配置固定,不可修改。</template>
<template v-else>非内置工位可调整类型(看板按「线下位」统计虚拟工位)。</template>
</div>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dlg.show = false">取消</el-button>
<el-button v-if="can('produce.station:edit')" type="primary" :disabled="dlg.isAdd && dlg.stationNo >= 1 && dlg.stationNo <= 12" @click="save">保存</el-button>
</template>
</el-dialog>
<!-- 终端可见页签配置 -->
<el-dialog v-model="tabDlg.show" :title="`工位${tabDlg.stationNo} - 终端可见页签`" width="480px">
<el-alert type="info" :closable="false" style="margin-bottom:12px"
title="勾选该工位终端允许显示的页签;全部不勾 = 显示全部页签。配置后终端下次拉取任务即生效。" />
<el-checkbox-group v-model="tabDlg.tabs">
<el-checkbox v-for="t in TAB_OPTIONS" :key="t.v" :value="t.v">{{ t.l }}</el-checkbox>
</el-checkbox-group>
<template #footer>
<el-button @click="tabDlg.show = false">取消</el-button>
<el-button v-if="can('produce.station:edit')" type="primary" @click="saveTabs">保存</el-button>
</template>
</el-dialog>
</el-card>
<PageHelp :data="helpStation" page="Station" />
</template>
<script setup>
import { reactive, ref, computed, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import request from '../utils/request'
import { can } from '../utils/perm'
import PageHelp from '../components/PageHelp.vue'
import { helpStation } from '../help'
const stations = ref([])
const flows = ref([])
// 接驳台主数据(真源在 dock 表):一工位可绑多个接驳台(左L/右R),展示按 dock.station_no 聚合
const dockByStation = ref({})
async function loadDocks() {
// GET /docks 返回裸数组(接驳台全量,非分页包裹),直接取数组本身
const data = await request.get('/docks')
const list = Array.isArray(data) ? data : (data?.list || [])
const map = {}
for (const d of list) {
const no = Number(d.stationNo) || 0
if (no <= 0) continue
;(map[no] = map[no] || []).push(d.dockCode)
}
dockByStation.value = map
}
function dockCodesOf(no) {
const codes = dockByStation.value[Number(no)] || []
return codes.length ? codes.join(' / ') : ''
}
function hasDockOf(no) {
return (dockByStation.value[Number(no)] || []).length > 0
}
// 终端页签固定集合(与工位终端 Main.vue 页签一一对应)
const TAB_OPTIONS = [
{ v: 'online', l: '上线建档' },
{ v: 'work', l: '作业' },
{ v: 'material', l: '物料' },
{ v: 'pdf', l: '工艺文件' },
{ v: 'inspect', l: '巡检' },
{ v: 'offline', l: '下线完工' }
]
const tabLabel = (v) => (TAB_OPTIONS.find((t) => t.v === v) || {}).l || v
// 筛选:绑定工艺(下拉)+ 产品工艺(名称模糊,反查列 client 端过滤;工位为全量小表无需后端分页)
const filterFlow = ref(null)
const filterPP = ref('')
const filterStatus = ref('ENABLED')
const ppOptions = ref([])
const rows = computed(() => {
return [...stations.value]
.sort((a, b) => (a.stationNo || 0) - (b.stationNo || 0))
.map((s) => ({ id: s.id, stationNo: s.stationNo, name: s.name, flowId: s.flowId, flowName: s.flowName, stationType: s.stationType, status: s.status, isBuiltin: !!s.isBuiltin, visibleTabs: Array.isArray(s.visibleTabs) ? s.visibleTabs : [], productProcesses: Array.isArray(s.productProcesses) ? s.productProcesses : [] }))
.filter((r) => (filterFlow.value ? r.flowId === filterFlow.value : true))
.filter((r) => (filterPP.value ? r.productProcesses.some((n) => n.toLowerCase().includes(filterPP.value.toLowerCase())) : true))
.filter((r) => (filterStatus.value ? r.status === filterStatus.value : true))
})
function resetFilter() {
filterFlow.value = null
filterPP.value = ''
filterStatus.value = 'ENABLED'
load()
}
async function toggleStationStatus(row) {
const to = row.status === 'ENABLED' ? 'DISABLED' : 'ENABLED'
const action = to === 'DISABLED' ? '停用' : '启用'
try {
await ElMessageBox.confirm(`确认${action}工位${row.stationNo}「${row.name}」?`, '提示', { type: 'warning' })
} catch { return }
await request.post('/stations/status', { id: row.id, status: to })
ElMessage.success(`已${action}`)
load()
}
// 操作列按钮已外露(2026-11-02):页签/停用·启用/删除直接绑定,不再经"更多"下拉分发
const dlg = reactive({ show: false, isAdd: false, title: '', id: 0, stationNo: 1, name: '', stationType: 'OFFLINE', isBuiltin: false })
// 终端可见页签编辑(空数组 = 显示全部)
const tabDlg = reactive({ show: false, id: 0, stationNo: 0, name: '', stationType: 'LINE', tabs: [] })
function openTabs(row) {
Object.assign(tabDlg, { show: true, id: row.id, stationNo: row.stationNo, name: row.name, stationType: row.stationType || 'LINE', tabs: [...row.visibleTabs] })
}
async function saveTabs() {
await request.post('/stations', {
id: tabDlg.id, stationNo: tabDlg.stationNo, name: tabDlg.name,
stationType: tabDlg.stationType, visibleTabs: tabDlg.tabs
})
ElMessage.success('页签配置已保存')
tabDlg.show = false
load()
}
async function load() {
stations.value = (await request.get('/stations')) || []
}
function openAdd() {
const used = new Set(stations.value.map((s) => s.stationNo))
let next = 14
while (used.has(next)) next++
Object.assign(dlg, { show: true, isAdd: true, title: '新增工位', id: 0, stationNo: next, name: '', stationType: 'OFFLINE', isBuiltin: false })
}
function openName(row) {
Object.assign(dlg, { show: true, isAdd: false, title: `工位${row.stationNo} - 修改`, id: row.id, stationNo: row.stationNo, name: row.name, stationType: row.stationType || 'LINE', isBuiltin: !!row.isBuiltin })
}
// 虚拟工位(线下位)行内重命名:点名称旁 ✎ 进入编辑,失焦或回车提交
const renamingId = ref(0)
const renameVal = ref('')
function startRename(row) {
renamingId.value = row.id
renameVal.value = row.name
}
async function commitRename(row) {
if (renamingId.value !== row.id) return
const v = (renameVal.value || '').trim()
renamingId.value = 0
if (!v) {
ElMessage.warning('名称不能为空')
await load()
return
}
if (v === row.name) return
try {
await request.post('/stations', { id: row.id, stationNo: row.stationNo, name: v, stationType: row.stationType || 'LINE' })
ElMessage.success('名称已更新')
} catch {
// 拦截器已提示
} finally {
await load()
}
}
async function save() {
if (!dlg.name) return ElMessage.warning('请输入工位名称')
if (dlg.isAdd && dlg.stationNo >= 1 && dlg.stationNo <= 12) {
return ElMessage.warning('物理工位 1~12 为硬件锁定,不可新增')
}
if (dlg.isAdd && stations.value.some((s) => s.stationNo === dlg.stationNo)) {
return ElMessage.warning(`工位${dlg.stationNo} 已存在,请换一个工位号`)
}
await request.post('/stations', {
id: dlg.id, stationNo: dlg.stationNo, name: dlg.name, stationType: dlg.isAdd ? 'OFFLINE' : dlg.stationType
})
ElMessage.success(dlg.isAdd ? '工位已新增' : '已保存')
dlg.show = false
load()
}
async function bindFlow(row, fid) {
try {
await request.post('/stations', { id: row.id, stationNo: row.stationNo, name: row.name, stationType: row.stationType || 'LINE', flowId: fid })
ElMessage.success(fid ? '已绑定工艺' : '已解除绑定')
} catch (e) {
// 规则3(fail-open):PLC 离线未确认 → 后端返回 3021(拦截器不弹 toast),此处弹二次确认
if (e && e.code === 3021) {
let confirmed = false
try {
await ElMessageBox.confirm(
`PLC 当前离线,无法确认工位${row.stationNo} 是否还有工件。请到现场确认工位已清空后再操作。`,
'PLC 离线',
{ type: 'warning', confirmButtonText: '已现场确认,继续', cancelButtonText: '取消' }
)
confirmed = true
} catch {
confirmed = false
}
if (confirmed) {
try {
await request.post('/stations', {
id: row.id, stationNo: row.stationNo, name: row.name,
stationType: row.stationType || 'LINE', flowId: fid, plcOfflineConfirmed: true
})
ElMessage.success(fid ? '已绑定工艺(PLC 离线已现场确认)' : '已解除绑定(PLC 离线已现场确认)')
} catch {
// 二次重发仍失败:拦截器已提示(如在途指令/托盘在位等硬拒绝)
}
}
}
// 其他错误拦截器已提示(如绑定到未启用的流程)
} finally {
await load()
}
}
async function remove(row) {
try {
await ElMessageBox.confirm(`确认删除工位${row.stationNo}「${row.name}」?`, '删除工位', { type: 'warning' })
} catch {
return
}
try {
await request.delete(`/stations/${row.id}`)
ElMessage.success('工位已删除')
} catch {
// 拦截器已提示(如内置工位不允许删除)
} finally {
await load()
}
}
// ---------- 工位派工已删除:路线由工单「工艺组合」决定,绑定关系即本页下拉选择 ----------
onMounted(async () => {
await Promise.all([load(), loadDocks()])
flows.value = (await request.get('/process-flows', { params: { pageSize: 1000, page: 1 } }))?.list || []
try {
ppOptions.value = (await request.get('/product-processes', { params: { pageSize: 1000, page: 1 } }))?.list || []
} catch { ppOptions.value = [] }
})
</script>