app.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Cookies from 'js-cookie'
  2. // import { getUnreadNotice } from '@/api/notificationCenter'
  3. const state = {
  4. sidebar: {
  5. opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
  6. withoutAnimation: false
  7. },
  8. device: 'desktop',
  9. l1Path: '',
  10. allUnreadNum: 0,
  11. show: null
  12. }
  13. const mutations = {
  14. SET_L1_PATH: (state, newPath) => {
  15. state.l1Path = newPath
  16. },
  17. TOGGLE_SIDEBAR: state => {
  18. state.sidebar.opened = !state.sidebar.opened
  19. state.sidebar.withoutAnimation = false
  20. if (state.sidebar.opened) {
  21. Cookies.set('sidebarStatus', 1)
  22. } else {
  23. Cookies.set('sidebarStatus', 0)
  24. }
  25. },
  26. CLOSE_SIDEBAR: (state, withoutAnimation) => {
  27. Cookies.set('sidebarStatus', 0)
  28. state.sidebar.opened = false
  29. state.sidebar.withoutAnimation = withoutAnimation
  30. },
  31. TOGGLE_DEVICE: (state, device) => {
  32. state.device = device
  33. },
  34. SET_UNREAD_NOTICE: (state, num) => {
  35. state.allUnreadNum = num
  36. },
  37. SET_SHOW: (state, bool) => {
  38. state.show = bool
  39. }
  40. }
  41. const actions = {
  42. toggleSideBar({ commit }) {
  43. commit('TOGGLE_SIDEBAR')
  44. },
  45. closeSideBar({ commit }, { withoutAnimation }) {
  46. commit('CLOSE_SIDEBAR', withoutAnimation)
  47. },
  48. toggleDevice({ commit }, device) {
  49. commit('TOGGLE_DEVICE', device)
  50. },
  51. getUnreadNum({ commit }) {
  52. // getUnreadNotice({ noticeType: '', readFlag: 'NO' }).then(res => {
  53. // console.log('获取未读数量')
  54. // commit('SET_UNREAD_NOTICE', res.data)
  55. // })
  56. }
  57. }
  58. export default {
  59. namespaced: true,
  60. state,
  61. mutations,
  62. actions
  63. }