Search.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div id="search" class="col-11">
  3. <form class="search-form row">
  4. <fieldset class="search col-3">
  5. <div>
  6. <label for="keys">Search</label>
  7. <input
  8. id="keys"
  9. v-model="keys"
  10. type="text"
  11. placeholder="search"
  12. @keydown.enter.prevent="submit"
  13. >
  14. <v-select
  15. id="search-type"
  16. type="select"
  17. placeholder="dans ..."
  18. append-to-body
  19. :calculate-position="withPopper"
  20. :options="searchTypeOptions"
  21. :clearable="false"
  22. :value="searchTypeValue"
  23. @input="onSearchTypeSelected"
  24. />
  25. </div>
  26. <span
  27. v-if="!isloading"
  28. class="mdi mdi-magnify"
  29. title="rechercher"
  30. @click.prevent="submit"
  31. @keydown.enter.prevent="submit"
  32. />
  33. <span
  34. v-else
  35. class="mdi mdi-loading"
  36. title="chargement"
  37. />
  38. <!-- <input
  39. id="submit-search"
  40. type="submit"
  41. name="search"
  42. value="Search"
  43. class="mdi mdi-magnify"
  44. @click.prevent="submit"
  45. @keyup.enter="submit"
  46. > -->
  47. </fieldset>
  48. <fieldset class="filters-nominum col-3">
  49. <span>Filters Nominum</span>
  50. </fieldset>
  51. <fieldset class="filters-locorum col-3">
  52. <span>Filters Nominum</span>
  53. </fieldset>
  54. <fieldset class="filters-operum col-3">
  55. <span>Filters Nominum</span>
  56. </fieldset>
  57. </form>
  58. </div>
  59. </template>
  60. <script>
  61. import { createPopper } from '@popperjs/core'
  62. import { mapActions, mapState } from 'vuex'
  63. export default {
  64. name: 'Search',
  65. data: () => ({
  66. searchTypeOptions: [
  67. { 'code': 'text', 'label': 'Dans les textes' },
  68. { 'code': 'nominum', 'label': 'Dans les personnes' },
  69. { 'code': 'locorum', 'label': 'Dans les lieux' },
  70. { 'code': 'operum', 'label': 'Dans les objets' }
  71. ],
  72. searchTypeValue: { 'code': 'text', 'label': 'Dans les textes' }
  73. }),
  74. computed: {
  75. keys: {
  76. get () { return this.$store.state.Search.keys },
  77. set (value) { this.$store.commit('Search/setKeys', value) }
  78. },
  79. ...mapState({
  80. isloading: state => state.Search.isloading
  81. })
  82. },
  83. methods: {
  84. ...mapActions({
  85. getResults: 'Search/getResults'
  86. }),
  87. submit () {
  88. console.log('submited', this.keys)
  89. this.getResults()
  90. },
  91. withPopper (dropdownList, component, { width }) {
  92. /**
  93. * We need to explicitly define the dropdown width since
  94. * it is usually inherited from the parent with CSS.
  95. */
  96. dropdownList.style.width = width
  97. /**
  98. * Here we position the dropdownList relative to the $refs.toggle Element.
  99. *
  100. * The 'offset' modifier aligns the dropdown so that the $refs.toggle and
  101. * the dropdownList overlap by 1 pixel.
  102. *
  103. * The 'toggleClass' modifier adds a 'drop-up' class to the Vue Select
  104. * wrapper so that we can set some styles for when the dropdown is placed
  105. * above.
  106. */
  107. const popper = createPopper(component.$refs.toggle, dropdownList, {
  108. placement: 'top',
  109. modifiers: [
  110. {
  111. name: 'offset',
  112. options: {
  113. offset: [0, -1]
  114. }
  115. },
  116. {
  117. name: 'toggleClass',
  118. enabled: true,
  119. phase: 'write',
  120. fn ({ state }) {
  121. component.$el.classList.toggle('drop-up', state.placement === 'top')
  122. }
  123. }]
  124. })
  125. /**
  126. * To prevent memory leaks Popper needs to be destroyed.
  127. * If you return function, it will be called just before dropdown is removed from DOM.
  128. */
  129. return () => popper.destroy()
  130. },
  131. onSearchTypeSelected (e) {
  132. console.log('onSearchTypeSelected', e)
  133. this.searchTypeValue = e
  134. }
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. </style>