Library.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div class="h-100 position-relative">
  3. <!-- BACKGROUND (mode) -->
  4. <component :is="mode" />
  5. <!-- FOREGROUND (texts) -->
  6. <section v-for="group in groups" :key="group.id" class="split-screen">
  7. <text-card :id="group.id" @open="openText(group, $event)" @close="closeText(group)" />
  8. <div>
  9. <text-card
  10. v-for="id in group.prod" :key="id"
  11. :id="id"
  12. @close="closeText(group, id)"
  13. />
  14. </div>
  15. </section>
  16. </div>
  17. </template>
  18. <script>
  19. import { CardList, CardMap, TreeMap } from './library'
  20. import TextCard from '@/components/text/TextCard'
  21. export default {
  22. name: 'Library',
  23. components: {
  24. CardList,
  25. CardMap,
  26. TreeMap,
  27. TextCard
  28. },
  29. props: {
  30. mode: { type: String, required: true },
  31. texts: { type: Array, required: true }
  32. },
  33. computed: {
  34. groups () {
  35. return this.texts.map(text => {
  36. const [id, ...prod] = text
  37. return { id, prod }
  38. })
  39. }
  40. },
  41. methods: {
  42. openText (group, id) {
  43. if (group.prod.includes(id)) return
  44. group.prod.push(id)
  45. this.updateQuery(this.groups)
  46. },
  47. closeText (group, id) {
  48. if (!id) {
  49. this.updateQuery(this.groups.filter(grp => grp !== group))
  50. } else {
  51. group.prod = group.prod.filter(id_ => id_ !== id)
  52. this.updateQuery(this.groups)
  53. }
  54. },
  55. updateQuery (groups) {
  56. // Update the route's query (will not reload the page) and let vue determine what changed.
  57. this.$router.push({
  58. query: {
  59. mode: this.mode,
  60. texts: groups.map(grp => [grp.id, ...grp.prod])
  61. }
  62. })
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. </style>