finish EdgeX

This commit is contained in:
ann 2023-02-21 15:36:29 +08:00
parent 352e0299fc
commit 785f25cd29
5 changed files with 87 additions and 48 deletions

View File

@ -13,15 +13,15 @@
<el-col :span="6">
<el-select v-model="selectedProtocal" style="width: 80%">
<el-option
v-for="it in protocals"
:key="it"
:label="it"
:value="it"
v-for="(key, val) in protocals"
:key="key"
:label="val"
:value="key"
/>
</el-select>
</el-col>
<el-col :span="16">
<p v-if="protocalOptions[protocals.indexOf(selectedProtocal)].options.length===0">该设备服务不需要设置通信协议</p>
<p v-if="protocalOptions[Object.values(protocals).indexOf(selectedProtocal)].options.length===0">该设备服务不需要设置通信协议</p>
<el-form-item
v-for="(item, index) in protocalList"
:key="'item'+index"
@ -55,16 +55,17 @@
label=""
>
<el-row :gutter="20">
<el-col :span="12">
<el-col :span="11">
<el-input v-model="item.key">
<template slot="prepend">PropertyName</template>
</el-input>
</el-col>
<el-col :span="12">
<el-col :span="11">
<el-input v-model="item.value">
<template slot="prepend">PropertyValue</template>
</el-input>
</el-col>
<el-col :span="2"><el-button icon="el-icon-delete" circle @click.prevent="removeTag(index)" /></el-col>
</el-row>
</el-form-item>
</el-col>
@ -87,30 +88,27 @@ export default {
}
},
data() {
const arr = []
for (const i in protocalOptions[0].options) {
arr.push({ key: protocalOptions[0].options[i], value: '' })
}
return {
radio: '1',
selectedProtocal: 'device-mqtt',
selectedProtocal: 'mqtt',
protocalList: arr,
protocalList2: [],
protocals,
protocalOptions
}
},
computed: {
autoEvents: {
get() {
return this.value
},
set(value) {
this.$emit('input', value)
}
},
protocalList() {
const arr = []
for (const i in this.protocalOptions[this.protocals.indexOf(this.selectedProtocal)].options) {
arr.push({ key: this.protocalOptions[this.protocals.indexOf(this.selectedProtocal)].options[i], value: '' })
}
return arr
},
// protocalList() {
// const arr = []
// for (const i in this.protocalOptions[Object.values(this.protocals).indexOf(this.selectedProtocal)].options) {
// arr.push({ key: this.protocalOptions[Object.values(this.protocals).indexOf(this.selectedProtocal)].options[i], value: '' })
// }
// return arr
// },
addTagNumCheck() {
let flag = false
this.protocalList2.forEach(e => {
@ -123,7 +121,16 @@ export default {
},
watch: {
radio(val) {
this.selectedProtocal = val === '1' ? 'device-mqtt' : ''
this.selectedProtocal = val === '1' ? 'mqtt' : ''
},
selectedProtocal(val) {
const arr = []
if (this.radio === '1' && val) {
for (const i in this.protocalOptions[Object.values(this.protocals).indexOf(val)].options) {
arr.push({ key: this.protocalOptions[Object.values(this.protocals).indexOf(val)].options[i], value: '' })
}
}
this.protocalList = arr
}
},
mounted() {
@ -134,6 +141,25 @@ export default {
},
removeTag(index) {
this.protocalList2.splice(index, 1)
},
checkData() {
if (!this.selectedProtocal) {
this.$message.warning('请输入协议名')
return false
} else {
return true
}
},
getData() {
const data = {}
const list = this.radio === '1' ? this.protocalList : this.protocalList2
data[this.selectedProtocal] = {}
list.forEach(e => {
if (e.key !== '') {
data[this.selectedProtocal][e.key] = e.value
}
})
return data
}
}
}

View File

@ -61,7 +61,7 @@
</el-form-item>
</el-form>
<auto-events v-show="stepNum === 3" ref="autoEventsForm" v-model="autoEvents" />
<add-protocal v-show="stepNum === 4" ref="addProtocalForm" v-model="protocals" />
<add-protocal v-show="stepNum === 4" ref="addProtocalForm" />
<div slot="footer" class="dialog-footer">
<el-button @click="createFormVisible = false"> </el-button>
<el-button v-if="stepNum!==0" type="primary" @click="prev">上一步</el-button>
@ -72,7 +72,7 @@
</template>
<script>
import { getEdgeDataByIpPath } from '@/api/edge/edge'
import { getEdgeDataByIpPath, postDeviceservice } from '@/api/edge/edge'
import List from '@/components/list.vue'
import AutoEvents from './autoEvents.vue'
import AddProtocal from './addProtocal.vue'
@ -114,7 +114,12 @@ export default {
{ prop: 'manufacturer', label: '维护者' },
{ prop: 'model', label: '模式' }
],
deviceData: {},
deviceData: {
name: '',
description: '',
labels: '',
adminState: 'UNLOCKED'
},
serviceList: [],
profileList: [],
selectedProfile: null,
@ -163,16 +168,26 @@ export default {
this.selectedProfile = e.name
},
createDevice() {
this.metaData = {
serviceName: this.selectedService,
profileName: this.selectedProfile,
apiVersion: 'v2',
operatingState: 'UP',
autoEvents: [],
protocols: {},
...this.deviceData
if (this.$refs.addProtocalForm.checkData()) {
const AE = this.autoEvents.map(e => { return { interval: e.interval + e.intervalUnit, onChange: e.onChange, sourceName: e.sourceName } })
this.metaData = {
serviceName: this.selectedService,
profileName: this.selectedProfile,
apiVersion: 'v2',
operatingState: 'UP',
autoEvents: AE,
protocols: this.$refs.addProtocalForm.getData(),
...this.deviceData
}
this.metaData.labels = this.metaData.labels.length ? this.metaData.labels.split(',') : []
postDeviceservice({ address: this.$route.query.ip, path: `core-metadata/api/v2/device`, postContent: [{ 'apiVersion': 'v2', 'device': this.metaData }] }).then(e => {
if (e.code === 200) {
this.createFormVisible = false
this.$message.success('添加成功')
this.$emit('getList')
}
})
}
this.metaData.labels = this.metaData.split(',')
},
prev() {
this.stepNum--
@ -191,8 +206,6 @@ export default {
case 3:
this.$refs.autoEventsForm.checkAE() ? this.$message.warning('请完成自动采集数据表单') : this.stepNum++
break
case 4:
console.log('sd')
}
}
}

View File

@ -52,7 +52,7 @@
<el-button size="medium" type="primary" @click="createFormVisible = true">添加</el-button>
</template>
</List>
<CreateDevice v-model="createFormVisible" />
<CreateDevice v-model="createFormVisible" @getList="getDevicelist" />
<el-dialog :close-on-click-modal="false" :title="deviceItemData.name" :visible.sync="dialogAutoEventsVisible">
<el-table
v-if="deviceItemData.autoEvents ? deviceItemData.autoEvents.length>0 : false"

View File

@ -1,12 +1,12 @@
const protocals = [
'device-mqtt',
'device-rest',
'device-virtual',
'device-modbus-tcp',
'device-modbus-rtu',
'device-onvif-camera',
'device-rfid-llrp'
]
const protocals = {
'device-mqtt': 'mqtt',
'device-rest': 'other-rest',
'device-virtual': 'other',
'device-modbus-tcp': 'modbus-tcp',
'device-modbus-rtu': 'modbus-rtu',
'device-onvif-camera': 'Onvif',
'device-rfid-llrp': 'tcp'
}
const protocalOptions = [
{ options: ['Schema', 'Host', 'Port', 'User', 'Password', 'Clientld', 'CommandTopic'] },
{ options: [] },