|
@@ -4,6 +4,9 @@ import "element-plus/dist/index.css";
|
|
|
import App from "./App.vue";
|
|
|
import router from "./pages/main/router";
|
|
|
import { createPinia } from "pinia";
|
|
|
+import { storeToRefs } from "pinia";
|
|
|
+import { useServerIpStore } from "./store/ServerIp";
|
|
|
+import { useServerPortStore } from "./store/ServerPort";
|
|
|
|
|
|
const app = createApp(App);
|
|
|
const pinia = createPinia();
|
|
@@ -12,3 +15,50 @@ app.use(pinia);
|
|
|
app.use(ElementPlus);
|
|
|
app.use(router);
|
|
|
app.mount("#app");
|
|
|
+
|
|
|
+const si = useServerIpStore();
|
|
|
+const { server_ip } = storeToRefs(si);
|
|
|
+const sp = useServerPortStore();
|
|
|
+const { server_port } = storeToRefs(sp);
|
|
|
+
|
|
|
+const xhr = new XMLHttpRequest();
|
|
|
+xhr.open("GET", window.location.href);
|
|
|
+xhr.onreadystatechange = function () {
|
|
|
+ if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
|
+ if (xhr.status === 200) {
|
|
|
+ const headers = xhr.getAllResponseHeaders();
|
|
|
+ let portRegExp: RegExp = /port:\s*(\d+)/i;
|
|
|
+ let matchResult: RegExpExecArray | null = portRegExp.exec(headers);
|
|
|
+ if (matchResult) {
|
|
|
+ let portValue: string = matchResult[1];
|
|
|
+ server_port.value = ":" + portValue;
|
|
|
+
|
|
|
+ // console.log(`当前端口为:${server_port.value}`);
|
|
|
+ // console.log(`当前ip为:${server_ip.value}`);
|
|
|
+ }
|
|
|
+ // const port = headers.match(/port: (\d+)/i)[1];
|
|
|
+ // console.log("Port:", headers);
|
|
|
+ } else {
|
|
|
+ console.error("There was a problem with the request.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+xhr.send();
|
|
|
+
|
|
|
+// fetch(window.location.href)
|
|
|
+// .then((response) => {
|
|
|
+// if (!response.ok) {
|
|
|
+// throw new Error("Network response was not ok");
|
|
|
+// }
|
|
|
+// const headers = response.headers;
|
|
|
+// const port = headers.get("port");
|
|
|
+// console.log("headers:", headers);
|
|
|
+
|
|
|
+// server_port.value = port ? ":" + port : ":7896";
|
|
|
+
|
|
|
+// console.log(`当前端口为:${server_port.value}`);
|
|
|
+// console.log(`当前ip为:${server_ip.value}`);
|
|
|
+// })
|
|
|
+// .catch((error) => {
|
|
|
+// console.error("There was a problem with the fetch operation: ", error);
|
|
|
+// });
|