index.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { NTabPane, NTabs } from 'naive-ui';
  2. import { PropType, defineComponent, 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 { emit } from 'process';
  7. import { useCatchStore } from '/src/store/modules/catchData';
  8. export default defineComponent({
  9. name: 'select-music',
  10. props: {
  11. type: {
  12. type: String,
  13. default: 'myResources'
  14. },
  15. /** 类型 */
  16. cardType: {
  17. type: String as PropType<'' | 'homerowk-record' | 'prepare'>,
  18. default: ''
  19. },
  20. /** 从哪里使用 */
  21. from: {
  22. type: String,
  23. default: ''
  24. }
  25. },
  26. emits: ['select', 'add'],
  27. setup(props, { emit }) {
  28. const { type } = toRefs(props);
  29. const tabType = ref(type.value);
  30. const catchStore = useCatchStore();
  31. onMounted(async () => {
  32. useResizeObserver(
  33. document.querySelector(
  34. '.select-resource .n-tabs-nav--top'
  35. ) as HTMLElement,
  36. (entries: any) => {
  37. const entry = entries[0];
  38. const { height } = entry.contentRect;
  39. document.documentElement.style.setProperty(
  40. '--modal-lesson-tab-height',
  41. height + 'px'
  42. );
  43. }
  44. );
  45. // 获取教材分类列表
  46. await catchStore.getMusicSheetCategory(true);
  47. });
  48. return () => (
  49. <div class={[styles.selectMusic, 'select-resource']}>
  50. <NTabs
  51. animated
  52. value={tabType.value}
  53. paneClass={styles.paneTitle}
  54. justifyContent="center"
  55. paneWrapperClass={styles.paneWrapperContainer}
  56. onUpdate:value={(val: string) => {
  57. tabType.value = val;
  58. }}>
  59. <NTabPane name="myResources" tab={'我的曲目'}>
  60. <SelectItem
  61. cardType={props.cardType}
  62. from={props.from}
  63. type="myResources"
  64. onAdd={(item: any) => emit('add', item)}
  65. />
  66. </NTabPane>
  67. <NTabPane name="shareResources" tab={'共享曲目'}>
  68. <SelectItem
  69. from={props.from}
  70. cardType={props.cardType}
  71. type="shareResources"
  72. onAdd={(item: any) => emit('add', item)}
  73. />
  74. </NTabPane>
  75. <NTabPane name="myCollect" tab="收藏曲目">
  76. <SelectItem
  77. from={props.from}
  78. cardType={props.cardType}
  79. type="myCollect"
  80. onAdd={(item: any) => emit('add', item)}
  81. />
  82. </NTabPane>
  83. </NTabs>
  84. </div>
  85. );
  86. }
  87. });