app.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const app = {
  2. state: {
  3. loading: true,
  4. page: ['home'],
  5. device: 'desktop',
  6. locale: 'zh-cn',
  7. adIsShow: true
  8. },
  9. mutations: {
  10. SET_PAGE: (state, value) => {
  11. state.page.push(value)
  12. },
  13. DELETE_PAGE: (state) => {
  14. if (state.page.length > 0) {
  15. state.page.splice(state.page.length-1,1)
  16. }
  17. },
  18. HIDE_AD: (state) => {
  19. state.adIsShow = false
  20. },
  21. GET_AD_STATUS: (state) => {
  22. return state.adIsShow
  23. },
  24. SET_LOCALE: (state, locale) => {
  25. state.locale = locale
  26. },
  27. HIDE_LOADING: (state) => {
  28. state.loading = false
  29. },
  30. GET_DATA: (state, name) => {
  31. const item = JSON.parse(JSON.stringify(name))
  32. if (state[item]) {
  33. return JSON.parse(JSON.stringify(state[item]))
  34. }
  35. },
  36. SET_DATA: (state, res) => {
  37. const item = JSON.parse(JSON.stringify(res))
  38. if (item.name && !state[item.name]) {
  39. state[item.name] = ''
  40. }
  41. state[item.name] = JSON.parse(JSON.stringify(item.value))
  42. },
  43. DELETE_DATA: (state, res) => {
  44. if (res.name && state[res.name]) {
  45. delete state[res.name]
  46. }
  47. }
  48. },
  49. actions: {
  50. showLoading: ({commit}) => {
  51. commit('SHOW_LOADING')
  52. },
  53. hideLoading: ({commit}) => {
  54. commit('HIDE_LOADING')
  55. },
  56. getData: ({commit}, data) => {
  57. commit('GET_DATA', data)
  58. },
  59. setData: ({commit}, data) => {
  60. commit('SET_DATA', data)
  61. },
  62. deleteData: ({commit}, data) => {
  63. commit('DELETE_DATA', data)
  64. },
  65. getAdStatus: ({commit}) => {
  66. commit('GET_AD_STATUS')
  67. },
  68. hideAd: ({commit}) => {
  69. commit('HIDE_AD')
  70. }
  71. }
  72. }
  73. export default app