From 58e286d80b77d19740b1edd901cebfa50e535237 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AD=99=E6=82=9F=E5=85=83?=
<88357633+SunWuyuan@users.noreply.github.com>
Date: Sun, 24 Nov 2024 08:55:05 +0800
Subject: [PATCH] Add server selection page
Add a new page for server selection and update backend URL handling.
* **ServerSelection.vue**: Create a new Vue component with a form to input and save the backend server URL to `localStorage`. Add methods to handle form submission and load the saved URL on component mount.
* **index.vue**: Update the `data` method to retrieve the backend URL from `localStorage`. Remove the hardcoded `backurl` value. Add a method to update the backend URL from `localStorage` on component mount. Update API requests to use the dynamic backend URL.
* **router/index.js**: Add a new route for the `ServerSelection` component.
---
For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/SunWuyuan/homeworkpage-frontend?shareId=XXXX-XXXX-XXXX-XXXX).
---
src/pages/ServerSelection.vue | 37 +++++++++++++++++++++++++++++++++++
src/pages/index.vue | 10 +++++++++-
src/router/index.js | 10 ++++++++++
3 files changed, 56 insertions(+), 1 deletion(-)
create mode 100644 src/pages/ServerSelection.vue
diff --git a/src/pages/ServerSelection.vue b/src/pages/ServerSelection.vue
new file mode 100644
index 0000000..3395290
--- /dev/null
+++ b/src/pages/ServerSelection.vue
@@ -0,0 +1,37 @@
+
+
+
+
+ Save
+
+
+
+
+
diff --git a/src/pages/index.vue b/src/pages/index.vue
index ff9e979..dd39f90 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -133,7 +133,7 @@ export default {
data() {
return {
- backurl: import.meta.env.VITE_BACKURL,
+ backurl: localStorage.getItem('backendServerUrl') || '',
currentEditSubject: null,
studentList: ["加载中"],
selectedSet: new Set(),
@@ -162,6 +162,7 @@ export default {
async mounted() {
try {
+ this.updateBackendUrl();
await this.initializeData();
} catch (err) {
console.error("初始化失败:", err);
@@ -344,6 +345,13 @@ export default {
this.selectedSet = new Set(res.data.attendance || []);
this.synced = true;
},
+
+ updateBackendUrl() {
+ const savedUrl = localStorage.getItem('backendServerUrl');
+ if (savedUrl) {
+ this.backurl = savedUrl;
+ }
+ },
},
};
diff --git a/src/router/index.js b/src/router/index.js
index 5d4b8bc..4a28343 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -34,3 +34,13 @@ router.isReady().then(() => {
})
export default router
+
+import ServerSelection from '@/pages/ServerSelection.vue'
+
+const routes = [
+ {
+ path: '/server-selection',
+ name: 'ServerSelection',
+ component: ServerSelection,
+ },
+]