search-group.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { defineComponent, reactive, onMounted } from 'vue';
  2. import styles from './index.module.less';
  3. import { NButton, NForm, NFormItem, NSpace } from 'naive-ui';
  4. import TheSearch from '/src/components/TheSearch';
  5. import { useCatchStore } from '/src/store/modules/catchData';
  6. import { useThrottleFn } from '@vueuse/core';
  7. export default defineComponent({
  8. name: 'search-group',
  9. emits: ['search', 'add'],
  10. setup(props, { emit }) {
  11. const catchStore = useCatchStore();
  12. const forms = reactive({
  13. keyword: '',
  14. musicSheetCategoriesId: null
  15. });
  16. const onSearch = () => {
  17. emit('search', forms);
  18. };
  19. const throttledFn = useThrottleFn(() => {
  20. onSearch();
  21. }, 500);
  22. onMounted(async () => {
  23. // 获取教材分类列表
  24. await catchStore.getMusicSheetCategory();
  25. // 获取声部列表
  26. await catchStore.getSubjects();
  27. });
  28. return () => (
  29. <div class={styles.searchGroup}>
  30. <NForm labelAlign="left" labelPlacement="left">
  31. <NFormItem label="教材:">
  32. <NSpace class={styles.spaceSection}>
  33. {catchStore.getAllMusicCategories.map((music: any) => (
  34. <NButton
  35. secondary={forms.musicSheetCategoriesId === music.id}
  36. quaternary={forms.musicSheetCategoriesId !== music.id}
  37. strong
  38. focusable={false}
  39. type={
  40. forms.musicSheetCategoriesId === music.id
  41. ? 'primary'
  42. : 'default'
  43. }
  44. onClick={() => {
  45. forms.musicSheetCategoriesId = music.id;
  46. throttledFn();
  47. }}>
  48. {music.name}
  49. </NButton>
  50. ))}
  51. </NSpace>
  52. </NFormItem>
  53. <TheSearch
  54. class={styles.inputSearch}
  55. round
  56. onSearch={(val: string) => {
  57. forms.keyword = val;
  58. throttledFn();
  59. }}
  60. />
  61. </NForm>
  62. </div>
  63. );
  64. }
  65. });