feat: apply teacher ownership UI rules

dev-QQq
chenyuan 2 months ago
parent 9def91daf9
commit 1ed2258925

@ -441,6 +441,9 @@ export function updateStudent(data) {
url: "/api/user/updateStudent", url: "/api/user/updateStudent",
method: "POST", method: "POST",
data, data,
params: {
operatorId: data.operatorId,
},
}); });
} }
// 学生管理删除 // 学生管理删除
@ -471,7 +474,7 @@ export function getTaskList(query) {
} }
// 任务分配 // 任务分配
export function addTask(data) { export function addTask(data) {
let { taskAllocationList, classId, schoolId } = data; let { taskAllocationList, classId, schoolId, userId } = data;
return request({ return request({
url: "/api/taskAllocation/updateTaskAllocationByClassId", url: "/api/taskAllocation/updateTaskAllocationByClassId",
method: "POST", method: "POST",
@ -479,6 +482,7 @@ export function addTask(data) {
params: { params: {
classId, classId,
schoolId, schoolId,
userId,
}, },
}); });
} }
@ -537,7 +541,7 @@ export function doRankOne(params) {
// 教师端初始化学生密码 // 教师端初始化学生密码
export function initStudentPassword(params) { export function initStudentPassword(params) {
return request({ return request({
url: "/api/user/updateTeacherPassword", url: "/api/user/updateStudentPassword",
method: "POST", method: "POST",
params, params,
}); });

@ -52,6 +52,11 @@
> >
<el-table-column label="班级名称" prop="schoolClass.className" align="center"></el-table-column> <el-table-column label="班级名称" prop="schoolClass.className" align="center"></el-table-column>
<el-table-column label="班级编号" prop="schoolClass.classSn" align="center"></el-table-column> <el-table-column label="班级编号" prop="schoolClass.classSn" align="center"></el-table-column>
<el-table-column label="创建人" align="center">
<template #default="{ row }">
<span>{{ row.schoolClass.createdByName || row.schoolClass.createdBy || "-" }}</span>
</template>
</el-table-column>
<el-table-column label="创建日期" prop="schoolClass.createTime" align="center"> <el-table-column label="创建日期" prop="schoolClass.createTime" align="center">
<template #default="{ row }"> <template #default="{ row }">
<span>{{ formatDate(row.schoolClass.createTime) }}</span> <span>{{ formatDate(row.schoolClass.createTime) }}</span>
@ -59,9 +64,12 @@
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center"> <el-table-column label="操作" align="center">
<template #default="{ row }"> <template #default="{ row }">
<el-button type="primary" text @click="editSchool(row.schoolClass)"></el-button> <template v-if="canOperateClass(row.schoolClass)">
<el-button type="danger" text @click="delSchool(row.schoolClass.schoolClassId)"></el-button> <el-button type="primary" text @click="editSchool(row.schoolClass)"></el-button>
<el-button type="primary" text @click="handleSuccess(row)"></el-button> <el-button type="danger" text @click="delSchool(row.schoolClass.schoolClassId)"></el-button>
<el-button type="primary" text @click="handleSuccess(row)"></el-button>
</template>
<el-tag v-else type="info">仅查看</el-tag>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -101,6 +109,7 @@ import useUserStore from "@/store/modules/user";
import { ElMessageBox } from "element-plus"; import { ElMessageBox } from "element-plus";
const userStore = useUserStore(); const userStore = useUserStore();
const currentUserId = computed(() => userStore.userInfo.userId);
import * as indexApi from "@/api/teacher"; import * as indexApi from "@/api/teacher";
const dialogVisible = ref(false); const dialogVisible = ref(false);
const loading = ref(false); const loading = ref(false);
@ -158,6 +167,7 @@ const editSchool = (row) => {
}); });
}; };
const add = () => { const add = () => {
formInline.value.userId = currentUserId.value;
indexApi.addClass(formInline.value).then((res) => { indexApi.addClass(formInline.value).then((res) => {
proxy.$message.success("添加成功"); proxy.$message.success("添加成功");
dialogVisible.value = false; dialogVisible.value = false;
@ -166,7 +176,7 @@ const add = () => {
}; };
const edit = () => { const edit = () => {
formInline.value.schoolId = userStore.userInfo.schoolId; formInline.value.schoolId = userStore.userInfo.schoolId;
formInline.value.userId = userStore.userInfo.userId; formInline.value.userId = currentUserId.value;
formInline.value.status = true; formInline.value.status = true;
indexApi.updateClass(formInline.value).then((res) => { indexApi.updateClass(formInline.value).then((res) => {
proxy.$message.success("编辑成功"); proxy.$message.success("编辑成功");
@ -174,6 +184,9 @@ const edit = () => {
getList(); getList();
}); });
}; };
const canOperateClass = (schoolClass) => {
return schoolClass?.createdBy === currentUserId.value;
};
// //
const submitForm = () => { const submitForm = () => {
status.value ? add() : edit(); status.value ? add() : edit();

@ -29,7 +29,7 @@
<el-col> <el-col>
<div style="display: flex; gap: 10px"> <div style="display: flex; gap: 10px">
<el-button type="primary" :icon="Plus" @click="addschool"></el-button> <el-button type="primary" :icon="Plus" @click="addschool"></el-button>
<el-upload action="http://192.168.2.12:7548/api/user/uploadStudentUserInfo" :show-file-list="false" :on-success="(res, file) => handleSuccess(res, file)"> <el-upload action="/api/user/uploadStudentUserInfo" :data="{ userId: currentUserId }" :show-file-list="false" :on-success="(res, file) => handleSuccess(res, file)">
<el-button type="primary" @click="editSchool(row)"></el-button> <el-button type="primary" @click="editSchool(row)"></el-button>
</el-upload> </el-upload>
<el-button type="warning" @click="exportTeacher"></el-button> <el-button type="warning" @click="exportTeacher"></el-button>
@ -63,10 +63,13 @@
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" width="400"> <el-table-column label="操作" align="center" width="400">
<template #default="{ row }"> <template #default="{ row }">
<el-button type="info" text @click="editSchool(row)"></el-button> <template v-if="canOperateStudent(row)">
<el-button type="danger" text @click="delSchool(row)"></el-button> <el-button type="info" text @click="editSchool(row)"></el-button>
<el-button type="success" text @click="initPassword(row, 0)">密码初始化</el-button> <el-button type="danger" text @click="delSchool(row)"></el-button>
<el-button type="primary" text @click="initPassword(row, 1)">数据初始化</el-button> <el-button type="success" text @click="initPassword(row, 0)">密码初始化</el-button>
<el-button type="primary" text @click="initPassword(row, 1)">数据初始化</el-button>
</template>
<el-tag v-else type="info">仅查看</el-tag>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -120,6 +123,7 @@ import { ElMessageBox } from "element-plus";
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
import useUserStore from "@/store/modules/user"; import useUserStore from "@/store/modules/user";
const userStore = useUserStore(); const userStore = useUserStore();
const currentUserId = computed(() => userStore.userInfo.userId);
import * as indexApi from "@/api/teacher"; import * as indexApi from "@/api/teacher";
const dialogVisible = ref(false); const dialogVisible = ref(false);
const loading = ref(false); const loading = ref(false);
@ -161,7 +165,7 @@ const getList = () => {
}; };
// //
const delSchool = (id) => { const delSchool = (id) => {
indexApi.deleteStudent({ userId: id.userId }).then((res) => { indexApi.deleteStudent({ userId: id.userId, operatorId: currentUserId.value }).then((res) => {
proxy.$message.success("删除成功"); proxy.$message.success("删除成功");
getList(); getList();
}); });
@ -186,6 +190,7 @@ const editSchool = (row) => {
const add = () => { const add = () => {
formInline.value.schoolMajorName = majorList.value?.filter((item) => item.schoolMajorId == formInline.value.schoolMajorId)[0].schoolMajorName; formInline.value.schoolMajorName = majorList.value?.filter((item) => item.schoolMajorId == formInline.value.schoolMajorId)[0].schoolMajorName;
formInline.value.schoolClassName = classList1.value?.filter((item) => item.schoolClassId == formInline.value.schoolClassId)[0].className; formInline.value.schoolClassName = classList1.value?.filter((item) => item.schoolClassId == formInline.value.schoolClassId)[0].className;
formInline.value.userId = currentUserId.value;
indexApi.addStudent(formInline.value).then((res) => { indexApi.addStudent(formInline.value).then((res) => {
proxy.$message.success("添加成功"); proxy.$message.success("添加成功");
dialogVisible.value = false; dialogVisible.value = false;
@ -194,6 +199,7 @@ const add = () => {
}; };
const edit = () => { const edit = () => {
formInline.value.status = true; formInline.value.status = true;
formInline.value.operatorId = currentUserId.value;
indexApi.updateStudent(formInline.value).then((res) => { indexApi.updateStudent(formInline.value).then((res) => {
proxy.$message.success("编辑成功"); proxy.$message.success("编辑成功");
dialogVisible.value = false; dialogVisible.value = false;
@ -267,6 +273,12 @@ const downloadTemplate = () => {
}; };
// //
const classList = ref([]); const classList = ref([]);
const classOwnerMap = computed(() => {
return new Map(classList.value.map((item) => [item.schoolClassId, item.createdBy]));
});
const canOperateStudent = (row) => {
return classOwnerMap.value.get(row.schoolClassId) === currentUserId.value;
};
const getClassList = () => { const getClassList = () => {
indexApi.getClassListBySchoolId({ schoolId: userStore.userInfo.schoolId }).then((res) => { indexApi.getClassListBySchoolId({ schoolId: userStore.userInfo.schoolId }).then((res) => {
classList.value = res.data; classList.value = res.data;
@ -278,7 +290,7 @@ const getClassByMajor = () => {
if (!formInline.value.schoolMajorId) return; if (!formInline.value.schoolMajorId) return;
formInline.value.schoolClassId = ""; formInline.value.schoolClassId = "";
indexApi.getClassListByMajorId({ schoolMajorId: formInline.value.schoolMajorId }).then((res) => { indexApi.getClassListByMajorId({ schoolMajorId: formInline.value.schoolMajorId }).then((res) => {
classList1.value = res.data; classList1.value = (res.data || []).filter((item) => item.createdBy === currentUserId.value);
}); });
}; };
// //
@ -290,7 +302,7 @@ const initPassword = (row, status) => {
type: "warning", type: "warning",
}) })
.then(() => { .then(() => {
indexApi.initStudentPassword({ userId: row.userId }).then((res) => { indexApi.initStudentPassword({ userId: row.userId, operatorId: currentUserId.value }).then((res) => {
proxy.$message.success("密码初始化成功"); proxy.$message.success("密码初始化成功");
getList(); getList();
}); });

@ -22,7 +22,7 @@
@select="handleSelect" @select="handleSelect"
@select-all="handleSelectAll" @select-all="handleSelectAll"
> >
<el-table-column label="勾选" type="selection" width="100" align="center" :reserve-selection="true"></el-table-column> <el-table-column label="勾选" type="selection" width="100" align="center" :reserve-selection="true" :selectable="canSelectTask"></el-table-column>
<el-table-column label="实训任务" prop="module" align="center"></el-table-column> <el-table-column label="实训任务" prop="module" align="center"></el-table-column>
</el-table> </el-table>
</div> </div>
@ -39,11 +39,14 @@ const tableData = ref([]);
const loading = ref(false); const loading = ref(false);
const tableRef = ref(null); const tableRef = ref(null);
const classId = ref(""); const classId = ref("");
const currentUserId = computed(() => userStore.userInfo.userId);
const selectedClass = computed(() => classList.value.find((item) => item.schoolClassId === classId.value));
const canOperateSelectedClass = computed(() => selectedClass.value?.createdBy === currentUserId.value);
// //
const getClassList = () => { const getClassList = () => {
indexApi.getClassListBySchoolId({ schoolId: userStore.userInfo.schoolId }).then((res) => { indexApi.getClassListBySchoolId({ schoolId: userStore.userInfo.schoolId }).then((res) => {
classList.value = res.data; classList.value = res.data || [];
classId.value = classList.value[0].schoolClassId; classId.value = classList.value[0]?.schoolClassId || "";
getTaskList(); getTaskList();
}); });
}; };
@ -75,12 +78,14 @@ const setInitialSelection = () => {
// //
const handleSelect = async (selection, row) => { const handleSelect = async (selection, row) => {
if (isInitializing.value) return; // if (isInitializing.value) return; //
if (!canOperateSelectedClass.value) return;
row.disabledStatus = row.disabledStatus == 0 ? 1 : 0; row.disabledStatus = row.disabledStatus == 0 ? 1 : 0;
handleTaskDistribution(tableData.value); handleTaskDistribution(tableData.value);
}; };
// //
const handleSelectAll = async (selection) => { const handleSelectAll = async (selection) => {
if (isInitializing.value) return; // if (isInitializing.value) return; //
if (!canOperateSelectedClass.value) return;
const newStatus = selection.length > 0 ? 0 : 1; // 01 const newStatus = selection.length > 0 ? 0 : 1; // 01
try { try {
loading.value = true; loading.value = true;
@ -126,11 +131,12 @@ function findMissingItems(arr1, arr2) {
// //
const handleTaskDistribution = (selection) => { const handleTaskDistribution = (selection) => {
const uniqueUsers = [...new Map(selection.map((item) => [item.module, item])).values()]; const uniqueUsers = [...new Map(selection.map((item) => [item.module, item])).values()];
indexApi.addTask({ taskAllocationList: uniqueUsers, classId: classId.value, schoolId: userStore.userInfo.schoolId }).then((res) => { indexApi.addTask({ taskAllocationList: uniqueUsers, classId: classId.value, schoolId: userStore.userInfo.schoolId, userId: currentUserId.value }).then((res) => {
getTaskList(); getTaskList();
proxy.$modal.msgSuccess("分配成功"); proxy.$modal.msgSuccess("分配成功");
}); });
}; };
const canSelectTask = () => canOperateSelectedClass.value;
// //
onMounted(() => { onMounted(() => {
getClassList(); getClassList();

Loading…
Cancel
Save