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

92 lines
3.5 KiB
Vue
Raw Normal View History

<template>
<el-card>
<el-alert type="info" :closable="false" style="margin-bottom:12px"
title="工位数以数据库为准(仅改名称,不增删工位)。本页为工位总览,每个工位的工艺流程在「关联工位」页维护:在下拉选择启用的工艺流程即绑定到该工位;一个工位只能有一个启用的工艺流程。" />
<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="绑定工艺流程" 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="操作" width="120" align="center" fixed="right">
<template #default="{ row }">
<el-button v-if="can('produce.station:edit')" size="small" @click="openName(row)">改名</el-button>
</template>
</el-table-column>
</el-table>
<el-dialog v-model="dlg.show" :title="`工位${dlg.stationNo} - 修改名称`" width="420px">
<el-form :model="dlg" label-width="90px">
<el-form-item label="工位名称" required>
<el-input v-model="dlg.name" placeholder="如 一号装配工位" />
</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'
import { ElMessage } 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 }))
})
const dlg = reactive({ show: false, id: 0, stationNo: 1, name: '' })
async function load() {
stations.value = (await request.get('/stations')) || []
}
function openName(row) {
Object.assign(dlg, { show: true, id: row.id, stationNo: row.stationNo, name: row.name })
}
async function save() {
if (!dlg.name) return ElMessage.warning('请输入工位名称')
await request.post('/stations', {
id: dlg.id, stationNo: dlg.stationNo, name: dlg.name
})
ElMessage.success('已保存')
dlg.show = false
load()
}
async function bindFlow(row, fid) {
try {
await request.post('/stations', { id: row.id, stationNo: row.stationNo, name: row.name, flowId: fid })
ElMessage.success(fid ? '已绑定工艺流程' : '已解除绑定')
} catch {
// 拦截器已提示(如绑定到未启用的流程)
} finally {
await load()
}
}
onMounted(async () => {
await load()
flows.value = (await request.get('/process-flows', { params: { pageSize: 1000, page: 1 } }))?.list || []
})
</script>