You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.vue 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <a-drawer :width="500" title="搜索" placement="right" :open="openSearchModel" @close="onClose">
  3. <template #extra>
  4. <a-button style="margin-right: 8px" @click="clearSearch">清空搜索</a-button>
  5. <a-button type="primary" @click="getData">搜索</a-button>
  6. </template>
  7. <a-form :model="commomParams.search">
  8. <a-row :gutter="[10]">
  9. <a-col span="24">
  10. <a-form-item>
  11. <a-input addon-before="文章" v-model:value="commomParams.search.keyword" placeholder="请输入文章"
  12. @keyup.enter="getData" />
  13. </a-form-item>
  14. </a-col>
  15. <a-col span="24">
  16. <a-form-item>
  17. <search-select placeholder="请选择栏目" :list="section_list" :select_value="commomParams.search.section_id"
  18. @searchData="sectionSearch" @getSelectValue="getSectionValue"
  19. :select_disabled="false"></search-select>
  20. </a-form-item>
  21. </a-col>
  22. </a-row>
  23. </a-form>
  24. </a-drawer>
  25. </template>
  26. <script lang="ts" setup>
  27. import { ref, onMounted, watch, computed } from 'vue';
  28. import { addArticle, updateArticle, listSection } from '@/apis/models';
  29. import { useCommon } from '@/hooks/useCommon';
  30. let { store, commomParams, openSearchModel, hideSearch } = useCommon();
  31. let props = defineProps(['search_params']);
  32. const emit = defineEmits();
  33. openSearchModel = computed(() => {
  34. sectionSearch()
  35. return store.state.openSearchModel;
  36. })
  37. interface listType {
  38. section_id : Number | 0,
  39. }
  40. commomParams.value.search = commomParams.value.search as listType;
  41. commomParams.value.search.section_id = null;
  42. // watch(() => props.search_params, (newVal) => {
  43. // emit('searchData', commomParams.value.search)
  44. // })
  45. const getData = () => {
  46. emit('searchData', commomParams.value.search);
  47. hideSearch()
  48. }
  49. // 清空搜索
  50. const clearSearch = () => {
  51. commomParams.value.search = {
  52. page: 1,
  53. pagesize: 10,
  54. sort: 'id',
  55. sortby: 'desc',
  56. keyword: ''
  57. }
  58. emit('clearData', commomParams.value.search);
  59. hideSearch()
  60. }
  61. const onClose = () => {
  62. clearSearch()
  63. hideSearch()
  64. }
  65. // 选择栏目/频道
  66. let section_list = ref<Object[]>([])
  67. const sectionSearch = (val : Object) => {
  68. listSection({keyword: val, pagesize: 200}).then((res : object) => {
  69. const data = res.data.sections.map((item : object) => ({
  70. label: item.name,
  71. value: item.id,
  72. }));
  73. section_list.value = data;
  74. })
  75. }
  76. const getSectionValue = (val : Object) => {
  77. commomParams.value.search.section_id = val.key;
  78. getData()
  79. }
  80. </script>
  81. <style>
  82. </style>