This commit is contained in:
alvis
2020-07-16 14:12:31 +08:00
parent 1c159a7bad
commit f746aef851
2140 changed files with 7218 additions and 4689 deletions

View File

@@ -0,0 +1,9 @@
const getters = {
sidebar: state => state.app.sidebar,
device: state => state.app.device,
visitedViews: state => state.tagsView.visitedViews,
cachedViews: state => state.tagsView.cachedViews,
userName: state => state.user.userName,
routes: state => state.router.routes
}
export default getters

View File

@@ -0,0 +1,25 @@
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
Vue.use(Vuex)
// https://webpack.js.org/guides/dependency-management/#requirecontext
const modulesFiles = require.context('./modules', true, /\.js$/)
// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
// set './app.js' => 'app'
const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
const value = modulesFiles(modulePath)
modules[moduleName] = value.default
return modules
}, {})
const store = new Vuex.Store({
modules,
getters
})
export default store

View File

@@ -0,0 +1,56 @@
import Cookies from 'js-cookie'
const state = {
sidebar: {
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
withoutAnimation: false
},
device: 'desktop',
size: Cookies.get('size') || 'medium'
}
const mutations = {
TOGGLE_SIDEBAR: state => {
state.sidebar.opened = !state.sidebar.opened
state.sidebar.withoutAnimation = false
if (state.sidebar.opened) {
Cookies.set('sidebarStatus', 1)
} else {
Cookies.set('sidebarStatus', 0)
}
},
CLOSE_SIDEBAR: (state, withoutAnimation) => {
Cookies.set('sidebarStatus', 0)
state.sidebar.opened = false
state.sidebar.withoutAnimation = withoutAnimation
},
TOGGLE_DEVICE: (state, device) => {
state.device = device
},
SET_SIZE: (state, size) => {
state.size = size
Cookies.set('size', size)
}
}
const actions = {
toggleSideBar ({ commit }) {
commit('TOGGLE_SIDEBAR')
},
closeSideBar ({ commit }, { withoutAnimation }) {
commit('CLOSE_SIDEBAR', withoutAnimation)
},
toggleDevice ({ commit }, device) {
commit('TOGGLE_DEVICE', device)
},
setSize ({ commit }, size) {
commit('SET_SIZE', size)
}
}
export default {
namespaced: true,
state,
mutations,
actions
}

View File

@@ -0,0 +1,56 @@
// initial state
const state = {
user: {
sexEnum: [{ key: 1, value: '男' }, { key: 2, value: '女' }],
statusEnum: [{ key: 1, value: '启用' }, { key: 2, value: '禁用' }],
levelEnum: [{ key: 1, value: '一年级' }, { key: 2, value: '二年级' }, { key: 3, value: '三年级' }, { key: 4, value: '四年级' }, { key: 5, value: '五年级' }, { key: 6, value: '六年级' },
{ key: 7, value: '初一' }, { key: 8, value: '初二' }, { key: 9, value: '初三' },
{ key: 10, value: '高一' }, { key: 11, value: '高二' }, { key: 12, value: '高三' }],
roleEnum: [{ key: 1, value: '学生' }, { key: 2, value: '教师' }, { key: 3, value: '管理员' }],
statusTag: [{ key: 1, value: 'success' }, { key: 2, value: 'danger' }],
statusBtn: [{ key: 1, value: '禁用' }, { key: 2, value: '启用' }]
},
exam: {
examPaper: {
paperTypeEnum: [{ key: 1, value: '固定试卷' }, { key: 4, value: '时段试卷' }, { key: 6, value: '任务试卷' }]
},
question: {
typeEnum: [{ key: 1, value: '单选题' }, { key: 2, value: '多选题' }, { key: 3, value: '判断题' }, { key: 4, value: '填空题' }, { key: 5, value: '简答题' }],
editUrlEnum: [{ key: 1, value: '/exam/question/edit/singleChoice', name: '单选题' },
{ key: 2, value: '/exam/question/edit/multipleChoice', name: '多选题' },
{ key: 3, value: '/exam/question/edit/trueFalse', name: '判断题' },
{ key: 4, value: '/exam/question/edit/gapFilling', name: '填空题' },
{ key: 5, value: '/exam/question/edit/shortAnswer', name: '简答题' }]
}
}
}
// getters
const getters = {
enumFormat: (state) => (arrary, key) => {
return format(arrary, key)
}
}
// actions
const actions = {}
// mutations
const mutations = {}
const format = function (array, key) {
for (let item of array) {
if (item.key === key) {
return item.value
}
}
return null
}
export default {
namespaced: true,
state,
getters,
actions,
mutations
}

View File

@@ -0,0 +1,43 @@
import subjectApi from '@/api/subject'
const state = {
subjects: []
}
const getters = {
subjectEnumFormat: (state) => (key) => {
for (let item of state.subjects) {
if (item.id === key) {
return item.name + ' ( ' + item.levelName + ' )'
}
}
return null
}
}
// actions
const actions = {
initSubject ({ commit }, action) {
subjectApi.list().then(re => {
commit('setSubjects', re.response)
if (action !== undefined) {
action()
}
})
}
}
// mutations
const mutations = {
setSubjects: (state, subjects) => {
state.subjects = subjects
}
}
export default {
namespaced: true,
state,
getters,
actions,
mutations
}

View File

@@ -0,0 +1,21 @@
import { constantRoutes } from '@/router'
let state = {
routes: constantRoutes
}
const mutations = {
initRoutes: (state) => {
state.routes = constantRoutes
}
}
const actions = {
}
export default {
namespaced: true,
state,
mutations,
actions
}

