完善设备信息功能迁移
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 = {}) { function apiParams (method, data = {}) {
return { return {
method: `equipment_management_equipment_model_equipment_category_${method}`, method: `production_configuration_device_model_device_category_${method}`,
platform: 'background', platform: 'background',
...data ...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) }) 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) { 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) }) 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) { export function getProductionLineList (data) {
return request({ return request({
url: BASE + 'list', url: BASE + 'list',

View File

@@ -862,16 +862,21 @@
"add": "Add", "add": "Add",
"edit": "Edit", "edit": "Edit",
"delete": "Delete", "delete": "Delete",
"batch_delete": "Batch Delete",
"import": "Import",
"export": "Export", "export": "Export",
"operation": "Operation", "operation": "Operation",
"add_title": "Add", "add_title": "Add Equipment",
"edit_title": "Edit", "edit_title": "Edit Equipment",
"confirm": "Confirm", "confirm": "Confirm",
"cancel": "Cancel", "cancel": "Cancel",
"tip": "Prompt", "tip": "Prompt",
"confirm_delete": "Delete this record?", "confirm_delete": "Delete this record?",
"confirm_batch_delete": "Batch delete selected equipment?",
"confirm_export": "Create export task?", "confirm_export": "Create export task?",
"operation_success": "Operation succeeded", "operation_success": "Operation succeeded",
"create_download_task_success": "Download task created",
"please_select_data": "Please select data",
"keyword": "Keyword", "keyword": "Keyword",
"enter_keyword": "Enter keyword", "enter_keyword": "Enter keyword",
"remark": "Remark", "remark": "Remark",
@@ -883,14 +888,41 @@
"enter_device_code": "Enter device code", "enter_device_code": "Enter device code",
"device_name": "Device Name", "device_name": "Device Name",
"enter_device_name": "Enter 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", "device_id": "Device ID",
"enter_device_id": "Enter device ID", "enter_device_id": "Enter device ID",
"device_type": "Device Type", "device_type": "Device Type",
"enter_device_type": "Enter device type", "enter_device_type": "Enter device type",
"area": "Area", "area": "Area",
"enter_area": "Enter area", "enter_area": "Enter area",
"select_area": "Please select area",
"line": "Line", "line": "Line",
"enter_line": "Enter 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", "standard": "Standard",
"enter_standard": "Enter standard", "enter_standard": "Enter standard",
"inspection_item_code": "Inspection Item Code", "inspection_item_code": "Inspection Item Code",

View File

@@ -862,16 +862,21 @@
"add": "新增", "add": "新增",
"edit": "编辑", "edit": "编辑",
"delete": "删除", "delete": "删除",
"batch_delete": "批量删除",
"import": "导入",
"export": "导出", "export": "导出",
"operation": "操作", "operation": "操作",
"add_title": "新增", "add_title": "新增设备信息",
"edit_title": "编辑", "edit_title": "编辑设备信息",
"confirm": "确定", "confirm": "确定",
"cancel": "取消", "cancel": "取消",
"tip": "提示", "tip": "提示",
"confirm_delete": "确认删除该记录?", "confirm_delete": "确认删除该记录?",
"confirm_batch_delete": "确认批量删除选中的设备信息?",
"confirm_export": "确认创建导出任务?", "confirm_export": "确认创建导出任务?",
"operation_success": "操作成功", "operation_success": "操作成功",
"create_download_task_success": "创建下载任务成功",
"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": "设备类别",
"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", "device_id": "设备ID",
"enter_device_id": "请输入设备ID", "enter_device_id": "请输入设备ID",
"device_type": "设备类别", "device_type": "设备类别",
"enter_device_type": "请输入设备类别", "enter_device_type": "请输入设备类别",
"area": "所属区域", "area": "所属区域",
"enter_area": "请输入所属区域", "enter_area": "请输入所属区域",
"select_area": "请选择所区",
"line": "所属产线", "line": "所属产线",
"enter_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": "标准", "standard": "标准",
"enter_standard": "请输入标准", "enter_standard": "请输入标准",
"inspection_item_code": "点检项目编码", "inspection_item_code": "点检项目编码",

View File

@@ -4,22 +4,25 @@
<div class="search-bar"> <div class="search-bar">
<el-form :inline="true" size="mini"> <el-form :inline="true" size="mini">
<el-form-item :label="$t(key('device_code'))"> <el-form-item :label="$t(key('device_code'))">
<el-input <el-input v-model="search.code" :placeholder="$t(key('enter_device_code'))" clearable style="width:180px" @keyup.enter.native="onSearch" />
v-model="search.device_code"
:placeholder="$t(key('enter_device_code'))"
clearable
style="width:200px"
@keyup.enter.native="onSearch"
/>
</el-form-item> </el-form-item>
<el-form-item :label="$t(key('device_name'))"> <el-form-item :label="$t(key('device_name'))">
<el-input <el-input v-model="search.name" :placeholder="$t(key('enter_device_name'))" clearable style="width:180px" @keyup.enter.native="onSearch" />
v-model="search.device_name" </el-form-item>
:placeholder="$t(key('enter_device_name'))" <el-form-item :label="$t(key('device_category'))">
clearable <el-select v-model="search.device_category_id" :placeholder="$t(key('select_device_category'))" clearable filterable style="width:180px" @focus="loadDeviceCategories">
style="width:200px" <el-option v-for="item in deviceCategoryOptions" :key="item.value" :label="item.label" :value="item.value" />
@keyup.enter.native="onSearch" </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-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" @click="onSearch">{{ $t(key('search')) }}</el-button> <el-button type="primary" icon="el-icon-search" @click="onSearch">{{ $t(key('search')) }}</el-button>
@@ -42,21 +45,131 @@
@selection-change="onSelect" @selection-change="onSelect"
/> />
<page-dialog-form <el-dialog
ref="dialogForm" :title="$t(dialogTitle)"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
:title="dialogTitle" width="60%"
width="40%" :close-on-click-modal="false"
:form-cols="formCols" destroy-on-close
:form-data="formData"
:rules="rules"
label-width="130px"
:submitting="submitting"
:confirm-text="key('confirm')"
:cancel-text="key('cancel')"
@submit="onDialogSubmit"
@close="onDialogClose" @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> </d2-container>
</template> </template>
@@ -66,12 +179,24 @@ import { useTableButtons } from '@/composables/useTableButtons'
import { i18nMixin } from '@/composables/useI18n' import { i18nMixin } from '@/composables/useI18n'
import { confirmMixin } from '@/composables/useConfirmHandle' import { confirmMixin } from '@/composables/useConfirmHandle'
import PageTable from '@/components/page-table' import PageTable from '@/components/page-table'
import PageDialogForm from '@/components/page-dialog-form' import {
import { getList, createItem, editItem, deleteItem, createExportTask } from '@/api/equipment-management/equipment-registry' 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 { export default {
name: 'equipment-management-equipment-registry', name: 'equipment-management-equipment-registry',
components: { PageTable, PageDialogForm }, components: { PageTable },
mixins: [i18nMixin('page.equipment_management.equipment_model.equipment_registry'), confirmMixin], mixins: [i18nMixin('page.equipment_management.equipment_model.equipment_registry'), confirmMixin],
data () { data () {
return { return {
@@ -83,122 +208,66 @@ export default {
dialogTitle: '', dialogTitle: '',
editId: '', editId: '',
handleType: 'create', handleType: 'create',
search: { search: { code: '', name: '', device_category_id: '', area_id: '', line_id: '' },
device_code: '',
device_name: ''
},
pagination: { current: 1, size: 10, total: 0 }, pagination: { current: 1, size: 10, total: 0 },
formData: { formData: this.emptyForm(),
device_code: '', deviceCategoryOptions: [],
device_name: '', areaOptions: [],
device_type_id: '', searchLineOptions: [],
device_status: '', formLineOptions: [],
area_id: '', importVisible: false,
line_id: '', importFileList: [],
remark: '' importRows: [],
}, importTableLoading: false,
importTemplateLoading: false,
importSubmitting: false,
rules: { rules: {
device_code: [{ required: true, message: this.key('enter_device_code'), trigger: 'blur' }], code: [
device_name: [{ required: true, message: this.key('enter_device_name'), trigger: 'blur' }] { 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: [], columns: [],
toolbarButtons: [], toolbarButtons: [],
rowButtons: [], 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%' }
}
]
]
} }
}, },
created () { created () {
this.columns = useTableColumns([ this.columns = useTableColumns([
{ prop: 'device_code', label: this.key('device_code'), minWidth: 140 }, { type: 'selection', width: 55 },
{ prop: 'device_name', label: this.key('device_name'), minWidth: 140 }, { prop: 'sort', label: this.key('sort'), width: 80 },
{ prop: 'device_type_name', label: this.key('device_type'), minWidth: 140 }, { prop: 'code', label: this.key('device_code'), minWidth: 130 },
{ prop: 'device_status', label: this.key('status'), minWidth: 140 }, { prop: 'name', label: this.key('device_name'), minWidth: 130 },
{ prop: 'area_name', label: this.key('area'), minWidth: 140 }, { prop: 'device_category_name', label: this.key('device_category'), minWidth: 130 },
{ prop: 'line_name', label: this.key('line'), minWidth: 140 }, { prop: 'design_ppm', label: this.key('design_ppm'), minWidth: 110 },
{ prop: 'remark', label: this.key('remark'), minWidth: 140 }, { 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' } { prop: '_actions', label: this.key('operation'), width: 170, fixed: 'right' }
]) ])
const btns = useTableButtons({ const btns = useTableButtons({
toolbar: [ 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: 'add', label: this.key('add'), icon: 'el-icon-plus', type: 'primary', auth: '/production_configuration/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: '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: [ row: [
{ key: 'edit', label: this.key('edit'), icon: 'el-icon-edit', auth: '/device_management/device_model/device_management/edit', onClick: this.openEdit }, { 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: '/device_management/device_model/device_management/delete', onClick: this.handleDelete } { 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.$permission)
this.toolbarButtons = btns.toolbarButtons this.toolbarButtons = btns.toolbarButtons
@@ -206,11 +275,34 @@ export default {
this.fetchData() this.fetchData()
}, },
methods: { methods: {
emptyForm () {
return {
code: '',
name: '',
ip: '',
manufacturer: '',
device_category_id: '',
fixed_asset_code: '',
design_ppm: '',
area_id: '',
line_id: '',
entry_time: '',
remark: ''
}
},
normalizeResponse (res) { normalizeResponse (res) {
const data = res && res.data !== undefined ? res.data : res const getTotal = (source, fallback) => {
if (Array.isArray(data)) return { list: data, total: data.length } if (!source) return fallback
if (data && Array.isArray(data.data)) return { list: data.data, total: Number(data.count || data.total || data.data.length) } const total = source.count ?? source.total ?? source.total_count ?? source.record_count
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 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 } return { list: [], total: 0 }
}, },
async fetchData () { async fetchData () {
@@ -229,12 +321,9 @@ export default {
this.fetchData() this.fetchData()
}, },
onReset () { onReset () {
this.search = { this.search = { code: '', name: '', device_category_id: '', area_id: '', line_id: '' }
device_code: '', this.searchLineOptions = []
device_name: '' this.onSearch()
}
this.pagination.current = 1
this.fetchData()
}, },
onPageChange (page) { onPageChange (page) {
this.pagination.current = page.current this.pagination.current = page.current
@@ -244,43 +333,64 @@ export default {
onSelect (rows) { onSelect (rows) {
this.selectedRows = rows this.selectedRows = rows
}, },
resetForm () { async loadDeviceCategories () {
this.formData = { if (this.deviceCategoryOptions.length) return
device_code: '', const res = await getEquipmentCategoryALL()
device_name: '', this.deviceCategoryOptions = this.normalizeResponse(res).list.map(item => ({ label: item.name, value: item.id, code: item.code }))
device_type_id: '', },
device_status: '', async loadAreas () {
area_id: '', if (this.areaOptions.length) return
line_id: '', const res = await getFactoryAreaALL()
remark: '' 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.editId = ''
this.formLineOptions = []
this.$nextTick(() => this.$refs.form && this.$refs.form.clearValidate())
}, },
openAdd () { openAdd () {
this.handleType = 'create' this.handleType = 'create'
this.dialogTitle = this.key('add_title') this.dialogTitle = this.key('add_title')
this.$nextTick(() => {
this.$refs.dialogForm && this.$refs.dialogForm.reset()
this.resetForm() this.resetForm()
this.loadDeviceCategories()
this.loadAreas()
this.dialogVisible = true this.dialogVisible = true
})
}, },
openEdit (row) { async openEdit (row) {
this.handleType = 'edit' this.handleType = 'edit'
this.dialogTitle = this.key('edit_title') this.dialogTitle = this.key('edit_title')
this.editId = row.id this.editId = row.id
this.formData = { this.formData = { ...this.emptyForm(), ...row }
device_code: row.device_code || '', await Promise.all([this.loadDeviceCategories(), this.loadAreas()])
device_name: row.device_name || '', if (this.formData.area_id) this.formLineOptions = await this.loadLines(this.formData.area_id)
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.dialogVisible = true this.dialogVisible = true
}, },
async onDialogSubmit () { onDialogSubmit () {
this.$refs.form.validate(async valid => {
if (!valid) return
this.submitting = true this.submitting = true
try { try {
if (this.handleType === 'create') await createItem(this.formData) if (this.handleType === 'create') await createItem(this.formData)
@@ -291,33 +401,121 @@ export default {
} finally { } finally {
this.submitting = false this.submitting = false
} }
})
}, },
onDialogClose () { onDialogClose () {
this.resetForm() this.resetForm()
}, },
async handleDelete (row) { async handleDelete (row) {
const cancelled = await this.$confirmAction( const cancelled = await this.$confirmAction({ message: this.key('confirm_delete'), title: this.key('tip') }, () => deleteItem({ id: [row.id] }))
{ message: this.key('confirm_delete'), title: this.key('tip') },
() => deleteItem({ id: [row.id] })
)
if (cancelled) return if (cancelled) return
this.$message.success(this.$t(this.key('operation_success'))) 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.pagination.current = Math.min(this.pagination.current, Math.ceil((this.pagination.total - 1) / this.pagination.size) || 1)
this.fetchData() this.fetchData()
}, },
async handleExport () { async handleBatchDelete () {
const cancelled = await this.$confirmAction( if (!this.selectedRows.length) {
{ message: this.key('confirm_export'), title: this.key('tip') }, this.$message.error(this.$t(this.key('please_select_data')))
() => createExportTask({ ...this.search }) 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 if (cancelled) return
this.$message.success(this.$t(this.key('operation_success'))) 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> </script>
<style scoped> <style scoped>
.search-bar { padding: 10px 0; } .search-bar {
/deep/ .el-form-item--mini.el-form-item { margin-bottom: 4px; } padding: 10px 0;
}
.import-form {
margin-top: 16px;
}
/deep/ .el-form-item--mini.el-form-item {
margin-bottom: 4px;
}
</style> </style>