app.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {
  2. uniAdminCacheKey
  3. } from '../constants.js'
  4. // #ifndef VUE3
  5. const statConfig = require('uni-stat-config').default || require('uni-stat-config');
  6. // #endif
  7. export default {
  8. namespaced: true,
  9. state: {
  10. inited: false,
  11. navMenu: [],
  12. routes: [],
  13. theme: uni.getStorageSync(uniAdminCacheKey.theme) || 'default',
  14. // #ifndef VUE3
  15. appName: process.env.VUE_APP_NAME || '',
  16. appid: statConfig && statConfig.appid || '',
  17. // #endif
  18. // #ifdef VUE3
  19. appName: process.env.UNI_APP_NAME || '',
  20. appid: process.env.UNI_APP_ID || ''
  21. // #endif
  22. },
  23. mutations: {
  24. SET_APP_NAME: (state, appName) => {
  25. state.appName = appName
  26. },
  27. SET_NAV_MENU: (state, navMenu) => {
  28. state.inited = true
  29. state.navMenu = navMenu
  30. },
  31. SET_ROUTES: (state, routes) => {
  32. state.routes = routes
  33. },
  34. SET_THEME: (state, theme) => {
  35. // #ifdef H5
  36. document
  37. .getElementsByTagName('body')[0]
  38. .setAttribute('data-theme', theme)
  39. // #endif
  40. uni.setStorageSync(uniAdminCacheKey.theme, theme)
  41. state.theme = theme
  42. }
  43. },
  44. actions: {
  45. init({
  46. commit,
  47. dispatch
  48. }) {
  49. // 初始化获取用户信息
  50. dispatch('user/getUserInfo', null, {
  51. root: true
  52. })
  53. },
  54. setAppName({
  55. commit
  56. }, appName) {
  57. commit('SET_APP_NAME', appName)
  58. },
  59. setRoutes({
  60. commit
  61. }, routes) {
  62. commit('SET_ROUTES', routes)
  63. }
  64. }
  65. }