ClassHomework.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <template>
  2. <div class="main">
  3. <div class="search">
  4. <img src="@/assets/search.svg" width="20px" height="20px"></img>
  5. <div class="searchInput">
  6. <input type="text" v-model.trim="searchInput" placeholder="输入姓名或学号" :disabled="!isTable">
  7. <div class="fix">
  8. <span>搜索</span>
  9. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#b8b8b8" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18l6-6-6-6"/></svg>
  10. </div>
  11. </div>
  12. <div class="Myselect">
  13. <select id="selectHomework" v-model="TheHomework" @change="changeHomework" :disabled="!isTable">
  14. <option value=-1>选择作业</option>
  15. <option v-for="item in Homeworksdata" :value="item.assignmentId">{{item.assignmentName}}</option>
  16. </select>
  17. <div class="show">
  18. {{ ShowTheHomework }}
  19. </div>
  20. </div>
  21. <div class="Myselect">
  22. <select id="selectSort" v-model="TheSort" :disabled="!isTable">
  23. <option value="无">排序方式</option>
  24. <option v-for="item in sortMethods" :value="item">{{item}}</option>
  25. </select>
  26. <div class="show">
  27. {{ ShowTheSort }}
  28. </div>
  29. </div>
  30. <classToggle v-model:isLeft="isTable">
  31. <template #left>
  32. table
  33. </template>
  34. <template #right>
  35. chart
  36. </template>
  37. </classToggle>
  38. <div class="exportButton">
  39. <button @click="exportData">导出数据</button>
  40. </div>
  41. </div>
  42. <div class="content">
  43. <div class="Loading" v-show="!DataLoading">Loading...</div>
  44. <div class="half-table" v-show="DataLoading">
  45. <classTable v-if="isTable">
  46. <template #head>
  47. <tr>
  48. <th>序号</th>
  49. <th>学生姓名</th>
  50. <th>学号</th>
  51. <th>成绩</th>
  52. </tr>
  53. </template>
  54. <template #body>
  55. <tr v-for="(item,index) in showData.slice(0,5)" :key="index+item.officialNumber">
  56. <template v-if="item.officialNumber!==0">
  57. <td>{{ (currentPage-1)*10+index+1 }}</td>
  58. <td
  59. @click="$router.push(`/home/studentDetail?classId=${classId}&courseId=${courseId}&stuId=${item.studentId}`)"
  60. @mouseenter="hoverStuId=item.studentId"
  61. @mouseleave="hoverStuId=-1"
  62. :class="{Gethover:hoverStuId===item.studentId,Blue:true}"
  63. >{{ item.stuName }}</td>
  64. <td>{{ item.officialNumber }}</td>
  65. <td @click="$router.push(`/home/assignment/${ShowTheHomeworkId}/correct?studentId=${item.studentId}`)">
  66. <div class="highScore" v-if="item.score>=80"> {{ item.score }}</div>
  67. <div class="midScore" v-else-if="item.score>=60"> {{ item.score }}</div>
  68. <div class="lowScore" v-else-if="item.score>0"> {{ item.score }}</div>
  69. <div class="uncorrected" v-else-if="item.status==='SUBMITTED'"> 未批改</div>
  70. <div class="unsubmitted" v-else-if="item.status==='NOT_SUBMITTED'"> 未提交</div>
  71. </td>
  72. </template>
  73. <template v-else>
  74. <td>&nbsp;</td>
  75. <td>&nbsp;</td>
  76. <td>&nbsp;</td>
  77. <td>&nbsp;</td>
  78. </template>
  79. </tr>
  80. </template>
  81. </classTable>
  82. <div ref="chartRef1" class="chart" v-else></div>
  83. </div>
  84. <div class="half-table" v-show="DataLoading">
  85. <classTable v-if="isTable">
  86. <template #head>
  87. <tr>
  88. <th>序号</th>
  89. <th>学生姓名</th>
  90. <th>学号</th>
  91. <th>成绩</th>
  92. </tr>
  93. </template>
  94. <template #body>
  95. <tr v-for="(item,index) in showData.slice(5,10)" :key="index+item.officialNumber">
  96. <template v-if="item.officialNumber!==0">
  97. <td>{{ (currentPage-1)*10+index+6 }}</td>
  98. <td
  99. @click="$router.push(`/home/studentDetail?classId=${classId}&courseId=${courseId}&stuId=${item.studentId}`)"
  100. @mouseenter="hoverStuId=item.studentId"
  101. @mouseleave="hoverStuId=-1"
  102. :class="{Gethover:hoverStuId===item.studentId,Blue:true}"
  103. >{{ item.stuName }}</td>
  104. <td>{{ item.officialNumber }}</td>
  105. <td @click="$router.push(`/home/assignment/${ShowTheHomeworkId}/correct?studentId=${item.studentId}`)">
  106. <div class="highScore" v-if="item.score>=80"> {{ item.score }}</div>
  107. <div class="midScore" v-else-if="item.score>=60"> {{ item.score }}</div>
  108. <div class="lowScore" v-else-if="item.score>0"> {{ item.score }}</div>
  109. <div class="uncorrected" v-else-if="item.status==='SUBMITTED'"> 未批改</div>
  110. <div class="unsubmitted" v-else-if="item.status==='NOT_SUBMITTED'"> 未提交</div>
  111. </td>
  112. </template>
  113. <template v-else>
  114. <td>&nbsp;</td>
  115. <td>&nbsp;</td>
  116. <td>&nbsp;</td>
  117. <td>&nbsp;</td>
  118. </template>
  119. </tr>
  120. </template>
  121. </classTable>
  122. <div ref="chartRef2" class="chart chart2" v-else></div>
  123. </div>
  124. </div>
  125. <div class="pages" v-show="DataLoading && isTable">
  126. <el-pagination
  127. v-model:current-page="currentPage"
  128. :page-size="10"
  129. :pager-count="5"
  130. layout="total, prev, pager, next"
  131. :total="searchData.length"
  132. />
  133. </div>
  134. </div>
  135. </template>
  136. <script setup lang="ts">
  137. import classTable from './components/classTable.vue';
  138. import classToggle from './components/classToggle.vue'
  139. import {onMounted, ref, computed, watch, nextTick } from 'vue';
  140. import { useRoute, useRouter } from 'vue-router';
  141. import { useStore } from "@/store"
  142. import {ElLoading, ElMessage} from "element-plus";
  143. import * as echarts from 'echarts'
  144. import useApis from "@/apis";
  145. import { log } from 'console';
  146. const apis = useApis()
  147. const store = useStore()
  148. const route = useRoute()
  149. const router = useRouter()
  150. const classId = +route.query.classId;
  151. const courseId = +route.query.courseId;
  152. const currentPage = ref(1)
  153. const searchInput = ref("")
  154. const TheHomework = ref(-1)
  155. const ShowTheHomework = ref("")
  156. const ShowTheHomeworkId = ref(-1)
  157. const TheSort = ref("无")
  158. const ShowTheSort = ref("默认")
  159. const hoverStuId = ref(-1)
  160. const StudentsDataLoading = ref(false)
  161. const HomeworkDataLoading = ref(false)
  162. const isTable = ref(true)
  163. const Studentsdata = ref([])
  164. const Homeworksdata = ref([])
  165. const sortMethods = ["默认","成绩从低到高","成绩从高到低","未批改优先","未提交优先"]
  166. const chartRef1 = ref(null)
  167. const chartRef2 = ref(null)
  168. const setChart = () => {
  169. const chartInstance = echarts.init(chartRef1.value)
  170. const chartInstance2 = echarts.init(chartRef2.value)
  171. let excellentnum=0, goodnum=0 , failnum=0 , uncorrectednum=0 , unsubmittednum=0
  172. Studentsdata.value.forEach((item)=>{
  173. if(item.status === "NOT_SUBMITTED"){
  174. unsubmittednum++
  175. }
  176. else if(item.status === "SUBMITTED"){
  177. uncorrectednum++
  178. }
  179. else if(item.score<60){
  180. failnum++
  181. }
  182. else if(item.score<80){
  183. goodnum++
  184. }
  185. else{
  186. excellentnum++
  187. }
  188. })
  189. const option = {
  190. title: {
  191. text: ShowTheHomework.value+'详情',
  192. // subtext: '纯属虚构',
  193. left: 'center'
  194. },
  195. tooltip: {
  196. trigger: 'item',
  197. formatter: '{b}: {d}%'
  198. },
  199. legend: {
  200. orient: 'vertical',
  201. left: 'left'
  202. },
  203. series: [
  204. {
  205. name: '作业组成',
  206. type: 'pie',
  207. radius: '50%',
  208. data: [
  209. { value: excellentnum, name: '优秀', itemStyle: { color: '#7ADBB0' } },
  210. { value: goodnum, name: '良好', itemStyle: { color: '#F0C05A' } },
  211. { value: failnum, name: '不及格', itemStyle: { color: '#F4A261' } },
  212. { value: unsubmittednum, name: '未提交', itemStyle: { color: '#C45C4A' } },
  213. { value: uncorrectednum, name: '未批改', itemStyle: { color: '#D9D9D9' } }
  214. ],
  215. emphasis: {
  216. itemStyle: {
  217. shadowBlur: 10,
  218. shadowOffsetX: 0,
  219. shadowColor: 'rgba(0, 0, 0, 0.5)'
  220. }
  221. }
  222. }
  223. ]
  224. }
  225. const option2 = {
  226. title: {
  227. text: ShowTheHomework.value+'详情',
  228. // subtext: '纯属虚构',
  229. left: 'center'
  230. },
  231. tooltip: {
  232. trigger: 'axis',
  233. axisPointer: {
  234. type: 'shadow' // 悬停时显示阴影效果
  235. },
  236. formatter: '{b}: {c}'
  237. },
  238. xAxis: {
  239. type: 'category',
  240. data: ['优秀', '良好', '不及格', '未提交', '未批改']
  241. },
  242. yAxis: {
  243. type: 'value',
  244. name: '人数'
  245. },
  246. series: [
  247. {
  248. name: '作业组成',
  249. type: 'bar',
  250. radius: '50%',
  251. data: [
  252. { value: excellentnum, name: '优秀', itemStyle: { color: '#7ADBB0' } },
  253. { value: goodnum, name: '良好', itemStyle: { color: '#F0C05A' } },
  254. { value: failnum, name: '不及格', itemStyle: { color: '#F4A261' } },
  255. { value: unsubmittednum, name: '未提交', itemStyle: { color: '#C45C4A' } },
  256. { value: uncorrectednum, name: '未批改', itemStyle: { color: '#D9D9D9' } }
  257. ],
  258. barWidth: '40%',
  259. emphasis: {
  260. itemStyle: {
  261. shadowBlur: 10,
  262. shadowOffsetX: 0,
  263. shadowColor: 'rgba(0, 0, 0, 0.5)'
  264. }
  265. }
  266. }
  267. ]
  268. }
  269. chartInstance.setOption(option)
  270. chartInstance2.setOption(option2)
  271. }
  272. const exportData = () => {
  273. console.log('exportData',classId,ShowTheHomeworkId.value)
  274. // apis.downLoadAllBehaviorDataByClass(classId,ShowTheHomeworkId.value)
  275. // apis.downLoadAllBehaviorData(ShowTheHomeworkId.value)
  276. apis.downLoadAllBehaviorDataByClass(classId,ShowTheHomeworkId.value)
  277. .then((res:any) => {
  278. if (res && res.status === 200){
  279. let blob = res.data as Blob;
  280. const fileName = `${ShowTheHomework.value}作业行为数据.xlsx`;
  281. if ('download' in document.createElement('a')) {
  282. const link = document.createElement('a');
  283. link.download = fileName;
  284. link.style.display = 'none';
  285. link.href = URL.createObjectURL(blob);
  286. document.body.appendChild(link);
  287. link.click();
  288. ElMessage.success('下载成功')
  289. URL.revokeObjectURL(link.href); // 释放URL对象
  290. document.body.removeChild(link);
  291. }
  292. }
  293. })
  294. .catch((err:any) => {
  295. console.log(err)
  296. ElMessage.success('下载失败')
  297. })
  298. }
  299. const identify = () => {
  300. if(store.user.role === "STUDENT"){
  301. router.push('/404')
  302. }
  303. }
  304. const getHomeworks = async () => {
  305. // console.log(courseId,classId);
  306. console.log(ShowTheHomeworkId.value);
  307. await apis.getAssignmentByCourseId(courseId)
  308. .then((res:any)=>{
  309. // console.log('----------------------');
  310. // console.log(res.data.data.records);
  311. res.data.data.records.forEach(item => Homeworksdata.value.push(item))
  312. if(res.data.data.records.length!=0){
  313. ShowTheHomework.value = res.data.data.records[0].assignmentName
  314. ShowTheHomeworkId.value = res.data.data.records[0].assignmentId
  315. }
  316. })
  317. // t.forEach(item => Homeworksdata.value.push(item))
  318. HomeworkDataLoading.value = true
  319. console.log('ShowTheHomeworkId',ShowTheHomeworkId.value);
  320. }
  321. const getStudents = () => {
  322. StudentsDataLoading.value=false
  323. console.log('+++++++++++++++++++++++');
  324. console.log(classId,ShowTheHomeworkId.value);
  325. apis.getClassStatesOfCourse(classId,ShowTheHomeworkId.value)
  326. .then((res:any)=>{
  327. console.log(res.data.data);
  328. Studentsdata.value = res.data.data
  329. })
  330. .catch((err:any)=>{
  331. console.log('-------------------------');
  332. console.log(err);
  333. })
  334. StudentsDataLoading.value = true
  335. }
  336. const changeHomework = () => {
  337. console.log(ShowTheHomework.value)
  338. getStudents()
  339. }
  340. const searchData = computed(()=>{
  341. if(searchInput.value===""){
  342. return Studentsdata.value
  343. }
  344. else{
  345. return Studentsdata.value.filter(student => {
  346. return (
  347. student.stuName.includes(searchInput.value) ||
  348. student.officialNumber.toString().includes(searchInput.value)
  349. )
  350. })
  351. }
  352. })
  353. const showData = computed(() => {
  354. const showdata = searchData.value.slice((currentPage.value-1)*10,currentPage.value*10)
  355. while(showdata.length<10){
  356. showdata.push( {
  357. "officialNumber": 0,
  358. "stuName": "",
  359. "status": "",
  360. "score": 0,
  361. "studentId": -1
  362. })
  363. }
  364. return showdata
  365. })
  366. const DataLoading = computed(() => {
  367. return StudentsDataLoading.value && HomeworkDataLoading.value
  368. })
  369. watch(TheHomework, () => {
  370. nextTick(() => {
  371. // console.log(ShowTheHomework.value,TheHomework.value);
  372. if(TheHomework.value != -1){
  373. let t = Homeworksdata.value.find(item=>item.assignmentId==TheHomework.value)
  374. ShowTheHomework.value = t.assignmentName
  375. ShowTheHomeworkId.value = t.assignmentId
  376. TheHomework.value = -1
  377. }
  378. // console.log(ShowTheHomework.value,TheHomework.value);
  379. });
  380. });
  381. watch(TheSort, () => {
  382. nextTick(() => {
  383. // console.log(ShowTheSort.value,TheSort.value);
  384. if(TheSort.value != "无"){
  385. ShowTheSort.value = TheSort.value
  386. TheSort.value = "无"
  387. }
  388. // console.log(ShowTheSort.value,TheSort.value);
  389. });
  390. });
  391. watch(ShowTheSort,(newData) =>{
  392. if(newData==="未提交优先"){
  393. Studentsdata.value = Studentsdata.value.sort((a,b)=>{
  394. return a.status === "NOT_SUBMITTED" ? -1 : b.status === "NOT_SUBMITTED" ? 1 : 0;
  395. })
  396. console.log("未批改已排序");
  397. console.log(Studentsdata.value);
  398. }
  399. else if(newData==="未批改优先"){
  400. Studentsdata.value = Studentsdata.value.sort((a,b)=>{
  401. return a.status === "SUBMITTED" ? -1 : b.status === "SUBMITTED" ? 1 : 0;
  402. })
  403. }
  404. else if(newData==="成绩从低到高"){
  405. Studentsdata.value = Studentsdata.value.sort((a,b)=>{
  406. if (a.status === "CORRECTED" && b.status !== "CORRECTED") return -1;
  407. if (a.status !== "CORRECTED" && b.status === "CORRECTED") return 1;
  408. return a.score - b.score;
  409. })
  410. }
  411. else if(newData==="成绩从高到低"){
  412. Studentsdata.value = Studentsdata.value.sort((a,b)=>{
  413. if (a.status === "CORRECTED" && b.status !== "CORRECTED") return -1;
  414. if (a.status !== "CORRECTED" && b.status === "CORRECTED") return 1;
  415. return b.score - a.score;
  416. })
  417. }
  418. })
  419. watch(isTable, (newVal) => {
  420. if(newVal === false){
  421. nextTick(()=>{
  422. console.log('chartRef1 dom:', chartRef1.value)
  423. setChart()
  424. })
  425. }
  426. })
  427. onMounted(async () => {
  428. await getHomeworks();
  429. if (ShowTheHomeworkId.value) {
  430. await getStudents();
  431. } else {
  432. console.warn('未获取到作业 ID,无法加载学生数据');
  433. }
  434. });
  435. </script>
  436. <style scoped>
  437. .main{
  438. display: flex;
  439. flex-direction: column;
  440. width: 100%;
  441. height: 100%;
  442. .search{
  443. height: 50px;
  444. width: 100%;
  445. display: flex;
  446. flex-direction: row;
  447. justify-content: flex-start;
  448. align-items: center;
  449. margin-top: 20px;
  450. .exportButton{
  451. height: 100%;
  452. display: flex;
  453. flex-direction: row;
  454. justify-content: flex-start;
  455. align-items: center;
  456. margin-left: 20px;
  457. button{
  458. height: 27px;
  459. padding: 0 10px;
  460. border: 2px solid #e4e7ed;
  461. border-radius: 7px;
  462. background-color: #4a90c4;
  463. color: #fff;
  464. font-weight: 600;
  465. }
  466. }
  467. .searchInput{
  468. height: 100%;
  469. display: flex;
  470. flex-direction: row;
  471. justify-content: flex-start;
  472. align-items: center;
  473. margin-left: 20px;
  474. input{
  475. border: 2px solid #e4e7ed;
  476. border-right: none;
  477. height: 27px;
  478. border-radius: 7px 0 0 7px;
  479. padding: 0 10px;
  480. color: #606266;
  481. }
  482. input::placeholder {
  483. color:#c2c4c9;
  484. }
  485. .fix{
  486. background-color: #f5f7fa;
  487. padding: 2px 10px;
  488. color:#b8b8b8;
  489. font-weight: 600;
  490. border: 2px solid #e4e7ed;
  491. border-radius: 0 7px 7px 0;
  492. }
  493. }
  494. .Myselect{
  495. margin-left: 15px;
  496. display: flex;
  497. flex-direction: row;
  498. select {
  499. border: none;
  500. background-color: #4a90c4;
  501. font-size: 14px;
  502. font-weight: 600;
  503. color:#fff;
  504. padding: 3px 10px;
  505. padding-right: 0;
  506. border-radius: 5px 0 0 5px;
  507. max-width: 100px;
  508. }
  509. select:focus {
  510. outline: none;
  511. border: none;
  512. background-color: #FFF;
  513. border: 3px solid #4a90c4;
  514. border-right: 0;
  515. color:#4a90c4;
  516. }
  517. .show{
  518. width: fit-content;
  519. color: #4a90c4;
  520. border: 3px solid #4a90c4;
  521. font-weight: 600;
  522. padding-left: 6px;
  523. padding-right: 5px;
  524. border-radius: 0 5px 5px 0;
  525. }
  526. }
  527. }
  528. .content{
  529. width: 100%;
  530. flex-grow: 1;
  531. display: flex;
  532. flex-direction: row;
  533. gap: 40px;
  534. .half-table{
  535. width: 50%;
  536. height: 100%;
  537. .highScore{
  538. padding: 2px 10px;
  539. background-color: #7ADBB0;
  540. color: #fff;
  541. border-radius: 20px;
  542. width: fit-content;
  543. margin: auto;
  544. }
  545. .midScore{
  546. padding: 2px 10px;
  547. background-color: #F0C05A;
  548. color: #fff;
  549. border-radius: 20px;
  550. width: fit-content;
  551. margin: auto;
  552. }
  553. .lowScore{
  554. padding: 2px 10px;
  555. background-color: #F4A261;
  556. color: #fff;
  557. border-radius: 20px;
  558. width: fit-content;
  559. margin: auto;
  560. }
  561. .unsubmitted{
  562. padding: 2px 10px;
  563. background-color: #C45C4A;
  564. color: #fff;
  565. border-radius: 20px;
  566. width: fit-content;
  567. margin: auto;
  568. }
  569. .uncorrected{
  570. padding: 2px 10px;
  571. background-color: #D9D9D9;
  572. color: #fff;
  573. border-radius: 20px;
  574. width: fit-content;
  575. margin: auto;
  576. }
  577. .chart{
  578. margin-top: 70px;
  579. margin-left: 30px;
  580. height: 300px;
  581. width: 100%;
  582. }
  583. .chart2{
  584. margin-left: 0;
  585. margin-right: 30px;
  586. padding-bottom: 50px;
  587. }
  588. }
  589. .Loading{
  590. font-size: 40px;
  591. color: #70bbdb;
  592. font-weight: 700;
  593. height: 100%;
  594. width: 100%;
  595. text-align: center;
  596. align-content: center;
  597. }
  598. }
  599. .pages{
  600. height: 30px;
  601. margin-top: 10px;
  602. }
  603. }
  604. </style>