|
@@ -1,25 +1,34 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { onMounted, reactive, ref } from 'vue';
|
|
|
+import { onMounted, ref, watch } from 'vue';
|
|
|
import { message } from 'ant-design-vue';
|
|
|
|
|
|
import { useRequest } from '@/hooks/request';
|
|
|
import { t } from '@/i18n';
|
|
|
-import { gatewayLinkAdd, gatewayLinkDelete, gatewayLinkGetList, getGatewayModelInterfaces } from '@/api';
|
|
|
+import {
|
|
|
+ gatewayLinkAdd,
|
|
|
+ gatewayLinkDelete,
|
|
|
+ gatewayLinkGetList,
|
|
|
+ obtainListInterfaces,
|
|
|
+ obtainListPhysicalInterfaces,
|
|
|
+} from '@/api';
|
|
|
|
|
|
import deviceInterface from '@/assets/img/device-interface.png';
|
|
|
|
|
|
import type {
|
|
|
- GatewayInterface,
|
|
|
InterfaceData,
|
|
|
- InterfaceList,
|
|
|
+ ListInterfaces,
|
|
|
+ ListPhysicalInterfaces,
|
|
|
RegisterGatewayForm,
|
|
|
UseGuideStepItemProps,
|
|
|
} from '@/types';
|
|
|
|
|
|
const props = defineProps<UseGuideStepItemProps<RegisterGatewayForm>>();
|
|
|
|
|
|
-let gatewayInterface: GatewayInterface[];
|
|
|
-const interfaceList = reactive<InterfaceList[]>([]);
|
|
|
+const currentStep = props.steps[props.stepIndex];
|
|
|
+
|
|
|
+const interfaceList = ref<ListInterfaces[]>([]);
|
|
|
+
|
|
|
+const listPhysicalInterfaces = ref<ListPhysicalInterfaces[]>([]);
|
|
|
|
|
|
const { handleRequest } = useRequest();
|
|
|
|
|
@@ -27,16 +36,28 @@ interface InterfaceStyle {
|
|
|
backgroundImage: string;
|
|
|
}
|
|
|
|
|
|
+interface LeftStyle {
|
|
|
+ left: string;
|
|
|
+}
|
|
|
+
|
|
|
// 定义一个响应式变量来存储样式对象
|
|
|
const interfaceStyle = ref<InterfaceStyle>({
|
|
|
backgroundImage: `url(${deviceInterface})`,
|
|
|
});
|
|
|
|
|
|
+const leftStyle = ref<LeftStyle>({
|
|
|
+ left: '229px',
|
|
|
+});
|
|
|
+
|
|
|
const interfaceData = ref<InterfaceData[]>([]);
|
|
|
|
|
|
const postGetList = () => {
|
|
|
handleRequest(async () => {
|
|
|
interfaceData.value = await gatewayLinkGetList(props.form.id);
|
|
|
+
|
|
|
+ if (interfaceData.value.length) {
|
|
|
+ currentStep.nextStepButtonDisabled = false;
|
|
|
+ }
|
|
|
});
|
|
|
};
|
|
|
|
|
@@ -47,22 +68,35 @@ const interfaceShow = (value: string) => {
|
|
|
|
|
|
// 添加接口列表
|
|
|
const addInterface = () => {
|
|
|
- if (props.form.linkType) {
|
|
|
- interfaceList.forEach((option) => {
|
|
|
- if (option.value === props.form.linkType) {
|
|
|
- handleRequest(async () => {
|
|
|
- await gatewayLinkAdd({
|
|
|
- linkTypeId: Number(option.value),
|
|
|
- linkName: option.label,
|
|
|
- gatewayId: props.form.id,
|
|
|
- });
|
|
|
- postGetList();
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- message.warning(t('registerGateway.pleaseSelectInterface'));
|
|
|
+ if (!props.form.interfaceId) {
|
|
|
+ return message.warning(t('registerGateway.pleaseSelectInterface'));
|
|
|
}
|
|
|
+
|
|
|
+ if (!props.form.protocolId) {
|
|
|
+ return message.warning(t('setupProtocol.plzSelectProtocolType'));
|
|
|
+ }
|
|
|
+
|
|
|
+ interfaceList.value.forEach((item) => {
|
|
|
+ if (item.id === props.form.protocolId) {
|
|
|
+ props.form.linkName = item.name;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ listPhysicalInterfaces.value.forEach((item) => {
|
|
|
+ if (item.id === props.form.interfaceId) {
|
|
|
+ props.form.protocolName = item.protocolName;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ handleRequest(async () => {
|
|
|
+ await gatewayLinkAdd({
|
|
|
+ interfaceId: props.form.interfaceId,
|
|
|
+ linkName: props.form.linkName,
|
|
|
+ gatewayId: props.form.id,
|
|
|
+ protocolType: props.form.protocolName,
|
|
|
+ });
|
|
|
+ postGetList();
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// 删除接口
|
|
@@ -73,17 +107,45 @@ const addDelete = (value: number) => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+const getListPhysicalInterfaces = (value: number) => {
|
|
|
+ handleRequest(async () => {
|
|
|
+ listPhysicalInterfaces.value = await obtainListPhysicalInterfaces(value);
|
|
|
+ if (listPhysicalInterfaces.value.length) {
|
|
|
+ props.form.protocolId = listPhysicalInterfaces.value[0].id;
|
|
|
+ } else {
|
|
|
+ props.form.protocolId = undefined;
|
|
|
+ }
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => props.form.interfaceId,
|
|
|
+ (count) => {
|
|
|
+ if (count) {
|
|
|
+ if (count === 3) {
|
|
|
+ leftStyle.value.left = '126px';
|
|
|
+ } else if (count === 4) {
|
|
|
+ leftStyle.value.left = '229px';
|
|
|
+ } else if (count === 1) {
|
|
|
+ leftStyle.value.left = '276px';
|
|
|
+ } else if (count === 2) {
|
|
|
+ leftStyle.value.left = '324px';
|
|
|
+ }
|
|
|
+ getListPhysicalInterfaces(count);
|
|
|
+ }
|
|
|
+ },
|
|
|
+);
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
handleRequest(async () => {
|
|
|
- gatewayInterface = await getGatewayModelInterfaces(props.form.modelId);
|
|
|
- gatewayInterface.forEach((item) => {
|
|
|
- interfaceList.push({
|
|
|
- value: String(item.id),
|
|
|
- label: item.dictValue,
|
|
|
- });
|
|
|
- });
|
|
|
+ interfaceList.value = await obtainListInterfaces(props.form.modelId);
|
|
|
+ if (interfaceList.value.length) {
|
|
|
+ props.form.interfaceId = interfaceList.value[0].id;
|
|
|
+ leftStyle.value.left = '126px';
|
|
|
+ getListPhysicalInterfaces(interfaceList.value[0].id);
|
|
|
+ }
|
|
|
+ postGetList();
|
|
|
});
|
|
|
- postGetList();
|
|
|
});
|
|
|
</script>
|
|
|
|
|
@@ -92,19 +154,33 @@ onMounted(() => {
|
|
|
<div class="use-guide-title">{{ $t('registerGateway.addInterface') }}</div>
|
|
|
<div class="use-guide-description">文本描述!!!</div>
|
|
|
|
|
|
- <AFormItem :label="$t('registerGateway.selectInterface')" name="linkType">
|
|
|
+ <AFormItem :label="$t('registerGateway.selectInterface')">
|
|
|
<ASelect
|
|
|
size="large"
|
|
|
ref="select"
|
|
|
- v-model:value="form.linkType"
|
|
|
+ v-model:value="form.interfaceId"
|
|
|
+ style="margin-left: 37px"
|
|
|
class="interface-select"
|
|
|
:options="interfaceList"
|
|
|
+ :field-names="{ label: 'name', value: 'id' }"
|
|
|
/>
|
|
|
- <AButton class="dev-but" type="primary" @click="addInterface">{{ $t('common.add') }}</AButton>
|
|
|
</AFormItem>
|
|
|
|
|
|
+ <AFormItem :label="$t('registerGateway.selectProtocolParameters')">
|
|
|
+ <ASelect
|
|
|
+ size="large"
|
|
|
+ ref="select"
|
|
|
+ v-model:value="form.protocolId"
|
|
|
+ class="interface-select"
|
|
|
+ :field-names="{ label: 'protocolName', value: 'id' }"
|
|
|
+ :options="listPhysicalInterfaces"
|
|
|
+ />
|
|
|
+ </AFormItem>
|
|
|
+
|
|
|
+ <AButton class="dev-but" type="primary" @click="addInterface">{{ $t('common.add') }}</AButton>
|
|
|
+
|
|
|
<div :style="interfaceStyle" class="interface-img">
|
|
|
- <div class="interface-bgc"></div>
|
|
|
+ <div v-if="form.interfaceId" class="interface-bgc" :style="leftStyle"></div>
|
|
|
</div>
|
|
|
<div class="use-guide-title">{{ $t('registerGateway.interfaceList') }}</div>
|
|
|
<div class="interface-container main-container">
|
|
@@ -112,14 +188,15 @@ onMounted(() => {
|
|
|
<ARow style="width: 100%">
|
|
|
<ACol :span="14">
|
|
|
<AFlex justify="flex-start" align="center">
|
|
|
- <AFlex class="interface-div1" :style="interfaceShow(item.valueType)" justify="center" align="center">
|
|
|
- <span class="interface-div1-span">{{ item.valueType }}</span>
|
|
|
+ <AFlex class="interface-div1" :style="interfaceShow(item.interfaceType)" justify="center" align="center">
|
|
|
+ <span class="interface-div1-span">{{ item.interfaceType }}</span>
|
|
|
</AFlex>
|
|
|
<div class="interface-div2">{{ item.linkName }}</div>
|
|
|
</AFlex>
|
|
|
</ACol>
|
|
|
<ACol :span="10">
|
|
|
- <AFlex justify="flex-end" align="center">
|
|
|
+ <AFlex justify="space-between" align="center">
|
|
|
+ <div class="interface-div2" style="margin-top: 6px; margin-right: 17px">{{ item.protocolType }}</div>
|
|
|
<AButton class="interface-but" type="link" danger @click="addDelete(item.id)">{{
|
|
|
$t('common.delete')
|
|
|
}}</AButton>
|
|
@@ -141,13 +218,12 @@ onMounted(() => {
|
|
|
|
|
|
.interface-select {
|
|
|
width: 240px;
|
|
|
- margin-left: 15px;
|
|
|
+ margin-left: 10px;
|
|
|
}
|
|
|
|
|
|
.interface-bgc {
|
|
|
position: relative;
|
|
|
top: 66px;
|
|
|
- left: 229px;
|
|
|
width: 53px;
|
|
|
height: 53px;
|
|
|
background-color: rgb(82 196 26 / 35%);
|