search-group-resources.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { PropType, defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import { NButton, NCarousel, NCarouselItem, NImage, NSpace } from 'naive-ui';
  4. import TheSearch from '/src/components/TheSearch';
  5. import iconSlideRight from '/src/views/prepare-lessons/images/icon-slide-right.png';
  6. import { nextTick } from 'process';
  7. export default defineComponent({
  8. name: 'search-group',
  9. props: {
  10. categoryChildList: {
  11. type: Array as PropType<any>,
  12. default: () => []
  13. },
  14. wikiCategoryId: {
  15. type: String,
  16. default: ''
  17. }
  18. },
  19. emits: ['search', 'add'],
  20. expose: ['init'],
  21. setup(props, { emit }) {
  22. // const catchStore = useCatchStore();
  23. const forms = reactive({
  24. currentIndex: 0,
  25. keyword: '',
  26. wikiCategoryId: props.wikiCategoryId || '',
  27. maxIndex: 0
  28. });
  29. const onSearch = () => {
  30. emit('search', forms);
  31. };
  32. const carouselRef = ref();
  33. const onChangeSlide = (type: string) => {
  34. if (type === 'left') {
  35. carouselRef.value?.prev();
  36. } else if (type === 'right') {
  37. carouselRef.value?.next();
  38. }
  39. };
  40. onMounted(async () => {
  41. // 获取教材分类列表
  42. // await catchStore.getMusicSheetCategory()
  43. // nextTick(() => {
  44. // carouselRef.value?.to(100);
  45. // });
  46. });
  47. return () => (
  48. <div class={styles.searchGroup}>
  49. <div class={[styles.searchCatatory]}>
  50. <NSpace size="small" class={styles.btnType}>
  51. {props.categoryChildList.length > 0 ? (
  52. <NButton
  53. type={
  54. forms.wikiCategoryId === props.wikiCategoryId
  55. ? 'primary'
  56. : 'default'
  57. }
  58. secondary={
  59. forms.wikiCategoryId === props.wikiCategoryId ? false : true
  60. }
  61. round
  62. size="small"
  63. focusable={false}
  64. onClick={() => {
  65. forms.wikiCategoryId = props.wikiCategoryId;
  66. onSearch();
  67. }}>
  68. 全部
  69. </NButton>
  70. ) : (
  71. ''
  72. )}
  73. <NCarousel
  74. ref={carouselRef}
  75. slidesPerView={'auto'}
  76. loop={false}
  77. class={styles.carouselContainer}
  78. showDots={false}
  79. spaceBetween={20}
  80. currentIndex={forms.currentIndex}
  81. onUpdate:currentIndex={(val: any) => {
  82. //
  83. // if (val > forms.maxIndex) {
  84. // forms.maxIndex = val;
  85. // carouselRef.value?.to(0);
  86. // }
  87. forms.currentIndex = val;
  88. }}>
  89. {props.categoryChildList.map((item: any) => (
  90. <NCarouselItem>
  91. <NButton
  92. type={
  93. forms.wikiCategoryId === item.id ? 'primary' : 'default'
  94. }
  95. secondary={forms.wikiCategoryId === item.id ? false : true}
  96. round
  97. size="small"
  98. focusable={false}
  99. onClick={() => {
  100. forms.wikiCategoryId = item.id;
  101. onSearch();
  102. }}>
  103. {item.name}
  104. </NButton>
  105. </NCarouselItem>
  106. ))}
  107. </NCarousel>
  108. <NSpace class={styles.swipeControll}>
  109. <div onClick={() => onChangeSlide('left')}>
  110. <NImage
  111. previewDisabled
  112. class={[
  113. styles.leftIcon
  114. // forms.currentIndex === 0 && styles.disabled
  115. ]}
  116. src={iconSlideRight}
  117. />
  118. </div>
  119. <div onClick={() => onChangeSlide('right')}>
  120. <NImage
  121. // class={
  122. // // forms.currentIndex == forms.openTableList.length - 4 &&
  123. // styles.disabled
  124. // }
  125. previewDisabled
  126. src={iconSlideRight}
  127. />
  128. </div>
  129. </NSpace>
  130. </NSpace>
  131. <TheSearch
  132. class={styles.inputSearch}
  133. placeholder="请输入乐器关键词"
  134. round
  135. onSearch={(val: string) => {
  136. forms.keyword = val;
  137. onSearch();
  138. }}
  139. />
  140. </div>
  141. </div>
  142. );
  143. }
  144. });