Base.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. const r = /,\s?$/
  65. let keys = params.get('keys').replace(r,'').split(', ')
  66. console.log('Base created, keys', keys)
  67. this.$store.commit('Search/setKeys', keys)
  68. this.pagetitle = keys.join(', ') //params.get('keys')
  69. } else {
  70. this.$store.commit('Search/reSetKeys')
  71. this.pagetitle = 'Base'
  72. }
  73. if (params.has('terms')) {
  74. console.log('Base created, has terms', params.get('terms'))
  75. // this.$store.commit('Search/setTerms', params.get('terms').split(','))
  76. this.$store.commit('Search/setTerms', JSON.parse(params.get('terms')))
  77. } else {
  78. this.$store.commit('Search/reSetTerms')
  79. }
  80. if (params.has('filters')) {
  81. this.$store.commit('Search/setFilters', params.get('filters').split(','))
  82. } else {
  83. this.$store.commit('Search/reSetFilters')
  84. }
  85. this.newSearch()
  86. },
  87. beforeRouteUpdate (to, from, next) {
  88. // when query change launch a new search
  89. console.log('Base beforeRouteUpdate', to, from, next)
  90. // todo text field of search form is not emptying on clicking on base after a search
  91. // this.$store.commit('Search/setKeys', to.query.keys)
  92. if (to.query.hasOwnProperty('terms')) {
  93. this.$store.commit('Search/setTerms', to.query.terms)
  94. }else{
  95. this.$store.commit('Search/reSetTerms')
  96. }
  97. if (to.query.hasOwnProperty('filters')) {
  98. this.$store.commit('Search/setFilters', to.query.filters)
  99. }else{
  100. this.$store.commit('Search/reSetFilters')
  101. }
  102. if (to.query.hasOwnProperty('keys')) {
  103. const r = /,\s?$/
  104. let keys = to.query.keys.replace(r,'').split(', ')
  105. console.log('Base created, keys', keys)
  106. this.$store.commit('Search/setKeys', keys)
  107. this.pagetitle = to.query.keys
  108. }else{
  109. this.$store.commit('Search/reSetKeys')
  110. }
  111. this.newSearch()
  112. next()
  113. },
  114. components: {
  115. Card,
  116. CardThematique
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. </style>