fix: 优化gateway的采集器新增,点位新增

This commit is contained in:
XieYongHong 2023-07-25 19:50:58 +08:00
parent ccbdef9f3c
commit 992e9a0aab
7 changed files with 192 additions and 164 deletions

View File

@ -61,3 +61,4 @@ export const scanOpcUAList = (data: any) =>
export const queryTypeList = () => server.get(`/data-collect/opc/data-types`); export const queryTypeList = () => server.get(`/data-collect/opc/data-types`);
export const getProviders = () => server.get('/data-collect/channel/gateway/codec/providers')

View File

@ -271,7 +271,7 @@ import {
import { ModBusRules, checkProviderData } from '../../data.ts'; import { ModBusRules, checkProviderData } from '../../data.ts';
import type { FormInstance } from 'ant-design-vue'; import type { FormInstance } from 'ant-design-vue';
import type { Rule } from 'ant-design-vue/lib/form'; import type { Rule } from 'ant-design-vue/lib/form';
import { cloneDeep } from 'lodash-es'; import {cloneDeep, omit} from 'lodash-es';
const props = defineProps({ const props = defineProps({
data: { data: {
@ -347,6 +347,14 @@ const handleOk = async () => {
address: data?.pointKey, address: data?.pointKey,
}; };
if (props.data.provider === 'GATEWAY') {
const configuration = cloneDeep(params.configuration)
params.configuration = {
configuration: configuration,
interval: params.interval
}
}
loading.value = true; loading.value = true;
const response = !id const response = !id
? await savePointBatch(params).catch(() => {}) ? await savePointBatch(params).catch(() => {})
@ -439,11 +447,20 @@ watch(
watch( watch(
() => props.data, () => props.data,
(value) => { (value) => {
if (value.id && value.provider === 'MODBUS_TCP') { if (value.id && ['MODBUS_TCP', 'GATEWAY'].includes(value.provider)) {
const _value: any = cloneDeep(value); const _value: any = cloneDeep(value);
const { writeByteCount, byteCount } = const { writeByteCount, byteCount } =
_value.configuration.parameter; props.data.provider === 'GATEWAY' ? _value.configuration.configuration.parameter: _value.configuration.parameter;
if (props.data.provider === 'GATEWAY') {
formData.value = {
...omit(_value, ['configuration']),
..._value.configuration,
}
} else {
formData.value = _value; formData.value = _value;
}
if (!!_value.accessModes[0]?.value) { if (!!_value.accessModes[0]?.value) {
formData.value.accessModes = value.accessModes.map( formData.value.accessModes = value.accessModes.map(
(i: any) => i.value, (i: any) => i.value,

View File

@ -40,16 +40,15 @@
v-model:value="formData.name" v-model:value="formData.name"
/> />
</j-form-item> </j-form-item>
<template v-if="provider === 'GATEWAY'">
<j-form-item <j-form-item
v-if="provider === 'GATEWAY'"
label="通讯协议" label="通讯协议"
:name="['configuration', 'collectorProvider']" :name="['collectorProvider']"
:rules="[{ required: true, message: '请选择通讯协议' }]" :rules="[{ required: true, message: '请选择通讯协议' }]"
> >
<j-select <j-select
style="width: 100%" style="width: 100%"
v-model:value="formData.configuration.collectorProvider" v-model:value="formData.collectorProvider"
:options="providerListItems" :options="providerListItems"
placeholder="请选择通讯协议" placeholder="请选择通讯协议"
allowClear allowClear
@ -58,8 +57,6 @@
:disabled="!!id" :disabled="!!id"
/> />
</j-form-item> </j-form-item>
</template>
<template v-else>
<j-form-item <j-form-item
v-if="visibleUnitId" v-if="visibleUnitId"
:name="['configuration', 'unitId']" :name="['configuration', 'unitId']"
@ -75,6 +72,7 @@
/> />
</j-form-item> </j-form-item>
<j-form-item <j-form-item
v-if="provider !== 'GATEWAY'"
:name="['configuration', 'inheritBreakerSpec', 'type']" :name="['configuration', 'inheritBreakerSpec', 'type']"
:rules="LeftTreeRules.type" :rules="LeftTreeRules.type"
label="点位熔断处理" label="点位熔断处理"
@ -90,7 +88,7 @@
@change="changeCardSelectType" @change="changeCardSelectType"
/> />
</j-form-item> </j-form-item>
<p style="color: #616161"> <p style="color: #616161" v-if="provider !== 'GATEWAY'">
{{ getTypeTooltip(formData.configuration.inheritBreakerSpec.type) }} {{ getTypeTooltip(formData.configuration.inheritBreakerSpec.type) }}
</p> </p>
<j-form-item <j-form-item
@ -147,7 +145,6 @@
:min="1" :min="1"
/> />
</j-form-item> </j-form-item>
</template>
<j-form-item label="说明" name="description"> <j-form-item label="说明" name="description">
<j-textarea <j-textarea
placeholder="请输入说明" placeholder="请输入说明"
@ -176,11 +173,10 @@
</j-modal> </j-modal>
</template> </template>
<script lang="ts" name="CollectorTreeSave" setup> <script lang="ts" name="CollectorTreeSave" setup>
import { save, update } from '@/api/data-collect/collector'; import { save, update, getProviders } from '@/api/data-collect/collector';
import { LeftTreeRules } from '../../data'; import { LeftTreeRules } from '../../data';
import type { FormInstance } from 'ant-design-vue'; import type { FormInstance } from 'ant-design-vue';
import {cloneDeep} from "lodash-es"; import {cloneDeep, omit} from "lodash-es";
import {getProviders} from "@/api/data-collect/channel";
import {protocolList} from "@/utils/consts"; import {protocolList} from "@/utils/consts";
const loading = ref(false); const loading = ref(false);
@ -208,13 +204,7 @@ const providerListItems = ref()
const geyProviderList = async () => { const geyProviderList = async () => {
const resp: any = await getProviders(); const resp: any = await getProviders();
if (resp.success) { if (resp.success) {
const arr = resp.result.filter( providerListItems.value = resp.result.map((item: any) => ({ label: item.name, value: item.id }))
(item: any) => ['collector-gateway', 'modbus-tcp', 'opc-ua'].includes(item.id),
).map((it: any) => it.id);
console.log(arr, protocolList)
providerListItems.value = protocolList.filter((item: any) =>
arr.includes(item.alias),
);
} else { } else {
providerListItems.value = [] providerListItems.value = []
} }
@ -255,12 +245,12 @@ const endianData = computed(() => {
const formData = ref({ const formData = ref({
channelId: undefined, channelId: undefined,
name: '', name: '',
collectorProvider: undefined,
configuration: { configuration: {
unitId: '', unitId: '',
type: 'LowerFrequency', type: 'LowerFrequency',
endian: 'BIG', endian: 'BIG',
endianIn: 'BIG', endianIn: 'BIG',
collectorProvider: undefined,
requsetTimeout: 2000, requsetTimeout: 2000,
inheritBreakerSpec: { inheritBreakerSpec: {
type: 'LowerFrequency', type: 'LowerFrequency',
@ -274,20 +264,32 @@ const formData = ref({
}); });
const handleOk = async () => { const handleOk = async () => {
const data = await formRef.value?.validate(); const _data: any = await formRef.value?.validate();
if (_data) {
const { name } = _channelListAll.value.find( const { name } = _channelListAll.value.find(
(item: any) => item.id === formData.value.channelId, (item: any) => item.id === formData.value.channelId,
); );
if (['GATEWAY'].includes(data?.provider)) { let _copyData = _data
data.configuration.inheritBreakerSpec.type = 'Ignore'
if (['GATEWAY'].includes(provider.value)) {
const copyData = cloneDeep(_data)
_copyData = omit(copyData, ['configuration', 'collectorProvider'])
_copyData.configuration = {
configuration: {
..._data.configuration,
inheritBreakerSpec: {
type: 'Ignore'
}
},
collectorProvider: _data.collectorProvider
}
} }
const params = { const params = {
...data, ..._copyData,
provider: provider.value, provider: provider.value,
channelName: name, channelName: name,
circuitBreaker: { circuitBreaker: {
@ -296,13 +298,19 @@ const handleOk = async () => {
}; };
loading.value = true; loading.value = true;
try {
const response = !id const response = !id
? await save(params).catch(() => { success: false }) ? await save(params)
: await update(id, { ...props.data, ...params }).catch(() => { success: false }); : await update(id, { ...props.data, ...params })
loading.value = false; loading.value = false;
if (response.success) { if (response.success) {
emit('change', true); emit('change', true);
} }
} catch (e) {
loading.value = false;
}
}
}; };
const getTypeTooltip = (value: string) => { const getTypeTooltip = (value: string) => {
@ -337,7 +345,7 @@ watch(
(value) => { (value) => {
const dt = _channelListAll.value.find((item) => item.id === value); const dt = _channelListAll.value.find((item) => item.id === value);
visibleUnitId.value = visibleEndian.value = visibleUnitId.value = visibleEndian.value =
dt?.provider && dt?.provider === 'MODBUS_TCP'; dt?.provider && ['MODBUS_TCP', 'GATEWAY'].includes(dt?.provider);
}, },
{ deep: true }, { deep: true },
); );
@ -347,7 +355,7 @@ watch(
(value) => { (value) => {
if (value.id) { if (value.id) {
let copyValue = cloneDeep(value) let copyValue = cloneDeep(value)
if (!copyValue?.configuration?.inheritBreakerSpec) { if (!copyValue?.configuration?.inheritBreakerSpec && copyValue.provider !== 'GATEWAY') {
copyValue.configuration = { copyValue.configuration = {
...copyValue.configuration, ...copyValue.configuration,
inheritBreakerSpec: { inheritBreakerSpec: {
@ -356,12 +364,17 @@ watch(
} }
copyValue.circuitBreaker.type = 'Ignore' copyValue.circuitBreaker.type = 'Ignore'
} }
formData.value = copyValue
const item = props.channelListAll.find( if (copyValue.provider === 'GATEWAY') {
(item: any) => item.id === formData.value.channelId, formData.value = {
); ...omit(copyValue, ['configuration']),
provider.value = item?.provider ...copyValue.configuration,
}
} else {
formData.value = copyValue
}
provider.value = copyValue?.provider
}; };
}, },
{ immediate: true, deep: true }, { immediate: true, deep: true },

View File

@ -28,13 +28,8 @@
placeholder="请选择" placeholder="请选择"
allowClear allowClear
:filter-option="filterOption" :filter-option="filterOption"
> :options="channelList"
<j-select-option @select="(_, option) => { record.provider = option.provider }"
v-for="item in channelList"
:key="item.value"
:value="item.value"
:label="item.label"
>{{ item.label }}</j-select-option
> >
</j-select> </j-select>
</j-form-item> </j-form-item>
@ -269,6 +264,7 @@ const onSave = () => {
(i: any) => i.channelId, (i: any) => i.channelId,
); );
if (arr && arr.length !== 0) { if (arr && arr.length !== 0) {
console.log(arr)
const resp = await saveMapping( const resp = await saveMapping(
instanceStore.current.id, instanceStore.current.id,
props.provider, props.provider,

View File

@ -139,7 +139,7 @@ const getTypeList = (result: Record<string, any>) => {
} else if (item.id === 'OneNet' || item.id === 'Ctwing') { } else if (item.id === 'OneNet' || item.id === 'Ctwing') {
item.type = 'cloud'; item.type = 'cloud';
cloud.push(item); cloud.push(item);
} else if (item.id === 'modbus-tcp' || item.id === 'opc-ua') { } else if (item.id === 'modbus-tcp' || item.id === 'opc-ua' || item.id === 'collector-gateway') {
item.type = 'channel'; item.type = 'channel';
channel.push(item); channel.push(item);
} else if ( } else if (

View File

@ -45,6 +45,7 @@ BackMap.set('gb28181-2016', getImage('/access/gb28181.png'));
BackMap.set('mqtt-client-gateway', getImage('/access/mqtt-broke.png')); BackMap.set('mqtt-client-gateway', getImage('/access/mqtt-broke.png'));
BackMap.set('edge-child-device', getImage('/access/child-device.png')); BackMap.set('edge-child-device', getImage('/access/child-device.png'));
BackMap.set('official-edge-gateway', getImage('/access/edge.png')); BackMap.set('official-edge-gateway', getImage('/access/edge.png'));
BackMap.set('collector-gateway', getImage('/access/collector-gateway.png'));
const descriptionList = { const descriptionList = {
'udp-device-gateway': 'udp-device-gateway':