app.js 1.3 KB
Newer Older
M
MicroMilo 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
import {
	uniAdminCacheKey
} from '../constants.js'

// #ifndef VUE3
const statConfig = require('uni-stat-config').default || require('uni-stat-config');
// #endif

export default {
	namespaced: true,
	state: {
		inited: false,
		navMenu: [],
		routes: [],
		theme: uni.getStorageSync(uniAdminCacheKey.theme) || 'default',
		// #ifndef VUE3
		appName: process.env.VUE_APP_NAME || '',
		appid: statConfig && statConfig.appid || '',
		// #endif
		// #ifdef VUE3
		appName: process.env.UNI_APP_NAME || '',
		appid: process.env.UNI_APP_ID || ''
		// #endif
	},
	mutations: {
		SET_APP_NAME: (state, appName) => {
			state.appName = appName
		},
		SET_NAV_MENU: (state, navMenu) => {
			state.inited = true
			state.navMenu = navMenu
		},
		SET_ROUTES: (state, routes) => {
			state.routes = routes
		},
		SET_THEME: (state, theme) => {
			// #ifdef H5
			document
				.getElementsByTagName('body')[0]
				.setAttribute('data-theme', theme)
			// #endif
			uni.setStorageSync(uniAdminCacheKey.theme, theme)
			state.theme = theme
		}
	},
	actions: {
		init({
			commit,
			dispatch
		}) {
			// 初始化获取用户信息
			dispatch('user/getUserInfo', null, {
				root: true
			})
		},
		setAppName({
			commit
		}, appName) {
			commit('SET_APP_NAME', appName)
		},
		setRoutes({
			commit
		}, routes) {
			commit('SET_ROUTES', routes)
		}
	}
}