diff --git a/src/api/teacher.js b/src/api/teacher.js index 3060c6c..db7da83 100644 --- a/src/api/teacher.js +++ b/src/api/teacher.js @@ -635,6 +635,12 @@ export function getOwnedTeachingClasses() { method: "get", }); } +export function getAccessibleTeachingClasses() { + return request({ + url: "/api/weight/accessibleTeachingClasses", + method: "get", + }); +} export function getTeachingClassWeight(teachingClassId) { return request({ url: "/api/weight/selectTeachingClassWeight", @@ -693,7 +699,7 @@ export function getScoreDetail(params) { params, }); } -// 保存老师对学生的人工评分 +// 保存班级创建教师对学生的人工评分 export function saveTeacherScore(params) { return request({ url: "/api/weight/saveTeacherScore", diff --git a/src/views/teacherEnd/score/index.vue b/src/views/teacherEnd/score/index.vue index 59621f1..937f030 100644 --- a/src/views/teacherEnd/score/index.vue +++ b/src/views/teacherEnd/score/index.vue @@ -28,14 +28,18 @@ - + - 导出 - 权重设置 - 成绩更新 + 导出 + + 权重设置 + + + 成绩更新 +
@@ -48,7 +52,7 @@ @@ -163,9 +171,12 @@ import * as indexApi from "@/api/teacher"; const { proxy } = getCurrentInstance(); import useUserStore from "@/store/modules/user"; const userStore = useUserStore(); +const currentUserId = computed(() => String(userStore.userInfo.userId || "")); const workingCapitalList = ref([]); const loading = ref(false); const savingScoreUserId = ref(""); +const classList = ref([]); +const teachingClassList = computed(() => classList.value.filter((item) => item.classType === "TEACHING")); const scoreParams = ref({ classId: "", index: 1, @@ -183,6 +194,17 @@ const WeightStart = ref(false); // 权重 const workingCapitalTotal = ref(0); const scoreWeightObj = ref({}); +const selectedTeachingClass = computed(() => teachingClassList.value.find( + (item) => item.schoolClassId === scoreParams.value.classId +)); +const canManageSelectedClass = computed(() => + Boolean(selectedTeachingClass.value) + && String(selectedTeachingClass.value.createdBy || "") === currentUserId.value +); +const classActionHint = computed(() => canManageSelectedClass.value + ? "" + : "权重设置和成绩更新仅限班级创建老师操作" +); const formatTrainingProgress = (row) => { if (row.trainingProgress === null || row.trainingProgress === undefined) return "--"; const percentage = Number(row.trainingProgress); @@ -214,6 +236,11 @@ const buildScoreQuery = () => { }; }; const getList = () => { + if (!scoreParams.value.classId) { + workingCapitalList.value = []; + workingCapitalTotal.value = 0; + return; + } loading.value = true; indexApi.getScoreList(buildScoreQuery()).then((res) => { workingCapitalList.value = (res.data.list || []).map((row) => ({ @@ -223,8 +250,7 @@ const getList = () => { : Number(row.teacherScore), })); workingCapitalTotal.value = res.data.total; - loading.value = false; - }); + }).finally(() => (loading.value = false)); }; const scoreweight = () => { if (!scoreParams.value.classId) { @@ -257,17 +283,32 @@ const workingCapitalWeightHandle = () => { } }); }; -const classList = ref([]); -const teachingClassList = computed(() => classList.value.filter((item) => item.classType === "TEACHING")); -const getClassList = () => { - indexApi.getOwnedTeachingClasses().then((res) => { - classList.value = res.data; +const getClassList = async () => { + try { + const res = await indexApi.getAccessibleTeachingClasses(); + classList.value = res.data || []; if (scoreParams.value.classId && !teachingClassList.value.some((item) => item.schoolClassId === scoreParams.value.classId)) { scoreParams.value.classId = ""; } - }); + if (!scoreParams.value.classId) { + const ownClass = teachingClassList.value.find((item) => String(item.createdBy || "") === currentUserId.value); + scoreParams.value.classId = (ownClass || teachingClassList.value[0])?.schoolClassId || ""; + } + getList(); + } catch (error) { + workingCapitalList.value = []; + workingCapitalTotal.value = 0; + } +}; +const handleClassChange = () => { + scoreParams.value.index = 1; + getList(); }; const exportExcel = () => { + if (!scoreParams.value.classId) { + proxy.$modal.msgWarning("请选择教学班后再导出成绩"); + return; + } const { index, size, ...query } = buildScoreQuery(); indexApi.exportScoreList(query).then((res) => { // 打开怎么是空的 @@ -282,7 +323,7 @@ const exportExcel = () => { }; const getClassScoreDetail = (row) => { if (!scoreParams.value.classId) { - proxy.$modal.msgWarning("请选择自己的教学班后再查看成绩详情"); + proxy.$modal.msgWarning("请选择教学班后再查看成绩详情"); return; } scoreDetailStudent.value = { @@ -335,7 +376,6 @@ const updateScore = () => { }; // 拿到当前路由信息 onMounted(() => { - getList(); getClassList(); }); @@ -380,4 +420,23 @@ onMounted(() => { font-variant-numeric: tabular-nums; } } + +.teacher-score-readonly { + display: inline-flex; + align-items: center; + gap: 8px; + + strong { + color: #63dcff; + font-size: 16px; + font-variant-numeric: tabular-nums; + } + + small { + padding: 2px 7px; + color: rgba(190, 218, 231, 0.68); + border: 1px solid rgba(96, 172, 207, 0.28); + border-radius: 999px; + } +} diff --git a/tests/score-center-class-access-teacher-score.static.test.cjs b/tests/score-center-class-access-teacher-score.static.test.cjs new file mode 100644 index 0000000..eb7c868 --- /dev/null +++ b/tests/score-center-class-access-teacher-score.static.test.cjs @@ -0,0 +1,21 @@ +const assert = require("node:assert/strict"); +const fs = require("node:fs"); +const path = require("node:path"); + +const root = path.resolve(__dirname, ".."); +const page = fs.readFileSync(path.join(root, "src/views/teacherEnd/score/index.vue"), "utf8"); +const api = fs.readFileSync(path.join(root, "src/api/teacher.js"), "utf8"); + +assert.match(page, /label="老师评分"/); +assert.match(page, /teacherScoreDraft/); +assert.match(page, /canManageSelectedClass/); +assert.match(page, /createdBy/); +assert.match(page, /saveTeacherScore/); +assert.match(page, /老师评分必须为0至100之间的数值/); +assert.match(page, /ownClass \|\| teachingClassList\.value\[0\]/); +assert.match(page, /getAccessibleTeachingClasses/); +assert.doesNotMatch(page, /onMounted\(\(\) => \{\s*getList\(\);\s*getClassList/); +assert.match(api, /url: "\/api\/weight\/saveTeacherScore"/); +assert.match(api, /url: "\/api\/weight\/accessibleTeachingClasses"/); + +console.log("score center class access and teacher score contract passed"); diff --git a/tests/teacher-score-scope.static.test.cjs b/tests/teacher-score-scope.static.test.cjs index e5f4f9b..21b71f7 100644 --- a/tests/teacher-score-scope.static.test.cjs +++ b/tests/teacher-score-scope.static.test.cjs @@ -8,7 +8,7 @@ const api = fs.readFileSync('src/api/teacher.js', 'utf8'); assert(api.includes('/api/weight/ownedTeachingClasses')); assert(api.includes('/api/weight/selectTeachingClassWeight')); assert(api.includes('/api/weight/updateTeachingClassWeight')); -assert(page.includes('getOwnedTeachingClasses')); +assert(page.includes('getAccessibleTeachingClasses')); assert(page.includes('互联网产品开发基础认知')); assert(page.includes('市场洞察与需求分析')); assert(page.includes('产品规划与设计'));