625 lines
32 KiB
Vue
625 lines
32 KiB
Vue
<template>
|
||
<el-card>
|
||
<el-alert type="info" :closable="false" style="margin-bottom:12px"
|
||
title="新增/停用/绑定工艺在此完成;虚拟工位(线下位)可在「工位名称」列直接点选重命名;内置工位名称锁定不可改、不可删除。" />
|
||
|
||
<!-- 工位模板:平铺展示(最多 20 个),点击应用 -->
|
||
<div style="margin-bottom:12px">
|
||
<div style="font-size:13px;font-weight:600;margin-bottom:6px">工位模板(点击应用,最多展示 20 个):</div>
|
||
<div style="display:flex;flex-wrap:wrap;gap:8px">
|
||
<el-button v-for="t in templates" :key="t.name" size="small" @click="openTemplate(t)">
|
||
{{ t.name }}<el-tag v-if="t.productCode" size="small" type="success" style="margin-left:6px">{{ t.productCode }}</el-tag>
|
||
</el-button>
|
||
<span v-if="!templates.length" style="color:#909399;font-size:12px">暂无工位模板</span>
|
||
</div>
|
||
</div>
|
||
|
||
<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-dialog v-model="tplDlg.show" :title="`工位模板 - ${tplDlg.name}`" width="620px">
|
||
<div style="font-weight:600;margin-bottom:8px">工位 → 绑定工艺</div>
|
||
<el-table :data="tplDlg.stations" border size="small" empty-text="该模板未配置工位">
|
||
<el-table-column prop="stationNo" label="工位" width="90" align="center" />
|
||
<el-table-column label="绑定工艺" min-width="220">
|
||
<template #default="{ row }">{{ flowNameOf(row.flowId) }}</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div style="margin-top:10px;font-size:13px">满足产品工艺:<b>{{ tplDlg.processNames.join('、') || '—' }}</b></div>
|
||
<div style="margin-top:6px;font-size:13px">适用产品:<b>{{ tplDlg.productCode || '不限定(跨产品模板)' }}</b></div>
|
||
<div style="margin-top:10px;font-size:13px">
|
||
本次要生产的产品:<el-select v-model="tplDlg.targetProductCode" clearable filterable placeholder="不选=跳过校验" style="width:230px;margin-left:6px">
|
||
<el-option v-for="c in productCodes" :key="c" :value="c" :label="c" />
|
||
</el-select>
|
||
<span style="margin-left:10px;color:#606266">当前混产模板:<b>{{ tplDlg.templateName || '未设置' }}</b> 支持成品:<b>{{ (tplDlg.products || []).join('、') || '—' }}</b></span>
|
||
</div>
|
||
<!-- 2026-11-13:打开即自动预检,单页内联真实结论与原因;有阻塞时「应用」禁用 -->
|
||
<div style="margin-top:10px" v-loading="tplDlg.prechecking">
|
||
<el-alert v-if="!tplDlg.precheckRows.length" type="success" :closable="false" title="预检通过:没有阻塞项。" />
|
||
<el-alert v-else :type="blockedCount ? 'warning' : 'success'" :closable="false"
|
||
:title="blockedCount ? `预检完成:${blockedCount} 个工位会被跳过,请处理后重开模板` : '预检通过:全部工位可套用'" />
|
||
<el-table v-if="tplDlg.precheckRows.length" :data="tplDlg.precheckRows" border size="small" style="margin-top:8px">
|
||
<el-table-column prop="stationNo" label="工位" width="70" align="center" />
|
||
<el-table-column label="当前绑定工序" min-width="120">
|
||
<template #default="{ row }">{{ row.currentFlowName || '未绑定' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="模板绑定工序" min-width="120">
|
||
<template #default="{ row }">{{ row.flowName || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="该模板支持的成品" min-width="130">
|
||
<template #default="{ row }">{{ (row.products || []).join('、') || tplDlg.products.join('、') || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="结论" width="80" align="center">
|
||
<template #default="{ row }"><el-tag :type="row.blocked ? 'danger' : 'success'" size="small">{{ row.blocked ? '跳过' : '可套用' }}</el-tag></template>
|
||
</el-table-column>
|
||
<el-table-column label="原因" min-width="200">
|
||
<template #default="{ row }">{{ (row.reasons || []).join(';') || '—' }}</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
<template #footer>
|
||
<el-button @click="tplDlg.show = false">取消</el-button>
|
||
<el-button type="primary" :disabled="tplDlg.prechecking || blockedCount > 0" @click="applyTemplate(tplDlg.targetProductCode)">应用</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 2026-11-13 拍板:清线确认单——五项(在制品/余料/托盘/PLC未完成任务/AGV在途)逐项确认,放行结果后端落 event_log -->
|
||
<el-dialog v-model="clearanceDlg.show" title="清线确认单" width="580px">
|
||
<el-alert type="warning" :closable="false" show-icon class="mb8"
|
||
title="即将切换生产新产品,请先确认产线已清线" />
|
||
<div style="font-size:13px;margin-bottom:8px">当前在用模板:<b>{{ clearanceDlg.templateName || '未设置' }}</b> 本次产品:<b>{{ clearanceDlg.productCode || '(绑定变更)' }}</b></div>
|
||
<el-checkbox-group v-model="clearanceDlg.confirmed" style="display:flex;flex-direction:column;gap:8px">
|
||
<el-checkbox v-for="it in clearanceDlg.items" :key="it.key" :value="it.key" :disabled="it.count === 0">
|
||
{{ it.label }} <b :style="{ color: it.count > 0 ? '#f56c6c' : '#67c23a' }">{{ it.count === 0 ? '已清(0)' : it.count + ' 项待处理' }}</b>
|
||
</el-checkbox>
|
||
</el-checkbox-group>
|
||
<div style="margin-top:10px;color:#909399;font-size:12px">PLC 离线等特殊情况可人工确认放行;勾选即留痕,形成可审计的「准备运行」证据。</div>
|
||
<template #footer>
|
||
<el-button @click="clearanceDlg.show = false">取消</el-button>
|
||
<el-button type="primary" :loading="clearanceDlg.busy" @click="confirmClearance">确认已清线并继续</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 套用前冲突清单:逐条列出跳过原因,用户确认后才提交 -->
|
||
<el-dialog v-model="precheckDlg.show" title="套用前检查" width="620px">
|
||
<div style="margin-bottom:8px;font-size:13px">
|
||
模板:<b>{{ precheckDlg.name }}</b> 适用产品:<b>{{ precheckDlg.productCode || '不限定' }}</b>
|
||
</div>
|
||
<el-alert v-if="precheckDlg.blockedCount" type="warning" :closable="false" show-icon
|
||
:title="`有 ${precheckDlg.blockedCount} 个工位会被跳过,其余工位仍会正常套用`" style="margin-bottom:10px" />
|
||
<el-alert v-else type="success" :closable="false" show-icon title="未发现冲突,全部工位可套用" style="margin-bottom:10px" />
|
||
<el-table :data="precheckDlg.rows" border size="small" max-height="320">
|
||
<el-table-column prop="stationNo" label="工位" width="80" align="center" />
|
||
<el-table-column label="绑定工艺" width="160">
|
||
<template #default="{ row }">{{ flowNameOf(row.flowId) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="结果 / 跳过原因" min-width="240">
|
||
<template #default="{ row }">
|
||
<span v-if="row.blocked" style="color:#e6a23c">{{ row.reasons.join(';') }}</span>
|
||
<span v-else style="color:#67c23a">可套用</span>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<template #footer>
|
||
<el-button @click="precheckDlg.show = false">返回修改</el-button>
|
||
<el-button type="primary" @click="confirmApplyTemplate">确认应用(跳过冲突工位)</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 模板应用结果(一次列全 applied / skipped / matched) -->
|
||
<el-dialog v-model="resultDlg.show" title="模板应用结果" width="520px">
|
||
<div style="margin-bottom:8px;font-size:13px">已应用工位:<b>{{ resultDlg.applied.length ? resultDlg.applied.map((n) => '工位' + n).join('、') : '—' }}</b></div>
|
||
<div style="margin-bottom:8px;font-size:13px">满足产品工艺:<b>{{ resultDlg.matched.length ? resultDlg.matched.join('、') : '—' }}</b></div>
|
||
<div style="font-weight:600;margin-bottom:6px">跳过的工位(冲突):</div>
|
||
<template v-if="resultDlg.skipped.length">
|
||
<div v-for="(s, i) in resultDlg.skipped" :key="i" style="color:#e6a23c;font-size:13px">工位{{ s.stationNo }}:{{ s.reason }}</div>
|
||
</template>
|
||
<div v-else style="color:#909399;font-size:13px">无</div>
|
||
<template #footer>
|
||
<el-button type="primary" @click="resultDlg.show = false">知道了</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
|
||
})
|
||
// 2026-11-16 纠偏:混产成品配置已移至「产线管理 → 当前产线可生产成品」,工位编辑只管工位本身。
|
||
ElMessage.success(dlg.isAdd ? '工位已新增' : '已保存')
|
||
dlg.show = false
|
||
load()
|
||
}
|
||
|
||
// 2026-11-13:改「工位绑定」也是清线门禁触发点;后端返回清线拒绝时弹确认单,逐项打勾后带 confirmed 重发。
|
||
async function bindFlow(row, fid, clearanceConfirmed = []) {
|
||
try {
|
||
await request.post('/stations', {
|
||
id: row.id, stationNo: row.stationNo, name: row.name, stationType: row.stationType || 'LINE',
|
||
flowId: fid, clearanceConfirmed
|
||
})
|
||
ElMessage.success(fid ? '已绑定工艺' : '已解除绑定')
|
||
} catch (e) {
|
||
const msg = String(e?.message || e?.msg || 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, clearanceConfirmed
|
||
})
|
||
ElMessage.success(fid ? '已绑定工艺(PLC 离线已现场确认)' : '已解除绑定(PLC 离线已现场确认)')
|
||
} catch { /* 拦截器已提示 */ }
|
||
}
|
||
} else if (msg.includes('清线')) {
|
||
await openClearance('', (keys) => bindFlow(row, fid, keys))
|
||
}
|
||
// 其他错误拦截器已提示(如绑定到未启用的流程)
|
||
} 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()
|
||
}
|
||
}
|
||
|
||
// ---------- 工位派工已删除:路线由工单「工艺组合」决定,绑定关系即本页下拉选择 ----------
|
||
|
||
// ---------- 工位模板(平铺展示 / 查看 / 应用)----------
|
||
const templates = ref([])
|
||
async function loadTemplates() {
|
||
try {
|
||
const data = await request.get('/station-templates')
|
||
templates.value = (data?.list || []).slice(0, 20)
|
||
} catch { templates.value = [] }
|
||
}
|
||
const flowNameOf = (id) => (flows.value.find((f) => f.id === id) || {}).name || ('工艺' + id)
|
||
// 2026-11-13 拍板:原「产品工艺页 → 生成工位模板」入口移入工位管理页,改名「保存当前绑定为模板」。
|
||
// 语义=快捷操作:把当前各工位绑定的基础工序(工位×工序)一键存成模板,不再从产品工艺反推。
|
||
async function saveCurrentBindingAsTemplate() {
|
||
let name = ''
|
||
try {
|
||
const r = await ElMessageBox.prompt('给这套工位绑定起个名字', '保存当前绑定为模板', {
|
||
inputValue: '当前工位绑定', confirmButtonText: '保存', cancelButtonText: '取消'
|
||
})
|
||
name = (r.value || '').trim()
|
||
} catch { return }
|
||
if (!name) return ElMessage.warning('模板名必填')
|
||
const bindings = (stations.value || [])
|
||
.filter((s) => Number(s.flowId) > 0)
|
||
.map((s) => ({ stationNo: s.stationNo, flowId: s.flowId }))
|
||
.sort((a, b) => a.stationNo - b.stationNo)
|
||
if (!bindings.length) return ElMessage.warning('当前没有任何工位绑定工序,无可保存的模板')
|
||
try {
|
||
await request.post('/station-templates', { name, productCode: '', processNames: [], stations: bindings })
|
||
ElMessage.success(`已把 ${bindings.length} 个工位的当前绑定保存为模板「${name}」`)
|
||
await loadTemplates()
|
||
} catch { /* 拦截器已提示 */ }
|
||
}
|
||
|
||
/* ---------- 混产模板:配置入口已移至「产线管理 → 当前产线可生产成品」(2026-11-16 纠偏),本页不再维护 ---------- */
|
||
|
||
// 2026-11-13 P12/P13:预检改为「打开即自动预检 + 单页内联结论与原因」,去掉「预检并应用」两步走。
|
||
const tplDlg = reactive({ show: false, name: '', productCode: '', targetProductCode: '', stations: [], processNames: [], precheckRows: [], prechecking: false, templateName: '', products: [] })
|
||
const productCodes = computed(() => [...new Set((ppOptions.value || []).map((p) => p.productCode).filter(Boolean))])
|
||
const blockedCount = computed(() => tplDlg.precheckRows.filter((r) => r.blocked).length)
|
||
|
||
async function doPrecheck() {
|
||
tplDlg.prechecking = true
|
||
try {
|
||
const resp = await request.post('/stations/apply-template/precheck', {
|
||
name: tplDlg.name, targetProductCode: tplDlg.targetProductCode
|
||
})
|
||
tplDlg.precheckRows = Array.isArray(resp?.rows) ? resp.rows : []
|
||
tplDlg.templateName = resp?.templateName || ''
|
||
tplDlg.products = Array.isArray(resp?.products) ? resp.products : []
|
||
} catch { tplDlg.precheckRows = [] }
|
||
tplDlg.prechecking = false
|
||
}
|
||
|
||
/* ---------- 清线确认单(2026-11-13 拍板:五项逐项打勾,人工放行留痕) ---------- */
|
||
const clearanceDlg = reactive({ show: false, busy: false, productCode: '', templateName: '', items: [], confirmed: [], retry: null })
|
||
async function openClearance(productCode, retry) {
|
||
try {
|
||
const r = await request.post('/mix-templates/clearance-check', { productCode: productCode || '', confirmed: [] })
|
||
clearanceDlg.productCode = productCode || ''
|
||
clearanceDlg.templateName = r?.templateName || ''
|
||
clearanceDlg.items = Array.isArray(r?.items) ? r.items : []
|
||
clearanceDlg.confirmed = []
|
||
clearanceDlg.retry = retry
|
||
if (!r?.needClearance || clearanceDlg.items.every((i) => i.count === 0)) {
|
||
if (retry) await retry([])
|
||
return
|
||
}
|
||
clearanceDlg.show = true
|
||
} catch (e) {
|
||
ElMessage.error('清线检查失败:' + String(e?.message || e))
|
||
}
|
||
}
|
||
async function confirmClearance() {
|
||
const pending = clearanceDlg.items.filter((i) => i.count > 0)
|
||
if (pending.some((i) => !clearanceDlg.confirmed.includes(i.key))) {
|
||
return ElMessage.warning('请逐项确认现场已清线后再继续')
|
||
}
|
||
clearanceDlg.busy = true
|
||
try {
|
||
const r = await request.post('/mix-templates/clearance-check', {
|
||
productCode: clearanceDlg.productCode, confirmed: clearanceDlg.confirmed
|
||
})
|
||
if (!r?.passed) return ElMessage.warning('仍有未确认的清线项')
|
||
clearanceDlg.show = false
|
||
if (clearanceDlg.retry) await clearanceDlg.retry(clearanceDlg.confirmed)
|
||
} catch (e) {
|
||
ElMessage.error('清线确认失败:' + String(e?.message || e))
|
||
} finally { clearanceDlg.busy = false }
|
||
}
|
||
|
||
async function openTemplate(t) {
|
||
tplDlg.name = t.name || ''
|
||
tplDlg.productCode = t.productCode || ''
|
||
// 默认目标产品=模板适用产品;用户可改选,改选后不一致会在预检时被拒
|
||
tplDlg.targetProductCode = t.productCode || ''
|
||
tplDlg.stations = Array.isArray(t.stations) ? t.stations : []
|
||
tplDlg.processNames = Array.isArray(t.processNames) ? t.processNames : []
|
||
tplDlg.precheckRows = []
|
||
tplDlg.show = true
|
||
await doPrecheck()
|
||
}
|
||
|
||
// 兼容旧弹窗引用(不再使用两步确认弹窗)
|
||
const precheckDlg = reactive({ show: false, name: '', productCode: '', targetProductCode: '', rows: [], blockedCount: 0 })
|
||
async function precheckTemplate() { await doPrecheck() }
|
||
async function confirmApplyTemplate() {
|
||
await applyTemplate(precheckDlg.targetProductCode)
|
||
precheckDlg.show = false
|
||
}
|
||
|
||
const resultDlg = reactive({ show: false, applied: [], skipped: [], matched: [] })
|
||
async function applyTemplate(targetProductCode, confirmed = []) {
|
||
try {
|
||
const resp = await request.post('/stations/apply-template', {
|
||
name: tplDlg.name, targetProductCode: targetProductCode || '', confirmed
|
||
})
|
||
tplDlg.show = false
|
||
resultDlg.applied = Array.isArray(resp?.applied) ? resp.applied : []
|
||
resultDlg.skipped = Array.isArray(resp?.skipped) ? resp.skipped : []
|
||
resultDlg.matched = Array.isArray(resp?.matched) ? resp.matched : []
|
||
resultDlg.show = true
|
||
await load()
|
||
} catch (e) {
|
||
const msg = String(e?.message || e?.msg || e || '')
|
||
if (msg.includes('清线')) {
|
||
await openClearance(targetProductCode || '', (keys) => applyTemplate(targetProductCode, keys))
|
||
}
|
||
// 其余错误由 request 拦截器统一提示
|
||
}
|
||
}
|
||
|
||
onMounted(async () => {
|
||
await Promise.all([load(), loadDocks(), loadTemplates()])
|
||
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>
|