app.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* eslint-disable no-empty */
  2. import Cookies from 'js-cookie'
  3. import { hasIndexErrData } from '@/views/main/api'
  4. import { permission } from '@/utils/directivePage'
  5. const state = {
  6. sidebar: {
  7. opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
  8. withoutAnimation: false
  9. },
  10. device: 'desktop',
  11. status: {
  12. indexErrData: false,
  13. remindMatterData: false,
  14. musicPatrol: false,
  15. studentInfo: false,
  16. teacherInfo: false,
  17. attendanceServe:false
  18. },
  19. }
  20. const mutations = {
  21. TOGGLE_SIDEBAR: state => {
  22. // state.sidebar.opened = !state.sidebar.opened
  23. state.sidebar.opened = true;
  24. state.sidebar.withoutAnimation = false
  25. if (state.sidebar.opened) {
  26. Cookies.set('sidebarStatus', 1)
  27. } else {
  28. Cookies.set('sidebarStatus', 0)
  29. }
  30. },
  31. CLOSE_SIDEBAR: (state, withoutAnimation) => {
  32. Cookies.set('sidebarStatus', 0)
  33. state.sidebar.opened = false
  34. state.sidebar.withoutAnimation = withoutAnimation
  35. },
  36. TOGGLE_DEVICE: (state, device) => {
  37. state.device = device
  38. },
  39. COMMIT_DOT_STATUS: (state, status) => {
  40. const { musicPatrol, studentInfo, teacherInfo,attendanceServe } = status
  41. state.status = {
  42. ...status,
  43. indexErrData: musicPatrol || studentInfo || teacherInfo || attendanceServe
  44. }
  45. toggleDot(state.status)
  46. }
  47. }
  48. const toggleDot = status => {
  49. const { indexErrData, remindMatterData } = status
  50. const dotStatus = indexErrData || remindMatterData
  51. setTimeout(() => {
  52. // const el = document.querySelector('.menu-wrapper a[href="#/main/main"] span')
  53. const el = document.querySelector('.el-scrollbar__view a.indexlayout-top-menu-li[href="#/main"] span')
  54. if (el) {
  55. if (dotStatus) {
  56. el.classList.add('main-dot')
  57. } else {
  58. el.classList.remove('main-dot')
  59. }
  60. }
  61. }, 500);
  62. }
  63. const actions = {
  64. toggleSideBar ({ commit }) {
  65. commit('TOGGLE_SIDEBAR')
  66. },
  67. closeSideBar ({ commit }, { withoutAnimation }) {
  68. commit('CLOSE_SIDEBAR', withoutAnimation)
  69. },
  70. toggleDevice ({ commit }, device) {
  71. commit('TOGGLE_DEVICE', device)
  72. },
  73. async setDotStatus({ commit }) {
  74. if (permission('hasIndexErrData')) {
  75. try {
  76. const res = await hasIndexErrData()
  77. commit('COMMIT_DOT_STATUS', res.data)
  78. } catch (error) {}
  79. }
  80. }
  81. }
  82. export default {
  83. namespaced: true,
  84. state,
  85. mutations,
  86. actions
  87. }