init
This commit is contained in:
102
src/vuex/modules/com.js
Normal file
102
src/vuex/modules/com.js
Normal file
@@ -0,0 +1,102 @@
|
||||
import * as types from '../types'
|
||||
import { getStore, setStore } from '@js/mUtils.js'
|
||||
|
||||
const baseUrl = process.env.NODE_ENV === 'development' ? 'http://192.168.81.107:8080/hlapp' : 'http://192.168.46.5:8080/hl_nlapp'
|
||||
|
||||
/**
|
||||
* App通用配置
|
||||
*/
|
||||
const state = {
|
||||
loading: false,
|
||||
showToast: false,
|
||||
showAlert: false,
|
||||
showSuccess: true,
|
||||
showFail: false,
|
||||
toastMsg: '退出登录',
|
||||
alertMsg: '操作成功',
|
||||
baseUrl: getStore('baseUrl') || baseUrl,
|
||||
setTime: getStore('setTime') || 5000,
|
||||
equipId: getStore('equipId') || 1
|
||||
}
|
||||
|
||||
const actions = {
|
||||
setLoadingState ({ commit }, status) {
|
||||
commit(types.COM_LOADING_STATUS, status)
|
||||
},
|
||||
showToast ({ commit }, status) {
|
||||
commit(types.COM_SHOW_TOAST, status)
|
||||
},
|
||||
showAlert ({ commit }, status) {
|
||||
commit(types.COM_SHOW_ALERT, status)
|
||||
},
|
||||
showSuccess ({ commit }, status) {
|
||||
commit(types.COM_SHOW_SUCCESS, status)
|
||||
},
|
||||
showFail ({ commit }, status) {
|
||||
commit(types.COM_SHOW_FAIL, status)
|
||||
},
|
||||
toastMsg ({ commit }, str) {
|
||||
commit(types.COM_TOAST_MSG, str)
|
||||
},
|
||||
alertMsg ({ commit }, str) {
|
||||
commit(types.COM_ALERT_MSG, str)
|
||||
},
|
||||
setConfig ({commit}, res) {
|
||||
setStore('baseUrl', res.baseUrl)
|
||||
setStore('setTime', res.setTime)
|
||||
setStore('equipId', res.equipId)
|
||||
commit(types.COM_CONFIG, res)
|
||||
}
|
||||
}
|
||||
|
||||
const getters = {
|
||||
loading: state => state.loading,
|
||||
showToast: state => state.showToast,
|
||||
showAlert: state => state.showAlert,
|
||||
baseUrl: state => state.baseUrl,
|
||||
setTime: state => state.setTime,
|
||||
equipId: state => state.equipId
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
[types.COM_LOADING_STATUS] (state, status) {
|
||||
state.loading = status
|
||||
},
|
||||
|
||||
[types.COM_SHOW_TOAST] (state, status) {
|
||||
state.showToast = status
|
||||
},
|
||||
|
||||
[types.COM_SHOW_ALERT] (state, status) {
|
||||
state.showAlert = status
|
||||
},
|
||||
|
||||
[types.COM_SHOW_SUCCESS] (state, status) {
|
||||
state.showSuccess = status
|
||||
},
|
||||
|
||||
[types.COM_SHOW_FAIL] (state, status) {
|
||||
state.showFail = status
|
||||
},
|
||||
|
||||
[types.COM_TOAST_MSG] (state, str) {
|
||||
state.toastMsg = str
|
||||
},
|
||||
|
||||
[types.COM_ALERT_MSG] (state, str) {
|
||||
state.alertMsg = str
|
||||
},
|
||||
|
||||
[types.COM_CONFIG] (state, res) {
|
||||
state.baseUrl = res.baseUrl
|
||||
state.setTime = res.setTime
|
||||
state.equipId = res.equipId
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
state,
|
||||
actions,
|
||||
getters,
|
||||
mutations
|
||||
}
|
||||
52
src/vuex/modules/user.js
Normal file
52
src/vuex/modules/user.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import * as types from '../types'
|
||||
import { getStore, setStore } from '@js/mUtils.js'
|
||||
|
||||
const state = {
|
||||
accountId: getStore('accountId') || '',
|
||||
accountName: getStore('accountName') || '',
|
||||
userName: getStore('userName') || '',
|
||||
deptUuid: getStore('deptUuid') || ''
|
||||
}
|
||||
|
||||
const getters = {
|
||||
accountId: state => state.accountId,
|
||||
accountName: state => state.accountName,
|
||||
userName: state => state.userName,
|
||||
deptUuid: state => state.deptUuid
|
||||
}
|
||||
|
||||
const actions = {
|
||||
setUserInfo ({ commit }, res) {
|
||||
setStore('accountId', res.account_id)
|
||||
setStore('accountName', res.account_name)
|
||||
setStore('userName', res.user_name)
|
||||
setStore('deptUuid', res.dept_uuid)
|
||||
commit(types.SET_USER_INFO, res)
|
||||
},
|
||||
setSignOut ({ commit }) {
|
||||
localStorage.removeItem('accountId')
|
||||
localStorage.removeItem('userName')
|
||||
localStorage.removeItem('accountName')
|
||||
localStorage.removeItem('deptUuid')
|
||||
commit(types.SET_SIGN_OUT)
|
||||
}
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
[types.SET_USER_INFO] (state, res) {
|
||||
state.accountId = res.account_id
|
||||
state.accountName = res.account_name
|
||||
state.userName = res.user_name
|
||||
state.memberName = res.member_name
|
||||
},
|
||||
[types.SET_SIGN_OUT] (state) {
|
||||
state.accountId = ''
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
Reference in New Issue
Block a user