完善设备信息功能迁移
Some checks failed
Release pipeline / publish (push) Has been cancelled
Release pipeline / Always run job (push) Has been cancelled

This commit is contained in:
sheng
2026-06-25 01:11:39 +08:00
parent f07f5d91c4
commit c19ec0f115
6 changed files with 479 additions and 192 deletions

View File

@@ -4,7 +4,7 @@ const BASE = 'production_configuration/device_model/device_category/'
function apiParams (method, data = {}) {
return {
method: `equipment_management_equipment_model_equipment_category_${method}`,
method: `production_configuration_device_model_device_category_${method}`,
platform: 'background',
...data
}

View File

@@ -28,6 +28,23 @@ export function batchDeleteItems (data) {
return request({ url: BASE + 'batch_delete', method: 'delete', data: params('production_configuration_device_model_device_management_batch_delete', data) })
}
export function getImportTemplate (data) {
return request({
url: BASE + 'get_import_template',
method: 'post',
responseType: 'blob',
data: params('production_configuration_device_model_device_management_get_import_template', data)
})
}
export function importData (data) {
return request({
url: BASE + 'device_data_import',
method: 'post',
data: params('production_configuration_device_model_device_management_device_data_import', data)
})
}
export function createExportTask (data) {
return request({ url: BASE + 'device_data_export_task', method: 'post', data: params('production_configuration_device_model_device_management_device_export_task', data) })
}

View File

@@ -10,6 +10,14 @@ function apiParams (method, data = {}) {
}
}
export function getProductionLineALL (data) {
return request({
url: BASE + 'all',
method: 'get',
params: apiParams('all', data)
})
}
export function getProductionLineList (data) {
return request({
url: BASE + 'list',

View File

@@ -862,16 +862,21 @@
"add": "Add",
"edit": "Edit",
"delete": "Delete",
"batch_delete": "Batch Delete",
"import": "Import",
"export": "Export",
"operation": "Operation",
"add_title": "Add",
"edit_title": "Edit",
"add_title": "Add Equipment",
"edit_title": "Edit Equipment",
"confirm": "Confirm",
"cancel": "Cancel",
"tip": "Prompt",
"confirm_delete": "Delete this record?",
"confirm_batch_delete": "Batch delete selected equipment?",
"confirm_export": "Create export task?",
"operation_success": "Operation succeeded",
"create_download_task_success": "Download task created",
"please_select_data": "Please select data",
"keyword": "Keyword",
"enter_keyword": "Enter keyword",
"remark": "Remark",
@@ -883,14 +888,41 @@
"enter_device_code": "Enter device code",
"device_name": "Device Name",
"enter_device_name": "Enter device name",
"device_category": "Device Category",
"select_device_category": "Please select device category",
"design_ppm": "Design PPM",
"enter_design_ppm": "Please enter design PPM",
"ip": "IP",
"enter_ip": "Please enter IP",
"manufacturer": "Manufacturer",
"enter_manufacturer": "Please enter manufacturer",
"fixed_asset_code": "Fixed Asset Code",
"enter_fixed_asset_code": "Please enter fixed asset code",
"entry_time": "Entry Time",
"select_entry_time": "Please select entry time",
"device_id": "Device ID",
"enter_device_id": "Enter device ID",
"device_type": "Device Type",
"enter_device_type": "Enter device type",
"area": "Area",
"enter_area": "Enter area",
"select_area": "Please select area",
"line": "Line",
"enter_line": "Enter line",
"production_line": "Production Line",
"select_production_line": "Please select production line",
"select_factory_first": "Please select area first",
"length_1_100": "Length must be 1 to 100 characters",
"device_data_import": "Equipment Import",
"import_warning": "Only xlsx or xls files following the template can be uploaded",
"import_table": "Import Table",
"select_file": "Select File",
"download_template": "Download Template",
"preview": "Preview",
"import_template_name": "Equipment Import Template",
"import_file_format_error": "Please upload xls or xlsx file",
"import_missing_column": "Column [{name}] does not exist in the file. Please check.",
"import_no_data": "Please import data first",
"standard": "Standard",
"enter_standard": "Enter standard",
"inspection_item_code": "Inspection Item Code",

View File

@@ -862,16 +862,21 @@
"add": "新增",
"edit": "编辑",
"delete": "删除",
"batch_delete": "批量删除",
"import": "导入",
"export": "导出",
"operation": "操作",
"add_title": "新增",
"edit_title": "编辑",
"add_title": "新增设备信息",
"edit_title": "编辑设备信息",
"confirm": "确定",
"cancel": "取消",
"tip": "提示",
"confirm_delete": "确认删除该记录?",
"confirm_batch_delete": "确认批量删除选中的设备信息?",
"confirm_export": "确认创建导出任务?",
"operation_success": "操作成功",
"create_download_task_success": "创建下载任务成功",
"please_select_data": "请选择数据",
"keyword": "关键字",
"enter_keyword": "请输入关键字",
"remark": "备注",
@@ -883,14 +888,41 @@
"enter_device_code": "请输入设备编码",
"device_name": "设备名称",
"enter_device_name": "请输入设备名称",
"device_category": "设备类别",
"select_device_category": "请选择设备类别",
"design_ppm": "设计PPM",
"enter_design_ppm": "请输入设计PPM",
"ip": "IP",
"enter_ip": "请输入IP",
"manufacturer": "厂商",
"enter_manufacturer": "请输入厂商",
"fixed_asset_code": "设备固定资产编码",
"enter_fixed_asset_code": "请输入设备固定资产编码",
"entry_time": "进场时间",
"select_entry_time": "请选择进场时间",
"device_id": "设备ID",
"enter_device_id": "请输入设备ID",
"device_type": "设备类别",
"enter_device_type": "请输入设备类别",
"area": "所属区域",
"enter_area": "请输入所属区域",
"select_area": "请选择所区",
"line": "所属产线",
"enter_line": "请输入所属产线",
"production_line": "产线",
"select_production_line": "请选择产线",
"select_factory_first": "请先选择所区",
"length_1_100": "长度在 1 到 100 个字符",
"device_data_import": "设备信息导入",
"import_warning": "上传的文件后缀必须是 xlsx 或 xls且根据模板上传否则不能上传成功",
"import_table": "导入表格",
"select_file": "选择文件",
"download_template": "下载模板",
"preview": "预览",
"import_template_name": "设备数据导入模板",
"import_file_format_error": "请上传 xls 或 xlsx 文件",
"import_missing_column": "文件不存在【{name}】数据列,请检查",
"import_no_data": "请先导入数据",
"standard": "标准",
"enter_standard": "请输入标准",
"inspection_item_code": "点检项目编码",

View File

@@ -4,22 +4,25 @@
<div class="search-bar">
<el-form :inline="true" size="mini">
<el-form-item :label="$t(key('device_code'))">
<el-input
v-model="search.device_code"
:placeholder="$t(key('enter_device_code'))"
clearable
style="width:200px"
@keyup.enter.native="onSearch"
/>
<el-input v-model="search.code" :placeholder="$t(key('enter_device_code'))" clearable style="width:180px" @keyup.enter.native="onSearch" />
</el-form-item>
<el-form-item :label="$t(key('device_name'))">
<el-input
v-model="search.device_name"
:placeholder="$t(key('enter_device_name'))"
clearable
style="width:200px"
@keyup.enter.native="onSearch"
/>
<el-input v-model="search.name" :placeholder="$t(key('enter_device_name'))" clearable style="width:180px" @keyup.enter.native="onSearch" />
</el-form-item>
<el-form-item :label="$t(key('device_category'))">
<el-select v-model="search.device_category_id" :placeholder="$t(key('select_device_category'))" clearable filterable style="width:180px" @focus="loadDeviceCategories">
<el-option v-for="item in deviceCategoryOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item :label="$t(key('area'))">
<el-select v-model="search.area_id" :placeholder="$t(key('select_area'))" clearable filterable style="width:180px" @focus="loadAreas" @change="onSearchAreaChange">
<el-option v-for="item in areaOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item :label="$t(key('production_line'))">
<el-select v-model="search.line_id" :placeholder="$t(key('select_production_line'))" clearable filterable style="width:180px" @focus="loadSearchLines">
<el-option v-for="item in searchLineOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="onSearch">{{ $t(key('search')) }}</el-button>
@@ -42,21 +45,131 @@
@selection-change="onSelect"
/>
<page-dialog-form
ref="dialogForm"
<el-dialog
:title="$t(dialogTitle)"
:visible.sync="dialogVisible"
:title="dialogTitle"
width="40%"
:form-cols="formCols"
:form-data="formData"
:rules="rules"
label-width="130px"
:submitting="submitting"
:confirm-text="key('confirm')"
:cancel-text="key('cancel')"
@submit="onDialogSubmit"
width="60%"
:close-on-click-modal="false"
destroy-on-close
@close="onDialogClose"
/>
>
<el-form ref="form" :model="formData" :rules="rules" label-width="130px" size="mini">
<el-row :gutter="16">
<el-col :span="12">
<el-form-item :label="$t(key('device_code'))" prop="code">
<el-input v-model="formData.code" :placeholder="$t(key('enter_device_code'))" clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t(key('ip'))" prop="ip">
<el-input v-model="formData.ip" :placeholder="$t(key('enter_ip'))" clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t(key('device_name'))" prop="name">
<el-input v-model="formData.name" :placeholder="$t(key('enter_device_name'))" clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t(key('manufacturer'))" prop="manufacturer">
<el-input v-model="formData.manufacturer" :placeholder="$t(key('enter_manufacturer'))" clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t(key('device_category'))" prop="device_category_id">
<el-select v-model="formData.device_category_id" :placeholder="$t(key('select_device_category'))" clearable filterable style="width:100%" @focus="loadDeviceCategories">
<el-option v-for="item in deviceCategoryOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t(key('fixed_asset_code'))" prop="fixed_asset_code">
<el-input v-model="formData.fixed_asset_code" :placeholder="$t(key('enter_fixed_asset_code'))" clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t(key('design_ppm'))" prop="design_ppm">
<el-input v-model="formData.design_ppm" :placeholder="$t(key('enter_design_ppm'))" clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t(key('entry_time'))" prop="entry_time">
<el-date-picker v-model="formData.entry_time" type="date" value-format="yyyy-MM-dd" :placeholder="$t(key('select_entry_time'))" clearable style="width:100%" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t(key('area'))" prop="area_id">
<el-select v-model="formData.area_id" :placeholder="$t(key('select_area'))" clearable filterable style="width:100%" @focus="loadAreas" @change="onFormAreaChange">
<el-option v-for="item in areaOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t(key('production_line'))" prop="line_id">
<el-select v-model="formData.line_id" :placeholder="$t(key('select_production_line'))" clearable filterable style="width:100%" @focus="loadFormLines">
<el-option v-for="item in formLineOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item :label="$t(key('remark'))" prop="remark">
<el-input v-model="formData.remark" type="textarea" :autosize="{ minRows: 2, maxRows: 6 }" :placeholder="$t(key('enter_remark'))" clearable />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer">
<el-button @click="dialogVisible = false">{{ $t(key('cancel')) }}</el-button>
<el-button type="primary" :loading="submitting" @click="onDialogSubmit">{{ $t(key('confirm')) }}</el-button>
</div>
</el-dialog>
<el-dialog
:title="$t(key('device_data_import'))"
:visible.sync="importVisible"
width="70%"
append-to-body
:close-on-click-modal="false"
@close="resetImport"
>
<el-alert :title="$t(key('import_warning'))" :closable="false" type="warning" show-icon />
<el-form label-width="130px" class="import-form">
<el-form-item :label="$t(key('import_table'))">
<el-upload
action=""
:multiple="false"
:auto-upload="false"
:show-file-list="true"
:file-list="importFileList"
accept=".xls,.xlsx"
:on-change="onImportFileChange"
>
<el-button slot="trigger" size="mini" type="success">{{ $t(key('select_file')) }}</el-button>
<el-button style="margin-left:10px" size="mini" type="primary" :loading="importTemplateLoading" @click.stop="downloadTemplate">
{{ $t(key('download_template')) }}
</el-button>
</el-upload>
</el-form-item>
<el-form-item :label="$t(key('preview'))">
<el-table v-loading="importTableLoading" :data="importRows" border height="360">
<el-table-column prop="code" :label="$t(key('device_code'))" min-width="120" />
<el-table-column prop="name" :label="$t(key('device_name'))" min-width="120" />
<el-table-column prop="device_category_name" :label="$t(key('device_category'))" min-width="120" />
<el-table-column prop="line_name" :label="$t(key('production_line'))" min-width="120" />
<el-table-column prop="ip" :label="$t(key('ip'))" min-width="120" />
<el-table-column prop="design_ppm" :label="$t(key('design_ppm'))" min-width="100" />
<el-table-column prop="manufacturer" :label="$t(key('manufacturer'))" min-width="120" />
<el-table-column prop="fixed_asset_code" :label="$t(key('fixed_asset_code'))" min-width="140" />
<el-table-column prop="entry_time" :label="$t(key('entry_time'))" min-width="120" />
<el-table-column prop="remark" :label="$t(key('remark'))" min-width="160" show-overflow-tooltip />
</el-table>
</el-form-item>
</el-form>
<div slot="footer">
<el-button @click="importVisible = false">{{ $t(key('cancel')) }}</el-button>
<el-button type="primary" :loading="importSubmitting" @click="submitImport">{{ $t(key('confirm')) }}</el-button>
</div>
</el-dialog>
</d2-container>
</template>
@@ -66,12 +179,24 @@ import { useTableButtons } from '@/composables/useTableButtons'
import { i18nMixin } from '@/composables/useI18n'
import { confirmMixin } from '@/composables/useConfirmHandle'
import PageTable from '@/components/page-table'
import PageDialogForm from '@/components/page-dialog-form'
import { getList, createItem, editItem, deleteItem, createExportTask } from '@/api/equipment-management/equipment-registry'
import {
getList,
createItem,
editItem,
deleteItem,
batchDeleteItems,
getImportTemplate,
importData,
createExportTask
} from '@/api/equipment-management/equipment-registry'
import { getEquipmentCategoryALL } from '@/api/equipment-management/equipment-category'
import { getFactoryAreaALL } from '@/api/production-master-data/factory-area'
import { getProductionLineALL } from '@/api/production-master-data/production-line'
import { downloadRename, readExcel } from '@/utils/file'
export default {
name: 'equipment-management-equipment-registry',
components: { PageTable, PageDialogForm },
components: { PageTable },
mixins: [i18nMixin('page.equipment_management.equipment_model.equipment_registry'), confirmMixin],
data () {
return {
@@ -83,122 +208,66 @@ export default {
dialogTitle: '',
editId: '',
handleType: 'create',
search: {
device_code: '',
device_name: ''
},
search: { code: '', name: '', device_category_id: '', area_id: '', line_id: '' },
pagination: { current: 1, size: 10, total: 0 },
formData: {
device_code: '',
device_name: '',
device_type_id: '',
device_status: '',
area_id: '',
line_id: '',
remark: ''
},
formData: this.emptyForm(),
deviceCategoryOptions: [],
areaOptions: [],
searchLineOptions: [],
formLineOptions: [],
importVisible: false,
importFileList: [],
importRows: [],
importTableLoading: false,
importTemplateLoading: false,
importSubmitting: false,
rules: {
device_code: [{ required: true, message: this.key('enter_device_code'), trigger: 'blur' }],
device_name: [{ required: true, message: this.key('enter_device_name'), trigger: 'blur' }]
code: [
{ required: true, message: this.key('enter_device_code'), trigger: 'blur' },
{ min: 1, max: 100, message: this.key('length_1_100'), trigger: 'blur' }
],
name: [
{ required: true, message: this.key('enter_device_name'), trigger: 'blur' },
{ min: 1, max: 100, message: this.key('length_1_100'), trigger: 'blur' }
],
device_category_id: [{ required: true, message: this.key('select_device_category'), trigger: 'change' }],
area_id: [{ required: true, message: this.key('select_area'), trigger: 'change' }],
line_id: [{ required: true, message: this.key('select_production_line'), trigger: 'change' }],
design_ppm: [{ required: true, message: this.key('enter_design_ppm'), trigger: 'blur' }]
},
columns: [],
toolbarButtons: [],
rowButtons: [],
formCols: [
[
{
type: 'input',
prop: 'device_code',
label: this.key('device_code'),
placeholder: this.key('enter_device_code'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'input',
prop: 'device_name',
label: this.key('device_name'),
placeholder: this.key('enter_device_name'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'input',
prop: 'device_type_id',
label: this.key('device_type'),
placeholder: this.key('enter_device_type'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'input',
prop: 'device_status',
label: this.key('status'),
placeholder: this.key('enter_status'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'input',
prop: 'area_id',
label: this.key('area'),
placeholder: this.key('enter_area'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'input',
prop: 'line_id',
label: this.key('line'),
placeholder: this.key('enter_line'),
clearable: true,
style: { width: '90%' }
}
],
[
{
type: 'input',
prop: 'remark',
label: this.key('remark'),
placeholder: this.key('enter_remark'),
inputType: 'textarea',
autosize: { minRows: 2, maxRows: 6 },
clearable: true,
style: { width: '90%' }
}
]
]
rowButtons: []
}
},
created () {
this.columns = useTableColumns([
{ prop: 'device_code', label: this.key('device_code'), minWidth: 140 },
{ prop: 'device_name', label: this.key('device_name'), minWidth: 140 },
{ prop: 'device_type_name', label: this.key('device_type'), minWidth: 140 },
{ prop: 'device_status', label: this.key('status'), minWidth: 140 },
{ prop: 'area_name', label: this.key('area'), minWidth: 140 },
{ prop: 'line_name', label: this.key('line'), minWidth: 140 },
{ prop: 'remark', label: this.key('remark'), minWidth: 140 },
{ type: 'selection', width: 55 },
{ prop: 'sort', label: this.key('sort'), width: 80 },
{ prop: 'code', label: this.key('device_code'), minWidth: 130 },
{ prop: 'name', label: this.key('device_name'), minWidth: 130 },
{ prop: 'device_category_name', label: this.key('device_category'), minWidth: 130 },
{ prop: 'design_ppm', label: this.key('design_ppm'), minWidth: 110 },
{ prop: 'area_name', label: this.key('area'), minWidth: 120 },
{ prop: 'line_name', label: this.key('production_line'), minWidth: 120 },
{ prop: 'ip', label: this.key('ip'), minWidth: 120 },
{ prop: 'manufacturer', label: this.key('manufacturer'), minWidth: 130 },
{ prop: 'fixed_asset_code', label: this.key('fixed_asset_code'), minWidth: 150 },
{ prop: 'entry_time', label: this.key('entry_time'), minWidth: 120 },
{ prop: 'remark', label: this.key('remark'), minWidth: 160 },
{ prop: 'create_time', label: this.key('create_time'), minWidth: 160 },
{ prop: '_actions', label: this.key('operation'), width: 170, fixed: 'right' }
])
const btns = useTableButtons({
toolbar: [
{ key: 'add', label: this.key('add'), icon: 'el-icon-plus', type: 'primary', auth: '/device_management/device_model/device_management/create', onClick: this.openAdd },
{ key: 'export', label: this.key('export'), icon: 'el-icon-download', auth: '/device_management/device_model/device_management/export', onClick: this.handleExport }
{ key: 'add', label: this.key('add'), icon: 'el-icon-plus', type: 'primary', auth: '/production_configuration/device_model/device_management/create', onClick: this.openAdd },
{ key: 'batchDelete', label: this.key('batch_delete'), icon: 'el-icon-delete', type: 'danger', auth: '/production_configuration/device_model/device_management/batch-delete', needSelection: true, onClick: this.handleBatchDelete },
{ key: 'import', label: this.key('import'), icon: 'el-icon-upload2', type: 'success', auth: '/production_configuration/device_model/device_management/import', onClick: this.openImport },
{ key: 'export', label: this.key('export'), icon: 'el-icon-download', auth: '/production_configuration/device_model/device_management/export', onClick: this.handleExport }
],
row: [
{ key: 'edit', label: this.key('edit'), icon: 'el-icon-edit', auth: '/device_management/device_model/device_management/edit', onClick: this.openEdit },
{ key: 'delete', label: this.key('delete'), icon: 'el-icon-delete', color: 'danger', auth: '/device_management/device_model/device_management/delete', onClick: this.handleDelete }
{ key: 'edit', label: this.key('edit'), icon: 'el-icon-edit', auth: '/production_configuration/device_model/device_management/edit', onClick: this.openEdit },
{ key: 'delete', label: this.key('delete'), icon: 'el-icon-delete', color: 'danger', auth: '/production_configuration/device_model/device_management/delete', onClick: this.handleDelete }
]
}, this.$permission)
this.toolbarButtons = btns.toolbarButtons
@@ -206,11 +275,34 @@ export default {
this.fetchData()
},
methods: {
emptyForm () {
return {
code: '',
name: '',
ip: '',
manufacturer: '',
device_category_id: '',
fixed_asset_code: '',
design_ppm: '',
area_id: '',
line_id: '',
entry_time: '',
remark: ''
}
},
normalizeResponse (res) {
const data = res && res.data !== undefined ? res.data : res
if (Array.isArray(data)) return { list: data, total: data.length }
if (data && Array.isArray(data.data)) return { list: data.data, total: Number(data.count || data.total || data.data.length) }
if (data && data.data && Array.isArray(data.data.data)) return { list: data.data.data, total: Number(data.data.count || data.data.total || data.data.data.length) }
const getTotal = (source, fallback) => {
if (!source) return fallback
const total = source.count ?? source.total ?? source.total_count ?? source.record_count
const value = Number(total)
return Number.isNaN(value) ? fallback : value
}
const containers = [res, res && res.data, res && res.data && res.data.data].filter(Boolean)
for (const item of containers) {
if (Array.isArray(item)) return { list: item, total: getTotal(res, item.length) }
const list = item.data || item.list || item.rows || item.records || item.items
if (Array.isArray(list)) return { list, total: getTotal(item, getTotal(res, list.length)) }
}
return { list: [], total: 0 }
},
async fetchData () {
@@ -229,12 +321,9 @@ export default {
this.fetchData()
},
onReset () {
this.search = {
device_code: '',
device_name: ''
}
this.pagination.current = 1
this.fetchData()
this.search = { code: '', name: '', device_category_id: '', area_id: '', line_id: '' }
this.searchLineOptions = []
this.onSearch()
},
onPageChange (page) {
this.pagination.current = page.current
@@ -244,80 +333,189 @@ export default {
onSelect (rows) {
this.selectedRows = rows
},
resetForm () {
this.formData = {
device_code: '',
device_name: '',
device_type_id: '',
device_status: '',
area_id: '',
line_id: '',
remark: ''
async loadDeviceCategories () {
if (this.deviceCategoryOptions.length) return
const res = await getEquipmentCategoryALL()
this.deviceCategoryOptions = this.normalizeResponse(res).list.map(item => ({ label: item.name, value: item.id, code: item.code }))
},
async loadAreas () {
if (this.areaOptions.length) return
const res = await getFactoryAreaALL()
this.areaOptions = this.normalizeResponse(res).list.map(item => ({ label: item.name, value: item.area_id || item.id }))
},
async loadLines (areaId) {
if (!areaId) {
this.$message.warning(this.$t(this.key('select_factory_first')))
return []
}
const res = await getProductionLineALL({ area_id: areaId })
return this.normalizeResponse(res).list.map(item => ({ label: item.name, value: item.id }))
},
async loadSearchLines () {
this.searchLineOptions = await this.loadLines(this.search.area_id)
},
async loadFormLines () {
this.formLineOptions = await this.loadLines(this.formData.area_id)
},
onSearchAreaChange () {
this.search.line_id = ''
this.searchLineOptions = []
},
onFormAreaChange () {
this.formData.line_id = ''
this.formLineOptions = []
},
resetForm () {
this.formData = this.emptyForm()
this.editId = ''
this.formLineOptions = []
this.$nextTick(() => this.$refs.form && this.$refs.form.clearValidate())
},
openAdd () {
this.handleType = 'create'
this.dialogTitle = this.key('add_title')
this.$nextTick(() => {
this.$refs.dialogForm && this.$refs.dialogForm.reset()
this.resetForm()
this.dialogVisible = true
})
this.resetForm()
this.loadDeviceCategories()
this.loadAreas()
this.dialogVisible = true
},
openEdit (row) {
async openEdit (row) {
this.handleType = 'edit'
this.dialogTitle = this.key('edit_title')
this.editId = row.id
this.formData = {
device_code: row.device_code || '',
device_name: row.device_name || '',
device_type_id: row.device_type_id || '',
device_status: row.device_status || '',
area_id: row.area_id || '',
line_id: row.line_id || '',
remark: row.remark || ''
}
this.formData = { ...this.emptyForm(), ...row }
await Promise.all([this.loadDeviceCategories(), this.loadAreas()])
if (this.formData.area_id) this.formLineOptions = await this.loadLines(this.formData.area_id)
this.dialogVisible = true
},
async onDialogSubmit () {
this.submitting = true
try {
if (this.handleType === 'create') await createItem(this.formData)
else await editItem({ ...this.formData, id: this.editId })
this.$message.success(this.$t(this.key('operation_success')))
this.dialogVisible = false
this.fetchData()
} finally {
this.submitting = false
}
onDialogSubmit () {
this.$refs.form.validate(async valid => {
if (!valid) return
this.submitting = true
try {
if (this.handleType === 'create') await createItem(this.formData)
else await editItem({ ...this.formData, id: this.editId })
this.$message.success(this.$t(this.key('operation_success')))
this.dialogVisible = false
this.fetchData()
} finally {
this.submitting = false
}
})
},
onDialogClose () {
this.resetForm()
},
async handleDelete (row) {
const cancelled = await this.$confirmAction(
{ message: this.key('confirm_delete'), title: this.key('tip') },
() => deleteItem({ id: [row.id] })
)
const cancelled = await this.$confirmAction({ message: this.key('confirm_delete'), title: this.key('tip') }, () => deleteItem({ id: [row.id] }))
if (cancelled) return
this.$message.success(this.$t(this.key('operation_success')))
this.pagination.current = Math.min(this.pagination.current, Math.ceil((this.pagination.total - 1) / this.pagination.size) || 1)
this.fetchData()
},
async handleExport () {
const cancelled = await this.$confirmAction(
{ message: this.key('confirm_export'), title: this.key('tip') },
() => createExportTask({ ...this.search })
)
async handleBatchDelete () {
if (!this.selectedRows.length) {
this.$message.error(this.$t(this.key('please_select_data')))
return
}
const ids = this.selectedRows.map(item => item.id)
const cancelled = await this.$confirmAction({ message: this.key('confirm_batch_delete'), title: this.key('tip') }, () => batchDeleteItems({ id: ids }))
if (cancelled) return
this.$message.success(this.$t(this.key('operation_success')))
this.fetchData()
},
openImport () {
this.resetImport()
this.importVisible = true
},
resetImport () {
this.importFileList = []
this.importRows = []
},
async downloadTemplate () {
this.importTemplateLoading = true
try {
const res = await getImportTemplate({})
downloadRename(res, 'xlsx', this.$t(this.key('import_template_name')))
} finally {
this.importTemplateLoading = false
}
},
getImportValue (row, names) {
for (const name of names) {
if (row[name] !== undefined && row[name] !== null) return row[name]
}
return ''
},
async onImportFileChange (file) {
if (!file || !/\.(xls|xlsx)$/i.test(file.name)) {
this.$message.error(this.$t(this.key('import_file_format_error')))
this.importFileList = []
return
}
this.importFileList = [file]
this.importTableLoading = true
try {
const rows = await readExcel(file.raw)
const required = ['设备编码', '设备名称', 'IP', '设备类别', '产线', '设计PPM', '厂商', '设备固定资产编码', '进场时间', '备注']
const first = rows[0] || {}
const missing = required.find(name => !Object.prototype.hasOwnProperty.call(first, name))
if (missing) {
this.$message.error(this.$t(this.key('import_missing_column'), { name: missing }))
this.importRows = []
return
}
this.importRows = rows.map(row => ({
code: this.getImportValue(row, ['设备编码']),
name: this.getImportValue(row, ['设备名称']),
ip: this.getImportValue(row, ['IP']),
device_category_name: this.getImportValue(row, ['设备类别']),
line_name: this.getImportValue(row, ['产线']),
design_ppm: this.getImportValue(row, ['设计PPM']),
manufacturer: this.getImportValue(row, ['厂商']),
fixed_asset_code: this.getImportValue(row, ['设备固定资产编码']),
entry_time: this.getImportValue(row, ['进场时间']),
remark: this.getImportValue(row, ['备注'])
}))
} finally {
this.importTableLoading = false
}
},
async submitImport () {
if (!this.importRows.length) {
this.$message.error(this.$t(this.key('import_no_data')))
return
}
this.importSubmitting = true
try {
await importData({ import_data: JSON.stringify(this.importRows) })
this.$message.success(this.$t(this.key('operation_success')))
this.importVisible = false
this.fetchData()
} finally {
this.importSubmitting = false
}
},
async handleExport () {
const cancelled = await this.$confirmAction({ message: this.key('confirm_export'), title: this.key('tip') }, () => createExportTask({ ...this.search, action: 'download' }))
if (cancelled) return
this.$message.success(this.$t(this.key('create_download_task_success')))
if (this.$router && this.$router.push) {
this.$router.push({ name: 'task' }).catch(() => {})
}
}
}
}
</script>
<style scoped>
.search-bar { padding: 10px 0; }
/deep/ .el-form-item--mini.el-form-item { margin-bottom: 4px; }
.search-bar {
padding: 10px 0;
}
.import-form {
margin-top: 16px;
}
/deep/ .el-form-item--mini.el-form-item {
margin-bottom: 4px;
}
</style>