mt-yd-ui/src/views/modules/monitoring/equipment.vue

518 lines
13 KiB
Vue
Raw Normal View History

2022-08-04 13:45:49 +08:00
<template>
2022-08-04 15:42:36 +08:00
<div class="mod-config">
2022-09-28 11:23:39 +08:00
<el-form :inline="true" :model="dataForm" @keyup.enter.native="currentChangeHandle(1)">
2022-08-04 15:42:36 +08:00
<el-form-item>
<el-input v-model="dataForm.key" :placeholder="$t('eq.name') + ' / ' + $t('eq.code')" clearable></el-input>
2022-08-04 15:42:36 +08:00
</el-form-item>
<el-form-item>
2022-09-28 11:23:39 +08:00
<el-button @click="currentChangeHandle(1)">{{ $t('search') }}</el-button>
2022-09-01 09:16:51 +08:00
<el-button v-if="$hasPermission('monitoring:equipment:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
2022-09-01 15:01:25 +08:00
<el-button v-if="$hasPermission('monitoring:equipment:export')" @click="exportHandle()">{{ $t('export') }}</el-button>
2022-08-04 15:42:36 +08:00
</el-form-item>
</el-form>
2022-08-05 16:03:38 +08:00
2022-09-30 15:04:19 +08:00
<base-table
:page="pageIndex"
:size="pageSize"
:data="dataList"
:table-head-configs="tableConfigs"
:max-height="calcMaxHeight(8)"
@operate-event="handleOperations"
@refreshDataList="getDataList"
/>
2022-08-04 15:42:36 +08:00
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="pageIndex"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
:total="totalPage"
layout="total, sizes, prev, pager, next, jumper"
2022-08-04 16:13:20 +08:00
></el-pagination>
2022-08-04 15:42:36 +08:00
<!-- 弹窗, 新增 / 修改 -->
2022-09-30 17:01:47 +08:00
<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" :configs="addOrUpdateConfigs" @refreshDataList="getDataList" @select-change="handleDialogSelectChange" />
2022-08-04 15:42:36 +08:00
</div>
2022-08-04 13:45:49 +08:00
</template>
<script>
2022-08-31 10:22:44 +08:00
import i18n from '@/i18n'
2022-08-16 14:07:33 +08:00
import AddOrUpdate from '@/components/base-dialog/addOrUpdate'
// import AddOrUpdate from './equipment-add-or-update'
2022-08-05 16:03:38 +08:00
import BaseTable from '@/components/base-table'
2022-08-08 10:54:23 +08:00
import TableOperateComponent from '@/components/base-table/components/operationComponent'
import TableTextComponent from '@/components/base-table/components/detailComponent'
2022-08-16 14:07:33 +08:00
import CKEditor from 'ckeditor4-vue'
2022-08-31 11:21:35 +08:00
import { calcMaxHeight } from '@/utils'
2022-09-01 09:16:51 +08:00
import { timeFilter } from '@/utils/filters'
2022-09-05 10:17:29 +08:00
import Cookies from 'js-cookie'
2022-08-05 16:03:38 +08:00
const tableConfigs = [
2022-08-08 10:07:15 +08:00
{
type: 'index',
2022-09-01 15:44:04 +08:00
name: i18n.t('index')
2022-08-08 10:07:15 +08:00
},
2022-08-31 10:22:44 +08:00
{
prop: 'createTime',
name: i18n.t('createTime'),
2022-09-01 09:16:51 +08:00
filter: timeFilter
2022-08-31 10:22:44 +08:00
},
2022-09-02 09:49:14 +08:00
{ prop: 'name', name: i18n.t('eq.name') },
{ prop: 'code', name: i18n.t('eq.code') },
{ prop: 'equipmentTypeName', name: i18n.t('eq.type') },
{ prop: 'groupName', name: i18n.t('eq.group') },
2022-09-01 15:44:04 +08:00
{ prop: 'enName', name: i18n.t('enname') },
2022-09-02 09:49:14 +08:00
{ prop: 'abbr', name: i18n.t('abbr') },
2022-09-30 17:01:47 +08:00
{ prop: 'lineName', name: i18n.t('pl.title') },
2022-09-30 15:04:19 +08:00
{ prop: 'sectionName', name: i18n.t('ws.title') },
2022-08-31 10:22:44 +08:00
{
prop: 'details',
2022-09-02 09:49:14 +08:00
name: i18n.t('detail'),
2022-08-31 10:22:44 +08:00
subcomponent: TableTextComponent,
actionName: 'view-detail'
},
{
prop: 'operations',
2022-09-01 15:01:25 +08:00
name: i18n.t('handle'),
2022-08-31 10:22:44 +08:00
fixed: 'right',
width: 180,
subcomponent: TableOperateComponent,
options: ['edit', 'delete']
}
2022-08-05 16:03:38 +08:00
]
2022-08-16 14:07:33 +08:00
const addOrUpdateConfigs = {
type: 'dialog',
infoUrl: '/monitoring/equipment',
fields: [
2022-09-02 09:49:14 +08:00
{ name: 'name', label: i18n.t('eq.name'), required: true },
2022-09-29 09:31:43 +08:00
{ name: 'code', label: i18n.t('eq.code'), api: '/monitoring/equipment/getCode' },
2022-09-01 15:44:04 +08:00
{ name: 'enName', label: i18n.t('enname') },
2022-09-02 09:49:14 +08:00
{ name: 'abbr', label: i18n.t('abbr') },
2022-08-31 10:22:44 +08:00
{
name: 'equipmentTypeId',
2022-09-02 09:49:14 +08:00
label: i18n.t('eq.type'),
2022-08-31 10:22:44 +08:00
required: true,
type: 'select',
options: []
},
2022-09-30 17:01:47 +08:00
{
name: 'lineId',
label: i18n.t('pl.title'),
required: true,
type: 'select',
options: [],
relatedField: 'sectionId', // 关联下面的id在更换lineId时会清空相应的sectionId选择结果
},
2022-09-30 15:04:19 +08:00
{
name: 'sectionId',
label: i18n.t('ws.title'),
required: true,
type: 'select',
options: []
},
{
name: 'sort',
label: i18n.t('ws.sort')
},
2022-08-31 10:22:44 +08:00
{
name: 'groupId',
2022-09-02 09:49:14 +08:00
label: i18n.t('eq.group'),
2022-08-31 10:22:44 +08:00
required: true,
type: 'select',
options: []
},
{
name: 'productionTime',
2022-09-02 09:49:14 +08:00
label: i18n.t('produceTime'),
type: 'date',
props: {
'type': 'date', // element-ui 的配置
2022-09-02 09:49:14 +08:00
'placeholder': i18n.t('hints.date'),
'value-format': 'yyyy-MM-ddTHH:mm:ss',
'style': {
width: '100%'
}
}
},
{
name: 'enterTime',
2022-09-02 09:49:14 +08:00
label: i18n.t('enterTime'),
type: 'date',
props: {
'type': 'date', // element-ui 的配置
2022-09-02 09:49:14 +08:00
'placeholder': i18n.t('hints.date'),
'value-format': 'yyyy-MM-ddTHH:mm:ss',
'style': {
width: '100%'
}
}
},
2022-08-31 10:22:44 +08:00
{
name: 'tvalue',
2022-09-02 09:49:14 +08:00
label: i18n.t('eq.tvalue'),
2022-08-31 10:22:44 +08:00
required: true,
rules: [
{
type: 'number',
2022-09-02 09:49:14 +08:00
message: i18n.t('hints.number'),
2022-08-31 10:22:44 +08:00
trigger: 'blur',
transform: val => Number(val)
}
]
},
{
name: 'processingTime',
2022-09-02 09:49:14 +08:00
label: i18n.t('eq.processingTime'),
2022-08-31 10:22:44 +08:00
rules: [
{
type: 'number',
2022-09-02 09:49:14 +08:00
message: i18n.t('hints.number'),
2022-08-31 10:22:44 +08:00
trigger: 'blur',
transform: val => Number(val)
}
]
},
2022-09-02 09:49:14 +08:00
{ name: 'manufacturer', label: i18n.t('manufacturer') },
{ name: 'spec', label: i18n.t('eq.grade') },
{
name: 'dataType',
2022-09-02 09:49:14 +08:00
label: i18n.t('eq.dtype'),
required: true,
type: 'select',
options: [
2022-09-02 09:49:14 +08:00
{ value: 0, label: i18n.t('eq.dtypenone') },
{ value: 1, label: i18n.t('eq.dtypeinput') },
{ value: 2, label: i18n.t('eq.dtypeoutput') }
]
},
2022-09-02 09:49:14 +08:00
{ name: 'remark', label: i18n.t('remark') }
2022-08-16 14:07:33 +08:00
],
extraComponents: [
{
name: 'description',
hasModel: true,
2022-09-02 09:49:14 +08:00
label: i18n.t('desc'),
2022-08-16 14:07:33 +08:00
fieldType: 'string',
component: CKEditor.component,
props: {
2022-09-05 10:17:29 +08:00
// value: 'tests',
2022-08-16 14:07:33 +08:00
config: {
// ckeditor 的配置: https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html
// toolbar: [['Bold']]
2022-09-05 10:17:29 +08:00
language: Cookies.get('language') || 'en'
2022-08-16 14:07:33 +08:00
}
}
},
{
name: 'files',
2022-09-02 14:09:41 +08:00
label: i18n.t('upload.title'),
2022-08-16 14:07:33 +08:00
fieldType: 'array',
component: () => import('@/components/base-upload'),
props: {
// 上传组件需要的 props
url: '/monitoring/attachment/uploadFileFormData',
2022-08-16 14:36:25 +08:00
extraParams: { typeCode: 'EquipmentInfoFile' },
2022-09-02 09:49:14 +08:00
buttonContent: i18n.t('upload.button'),
tip: i18n.t('hints.upload2m')
2022-08-16 14:07:33 +08:00
}
},
{
name: 'files',
2022-09-02 09:49:14 +08:00
label: i18n.t('eq.image'),
2022-08-16 14:07:33 +08:00
fieldType: 'array',
component: () => import('@/components/base-upload'),
props: {
// 上传组件需要的 props
url: '/monitoring/attachment/uploadFileFormData',
2022-08-16 14:36:25 +08:00
extraParams: { typeCode: 'EquipmentInfoImage' },
2022-09-02 09:49:14 +08:00
buttonContent: i18n.t('upload.button'),
tip: i18n.t('hints.upload2mPic')
2022-08-16 14:07:33 +08:00
}
}
],
subtable: {
2022-09-02 09:49:14 +08:00
title: i18n.t('eq.viewattr'),
url: '/monitoring/equipmentAttr',
relatedField: 'equipmentId',
tableConfigs: [
{ type: 'index', width: 100, name: i18n.t('index') },
2022-09-01 15:01:25 +08:00
{ prop: 'createTime', name: i18n.t('createTime'), filter: timeFilter },
2022-09-01 15:44:04 +08:00
{ prop: 'attrName', name: i18n.t('attrName'), formField: true },
{ prop: 'attrValue', name: i18n.t('attrValue'), formField: true },
2022-08-31 10:22:44 +08:00
{
prop: 'operations',
2022-09-01 15:01:25 +08:00
name: i18n.t('handle'),
2022-08-31 10:22:44 +08:00
fixed: 'right',
width: 180,
subcomponent: TableOperateComponent,
options: ['edit', 'delete']
}
]
},
2022-08-16 14:07:33 +08:00
operations: [
{ name: 'cancel', showAlways: true },
2022-08-31 10:22:44 +08:00
{
name: 'save',
url: '/monitoring/equipment',
permission: 'monitoring:equipment:save',
2022-08-31 10:22:44 +08:00
showOnEdit: false
},
{
name: 'update',
url: '/monitoring/equipment',
permission: 'monitoring:equipment:update',
2022-08-31 10:22:44 +08:00
showOnEdit: true
}
2022-08-16 14:07:33 +08:00
]
}
2022-08-04 15:42:36 +08:00
export default {
data() {
return {
2022-08-31 11:21:35 +08:00
calcMaxHeight,
2022-08-05 16:03:38 +08:00
tableConfigs,
2022-08-16 14:07:33 +08:00
addOrUpdateConfigs,
2022-08-04 15:42:36 +08:00
dataForm: {
key: ''
},
dataList: [],
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
dataListSelections: [],
addOrUpdateVisible: false
}
},
components: {
2022-08-05 16:03:38 +08:00
AddOrUpdate,
BaseTable
2022-08-04 15:42:36 +08:00
},
activated() {
console.log('activated')
this.getDataList()
this.getGroupList()
2022-09-30 17:01:47 +08:00
this.getPlList()
this.getTypeList()
2022-08-04 15:42:36 +08:00
},
methods: {
2022-09-30 17:01:47 +08:00
// 获取产线列表,用于刷新工段列表
getPlList() {
2022-09-30 15:04:19 +08:00
this.$http({
2022-09-30 17:01:47 +08:00
url: this.$http.adornUrl('/monitoring/productionLine/list'),
2022-09-30 15:04:19 +08:00
method: 'get'
2022-09-30 17:01:47 +08:00
}).then(({ data: res }) => {
const plConfig = this.addOrUpdateConfigs.fields.find(item => item.name === 'lineId')
plConfig.options =
res.data?.map(item => ({
value: item.id,
label: item.name
})) || []
})
},
// 获取工段列表
getWsList(id) {
let params = {
page: 1,
limit: 999
}
if (id) {
params.lineId = id
}
this.$http({
url: this.$http.adornUrl('/monitoring/workshopSection/page'),
method: 'get',
params: this.$http.adornParams(params)
}).then(({ data: res }) => {
2022-09-30 15:04:19 +08:00
const wsConfig = this.addOrUpdateConfigs.fields.find(item => item.name === 'sectionId')
wsConfig.options =
2022-09-30 17:01:47 +08:00
res.data?.list?.map(item => ({
2022-09-30 15:04:19 +08:00
value: item.id,
label: item.name
})) || []
})
},
// 获取设备类型列表
getTypeList() {
this.$http({
url: this.$http.adornUrl('/monitoring/equipmentType/page'),
method: 'get',
params: this.$http.adornParams({
// page: this.pageIndex,
// limit: this.pageSize,
// key: this.dataForm.key
})
}).then(({ data }) => {
2022-09-01 09:16:51 +08:00
const eqTypeConfig = this.addOrUpdateConfigs.fields.find(item => item.name === 'equipmentTypeId')
2022-08-31 10:22:44 +08:00
eqTypeConfig.options =
data.data?.list?.map(item => ({
value: item.id,
label: item.name
})) || []
})
},
// 获取设备分组列表
getGroupList() {
this.$http({
url: this.$http.adornUrl('/monitoring/equipmentGroup/page'),
method: 'get',
params: this.$http.adornParams({
// page: this.pageIndex,
// limit: this.pageSize,
// key: this.dataForm.key
})
}).then(({ data }) => {
2022-09-01 09:16:51 +08:00
const groupConfig = this.addOrUpdateConfigs.fields.find(item => item.name === 'groupId')
2022-08-31 10:22:44 +08:00
groupConfig.options =
data.data?.list?.map(item => ({
value: item.id,
label: item.name
})) || []
})
},
2022-08-04 15:42:36 +08:00
// 获取数据列表
getDataList() {
this.dataListLoading = true
this.$http({
url: this.$http.adornUrl('/monitoring/equipment/page'),
method: 'get',
params: this.$http.adornParams({
page: this.pageIndex,
limit: this.pageSize,
key: this.dataForm.key
})
}).then(({ data }) => {
if (data && data.code === 0) {
2022-09-01 09:30:44 +08:00
this.dataList = data.data.list
// this.dataList = new Array(20).fill('1')
// console.log('data list', this.dataList)
2022-08-04 16:13:20 +08:00
this.totalPage = data.data.total
2022-08-04 15:42:36 +08:00
} else {
this.dataList = []
this.totalPage = 0
}
this.dataListLoading = false
})
},
// 每页数
sizeChangeHandle(val) {
this.pageSize = val
this.pageIndex = 1
this.getDataList()
},
// 当前页
currentChangeHandle(val) {
this.pageIndex = val
this.getDataList()
},
// 多选
selectionChangeHandle(val) {
this.dataListSelections = val
},
2022-09-30 17:01:47 +08:00
// 对话框里的某个选择改变了
handleDialogSelectChange({ name, id }) {
switch (name) {
case 'lineId':
this.getWsList(id)
}
},
2022-08-16 14:07:33 +08:00
handleOperations({ type, data: id }) {
switch (type) {
case 'view-detail':
// const { name, code } = this.dataList.find(item => item.id === id)
// this.$router.push({
// name: 'monitoring-equipmentAdd',
// params: {
// isdetail: true,
// equipmentId: id
// }
// })
// break
return this.addOrUpdateHandle(id, true)
2022-08-16 14:07:33 +08:00
case 'edit':
return this.addOrUpdateHandle(id)
case 'delete':
return this.deleteHandle(id)
}
},
exportHandle() {
// this.$http.get(this.$http.adornUrl('/monitoring/equipment/export')).then(({ data: res }) => {
2022-08-31 10:22:44 +08:00
this.$http({
url: this.$http.adornUrl('/monitoring/equipment/export'),
method: 'get',
responseType: 'blob'
}).then(res => {
let fileName = 'equipment-list.xls'
if (res.headers['content-disposition']) {
const contentDisposition = res.headers['content-disposition']
2022-09-01 09:16:51 +08:00
fileName = contentDisposition.slice(contentDisposition.indexOf('filename=') + 9)
}
2022-08-31 10:22:44 +08:00
fileName = decodeURIComponent(fileName)
const blob = new Blob([res.data])
if ('download' in document.createElement('a')) {
const alink = document.createElement('a')
alink.download = fileName
alink.style.display = 'none'
alink.target = '_blank'
alink.href = URL.createObjectURL(blob)
document.body.appendChild(alink)
alink.click()
URL.revokeObjectURL(alink.href)
document.body.removeChild(alink)
} else {
navigator.msSaveBlob(blob, fileName)
}
2022-08-16 14:07:33 +08:00
})
},
// 新增 / 修改
addOrUpdateHandle(id, isdetail = false) {
this.addOrUpdateVisible = true
this.$nextTick(() => {
this.$refs.addOrUpdate.init(id, isdetail)
2022-08-04 15:42:36 +08:00
})
// this.$router.push({
// name: 'monitoring-equipmentAdd',
// params: {
// equipmentId: id
// }
// })
2022-08-04 15:42:36 +08:00
},
// 删除
deleteHandle(id) {
var ids = id
? [id]
: this.dataListSelections.map(item => {
return item.id
})
2022-09-02 09:49:14 +08:00
this.$confirm(`${i18n.t('prompt.info', { handle: id ? i18n.t('delete').toLowerCase() : i18n.t('deleteBatch').toLowerCase() })}`, i18n.t('prompt.title'), {
2022-09-01 15:01:25 +08:00
confirmButtonText: i18n.t('confirm'),
cancelButtonText: i18n.t('cancel'),
2022-09-01 09:16:51 +08:00
type: 'warning'
}).then(() => {
2022-08-04 15:42:36 +08:00
this.$http({
url: this.$http.adornUrl('/monitoring/equipment'),
method: 'delete',
2022-08-11 14:22:23 +08:00
data: this.$http.adornData(ids, false, 'raw')
2022-08-04 15:42:36 +08:00
}).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
2022-09-02 09:49:14 +08:00
message: i18n.t('prompt.success'),
2022-08-04 15:42:36 +08:00
type: 'success',
duration: 1500,
onClose: () => {
this.getDataList()
}
})
} else {
this.$message.error(data.msg)
}
})
})
}
}
}
2022-08-04 13:45:49 +08:00
</script>