app.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const app = {
  2. state: {
  3. loading: true,
  4. device: 'desktop',
  5. locale: 'zh-cn'
  6. },
  7. mutations: {
  8. SET_LOCALE: (state, locale) => {
  9. state.locale = locale
  10. },
  11. HIDE_LOADING: (state) => {
  12. state.loading = false
  13. },
  14. GET_DATA: (state, name) => {
  15. const item = JSON.parse(JSON.stringify(name))
  16. if (state[item]) {
  17. return JSON.parse(JSON.stringify(state[item]))
  18. }
  19. },
  20. SET_DATA: (state, res) => {
  21. const item = JSON.parse(JSON.stringify(res))
  22. if (item.name && !state[item.name]) {
  23. state[item.name] = ''
  24. }
  25. state[item.name] = JSON.parse(JSON.stringify(item.value))
  26. },
  27. DELETE_DATA: (state, res) => {
  28. if (res.name && state[res.name]) {
  29. delete state[res.name]
  30. }
  31. }
  32. },
  33. actions: {
  34. showLoading: ({ commit }) => {
  35. commit('SHOW_LOADING')
  36. },
  37. hideLoading: ({ commit }) => {
  38. commit('HIDE_LOADING')
  39. },
  40. getData: ({ commit }, data) => {
  41. commit('GET_DATA', data)
  42. },
  43. setData: ({ commit }, data) => {
  44. commit('SET_DATA', data)
  45. },
  46. deleteData: ({ commit }, data) => {
  47. commit('DELETE_DATA', data)
  48. }
  49. }
  50. }
  51. export default app