|
|
|
|
|
<template>
|
|
|
|
|
|
<div class="task app-container">
|
|
|
|
|
|
<div class="online">
|
|
|
|
|
|
<span>班级:</span>
|
|
|
|
|
|
<el-select placeholder="" v-model="classId" clearable class="ml10" @change="getTaskList">
|
|
|
|
|
|
<el-option v-for="school in classList" :key="school.schoolClassId" :label="school.className" :value="school.schoolClassId" />
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-table
|
|
|
|
|
|
:data="tableData"
|
|
|
|
|
|
border
|
|
|
|
|
|
v-loading="loading"
|
|
|
|
|
|
style="width: 80%; margin-top: 20px"
|
|
|
|
|
|
height="600"
|
|
|
|
|
|
ref="tableRef"
|
|
|
|
|
|
:header-cell-style="{
|
|
|
|
|
|
color: '#fff',
|
|
|
|
|
|
fontSize: '14px',
|
|
|
|
|
|
backgroundColor: '#6A7DE9!important',
|
|
|
|
|
|
}"
|
|
|
|
|
|
row-key="id"
|
|
|
|
|
|
@select="handleSelect"
|
|
|
|
|
|
@select-all="handleSelectAll"
|
|
|
|
|
|
>
|
|
|
|
|
|
<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>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
const { proxy } = getCurrentInstance();
|
|
|
|
|
|
import useUserStore from "@/store/modules/user";
|
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
import * as indexApi from "@/api/teacher";
|
|
|
|
|
|
import { onMounted } from "vue";
|
|
|
|
|
|
const classList = ref([]);
|
|
|
|
|
|
const tableData = ref([]);
|
|
|
|
|
|
const loading = ref(false);
|
|
|
|
|
|
const tableRef = ref(null);
|
|
|
|
|
|
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 = () => {
|
|
|
|
|
|
indexApi.getClassListBySchoolId({ schoolId: userStore.userInfo.schoolId }).then((res) => {
|
|
|
|
|
|
classList.value = res.data || [];
|
|
|
|
|
|
classId.value = classList.value[0]?.schoolClassId || "";
|
|
|
|
|
|
getTaskList();
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
// 获取任务列表
|
|
|
|
|
|
const getTaskList = () => {
|
|
|
|
|
|
loading.value = true;
|
|
|
|
|
|
indexApi.getTaskList({ classId: classId.value }).then((res) => {
|
|
|
|
|
|
tableData.value = res.data;
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
|
setInitialSelection();
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
// 其他引入和定义保持不变
|
|
|
|
|
|
|
|
|
|
|
|
const isInitializing = ref(true); // 添加初始化标志
|
|
|
|
|
|
|
|
|
|
|
|
// 修改初始化方法
|
|
|
|
|
|
const setInitialSelection = () => {
|
|
|
|
|
|
isInitializing.value = true;
|
|
|
|
|
|
proxy.$nextTick(() => {
|
|
|
|
|
|
tableData.value.forEach((row) => {
|
|
|
|
|
|
if (row.disabledStatus == 0) {
|
|
|
|
|
|
tableRef.value.toggleRowSelection(row, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
isInitializing.value = false; // 初始化完成
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
// 修改单选处理方法
|
|
|
|
|
|
const handleSelect = async (selection, row) => {
|
|
|
|
|
|
if (isInitializing.value) return; // 初始化时不处理
|
|
|
|
|
|
if (!canOperateSelectedClass.value) return;
|
|
|
|
|
|
row.disabledStatus = row.disabledStatus == 0 ? 1 : 0;
|
|
|
|
|
|
handleTaskDistribution(tableData.value);
|
|
|
|
|
|
};
|
|
|
|
|
|
// 修改全选处理方法
|
|
|
|
|
|
const handleSelectAll = async (selection) => {
|
|
|
|
|
|
if (isInitializing.value) return; // 初始化时不处理
|
|
|
|
|
|
if (!canOperateSelectedClass.value) return;
|
|
|
|
|
|
const newStatus = selection.length > 0 ? 0 : 1; // 全选为0,取消为1
|
|
|
|
|
|
try {
|
|
|
|
|
|
loading.value = true;
|
|
|
|
|
|
// 更新本地状态
|
|
|
|
|
|
tableData.value.forEach((item) => {
|
|
|
|
|
|
item.disabledStatus = newStatus;
|
|
|
|
|
|
});
|
|
|
|
|
|
handleTaskDistribution(tableData.value);
|
|
|
|
|
|
selection.length = 0;
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("批量更新失败:", error);
|
|
|
|
|
|
// 恢复选中状态
|
|
|
|
|
|
proxy.$nextTick(() => {
|
|
|
|
|
|
if (newStatus === 0) {
|
|
|
|
|
|
tableRef.value.clearSelection();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tableRef.value.toggleAllSelection();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
// let { missingInArr2, missingInArr1 } = findMissingItems(selection, tableData.value);
|
|
|
|
|
|
// missingInArr1.forEach((item) => {
|
|
|
|
|
|
// item.disabledStatus = 1;
|
|
|
|
|
|
// });
|
|
|
|
|
|
// selection.forEach((item) => {
|
|
|
|
|
|
// item.disabledStatus = 0;
|
|
|
|
|
|
// });
|
|
|
|
|
|
// console.log(missingInArr1, selection, selection.length > 0 ? "selection" : "missingInArr1");
|
|
|
|
|
|
// handleTaskDistribution(selection.length > 0 ? selection : missingInArr1);
|
|
|
|
|
|
};
|
|
|
|
|
|
function findMissingItems(arr1, arr2) {
|
|
|
|
|
|
// 找出arr1中有但arr2中没有的元素
|
|
|
|
|
|
const missingInArr2 = arr1.filter((item) => !arr2.includes(item));
|
|
|
|
|
|
// 找出arr2中有但arr1中没有的元素
|
|
|
|
|
|
const missingInArr1 = arr2.filter((item) => !arr1.includes(item));
|
|
|
|
|
|
return {
|
|
|
|
|
|
missingInArr2,
|
|
|
|
|
|
missingInArr1,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
// 修改任务分配
|
|
|
|
|
|
const handleTaskDistribution = (selection) => {
|
|
|
|
|
|
const uniqueUsers = [...new Map(selection.map((item) => [item.module, item])).values()];
|
|
|
|
|
|
indexApi.addTask({ taskAllocationList: uniqueUsers, classId: classId.value, schoolId: userStore.userInfo.schoolId, userId: currentUserId.value }).then((res) => {
|
|
|
|
|
|
getTaskList();
|
|
|
|
|
|
proxy.$modal.msgSuccess("分配成功");
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
const canSelectTask = () => canOperateSelectedClass.value;
|
|
|
|
|
|
// 恢复选中状态
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
getClassList();
|
|
|
|
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang='scss' scoped>
|
|
|
|
|
|
.task {
|
|
|
|
|
|
height: calc(100vh - 70px);
|
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|