Base.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div id="Base">
  3. <div class="loading" v-if="!searchinfos">
  4. <span>{{ $t('default.Loading…') }}</span>
  5. </div>
  6. <div class="cards-list" v-else>
  7. <aside class="search-info">
  8. {{ searchinfos }}
  9. </aside>
  10. <div class="loading" v-if="!items.length & !noresults">
  11. <span>{{ $t('default.Loading…') }}</span>
  12. </div>
  13. <ul v-else>
  14. <li v-for="item in items" v-bind:key="item.id">
  15. <Card v-if="item.bundle == 'materiau'" :item="item"/>
  16. <CardThematique v-if="item.bundle == 'thematique'" :item="item"/>
  17. </li>
  18. </ul>
  19. <infinite-loading
  20. v-if="count > limit"
  21. @infinite="nextPage"
  22. >
  23. <div slot="no-more">No more results</div>
  24. </infinite-loading>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import Card from 'vuejs/components/Content/Card'
  30. import CardThematique from 'vuejs/components/Content/CardThematique'
  31. import { mapState, mapActions } from 'vuex'
  32. export default {
  33. name: "Base",
  34. data() {
  35. return {
  36. pagetitle:"Base",
  37. // searchinfos: null
  38. }
  39. },
  40. computed: {
  41. ...mapState({
  42. items: state => state.Search.items,
  43. searchinfos: state => state.Search.infos,
  44. count: state => state.Search.count,
  45. noresults: state => state.Search.noresults,
  46. limit: state => state.Search.limit
  47. })
  48. },
  49. methods: {
  50. ...mapActions({
  51. newSearch: 'Search/newSearch',
  52. nextPage: 'Search/nextPage'
  53. }),
  54. // infiniteHandler($state){
  55. // console.log('inifiniteHandler', $state)
  56. // this.nextPage()
  57. // }
  58. },
  59. created() {
  60. // at first page load or first route entering launch a search if params exists in url query
  61. console.log('Base created() location',window.location)
  62. let params = new URLSearchParams(window.location.search)
  63. if (params.has('keys')) {
  64. this.$store.commit('Search/setKeys', params.get('keys'))
  65. this.pagetitle = params.get('keys')
  66. } else {
  67. this.$store.commit('Search/setKeys', '')
  68. this.pagetitle = 'Base'
  69. }
  70. if (params.has('term')) {
  71. this.$store.commit('Search/setTerm', params.get('term'))
  72. } else {
  73. this.$store.commit('Search/setTerm', '')
  74. }
  75. if (params.has('filters')) {
  76. this.$store.commit('Search/setFilters', params.get('filters').split(','))
  77. } else {
  78. this.$store.commit('Search/setFilters', [])
  79. }
  80. this.newSearch()
  81. },
  82. beforeRouteUpdate (to, from, next) {
  83. // when query change launch a new search
  84. console.log('Base beforeRouteUpdate', to, from, next)
  85. this.$store.commit('Search/setKeys', to.query.keys)
  86. this.$store.commit('Search/setTerm', to.query.term)
  87. this.$store.commit('Search/setFilters', to.query.filters)
  88. this.pagetitle = to.query.keys
  89. this.newSearch()
  90. next()
  91. },
  92. components: {
  93. Card,
  94. CardThematique
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. </style>