index.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import { defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import { NInput, NScrollbar, NSelect, NSpin, NThing } from 'naive-ui';
  4. import { useRouter } from 'vue-router';
  5. import { BOOK_DATA } from '/src/views/natural-resources/model/add-teaching';
  6. import { classGroupPage, courseScheduleStart } from '../../api';
  7. import { useThrottleFn } from '@vueuse/core';
  8. import TheEmpty from '/src/components/TheEmpty';
  9. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  10. import { state } from '/src/state';
  11. import { nextTick } from 'process';
  12. const classList: any = [];
  13. for (let i = 1; i <= 40; i++) {
  14. classList.push({ label: i + '班', value: i });
  15. }
  16. export default defineComponent({
  17. name: 'attend-class',
  18. emits: ['close', 'preview'],
  19. setup(props, { emit }) {
  20. const prepareStore = usePrepareStore();
  21. const router = useRouter();
  22. const forms = reactive({
  23. keyword: null,
  24. currentGradeNum: null,
  25. currentClass: null
  26. });
  27. const list = ref([] as any);
  28. const loading = ref(false);
  29. // 开始上课
  30. const onAttendClass = async (item: any) => {
  31. try {
  32. const res = await courseScheduleStart({
  33. lessonCoursewareKnowledgeDetailId: prepareStore.selectKey,
  34. classGroupId: item.id
  35. });
  36. emit('close');
  37. emit('preview', {
  38. type: 'class',
  39. classId: res.data, // 上课编号
  40. classGroupId: item.id,
  41. subjectId: prepareStore.getSubjectId,
  42. detailId: prepareStore.getSelectKey,
  43. lessonCourseId: prepareStore.getBaseCourseware.id
  44. });
  45. if (window.matchMedia('(display-mode: standalone)').matches) {
  46. state.application = window.matchMedia(
  47. '(display-mode: standalone)'
  48. ).matches;
  49. setTimeout(() => {
  50. fscreen();
  51. }, 200);
  52. }
  53. } catch {
  54. //
  55. }
  56. };
  57. const fscreen = () => {
  58. const el = document.documentElement;
  59. const isFullscreen =
  60. document.fullScreen ||
  61. document.mozFullScreen ||
  62. document.webkitIsFullScreen;
  63. if (!isFullscreen) {
  64. //进入全屏
  65. (el.requestFullscreen && el.requestFullscreen()) ||
  66. (el.mozRequestFullScreen && el.mozRequestFullScreen()) ||
  67. (el.webkitRequestFullscreen && el.webkitRequestFullscreen()) ||
  68. (el.msRequestFullscreen && el.msRequestFullscreen());
  69. } else {
  70. //退出全屏
  71. document.exitFullscreen
  72. ? document.exitFullscreen()
  73. : document.mozCancelFullScreen
  74. ? document.mozCancelFullScreen()
  75. : document.webkitExitFullscreen
  76. ? document.webkitExitFullscreen()
  77. : '';
  78. }
  79. };
  80. const getList = async () => {
  81. loading.value = true;
  82. try {
  83. const { data } = await classGroupPage({
  84. page: 1,
  85. rows: 99,
  86. ...forms
  87. });
  88. const result = data.rows || [];
  89. result.forEach((item: any) => {
  90. // 判断班级里面有学生的
  91. if (item.preStudentNum > 0) {
  92. list.value.push(item);
  93. }
  94. });
  95. } catch {
  96. //
  97. }
  98. loading.value = false;
  99. };
  100. const throttleFn = useThrottleFn(() => getList(), 500);
  101. onMounted(() => {
  102. getList();
  103. });
  104. return () => (
  105. <div class={styles.attendClass}>
  106. <div class={styles.attendClassSearch}>
  107. <NInput
  108. placeholder="请输入班级名称"
  109. clearable
  110. v-model:value={forms.keyword}
  111. onKeyup={(e: KeyboardEvent) => {
  112. if (e.code === 'Enter') {
  113. throttleFn();
  114. }
  115. }}
  116. onClear={() => throttleFn()}>
  117. {{
  118. prefix: () => (
  119. <span
  120. class="icon-search-input"
  121. onClick={() => throttleFn()}></span>
  122. )
  123. }}
  124. </NInput>
  125. <NSelect
  126. placeholder="全部年级"
  127. clearable
  128. options={
  129. [{ label: '全部年级', value: null }, ...BOOK_DATA.grades] as any
  130. }
  131. v-model:value={forms.currentGradeNum}
  132. onUpdate:value={() => throttleFn()}
  133. />
  134. <NSelect
  135. placeholder="全部班级"
  136. clearable
  137. options={[{ label: '全部班级', value: null }, ...classList]}
  138. v-model:value={forms.currentClass}
  139. onUpdate:value={() => throttleFn()}
  140. />
  141. </div>
  142. <NScrollbar class={styles.classList}>
  143. <NSpin show={loading.value}>
  144. <div
  145. class={[
  146. styles.listSection,
  147. !loading.value && list.value.length <= 0
  148. ? styles.emptySection
  149. : ''
  150. ]}>
  151. {list.value.map((item: any) => (
  152. <div onClick={() => onAttendClass(item)}>
  153. <NThing class={[styles.thingItem, 'isFull']}>
  154. {{
  155. header: () => (
  156. <div class={styles.title}>
  157. {item.name} {item.preStudentNum}人
  158. </div>
  159. ),
  160. default: () =>
  161. item.lastStudy && (
  162. <div class={styles.content}>{item.lastStudy}</div>
  163. )
  164. }}
  165. </NThing>
  166. </div>
  167. ))}
  168. {!loading.value && list.value.length <= 0 && <TheEmpty />}
  169. </div>
  170. </NSpin>
  171. </NScrollbar>
  172. </div>
  173. );
  174. }
  175. });