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

171 lines
7.7 KiB
Vue
Raw Normal View History

<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">虚拟工位(如 0 上线位、13 下线位)类型选「线下位」,不连 PLC、仅记录上下线。</span>
</div>
<el-table :data="rows" border size="small">
<el-table-column prop="stationNo" label="工位号" width="90" align="center" />
<el-table-column prop="name" label="工位名称" min-width="170" show-overflow-tooltip />
<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>
2026-09-18 18:54:54 +08:00
<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">
2026-09-18 18:54:54 +08:00
<template #default="{ row }">
<el-tag size="small" :type="row.hasDock ? 'success' : 'info'">{{ row.hasDock ? '有' : '无' }}</el-tag>
</template>
</el-table-column>
<el-table-column label="接驳台编码" min-width="150">
<template #default="{ row }">
<span v-if="row.dockCode">{{ row.dockCode }}</span>
<span v-else style="color:#909399">未绑定</span>
</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>
2026-09-18 18:54:54 +08:00
<el-table-column label="操作" width="170" align="center" fixed="right">
<template #default="{ row }">
<el-button v-if="can('produce.station:edit')" size="small" @click="openName(row)">改名</el-button>
2026-09-18 18:54:54 +08:00
<el-button v-if="can('produce.station:delete') && !row.isBuiltin" size="small" type="danger" @click="remove(row)">删除</el-button>
</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="0" :max="999" :disabled="!dlg.isAdd" style="width:100%" />
<div v-if="dlg.isAdd" style="color:#909399;font-size:12px;line-height:1.5;margin-top:4px">
自定义工位号,可与现有工位不连续(如 14、15…);0 为上线位、13 为下线位以外的编号均按物理/虚拟位识别。
</div>
</el-form-item>
<el-form-item label="工位名称" required>
<el-input v-model="dlg.name" placeholder="如 一号装配工位" />
</el-form-item>
<el-form-item label="工位类型">
2026-09-18 18:54:54 +08:00
<el-radio-group v-model="dlg.stationType" :disabled="dlg.isBuiltin">
<el-radio label="LINE">线上位(连 PLC)</el-radio>
<el-radio label="OFFLINE">线下位(虚拟,不连 PLC)</el-radio>
</el-radio-group>
2026-09-18 18:54:54 +08:00
<div v-if="dlg.isBuiltin" style="color:#909399;font-size:12px;line-height:1.5;margin-top:4px">
内置工位需与 PLC 通讯并按顺序流转,工位类型不可修改。
</div>
</el-form-item>
<el-form-item v-if="dlg.hasDock" label="接驳台编码">
<div style="color:#909399;font-size:12px;line-height:1.5">
接驳台与工位的 1:1 绑定由系统预置(种子初始化),页面不可更改。
</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" @click="save">保存</el-button>
</template>
</el-dialog>
</el-card>
<PageHelp :data="helpStation" page="Station" />
</template>
<script setup>
import { reactive, ref, computed, onMounted } from 'vue'
2026-09-18 18:54:54 +08:00
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([])
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, isBuiltin: !!s.isBuiltin, hasDock: !!s.hasDock, dockCode: s.dockCode || '' }))
})
const dlg = reactive({ show: false, isAdd: false, title: '', id: 0, stationNo: 1, name: '', stationType: 'LINE', isBuiltin: false, hasDock: false })
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: 'LINE', isBuiltin: false, hasDock: 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, hasDock: !!row.hasDock })
}
async function save() {
if (!dlg.name) return ElMessage.warning('请输入工位名称')
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.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 {
// 拦截器已提示(如绑定到未启用的流程)
} finally {
await load()
}
}
2026-09-18 18:54:54 +08:00
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 load()
flows.value = (await request.get('/process-flows', { params: { pageSize: 1000, page: 1 } }))?.list || []
})
</script>