diff --git a/src/pages/settings.vue b/src/pages/settings.vue index 105c981..9c7e1b3 100644 --- a/src/pages/settings.vue +++ b/src/pages/settings.vue @@ -32,10 +32,99 @@ - 云端学生列表设置 + + 学生列表设置 + + + {{ showAdvancedEdit ? '基础编辑' : '高级编辑' }} + + + - - 保存 + +
+ + + + + + + + + + + + + {{ index + 1 }}. + {{ student }} + + + + + +
+
+ + +
+ +
+
+ + + + + 保存 + + + 重置 + + +
@@ -189,6 +278,8 @@ export default { fontSize: '28', autoSave: false, refreshBeforeEdit: false, + showAdvancedEdit: false, + newStudent: '', }; }, @@ -196,6 +287,21 @@ export default { this.loadSettings(); }, + watch: { + students: { + handler(newVal) { + this.studentsList = newVal.split('\n').filter(s => s.trim()); + }, + immediate: true + }, + studentsList: { + handler(newVal) { + this.students = newVal.join('\n'); + }, + deep: true + } + }, + methods: { loadSettings() { const savedDomain = localStorage.getItem('backendServerDomain'); @@ -210,6 +316,7 @@ export default { if (localStorage.getItem('studentList')) { this.students = localStorage.getItem('studentList').replace(/,/g, '\n'); + this.studentsList = this.students.split('\n').filter(s => s.trim()); } this.autoRefresh = localStorage.getItem('autoRefresh') === 'true'; @@ -252,16 +359,23 @@ export default { async saveStudents() { try { - this.studentsList = this.students.split('\n'); - await axios.put(`${this.serverDomain}/students`, { + const domain = localStorage.getItem('backendServerDomain'); + const classNum = localStorage.getItem('classNumber'); + + if (!domain || !classNum) { + throw new Error('请先设置服务器域名和班号'); + } + + await axios.put(`${domain}/${classNum}/students`, { studentList: this.studentsList, id: 1, }); - localStorage.setItem('studentList', this.students); + + localStorage.setItem('studentList', this.studentsList.join(',')); this.showMessage('保存成功'); } catch (error) { console.error(error); - this.showMessage('保存失败,请检查学生列表'); + this.showMessage(error.message || '保存失败,请检查服务器设置和学生列表'); } }, @@ -303,6 +417,28 @@ export default { ); }, + addStudent() { + const student = this.newStudent.trim(); + if (student && !this.studentsList.includes(student)) { + this.studentsList.push(student); + this.newStudent = ''; + } + }, + + removeStudent(index) { + this.studentsList.splice(index, 1); + }, + + reloadStudentList() { + const savedList = localStorage.getItem('studentList'); + if (savedList) { + this.students = savedList.replace(/,/g, '\n'); + } else { + this.students = ''; + this.studentsList = []; + } + }, + showMessage(text) { this.snackbarText = text; this.snackbar = true; @@ -312,6 +448,14 @@ export default {