Commit 7bdcd41a3e730b960480f4ee34af06c91f9aca37

Authored by fengtao
1 parent d9b58acf

feat:设备列表新增TBox远程连接

@@ -17,6 +17,7 @@ enum EDeviceConfigApi { @@ -17,6 +17,7 @@ enum EDeviceConfigApi {
17 DEVICE_CONFIG_EXPORT = '/deviceProfile/export', 17 DEVICE_CONFIG_EXPORT = '/deviceProfile/export',
18 DEVICE_CONFIG_IMPORT = '/deviceProfile/import', 18 DEVICE_CONFIG_IMPORT = '/deviceProfile/import',
19 SET_DEVICE_ISDEFAULT = '/deviceProfile', 19 SET_DEVICE_ISDEFAULT = '/deviceProfile',
  20 + FRP_API = '/frp/',
20 } 21 }
21 22
22 /** 23 /**
@@ -114,3 +115,18 @@ export const setDeviceProfileIsDefaultApi = (id: string, v, params?: {}) => { @@ -114,3 +115,18 @@ export const setDeviceProfileIsDefaultApi = (id: string, v, params?: {}) => {
114 } 115 }
115 ); 116 );
116 }; 117 };
  118 +
  119 +/**
  120 + * Frp内网穿透信息API
  121 + */
  122 +export const frpGetInfoApi = (proxyName: string) => {
  123 + return defHttp.get({
  124 + url: `${EDeviceConfigApi.FRP_API}${proxyName}`,
  125 + });
  126 +};
  127 +
  128 +export const frpPutInfoApi = (proxyName: string, enableRemote: number) => {
  129 + return defHttp.put({
  130 + url: `${EDeviceConfigApi.FRP_API}${proxyName}/${enableRemote}`,
  131 + });
  132 +};
@@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
28 tab="TBox" 28 tab="TBox"
29 v-if="deviceDetail?.deviceType === 'GATEWAY' && deviceDetail?.brand == 'TBox'" 29 v-if="deviceDetail?.deviceType === 'GATEWAY' && deviceDetail?.brand == 'TBox'"
30 > 30 >
31 - <TBoxDetail /> 31 + <TBoxDetail :deviceDetail="deviceDetail" />
32 </TabPane> 32 </TabPane>
33 <!-- 网关设备并且是TBox --> 33 <!-- 网关设备并且是TBox -->
34 </Tabs> 34 </Tabs>
@@ -53,12 +53,6 @@ @@ -53,12 +53,6 @@
53 <a-button type="primary" class="mr-4" @click="copyTbDeviceId">复制设备ID</a-button> 53 <a-button type="primary" class="mr-4" @click="copyTbDeviceId">复制设备ID</a-button>
54 <a-button type="primary" class="mr-4" @click="copyDeviceToken">复制访问令牌</a-button> 54 <a-button type="primary" class="mr-4" @click="copyDeviceToken">复制访问令牌</a-button>
55 <a-button type="primary" class="mr-4" @click="manageDeviceToken">管理设备凭证</a-button> 55 <a-button type="primary" class="mr-4" @click="manageDeviceToken">管理设备凭证</a-button>
56 - <!-- <a-button  
57 - type="primary"  
58 - v-if="deviceDetail.deviceType == 'GATEWAY'"  
59 - @click="remoteConnectiondGateway"  
60 - >远程连接边缘网关</a-button  
61 - > -->  
62 <ManageDeviceTokenModal @register="registerModal" /> 56 <ManageDeviceTokenModal @register="registerModal" />
63 </div> 57 </div>
64 <div v-if="deviceDetail?.deviceInfo?.address" class="mt-4"> 58 <div v-if="deviceDetail?.deviceInfo?.address" class="mt-4">
1 <template> 1 <template>
2 - <div>TBox</div> 2 + <div>
  3 + <BasicTable @register="registerTable" :dataSource="tableData">
  4 + <template #status>
  5 + <Switch
  6 + checked-children="开"
  7 + un-checked-children="关"
  8 + v-model:checked="checked"
  9 + @change="handleChange"
  10 + />
  11 + </template>
  12 + </BasicTable>
  13 + <div style="margin-top: -54vh">
  14 + <a-button type="primary" class="mr-4" :disabled="disabled" @click="handleFrpRemote"
  15 + >远程连接</a-button
  16 + >
  17 + </div>
  18 + </div>
