search-group-resources.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { PropType, defineComponent, onMounted, reactive } from 'vue';
  2. import styles from './index.module.less';
  3. import { NButton, NSpace } from 'naive-ui';
  4. import TheSearch from '/src/components/TheSearch';
  5. export default defineComponent({
  6. name: 'search-group',
  7. props: {
  8. categoryChildList: {
  9. type: Array as PropType<any>,
  10. default: () => []
  11. },
  12. wikiCategoryId: {
  13. type: String,
  14. default: ''
  15. }
  16. },
  17. emits: ['search', 'add'],
  18. expose: ['init'],
  19. setup(props, { emit }) {
  20. // const catchStore = useCatchStore();
  21. const forms = reactive({
  22. keyword: '',
  23. wikiCategoryId: props.wikiCategoryId || ''
  24. });
  25. const onSearch = () => {
  26. emit('search', forms);
  27. };
  28. onMounted(async () => {
  29. // 获取教材分类列表
  30. // await catchStore.getMusicSheetCategory()
  31. });
  32. return () => (
  33. <div class={styles.searchGroup}>
  34. <div class={[styles.searchCatatory]}>
  35. <NSpace size="small" class={styles.btnType}>
  36. {props.categoryChildList.length > 0 ? (
  37. <NButton
  38. type={
  39. forms.wikiCategoryId === props.wikiCategoryId
  40. ? 'primary'
  41. : 'default'
  42. }
  43. secondary={
  44. forms.wikiCategoryId === props.wikiCategoryId ? false : true
  45. }
  46. round
  47. size="small"
  48. focusable={false}
  49. onClick={() => {
  50. forms.wikiCategoryId = props.wikiCategoryId;
  51. onSearch();
  52. }}>
  53. 全部
  54. </NButton>
  55. ) : (
  56. <span></span>
  57. )}
  58. {props.categoryChildList.map((item: any) => (
  59. <NButton
  60. type={forms.wikiCategoryId === item.id ? 'primary' : 'default'}
  61. secondary={forms.wikiCategoryId === item.id ? false : true}
  62. round
  63. size="small"
  64. focusable={false}
  65. onClick={() => {
  66. forms.wikiCategoryId = item.id;
  67. onSearch();
  68. }}>
  69. {item.name}
  70. </NButton>
  71. ))}
  72. </NSpace>
  73. <TheSearch
  74. class={styles.inputSearch}
  75. placeholder="请输入乐器名称"
  76. round
  77. onSearch={(val: string) => {
  78. forms.keyword = val;
  79. onSearch();
  80. }}
  81. />
  82. </div>
  83. </div>
  84. );
  85. }
  86. });