mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2025-07-04 18:39:22 +00:00
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).
This commit is contained in:
parent
8c30232ece
commit
58e286d80b
37
src/pages/ServerSelection.vue
Normal file
37
src/pages/ServerSelection.vue
Normal file
@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<v-container>
|
||||
<v-form @submit.prevent="saveServerUrl">
|
||||
<v-text-field
|
||||
v-model="serverUrl"
|
||||
label="Backend Server URL"
|
||||
required
|
||||
/>
|
||||
<v-btn type="submit" color="primary">Save</v-btn>
|
||||
</v-form>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
serverUrl: ''
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
saveServerUrl() {
|
||||
localStorage.setItem('backendServerUrl', this.serverUrl);
|
||||
alert('Server URL saved!');
|
||||
},
|
||||
loadServerUrl() {
|
||||
const savedUrl = localStorage.getItem('backendServerUrl');
|
||||
if (savedUrl) {
|
||||
this.serverUrl = savedUrl;
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.loadServerUrl();
|
||||
}
|
||||
};
|
||||
</script>
|
@ -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;
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
@ -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,
|
||||
},
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user