index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { PropType, defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import { NButton, NInput, NSelect } from 'naive-ui';
  4. import { useCatchStore } from '/src/store/modules/catchData';
  5. import { useThrottleFn } from '@vueuse/core';
  6. import { api_chapterLessonCoursewareTag_queryAll } from '/src/views/prepare-lessons/api';
  7. export default defineComponent({
  8. name: 'resource-search-group',
  9. emits: ['search'],
  10. setup(props, { emit }) {
  11. const catchStore = useCatchStore();
  12. const forms = reactive({
  13. keyword: '',
  14. chapterLessonCoursewareTagId: ''
  15. });
  16. const tagList = ref<any[]>([]);
  17. const onSearch = () => {
  18. emit('search', forms);
  19. };
  20. const throttledFn = useThrottleFn(() => onSearch(), 500);
  21. const getTagAll = async () => {
  22. const { data } = await api_chapterLessonCoursewareTag_queryAll();
  23. const result = data || [];
  24. tagList.value = [{ name: '全部', id: '' }, ...result];
  25. };
  26. getTagAll();
  27. // onMounted(async () => {});
  28. return () => (
  29. <>
  30. <div class={styles.searchGroup}>
  31. <NSelect
  32. placeholder="请选择课件标签"
  33. class={styles.searchSelect2}
  34. options={tagList.value}
  35. labelField="name"
  36. valueField="id"
  37. v-model:value={forms.chapterLessonCoursewareTagId}
  38. onUpdate:value={() => {
  39. throttledFn();
  40. }}
  41. />
  42. <NInput
  43. type="text"
  44. placeholder="请输入课件/作者名称"
  45. clearable={false}
  46. v-model:value={forms.keyword}
  47. class={styles.inputSearch}
  48. onKeyup={(e: KeyboardEvent) => {
  49. if (e.code === 'Enter') {
  50. throttledFn();
  51. }
  52. }}
  53. onClear={() => {
  54. forms.keyword = '';
  55. throttledFn();
  56. }}>
  57. {{
  58. prefix: () => (
  59. <span
  60. class={'icon-search-input'}
  61. onClick={() => throttledFn()}></span>
  62. )
  63. }}
  64. </NInput>
  65. </div>
  66. </>
  67. );
  68. }
  69. });