3 </template> 19 </template>
4 20
5 -<script setup lang="ts"></script> 21 +<script setup lang="ts">
  22 + import { ref, nextTick } from 'vue';
  23 + import { BasicTable, useTable, BasicColumn } from '/@/components/Table';
  24 + import { Switch } from 'ant-design-vue';
  25 + import { h } from 'vue';
  26 + import { Tag } from 'ant-design-vue';
  27 + import { frpGetInfoApi, frpPutInfoApi } from '/@/api/device/deviceConfigApi';
  28 + import { useMessage } from '/@/hooks/web/useMessage';
  29 +
  30 + const props = defineProps({
  31 + deviceDetail: {
  32 + type: Object,
  33 + required: true,
  34 + },
  35 + });
  36 +
  37 + const { createMessage } = useMessage();
  38 + const tableData: any = ref([]);
  39 + const checked = ref<boolean>(false);
  40 + const disabled = ref<boolean>(true);
  41 + const viewDeviceColumn: BasicColumn[] = [
  42 + {
  43 + title: 'Frp连接状态',
  44 + dataIndex: 'status',
  45 + width: 80,
  46 + customRender: ({ record }) => {
  47 + const status = record.status;
  48 + const color = status == 1 ? 'green' : 'red';
  49 + const text = status == 1 ? '在线' : '离线';
  50 + return h(Tag, { color }, () => text);
  51 + },
  52 + },
  53 + {
  54 + title: '远程连接',
  55 + dataIndex: 'enableRemote',
  56 + width: 80,
  57 + slots: { customRender: 'status' },
  58 + },
  59 + {
  60 + title: '设备SN',
  61 + dataIndex: 'proxyName',
  62 + width: 120,
  63 + },
  64 + ];
  65 + const [registerTable] = useTable({
  66 + title: 'TBox信息',
  67 + columns: viewDeviceColumn,
  68 + showIndexColumn: false,
  69 + clickToRowSelect: false,
  70 + showTableSetting: false,
  71 + bordered: true,
  72 + });
  73 + const enableRemote = ref(0);
  74 + const proxyName = ref('');
  75 + const remotePort = ref(0);
  76 + const address = ref('');
  77 + const getTableData = async () => {
  78 + const res = await frpGetInfoApi('1000000061664FF');
  79 + // const res = await frpGetInfoApi(props.deviceDetail.sn);
  80 + enableRemote.value = res.enableRemote;
  81 + proxyName.value = res.proxyName;
  82 + remotePort.value = res.remotePort;
  83 + address.value = res.address;
  84 + if (res.enableRemote == 1) {
  85 + checked.value = true;
  86 + disabled.value = false;
  87 + } else {
  88 + checked.value = false;
  89 + disabled.value = true;
  90 + }
  91 + tableData.value.push({
  92 + enableRemote: res.enableRemote,
  93 + proxyName: res.proxyName,
  94 + status: res.status,
  95 + });
  96 + };
  97 + const handleFrpRemote = async () => {
  98 + if (enableRemote.value == 1) {
  99 + window.open(`${address.value}`);
  100 + }
  101 + };
  102 + nextTick(() => {
  103 + getTableData();
  104 + });
  105 + const handleChange = async (e) => {
  106 + if (e) {
  107 + disabled.value = false;
  108 + enableRemote.value = 1;
  109 + const res = await frpPutInfoApi(proxyName.value, enableRemote.value);
  110 + if (res.enableRemote == 1) {
  111 + createMessage.success('开启成功');
  112 + getTableData();
  113 + }
  114 + } else {
  115 + disabled.value = true;
  116 + enableRemote.value = 0;
  117 + const res = await frpPutInfoApi(proxyName.value, enableRemote.value);
  118 + if (res.enableRemote == 0) {
  119 + createMessage.success('关闭成功');
  120 + getTableData();
  121 + }
  122 + }
  123 + };
  124 +</script>
6 <style lang="less" scoped></style> 125 <style lang="less" scoped></style>