index.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { defineComponent, onMounted, ref, computed } from 'vue';
  2. import styles from './index.module.less';
  3. import DirectoryList from './components/directory-main';
  4. import LessonMain from './components/lesson-main';
  5. import ResourceMain from './components/resource-main';
  6. import { useResizeObserver } from '@vueuse/core';
  7. import { onBeforeRouteLeave } from 'vue-router';
  8. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  9. import { storeToRefs } from 'pinia';
  10. import LessonsGuide from '@/custom-plugins/guide-page/lessons-guide';
  11. export default defineComponent({
  12. name: 'prepare-lessons',
  13. setup() {
  14. const prepareStore = usePrepareStore();
  15. console.log(prepareStore, 'prepareStore');
  16. const { treeList, coursewareList } = storeToRefs(prepareStore);
  17. const showGuide = computed(() => {
  18. return treeList.value.length > 0 && coursewareList.value.length > 0;
  19. });
  20. const directroyRef = ref();
  21. onMounted(() => {
  22. useResizeObserver(
  23. document.querySelector('#lessons-1') as HTMLElement,
  24. (entries: any) => {
  25. const entry = entries[0];
  26. const { height } = entry.contentRect;
  27. document.documentElement.style.setProperty(
  28. '--window-page-lesson-height',
  29. height + 'px'
  30. );
  31. }
  32. );
  33. });
  34. // 当前页面离开时
  35. onBeforeRouteLeave(() => {
  36. // 离开时恢复默认
  37. prepareStore.setTabType('courseware');
  38. prepareStore.setSelectMusicStatus(false);
  39. prepareStore.setSelectResourceStatus(false);
  40. prepareStore.setIsAddResource(false);
  41. prepareStore.setIsAddTrain(false);
  42. prepareStore.setIsEditResource(false);
  43. prepareStore.setIsEditTrain(false);
  44. // prepareStore.setCoursewareList([]);
  45. // prepareStore.setTreeList([]);
  46. // prepareStore.setTrainList([]);
  47. });
  48. return () => (
  49. <div class={styles.prepareLessons}>
  50. {/* 左侧目录 */}
  51. <div class={styles.directoryMain} ref={directroyRef.value}>
  52. <DirectoryList />
  53. </div>
  54. {/* 中间排课 */}
  55. <div class={styles.lessonMain}>
  56. <LessonMain />
  57. </div>
  58. {/* 资源 */}
  59. <div
  60. class={[
  61. styles.resourceMain
  62. // prepareStore.getSelectMusicStatus ||
  63. // prepareStore.getSelectResourceStatus
  64. // ? styles.resourceClose
  65. // : ''
  66. ]}
  67. id="lessons-1">
  68. <ResourceMain />
  69. </div>
  70. {showGuide.value ? <LessonsGuide></LessonsGuide> : null}
  71. </div>
  72. );
  73. }
  74. });