index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { NTabPane, NTabs } from 'naive-ui';
  2. import { defineComponent, nextTick, onMounted, ref, toRefs } from 'vue';
  3. import styles from './index.module.less';
  4. import SelectItem from './select-item';
  5. import { useResizeObserver } from '@vueuse/core';
  6. import { useCatchStore } from '/src/store/modules/catchData';
  7. export default defineComponent({
  8. name: 'select-resources',
  9. props: {
  10. type: {
  11. type: String,
  12. default: 'myResources'
  13. },
  14. /** 从哪里使用 */
  15. from: {
  16. type: String,
  17. default: ''
  18. }
  19. },
  20. emits: ['select'],
  21. setup(props) {
  22. const { type } = toRefs(props);
  23. const tabType = ref(type.value);
  24. const catchStore = useCatchStore();
  25. onMounted(async () => {
  26. nextTick(() => {
  27. useResizeObserver(
  28. document.querySelector(
  29. '.select-resource .n-tabs-nav--top'
  30. ) as HTMLElement,
  31. (entries: any) => {
  32. const entry = entries[0];
  33. const { height } = entry.contentRect;
  34. console.log(height, 'height - 11');
  35. document.documentElement.style.setProperty(
  36. '--modal-lesson-tab-height',
  37. height + 'px'
  38. );
  39. }
  40. );
  41. });
  42. // 获取教材分类列表
  43. await catchStore.getMusicSheetCategory(true);
  44. });
  45. return () => (
  46. <div class={[styles.selectMusic, 'select-resource']}>
  47. <NTabs
  48. animated
  49. value={tabType.value}
  50. paneClass={styles.paneTitle}
  51. justifyContent="center"
  52. paneWrapperClass={styles.paneWrapperContainer}
  53. onUpdate:value={(val: string) => {
  54. tabType.value = val;
  55. }}>
  56. {props.from !== 'class' && (
  57. <NTabPane name="relateResources" tab={'相关资源'}>
  58. <SelectItem type="relateResources" />
  59. </NTabPane>
  60. )}
  61. <NTabPane
  62. name="shareResources"
  63. tab={props.from === 'class' ? '共享曲目' : '共享资源'}>
  64. <SelectItem type="shareResources" from={props.from} />
  65. </NTabPane>
  66. <NTabPane
  67. name="myResources"
  68. tab={props.from === 'class' ? '我的曲目' : '我的资源'}>
  69. <SelectItem type="myResources" from={props.from} />
  70. </NTabPane>
  71. <NTabPane name="myCollect" tab="我的收藏">
  72. <SelectItem type="myCollect" from={props.from} />
  73. </NTabPane>
  74. </NTabs>
  75. </div>
  76. );
  77. }
  78. });