View File

@@ -0,0 +1,176 @@
const state = {
visitedViews: [],
cachedViews: []
}
const mutations = {
ADD_VISITED_VIEW: (state, view) => {
if (state.visitedViews.some(v => v.path === view.path)) return
state.visitedViews.push(
Object.assign({}, view, {
title: view.meta.title || 'no-name'
})
)
},
ADD_CACHED_VIEW: (state, view) => {
if (state.cachedViews.includes(view.name)) return
if (!view.meta.noCache) {
state.cachedViews.push(view.name)
}
},
DEL_VISITED_VIEW: (state, view) => {
for (const [i, v] of state.visitedViews.entries()) {
if (v.path === view.path) {
state.visitedViews.splice(i, 1)
break
}
}
},
DEL_CACHED_VIEW: (state, view) => {
for (const i of state.cachedViews) {
if (i === view.name) {
const index = state.cachedViews.indexOf(i)
state.cachedViews.splice(index, 1)
break
}
}
},
DEL_OTHERS_VISITED_VIEWS: (state, view) => {
state.visitedViews = state.visitedViews.filter(v => {
return v.meta.affix || v.path === view.path
})
},
DEL_OTHERS_CACHED_VIEWS: (state, view) => {
for (const i of state.cachedViews) {
if (i === view.name) {
const index = state.cachedViews.indexOf(i)
state.cachedViews = state.cachedViews.slice(index, index + 1)
break
}
}
},
DEL_ALL_VISITED_VIEWS: state => {
// keep affix tags
const affixTags = state.visitedViews.filter(tag => tag.meta.affix)
state.visitedViews = affixTags
},
DEL_ALL_CACHED_VIEWS: state => {
state.cachedViews = []
},
UPDATE_VISITED_VIEW: (state, view) => {
for (let v of state.visitedViews) {
if (v.path === view.path) {
v = Object.assign(v, view)
state.currentView = v
break
}
}
}
}
const actions = {
addView ({ dispatch }, view) {
dispatch('addVisitedView', view)
dispatch('addCachedView', view)
},
addVisitedView ({ commit }, view) {
commit('ADD_VISITED_VIEW', view)
},
addCachedView ({ commit }, view) {
commit('ADD_CACHED_VIEW', view)
},
delCurrentView ({ dispatch, state }, _this) {
let view = _this.$route
for (let v of state.visitedViews) {
if (v.path === view.path) {
return new Promise(resolve => {
dispatch('delVisitedView', v)
dispatch('delCachedView', v)
resolve()
})
}
}
},
delView ({ dispatch, state }, view) {
return new Promise(resolve => {
dispatch('delVisitedView', view)
dispatch('delCachedView', view)
resolve({
visitedViews: [...state.visitedViews],
cachedViews: [...state.cachedViews]
})
})
},
delVisitedView ({ commit, state }, view) {
return new Promise(resolve => {
commit('DEL_VISITED_VIEW', view)
resolve([...state.visitedViews])
})
},
delCachedView ({ commit, state }, view) {
return new Promise(resolve => {
commit('DEL_CACHED_VIEW', view)
resolve([...state.cachedViews])
})
},
delOthersViews ({ dispatch, state }, view) {
return new Promise(resolve => {
dispatch('delOthersVisitedViews', view)
dispatch('delOthersCachedViews', view)
resolve({
visitedViews: [...state.visitedViews],
cachedViews: [...state.cachedViews]
})
})
},
delOthersVisitedViews ({ commit, state }, view) {
return new Promise(resolve => {
commit('DEL_OTHERS_VISITED_VIEWS', view)
resolve([...state.visitedViews])
})
},
delOthersCachedViews ({ commit, state }, view) {
return new Promise(resolve => {
commit('DEL_OTHERS_CACHED_VIEWS', view)
resolve([...state.cachedViews])
})
},
delAllViews ({ dispatch, state }, view) {
return new Promise(resolve => {
dispatch('delAllVisitedViews', view)
dispatch('delAllCachedViews', view)
resolve({
visitedViews: [...state.visitedViews],
cachedViews: [...state.cachedViews]
})
})
},
delAllVisitedViews ({ commit, state }) {
return new Promise(resolve => {
commit('DEL_ALL_VISITED_VIEWS')
resolve([...state.visitedViews])
})
},
delAllCachedViews ({ commit, state }) {
return new Promise(resolve => {
commit('DEL_ALL_CACHED_VIEWS')
resolve([...state.cachedViews])
})
},
updateVisitedView ({ commit, state }, view) {
commit('UPDATE_VISITED_VIEW', view)
}
}
export default {
namespaced: true,
state,
mutations,
actions
}

View File

@@ -0,0 +1,39 @@
import Cookies from 'js-cookie'
import userApi from '@/api/user'
// initial state
const state = {
userName: Cookies.get('adminUserName'),
userInfo: Cookies.get('adminUserInfo')
}
// actions
const actions = {
initUserInfo ({ commit }) {
userApi.getCurrentUser().then(re => {
commit('setUserInfo', re.response)
})
}
}
// mutations
const mutations = {
setUserName (state, userName) {
state.userName = userName
Cookies.set('adminUserName', userName, { expires: 30 })
},
setUserInfo: (state, userInfo) => {
state.userInfo = userInfo
Cookies.set('adminUserInfo', userInfo, { expires: 30 })
},
clearLogin (state) {
Cookies.remove('adminUserName')
Cookies.remove('adminUserInfo')
}
}
export default {
namespaced: true,
state,
mutations,
actions
}