nebula/store/index.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-08-04 21:50:59 +08:00
import { isServer } from '~/environment'
2020-07-02 23:45:27 +08:00
export const state = () => {
return {
2020-07-03 11:04:25 +08:00
activeMenu: 'index',
2020-07-31 16:17:12 +08:00
oauth: null,
2020-08-06 15:44:29 +08:00
userInfo: null,
locale: 'zh_CN',
2022-01-14 10:38:55 +08:00
uploadHeaders: '',
fingerprint: ''
2020-07-02 23:45:27 +08:00
}
}
2020-07-03 11:04:25 +08:00
export const mutations = {
setActiveMenu (state, activeMenu) {
state.activeMenu = activeMenu
},
setUploadHeaders(state, data){
state.uploadHeaders = data
},
2022-01-14 10:38:55 +08:00
setFingerprint (state, fingerprint) {
state.fingerprint = fingerprint
2020-07-03 11:04:25 +08:00
}
}
2020-06-22 17:13:42 +08:00
export const actions = {
2020-06-21 21:56:34 +08:00
nuxtServerInit(store, {req}) {
// 初始化时的全局任务
2020-08-04 21:50:59 +08:00
const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
const browser = {
versions: function() {
return { //移动终端浏览器版本信息
trident: userAgent.indexOf('Trident') > -1, //IE内核
presto: userAgent.indexOf('Presto') > -1, //opera内核
webKit: userAgent.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: userAgent.indexOf('Gecko') > -1 && userAgent.indexOf('KHTML') == -1, //火狐内核
mobile: !!userAgent.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
ios: !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: userAgent.indexOf('Android') > -1 || userAgent.indexOf('Linux') > -1, //android终端或uc浏览器
iPhone: userAgent.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
iPad: userAgent.indexOf('iPad') > -1, //是否iPad
webApp: userAgent.indexOf('Safari') == -1 //是否web应用程序没有头部与底部
2020-08-04 21:50:59 +08:00
};
} ()
}
if (browser.versions.mobile) {
// 移动端
store.commit('global/updateMobileState', true)
}
2020-08-02 00:25:44 +08:00
2020-06-21 21:56:34 +08:00
const initFetchAppData = [
// 内容数据
2020-08-11 22:39:59 +08:00
store.dispatch('topic/fetchNavList'),
2021-05-20 22:02:49 +08:00
store.dispatch('article/fetchList')
2020-06-21 21:56:34 +08:00
]
2020-08-02 00:25:44 +08:00
2020-06-21 21:56:34 +08:00
return Promise.all(initFetchAppData)
2020-06-19 17:10:44 +08:00
}
2020-06-22 17:13:42 +08:00
}