Connect task CAD, PDF and PLY to the supplier workspace and preserve paired result provenance. Add fixture framework download/copy, reduce idle map and task polling, improve tab navigation, and update standalone schema migration.
528 lines
18 KiB
Vue
528 lines
18 KiB
Vue
<template>
|
||
<main class="inspect-page">
|
||
<header class="inspect-header"
|
||
><div class="inspect-kicker">检测计划模板</div
|
||
><div class="inspect-title-line"
|
||
><div
|
||
><h1>检测计划模板</h1
|
||
><p>维护模板名称、检测项与公差,统一新建检测和计划调整的检测依据。</p></div
|
||
><el-button @click="$router.back()">返回任务</el-button><el-button type="primary" v-hasPermi="['lab:result:confirm']" @click="edit()"
|
||
><Icon icon="ep:plus" class="mr-6px" />新建模板</el-button
|
||
></div
|
||
></header
|
||
>
|
||
<el-alert v-if="error" :title="error" type="error" show-icon @close="error = ''" />
|
||
<section class="inspect-panel inspect-search"
|
||
><el-input
|
||
v-model="query.name"
|
||
placeholder="搜索模板名称"
|
||
clearable
|
||
style="width: 280px"
|
||
@keyup.enter="search"
|
||
><template #prefix><Icon icon="ep:search" /></template></el-input
|
||
><el-select v-model="query.enabled" clearable placeholder="全部状态" style="width: 150px"
|
||
><el-option label="已启用" value="true" /><el-option
|
||
label="已停用"
|
||
value="false" /></el-select
|
||
><el-button type="primary" plain @click="search">查询</el-button
|
||
><el-button @click="reset">重置</el-button
|
||
><span class="inspect-sub ml-auto">共 {{ total }} 个模板</span></section
|
||
>
|
||
<section class="inspect-panel"
|
||
><el-table :data="list" v-loading="loading"
|
||
><el-table-column label="模板名称" min-width="270"
|
||
><template #default="s"
|
||
><div class="inspect-table-title"
|
||
><span class="inspect-table-icon"><Icon icon="ep:document-copy" :size="20" /></span
|
||
><div
|
||
><strong>{{ s.row.name }}</strong
|
||
><div class="inspect-sub">{{ s.row.description || '—' }}</div></div
|
||
></div
|
||
></template
|
||
></el-table-column
|
||
><el-table-column
|
||
prop="partNumbers"
|
||
label="自动匹配零件号"
|
||
min-width="200"
|
||
show-overflow-tooltip
|
||
/><el-table-column prop="rowCount" label="检测项" width="90" /><el-table-column
|
||
label="版本"
|
||
width="85"
|
||
><template #default="s">V{{ s.row.revision }}</template></el-table-column
|
||
><el-table-column label="状态" width="100"
|
||
><template #default="s"
|
||
><el-tag :type="s.row.enabled ? 'success' : 'info'">{{
|
||
s.row.enabled ? '已启用' : '已停用'
|
||
}}</el-tag></template
|
||
></el-table-column
|
||
><el-table-column label="更新时间" width="175"
|
||
><template #default="s">{{ dateText(s.row.updateTime) }}</template></el-table-column
|
||
><el-table-column label="操作" fixed="right" width="240"
|
||
><template #default="s"
|
||
><el-button link type="primary" @click="edit(s.row)">{{
|
||
writable ? '编辑字段' : '查看'
|
||
}}</el-button
|
||
><el-button link v-hasPermi="['lab:result:confirm']" @click="edit(s.row, true)"
|
||
>复制</el-button
|
||
><el-button link @click="exportTemplate(s.row)">导出</el-button
|
||
><el-button
|
||
link
|
||
type="danger"
|
||
v-hasPermi="['lab:result:confirm']"
|
||
@click="remove(s.row)"
|
||
>删除</el-button
|
||
></template
|
||
></el-table-column
|
||
><template #empty
|
||
><el-empty description="暂无检测计划模板"
|
||
><el-button type="primary" v-hasPermi="['lab:result:confirm']" @click="edit()"
|
||
>新建模板</el-button
|
||
></el-empty
|
||
></template
|
||
></el-table
|
||
><Pagination
|
||
:total="total"
|
||
v-model:page="query.pageNo"
|
||
v-model:limit="query.pageSize"
|
||
@pagination="load"
|
||
/></section>
|
||
<el-drawer
|
||
v-model="drawer"
|
||
:title="model.id ? '维护检测计划模板' : '新建检测计划模板'"
|
||
size="min(96vw, 1320px)"
|
||
:before-close="close"
|
||
destroy-on-close
|
||
>
|
||
<div v-loading="editing"
|
||
><el-alert
|
||
v-if="editError"
|
||
:title="editError"
|
||
type="error"
|
||
show-icon
|
||
:closable="false"
|
||
/><el-alert
|
||
title="保存后会更新模板版本。已经建立的检测任务继续使用当时的计划;需要更新时可在任务中重新载入模板。"
|
||
type="info"
|
||
:closable="false"
|
||
/>
|
||
<el-form
|
||
ref="form"
|
||
:model="model"
|
||
label-position="top"
|
||
:disabled="saving || !writable"
|
||
class="template-form"
|
||
><el-row :gutter="20"
|
||
><el-col :span="14"
|
||
><el-form-item
|
||
label="模板名称"
|
||
prop="name"
|
||
:rules="[{ required: true, message: '请输入模板名称', trigger: 'blur' }]"
|
||
><el-input
|
||
v-model="model.name"
|
||
maxlength="100"
|
||
show-word-limit
|
||
placeholder="如:管类零件尺寸检测" /></el-form-item></el-col
|
||
><el-col :span="6"
|
||
><el-form-item label="状态"
|
||
><el-switch
|
||
v-model="model.enabled"
|
||
active-text="启用"
|
||
inactive-text="停用" /></el-form-item></el-col
|
||
><el-col :span="4"
|
||
><el-form-item label="当前版本"
|
||
><el-tag>{{
|
||
model.id ? 'V' + model.revision : '首次保存 V1'
|
||
}}</el-tag></el-form-item
|
||
></el-col
|
||
></el-row
|
||
><el-form-item label="自动匹配零件号"
|
||
><el-input
|
||
v-model="model.partNumbers"
|
||
maxlength="500"
|
||
placeholder="可填写多个完整零件号,以逗号分隔;留空时由操作员手动选择模板" /></el-form-item
|
||
><el-form-item label="模板说明"
|
||
><el-input
|
||
v-model="model.description"
|
||
maxlength="1000"
|
||
type="textarea"
|
||
:rows="2"
|
||
placeholder="适用零件、图纸版本或检测要求" /></el-form-item
|
||
></el-form>
|
||
<div class="template-items-heading"
|
||
><div
|
||
><h3
|
||
>检测项与字段内容 <el-tag size="small">{{ model.rows.length }} 项</el-tag></h3
|
||
><p>按行维护名称、几何类型、控制项、名义值、公差与备注。尺寸单位为 mm。</p></div
|
||
><div class="template-tools" v-if="writable"
|
||
><el-button @click="jsonInput?.click()" :disabled="saving">导入 JSON</el-button
|
||
><el-button
|
||
type="primary"
|
||
plain
|
||
@click="addRow"
|
||
:disabled="saving || model.rows.length >= 500"
|
||
><Icon icon="ep:plus" class="mr-4px" />添加检测项</el-button
|
||
><input ref="jsonInput" type="file" accept=".json" hidden @change="importJson" /></div
|
||
></div>
|
||
<el-table :data="model.rows" border max-height="500" class="template-fields"
|
||
><el-table-column type="index" label="序号" width="60" /><el-table-column
|
||
label="检测项名称"
|
||
min-width="180"
|
||
><template #default="s"
|
||
><el-input
|
||
v-model="s.row.name"
|
||
maxlength="120"
|
||
:disabled="!writable || saving"
|
||
placeholder="如:中心孔直径" /></template></el-table-column
|
||
><el-table-column label="几何类型" width="150"
|
||
><template #default="s"
|
||
><el-select
|
||
v-model="s.row.type"
|
||
:disabled="!writable || saving"
|
||
@change="changeType(s.row)"
|
||
><el-option
|
||
v-for="o in types"
|
||
:key="o.value"
|
||
:value="o.value"
|
||
:label="o.label" /></el-select></template></el-table-column
|
||
><el-table-column label="控制项" width="125"
|
||
><template #default="s"
|
||
><el-select
|
||
v-model="s.row.control"
|
||
filterable
|
||
allow-create
|
||
default-first-option
|
||
:disabled="!writable || saving"
|
||
><el-option
|
||
v-for="v in ['直径', '长度', '孔距', '面距', '点间距', '平面度', '圆柱度']"
|
||
:key="v"
|
||
:value="v"
|
||
:label="v" /></el-select></template></el-table-column
|
||
><el-table-column label="名义 / mm" width="155"
|
||
><template #default="s"
|
||
><el-input-number
|
||
v-model="s.row.nominal_mm"
|
||
:min="0"
|
||
:max="10000000"
|
||
:precision="4"
|
||
:controls="false"
|
||
:disabled="!writable || saving"
|
||
style="width: 100%" /></template></el-table-column
|
||
><el-table-column label="公差" width="135"
|
||
><template #default="s"
|
||
><el-input
|
||
v-model="s.row.tol_text"
|
||
:disabled="!writable || saving"
|
||
placeholder="±0.1 / +0.1/0" /></template></el-table-column
|
||
><el-table-column label="备注" min-width="180"
|
||
><template #default="s"
|
||
><el-input
|
||
v-model="s.row.notes"
|
||
:disabled="!writable || saving"
|
||
type="textarea"
|
||
:autosize="{ minRows: 1, maxRows: 3 }"
|
||
maxlength="1000"
|
||
placeholder="测量位置、图纸标注等" /></template></el-table-column
|
||
><el-table-column v-if="writable" label="操作" width="160" fixed="right"
|
||
><template #default="s"
|
||
><el-button link :disabled="saving || s.$index === 0" @click="moveRow(s.$index, -1)"
|
||
>上移</el-button
|
||
><el-button
|
||
link
|
||
:disabled="saving || s.$index === model.rows.length - 1"
|
||
@click="moveRow(s.$index, 1)"
|
||
>下移</el-button
|
||
><el-button
|
||
link
|
||
type="danger"
|
||
:disabled="saving"
|
||
@click="model.rows.splice(s.$index, 1)"
|
||
>移除</el-button
|
||
></template
|
||
></el-table-column
|
||
><template #empty><el-empty description="点击添加检测项,开始定义模板字段" /></template
|
||
></el-table>
|
||
<p class="inspect-sub mt-12px"
|
||
>公差可留空;支持
|
||
±0.1、+0.025/0、+1/-0.5。未设置公差的检测项保留测量值,显示“未设公差”。</p
|
||
></div
|
||
>
|
||
<template #footer
|
||
><div class="template-footer"
|
||
><span class="inspect-sub">{{ dirty ? '有修改待保存' : '模板内容已同步' }}</span
|
||
><el-button :disabled="saving" @click="close(() => (drawer = false))">关闭</el-button
|
||
><el-button
|
||
v-if="writable"
|
||
type="primary"
|
||
:loading="saving"
|
||
:disabled="editing"
|
||
@click="save"
|
||
>保存模板</el-button
|
||
></div
|
||
></template
|
||
>
|
||
</el-drawer>
|
||
</main>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import * as Api from '@/api/lab/inspection'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { dateText } from './display'
|
||
import { checkPermi } from '@/utils/permission'
|
||
import './inspection.scss'
|
||
defineOptions({ name: 'LabInspectionTemplates' })
|
||
const writable = computed(() => checkPermi(['lab:result:confirm'])),
|
||
list = ref<any[]>([]),
|
||
total = ref(0),
|
||
loading = ref(false),
|
||
error = ref(''),
|
||
drawer = ref(false),
|
||
editing = ref(false),
|
||
saving = ref(false),
|
||
editError = ref(''),
|
||
form = ref(),
|
||
jsonInput = ref<HTMLInputElement>(),
|
||
baseline = ref('')
|
||
const model = ref<any>({ name: '', description: '', partNumbers: '', enabled: true, rows: [] }),
|
||
dirty = computed(() => JSON.stringify(model.value) !== baseline.value),
|
||
query = reactive({ name: '', enabled: '', pageNo: 1, pageSize: 20 })
|
||
const types = [
|
||
{ value: 'circle', label: '圆 / 孔 / 管径' },
|
||
{ value: 'distance', label: '长度 / 距离' },
|
||
{ value: 'hole_distance', label: '孔心距' },
|
||
{ value: 'plane_distance', label: '平行面距' },
|
||
{ value: 'point_distance', label: '扫描点间距' },
|
||
{ value: 'plane', label: '平面' },
|
||
{ value: 'cylinder', label: '圆柱' }
|
||
]
|
||
let sequence = 0
|
||
async function load() {
|
||
const owner = ++sequence
|
||
loading.value = true
|
||
try {
|
||
const data = await Api.templatePage({ ...query })
|
||
if (owner === sequence) {
|
||
list.value = data.list
|
||
total.value = data.total
|
||
error.value = ''
|
||
}
|
||
} catch (e: any) {
|
||
if (owner === sequence) error.value = e?.message || '模板查询失败'
|
||
} finally {
|
||
if (owner === sequence) loading.value = false
|
||
}
|
||
}
|
||
function search() {
|
||
query.pageNo = 1
|
||
void load()
|
||
}
|
||
function reset() {
|
||
query.name = ''
|
||
query.enabled = ''
|
||
search()
|
||
}
|
||
async function edit(row?: any, copy = false) {
|
||
editing.value = true
|
||
editError.value = ''
|
||
try {
|
||
const data = row
|
||
? await Api.templateDetail(row.id)
|
||
: { name: '', description: '', partNumbers: '', enabled: true, rows: [] }
|
||
if (copy) {
|
||
delete data.id
|
||
delete data.revision
|
||
delete data.builtinKey
|
||
data.name = (data.name + ' · 副本').slice(0, 100)
|
||
data.partNumbers = ''
|
||
data.enabled = false
|
||
}
|
||
model.value = JSON.parse(JSON.stringify(data))
|
||
baseline.value = JSON.stringify(model.value)
|
||
drawer.value = true
|
||
} catch (e: any) {
|
||
error.value = e?.message || '读取模板失败'
|
||
} finally {
|
||
editing.value = false
|
||
}
|
||
}
|
||
function addRow() {
|
||
model.value.rows.push({
|
||
table: 'feature',
|
||
type: 'circle',
|
||
name: '检测项 ' + (model.value.rows.length + 1),
|
||
control: '直径',
|
||
nominal_mm: null,
|
||
tol_text: '',
|
||
notes: ''
|
||
})
|
||
}
|
||
function changeType(row: any) {
|
||
const feature = ['circle', 'plane', 'cylinder'].includes(row.type)
|
||
row.table = feature ? 'feature' : 'gauge'
|
||
row.control = {
|
||
circle: '直径',
|
||
plane: '平面度',
|
||
cylinder: '圆柱度',
|
||
distance: '长度',
|
||
hole_distance: '孔距',
|
||
plane_distance: '面距',
|
||
point_distance: '点间距'
|
||
}[row.type]
|
||
}
|
||
function moveRow(index: number, offset: number) {
|
||
const rows = model.value.rows
|
||
;[rows[index], rows[index + offset]] = [rows[index + offset], rows[index]]
|
||
}
|
||
async function close(done: () => void) {
|
||
if (saving.value) return
|
||
if (dirty.value) {
|
||
try {
|
||
await ElMessageBox.confirm('当前模板有未保存修改,是否放弃修改并关闭?', '关闭模板', {
|
||
confirmButtonText: '放弃修改',
|
||
cancelButtonText: '继续编辑'
|
||
})
|
||
} catch {
|
||
return
|
||
}
|
||
}
|
||
done()
|
||
}
|
||
async function save() {
|
||
if (saving.value) return
|
||
editError.value = ''
|
||
try {
|
||
await form.value.validate()
|
||
if (!model.value.rows.length) throw new Error('请至少添加一个检测项')
|
||
for (const [i, row] of model.value.rows.entries()) {
|
||
if (!row.name?.trim() || row.nominal_mm == null || !Number.isFinite(Number(row.nominal_mm)))
|
||
throw new Error(`第 ${i + 1} 项:请填写名称和有效名义值`)
|
||
}
|
||
saving.value = true
|
||
model.value = await Api.saveTemplate(model.value)
|
||
baseline.value = JSON.stringify(model.value)
|
||
ElMessage.success('模板已保存,版本 V' + model.value.revision)
|
||
await load()
|
||
} catch (e: any) {
|
||
editError.value = e?.message || '请检查模板名称与检测项字段'
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
async function remove(row: any) {
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`删除模板「${row.name}」?已有检测任务和报告继续保留。`,
|
||
'删除模板',
|
||
{ type: 'warning' }
|
||
)
|
||
await Api.removeTemplate(row.id, row.revision)
|
||
ElMessage.success('模板已删除')
|
||
await load()
|
||
} catch (e: any) {
|
||
if (e !== 'cancel' && e !== 'close') error.value = e?.message || '删除失败'
|
||
}
|
||
}
|
||
async function exportTemplate(row: any) {
|
||
try {
|
||
const data = await Api.templateDetail(row.id)
|
||
Api.saveBlob(
|
||
new Blob(
|
||
[
|
||
JSON.stringify(
|
||
{
|
||
schema_version: 1,
|
||
unit: 'mm',
|
||
name: data.name,
|
||
description: data.description,
|
||
partNumbers: data.partNumbers,
|
||
rows: data.rows
|
||
},
|
||
null,
|
||
2
|
||
)
|
||
],
|
||
{ type: 'application/json;charset=utf-8' }
|
||
),
|
||
data.name + '-V' + data.revision + '.json'
|
||
)
|
||
} catch (e: any) {
|
||
error.value = e?.message || '导出失败'
|
||
}
|
||
}
|
||
async function importJson(e: Event) {
|
||
const input = e.target as HTMLInputElement,
|
||
file = input.files?.[0]
|
||
if (!file) return
|
||
try {
|
||
if (file.size > 2 * 1024 * 1024) throw new Error('模板 JSON 不得超过 2 MB')
|
||
const data = JSON.parse(await file.text())
|
||
const rows = Array.isArray(data) ? data : data.rows
|
||
if (!Array.isArray(rows) || !rows.length || rows.length > 500)
|
||
throw new Error('JSON 需包含 1–500 个检测项 rows')
|
||
if (dirty.value) await ElMessageBox.confirm('导入会替换当前字段内容,是否继续?', '导入模板')
|
||
model.value.rows = rows
|
||
if (!model.value.name && data.name) model.value.name = data.name
|
||
editError.value = ''
|
||
} catch (e: any) {
|
||
if (e !== 'cancel' && e !== 'close') editError.value = e?.message || 'JSON 模板无效'
|
||
} finally {
|
||
input.value = ''
|
||
}
|
||
}
|
||
onMounted(load)
|
||
</script>
|
||
<style scoped>
|
||
.template-form {
|
||
margin-top: 22px;
|
||
}
|
||
.template-items-heading {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 16px;
|
||
margin: 12px 0 18px;
|
||
}
|
||
.template-items-heading h3 {
|
||
font-size: 15px;
|
||
margin: 0 0 8px;
|
||
}
|
||
.template-items-heading p {
|
||
margin: 0;
|
||
color: var(--el-text-color-secondary);
|
||
font-size: 12px;
|
||
}
|
||
.template-tools {
|
||
display: flex;
|
||
gap: 10px;
|
||
flex-wrap: wrap;
|
||
}
|
||
.template-tools .el-button + .el-button {
|
||
margin-left: 0;
|
||
}
|
||
.template-footer {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
.template-footer > span {
|
||
margin-right: auto;
|
||
}
|
||
.template-footer .el-button + .el-button {
|
||
margin-left: 0;
|
||
}
|
||
.template-fields :deep(.el-table__cell) {
|
||
padding: 10px 0;
|
||
}
|
||
.template-fields :deep(.el-button + .el-button) {
|
||
margin-left: 6px;
|
||
}
|
||
.inspect-table-title strong {
|
||
font-weight: 500;
|
||
}
|
||
@media (max-width: 800px) {
|
||
.template-items-heading {
|
||
align-items: flex-start;
|
||
flex-direction: column;
|
||
}
|
||
}
|
||
</style>
|