all.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict'
  2. import $ from 'jquery'
  3. import Vue from 'vue'
  4. import _ from 'lodash'
  5. const rootUrl = '/'
  6. module.exports = (alerts, socket) => {
  7. if ($('#page-type-all').length) {
  8. let vueAllPages = new Vue({ // eslint-disable-line no-unused-vars
  9. el: '#page-type-all',
  10. data: {
  11. tree: []
  12. },
  13. methods: {
  14. fetch: function (basePath) {
  15. let self = this
  16. $('#notifload').addClass('active')
  17. Vue.nextTick(() => {
  18. socket.emit('treeFetch', { basePath }, (data) => {
  19. if (self.tree.length > 0) {
  20. let curTree = _.last(self.tree)
  21. curTree.hasChildren = true
  22. _.find(curTree.pages, { _id: basePath }).isActive = true
  23. }
  24. self.tree.push({
  25. hasChildren: false,
  26. pages: data
  27. })
  28. $('#notifload').removeClass('active')
  29. })
  30. })
  31. },
  32. goto: function (entryPath) {
  33. window.location.assign(rootUrl + entryPath)
  34. }
  35. },
  36. mounted: function () {
  37. let basePath = window.location.pathname.slice(0, -4)
  38. if (basePath.length > 1) {
  39. basePath = basePath.slice(1)
  40. }
  41. this.fetch(basePath)
  42. }
  43. })
  44. }
  45. }