index.tsx 2.6 KB

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