app.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import Cookies from 'js-cookie'
  2. import { getLanguage } from '@/i18n/index'
  3. const state = {
  4. sidebar: {
  5. opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
  6. withoutAnimation: false
  7. },
  8. device: 'desktop',
  9. language: getLanguage(),
  10. size: Cookies.get('size') || 'mini',
  11. treeWidth: '18%',
  12. minMainHeight: window.screen.height - 465,
  13. pageTableHeaderHeight: 0
  14. }
  15. const mutations = {
  16. PAGE_TABLE_HEADER_HEIGHT: (state, height) => {
  17. state.pageTableHeaderHeight = height
  18. },
  19. TOGGLE_SIDEBAR: state => {
  20. state.sidebar.opened = !state.sidebar.opened
  21. state.sidebar.withoutAnimation = false
  22. if (state.sidebar.opened) {
  23. Cookies.set('sidebarStatus', 1)
  24. } else {
  25. Cookies.set('sidebarStatus', 0)
  26. }
  27. },
  28. CLOSE_SIDEBAR: (state, withoutAnimation) => {
  29. Cookies.set('sidebarStatus', 0)
  30. state.sidebar.opened = false
  31. state.sidebar.withoutAnimation = withoutAnimation
  32. },
  33. TOGGLE_DEVICE: (state, device) => {
  34. state.device = device
  35. },
  36. SET_LANGUAGE: (state, language) => {
  37. state.language = language
  38. Cookies.set('language', language)
  39. },
  40. SET_SIZE: (state, size) => {
  41. state.size = size
  42. Cookies.set('size', size)
  43. }
  44. }
  45. const actions = {
  46. pageTableHeaderHeight({ commit }, { height }) {
  47. commit('PAGE_TABLE_HEADER_HEIGHT', height)
  48. },
  49. toggleSideBar({ commit }) {
  50. commit('TOGGLE_SIDEBAR')
  51. },
  52. closeSideBar({ commit }, { withoutAnimation }) {
  53. commit('CLOSE_SIDEBAR', withoutAnimation)
  54. },
  55. toggleDevice({ commit }, device) {
  56. commit('TOGGLE_DEVICE', device)
  57. },
  58. setLanguage({ commit }, language) {
  59. commit('SET_LANGUAGE', language)
  60. },
  61. setSize({ commit }, size) {
  62. commit('SET_SIZE', size)
  63. }
  64. }
  65. export default {
  66. namespaced: true,
  67. state,
  68. mutations,
  69. actions
  70. }