刘洋 hai 7 meses
pai
achega
aea3db97f4
Modificáronse 2 ficheiros con 34 adicións e 14 borrados
  1. 3 2
      src/render/ap/system.ts
  2. 31 12
      src/render/views/Login/IpSet.vue

+ 3 - 2
src/render/ap/system.ts

@@ -1,9 +1,10 @@
 import { request } from "@/utils/request";
 
-export const getServerStatus = () =>
+export const getServerStatus = (prefix = "") =>
   request({
-    url: "/api/sys/status",
+    url: prefix + "/api/sys/status",
     loading: true,
+    timeout: 5000,
   });
 
 export const adminLogin = (params: { loginName: string; password: string }) =>

+ 31 - 12
src/render/views/Login/IpSet.vue

@@ -32,14 +32,19 @@
             ref="input4"
           />
           <img class="maohao" src="../../assets/imgs/maohao.png" />
-          <a-input v-model:value="ipData.port" class="ip-num" ref="input5" />
+          <a-input
+            v-model:value="ipData.port"
+            class="ip-num"
+            ref="input5"
+            @input="checked = false"
+          />
         </div>
         <div class="pt-20px flex items-center">
-          <qm-button @click="checkClicked = true">验证</qm-button>
+          <qm-button @click="toCheck">验证</qm-button>
           <a-tag
             color="success"
             class="tag check-tag"
-            v-if="checkClicked && IPV4Single()"
+            v-if="checked && checkResult"
           >
             <template #icon>
               <check-circle-filled />
@@ -49,7 +54,7 @@
           <a-tag
             color="error"
             class="tag check-tag"
-            v-if="checkClicked && !IPV4Single()"
+            v-if="checked && !checkResult"
           >
             <template #icon>
               <close-circle-filled />
@@ -62,7 +67,7 @@
         <div class="text-right">
           <qm-button
             type="primary"
-            :disabled="!(checkClicked && IPV4Single())"
+            :disabled="!(checked && checkResult)"
             @click="nextStep"
             >下一步 <template #icon> <SwapRightOutlined /> </template
           ></qm-button>
@@ -81,7 +86,10 @@ import {
 } from "@ant-design/icons-vue";
 import FooterInfo from "@/components/FooterInfo/index.vue";
 import { local, session } from "@/utils/tool";
+import { getServerStatus } from "@/ap/system";
 
+const checked = ref(false);
+const checkResult = ref(false);
 const input2 = ref();
 const input3 = ref();
 const input4 = ref();
@@ -109,11 +117,11 @@ onMounted(() => {
   }
 });
 const changeFocus = (val: string, el: any) => {
+  checked.value = false;
   if (val?.length == 3) {
     el.focus();
   }
 };
-const checkClicked = ref(false);
 
 const IPV4Single = () => {
   const ipStr = `${ipData.ip1}.${ipData.ip2}.${ipData.ip3}.${ipData.ip4}:${ipData.port}`;
@@ -121,13 +129,24 @@ const IPV4Single = () => {
     /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?):\d{1,5}$/;
   return IPV4.test(ipStr);
 };
-
-// const showCheckResult = computed(() => {
-//   return checkClicked.value && !IPV4Single();
-// });
-
-const nextStep = () => {
+const toCheck = () => {
+  checked.value = true;
   if (IPV4Single()) {
+    getServerStatus(
+      `http://${ipData.ip1}.${ipData.ip2}.${ipData.ip3}.${ipData.ip4}:${ipData.port}`
+    )
+      .then(() => {
+        checkResult.value = true;
+      })
+      .catch(() => {
+        checkResult.value = false;
+      });
+  } else {
+    checkResult.value = false;
+  }
+};
+const nextStep = () => {
+  if (checked.value && checkResult.value) {
     local.set(
       "baseUrl",
       `http://${ipData.ip1}.${ipData.ip2}.${ipData.ip3}.${ipData.ip4}:${ipData.port}`