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 1/4] 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 @@ + + + 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, + }, +] From e54b30a68316aa568480e2daf4a18c1941eb23f4 Mon Sep 17 00:00:00 2001 From: SunWuyuan <1847261658@qq.com> Date: Sun, 24 Nov 2024 09:32:05 +0800 Subject: [PATCH 2/4] 1 --- .env | 2 +- public/config.json | 27 +++++++++ src/components/AppHeader.vue | 15 +++++ src/components/ServerSelection.vue | 59 +++++++++++++++++++ src/pages/ServerSelection.vue | 37 ------------ src/pages/index.vue | 93 +++++++++++++++++++----------- src/router/index.js | 10 ---- 7 files changed, 160 insertions(+), 83 deletions(-) create mode 100644 public/config.json create mode 100644 src/components/AppHeader.vue create mode 100644 src/components/ServerSelection.vue delete mode 100644 src/pages/ServerSelection.vue diff --git a/.env b/.env index e6a9286..13cd355 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -VITE_BACKURL='http://localhost:3030' \ No newline at end of file +VITE_BACKURL='https://class1.wuyuan.dev' \ No newline at end of file diff --git a/public/config.json b/public/config.json new file mode 100644 index 0000000..d2b9fe4 --- /dev/null +++ b/public/config.json @@ -0,0 +1,27 @@ +{ + "studentList": [ + "张三", + "李四", + "王五", + "赵六", + "钱七" + ], + "homeworkArrange": [ + [ + "语文", + "数学", + "英语" + ], + [ + "物理", + "化学", + "生物" + ], + [ + "政治", + "历史", + "地理" + ] + ], + "url": "http://localhost:3030" +} \ No newline at end of file diff --git a/src/components/AppHeader.vue b/src/components/AppHeader.vue new file mode 100644 index 0000000..635511d --- /dev/null +++ b/src/components/AppHeader.vue @@ -0,0 +1,15 @@ + + + diff --git a/src/components/ServerSelection.vue b/src/components/ServerSelection.vue new file mode 100644 index 0000000..d099e8f --- /dev/null +++ b/src/components/ServerSelection.vue @@ -0,0 +1,59 @@ + + + diff --git a/src/pages/ServerSelection.vue b/src/pages/ServerSelection.vue deleted file mode 100644 index 3395290..0000000 --- a/src/pages/ServerSelection.vue +++ /dev/null @@ -1,37 +0,0 @@ - - - diff --git a/src/pages/index.vue b/src/pages/index.vue index dd39f90..5f6d412 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -1,11 +1,24 @@