首次提交
This commit is contained in:
@@ -6,11 +6,20 @@
|
||||
>
|
||||
<v-card-item>
|
||||
<template #prepend>
|
||||
<v-icon class="mr-2" icon="mdi-account-tie" size="large"/>
|
||||
<v-icon
|
||||
class="mr-2"
|
||||
icon="mdi-account-tie"
|
||||
size="large"
|
||||
/>
|
||||
</template>
|
||||
<v-card-title class="text-h6">教师列表</v-card-title>
|
||||
<v-card-title class="text-h6">
|
||||
教师列表
|
||||
</v-card-title>
|
||||
<template #append>
|
||||
<unsaved-warning :show="unsavedChanges" message="有未保存的更改"/>
|
||||
<unsaved-warning
|
||||
:show="unsavedChanges"
|
||||
message="有未保存的更改"
|
||||
/>
|
||||
<v-btn
|
||||
:color="modelValue.advanced ? 'primary' : undefined"
|
||||
prepend-icon="mdi-code-braces"
|
||||
@@ -30,7 +39,13 @@
|
||||
indeterminate
|
||||
/>
|
||||
|
||||
<v-alert v-if="error" class="mb-4" closable type="error" variant="tonal">
|
||||
<v-alert
|
||||
v-if="error"
|
||||
class="mb-4"
|
||||
closable
|
||||
type="error"
|
||||
variant="tonal"
|
||||
>
|
||||
{{ error }}
|
||||
</v-alert>
|
||||
|
||||
@@ -38,10 +53,16 @@
|
||||
<!-- 普通编辑模式 -->
|
||||
<div v-if="!modelValue.advanced">
|
||||
<!-- 添加教师表单 -->
|
||||
<v-card class="mb-6" variant="outlined">
|
||||
<v-card
|
||||
class="mb-6"
|
||||
variant="outlined"
|
||||
>
|
||||
<v-card-text>
|
||||
<v-row>
|
||||
<v-col cols="12" md="4">
|
||||
<v-col
|
||||
cols="12"
|
||||
md="4"
|
||||
>
|
||||
<v-text-field
|
||||
v-model="newTeacher.name"
|
||||
density="comfortable"
|
||||
@@ -52,7 +73,10 @@
|
||||
variant="outlined"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="12" md="5">
|
||||
<v-col
|
||||
cols="12"
|
||||
md="5"
|
||||
>
|
||||
<v-combobox
|
||||
v-model="newTeacher.subjects"
|
||||
:items="commonSubjects"
|
||||
@@ -68,7 +92,11 @@
|
||||
variant="outlined"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="12" md="3" class="d-flex align-center gap-2">
|
||||
<v-col
|
||||
cols="12"
|
||||
md="3"
|
||||
class="d-flex align-center gap-2"
|
||||
>
|
||||
<v-checkbox
|
||||
v-model="newTeacher.isHeadTeacher"
|
||||
density="comfortable"
|
||||
@@ -91,7 +119,10 @@
|
||||
<!-- 教师列表 -->
|
||||
<v-row v-if="modelValue.list.length === 0">
|
||||
<v-col cols="12">
|
||||
<v-alert type="info" variant="tonal">
|
||||
<v-alert
|
||||
type="info"
|
||||
variant="tonal"
|
||||
>
|
||||
暂无教师信息,请添加教师
|
||||
</v-alert>
|
||||
</v-col>
|
||||
@@ -155,7 +186,10 @@
|
||||
</v-chip>
|
||||
</div>
|
||||
|
||||
<div v-if="editState.index === index" class="mt-2">
|
||||
<div
|
||||
v-if="editState.index === index"
|
||||
class="mt-2"
|
||||
>
|
||||
<v-combobox
|
||||
v-model="editState.teacher.subjects"
|
||||
:items="commonSubjects"
|
||||
@@ -175,7 +209,10 @@
|
||||
label="班主任"
|
||||
/>
|
||||
</div>
|
||||
<div v-else class="mt-1">
|
||||
<div
|
||||
v-else
|
||||
class="mt-1"
|
||||
>
|
||||
<v-chip
|
||||
v-for="(subject, sIndex) in teacher.subjects"
|
||||
:key="sIndex"
|
||||
@@ -235,13 +272,16 @@
|
||||
</div>
|
||||
|
||||
<!-- 高级编辑模式 -->
|
||||
<div v-else class="pt-2">
|
||||
<div
|
||||
v-else
|
||||
class="pt-2"
|
||||
>
|
||||
<v-textarea
|
||||
v-model="modelValue.text"
|
||||
hint="JSON 格式编辑教师列表。每个教师需包含 name、subjects(数组)、isHeadTeacher(布尔值)"
|
||||
label="批量编辑教师列表 (JSON)"
|
||||
persistent-hint
|
||||
placeholder='[{"name":"教师姓名","subjects":["语文","数学"],"isHeadTeacher":true}]'
|
||||
placeholder="[{"name":"教师姓名","subjects":["语文","数学"],"isHeadTeacher":true}]"
|
||||
rows="15"
|
||||
variant="outlined"
|
||||
@update:model-value="handleTextInput"
|
||||
@@ -250,7 +290,10 @@
|
||||
</v-expand-transition>
|
||||
|
||||
<v-row class="mt-6">
|
||||
<v-col class="d-flex gap-2" cols="12">
|
||||
<v-col
|
||||
class="d-flex gap-2"
|
||||
cols="12"
|
||||
>
|
||||
<v-btn
|
||||
:disabled="loading"
|
||||
:loading="loading"
|
||||
@@ -282,7 +325,6 @@
|
||||
import UnsavedWarning from "../common/UnsavedWarning.vue";
|
||||
import "@/styles/warnings.scss";
|
||||
import dataProvider from "@/utils/dataProvider";
|
||||
import {getSetting} from "@/utils/settings";
|
||||
|
||||
export default {
|
||||
name: "TeacherListCard",
|
||||
@@ -354,17 +396,15 @@ export default {
|
||||
this.error = null;
|
||||
try {
|
||||
this.loading = true;
|
||||
const classNum = getSetting("server.classNumber");
|
||||
|
||||
if (!classNum) {
|
||||
throw new Error("请先设置班号");
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await dataProvider.loadData("classworks-list-teacher");
|
||||
console.log("loadTeachers response:", response);
|
||||
|
||||
if (response.success !== false && Array.isArray(response)) {
|
||||
this.modelValue.list = response.map((item) => ({
|
||||
// 兼容返回数组或包含 value 属性的对象
|
||||
const dataArray = Array.isArray(response) ? response : (response && Array.isArray(response.value) ? response.value : null);
|
||||
|
||||
if (response.success != false && dataArray) {
|
||||
this.modelValue.list = dataArray.map((item) => ({
|
||||
name: item.name || "",
|
||||
subjects: Array.isArray(item.subjects) ? item.subjects : [],
|
||||
isHeadTeacher: Boolean(item.isHeadTeacher),
|
||||
@@ -391,12 +431,7 @@ export default {
|
||||
|
||||
async saveTeachers() {
|
||||
try {
|
||||
const classNum = getSetting("server.classNumber");
|
||||
|
||||
if (!classNum) {
|
||||
throw new Error("请先设置班号");
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
const formattedList = this.modelValue.list.map((teacher) => ({
|
||||
name: teacher.name,
|
||||
subjects: Array.isArray(teacher.subjects) ? teacher.subjects : [],
|
||||
@@ -419,6 +454,8 @@ export default {
|
||||
} catch (error) {
|
||||
console.error("保存教师列表失败:", error);
|
||||
this.$message?.error("保存失败", error.message || "请重试");
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -476,16 +513,17 @@ export default {
|
||||
},
|
||||
|
||||
startEdit(index, teacher) {
|
||||
if (this._editTimeout) clearTimeout(this._editTimeout);
|
||||
this.editState.index = index;
|
||||
// 深度拷贝以防直接修改原对象
|
||||
this.editState.teacher = {
|
||||
name: teacher.name,
|
||||
subjects: [...teacher.subjects],
|
||||
isHeadTeacher: teacher.isHeadTeacher,
|
||||
...teacher,
|
||||
subjects: [...(teacher.subjects || [])],
|
||||
};
|
||||
},
|
||||
|
||||
saveEdit() {
|
||||
if (this.editState.index !== -1) {
|
||||
if (this.editState.index !== -1 && this.editState.teacher) {
|
||||
const newName = this.editState.teacher.name.trim();
|
||||
if (!newName) {
|
||||
this.$message?.warning("提示", "教师姓名不能为空");
|
||||
@@ -502,8 +540,12 @@ export default {
|
||||
isHeadTeacher: this.editState.teacher.isHeadTeacher,
|
||||
};
|
||||
|
||||
this.editState.index = -1;
|
||||
this.editState.teacher = null;
|
||||
// 延迟重置状态,防止DOM突变导致丢失按钮点击事件
|
||||
if (this._editTimeout) clearTimeout(this._editTimeout);
|
||||
this._editTimeout = setTimeout(() => {
|
||||
this.editState.index = -1;
|
||||
this.editState.teacher = null;
|
||||
}, 200);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user