index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <script setup lang="ts">
  2. import {GradeList} from "@/api/grade/types";
  3. import { watch } from "vue";
  4. import { useUserStore } from "@/store/modules/user";
  5. import {getGradeSelect} from "@/api/grade";
  6. import {getStudentLists} from "@/api/student";
  7. import {StudentItem, StudentList, StudentParams} from "@/api/student/types";
  8. const userStore = useUserStore();
  9. defineOptions({
  10. name: "StudentIndex",
  11. inheritAttrs: false,
  12. });
  13. /**
  14. * 班级数据
  15. */
  16. const gradeData = ref<GradeList[]>();
  17. // 班级编号
  18. let gradeId = ref(0);
  19. async function getGradeData(schoolId: number) {
  20. getGradeSelect(schoolId)
  21. .then(({ data }) => {
  22. gradeData.value = data;
  23. gradeData.value?.unshift({ id: 0, name: "全部班级" })
  24. })
  25. .catch((error) => {
  26. gradeData.value = [];
  27. gradeData.value?.unshift({ id: 0, name: "全部班级" })
  28. console.log(error);
  29. });
  30. }
  31. /**
  32. * 学生数据
  33. */
  34. const studentSearch:StudentParams = reactive({
  35. school_id: userStore.schoolId,
  36. grade_id: 0,
  37. search: "",
  38. page_no: 1,
  39. page_size: 12,
  40. });
  41. // 0加载中,1数据正常,2数据为空
  42. const dataStatus = ref(0);
  43. const studentCount = ref(0);
  44. const studentData = ref<StudentItem[]>();
  45. async function getStudentData(schoolId) {
  46. studentSearch.school_id = schoolId;
  47. getStudentLists(studentSearch)
  48. .then(({ data }) => {
  49. const {count, lists} = data;
  50. studentCount.value = count;
  51. studentData.value = lists;
  52. dataStatus.value = 1;
  53. })
  54. .catch((error) => {
  55. dataStatus.value = 2;
  56. console.log(error);
  57. });
  58. }
  59. function getStudentSearch(){
  60. getStudentData(userStore.schoolId);
  61. }
  62. onMounted(() => {
  63. // 获取班级
  64. getGradeData(userStore.schoolId);
  65. // 获取学生数据
  66. getStudentData(userStore.schoolId);
  67. });
  68. watch(
  69. () => userStore.schoolId,
  70. (newValue) => {
  71. // 学校切换后重新加载数据
  72. studentSearch.grade_id = 0;
  73. studentSearch.search = "";
  74. getGradeData(newValue);
  75. getStudentData(userStore.schoolId);
  76. }
  77. );
  78. </script>
  79. <template>
  80. <div class="student-container">
  81. <!-- 学生查找 -->
  82. <div class="student-search">
  83. <el-select v-model="studentSearch.grade_id" placeholder="全部班级" size="large">
  84. <el-option
  85. v-for="item in gradeData"
  86. :key="item.id"
  87. :label="item.name"
  88. :value="item.id"
  89. />
  90. </el-select>
  91. <el-input
  92. v-model="studentSearch.search"
  93. size="large"
  94. placeholder="请输入学生名称或手机号码"
  95. />
  96. <el-button size="large" type="primary" @click="getStudentSearch()">查找</el-button>
  97. <span>共<b>{{ studentCount }}</b>人</span>
  98. </div>
  99. <!-- 学生数据 -->
  100. <div class="list-table">
  101. <el-table :data="studentData" style="width:100%">
  102. <el-table-column type="index" label="序号" align="center" width="80" />
  103. <el-table-column prop="name" label="学生名称" align="center" />
  104. <el-table-column prop="grade_name" label="所在班级" align="center" />
  105. <el-table-column prop="phone" label="手机号码" align="center" />
  106. <el-table-column prop="create_time" label="注册时间" align="center" />
  107. <el-table-column prop="count" label="训练次数" align="center" />
  108. <el-table-column />
  109. <el-table-column label="操作" align="center" >
  110. <template #default="scope">
  111. <router-link v-if="scope.row.count>16" :to="'/student/result?id='+scope.row.id" class="table-btn">训练效果分析</router-link>
  112. <button v-else class="table-btn disabled" @click="ElMessage.error('该学生训练数据还不足以进行训练效果分析,请至少完成16次专注力训练后再来查看。')">训练效果分析</button>
  113. </template>
  114. </el-table-column>
  115. <!-- 无数据插槽 -->
  116. <template #empty>
  117. <div class="empty">
  118. <img src="../../assets/empty.png" alt="数据为空">
  119. <p v-if="dataStatus == 0">加载中...</p>
  120. <p v-if="dataStatus == 2">暂时还没有任何学生绑定学校!</p>
  121. </div>
  122. </template>
  123. </el-table>
  124. <pagination
  125. v-if="studentCount > 0"
  126. v-model:total="studentCount"
  127. v-model:page="studentSearch.page_no"
  128. v-model:limit="studentSearch.page_size"
  129. @pagination="getStudentSearch()"
  130. />
  131. </div>
  132. </div>
  133. </template>
  134. <style lang="scss" scoped>
  135. .student-container {
  136. position: relative;
  137. padding: 20px 30px;
  138. }
  139. .student-search {
  140. margin-bottom: 20px;
  141. font-size: 16px;
  142. .el-select {
  143. width: 180px;
  144. margin: 0 20px 0 0;
  145. }
  146. .el-input {
  147. width: 250px;
  148. margin: 0;
  149. }
  150. :deep(.el-input__inner) {
  151. font-size: 16px;
  152. }
  153. .el-button {
  154. font-size: 16px;
  155. padding: 0 26px;
  156. margin: 0 20px;
  157. border-radius: 10px;
  158. background: #4284f2;
  159. }
  160. b {
  161. font-size: 20px;
  162. }
  163. }
  164. :deep(.el-input__wrapper) {
  165. background: #ffffff;
  166. border-radius: 12px;
  167. }
  168. :deep(.el-input__wrapper) {
  169. box-shadow: none !important;
  170. }
  171. /* 自定义 el-select 样式 */
  172. /* el-select 各种边框线隐藏**/
  173. :deep(.el-select) {
  174. --el-select-input-focus-border-color: none !important;
  175. }
  176. :deep(.el-select .el-input__wrapper.is-focus) {
  177. box-shadow: none !important;
  178. }
  179. :deep(.el-select:hover:not(.el-select--disabled) .el-input__wrapper) {
  180. box-shadow: none !important;
  181. }
  182. :deep(.el-table th.el-table__cell) {
  183. background: #e9ebee;
  184. }
  185. .list-table {
  186. background: #ffffff;
  187. border-radius: 25px;
  188. overflow: hidden;
  189. .table-btn {
  190. display: inline-block;
  191. height: 38px;
  192. line-height: 38px;
  193. padding: 0 15px;
  194. background: #4284f2;
  195. border-radius: 6px;
  196. color: #ffffff;
  197. &.disabled {
  198. background: #bfbfbf;
  199. cursor: not-allowed;
  200. }
  201. }
  202. }
  203. .empty{
  204. padding:100px 0;
  205. }
  206. </style>