v3.0.6
This commit is contained in:
61
source/vue/xzs-student/src/store/modules/enumItem.js
Normal file
61
source/vue/xzs-student/src/store/modules/enumItem.js
Normal file
@@ -0,0 +1,61 @@
|
||||
// initial state
|
||||
const state = {
|
||||
user: {
|
||||
sexEnum: [{ 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: '管理员' }],
|
||||
message: {
|
||||
readTag: [{ key: true, value: 'success' }, { key: false, value: 'warning' }],
|
||||
readText: [{ key: true, value: '已读' }, { key: false, value: '未读' }]
|
||||
}
|
||||
},
|
||||
exam: {
|
||||
examPaper: {
|
||||
paperTypeEnum: [{ key: 1, value: '固定试卷' }, { key: 4, value: '时段试卷' }]
|
||||
},
|
||||
examPaperAnswer: {
|
||||
statusEnum: [{ key: 1, value: '待批改' }, { key: 2, value: '完成' }],
|
||||
statusTag: [{ key: 1, value: 'warning' }, { key: 2, value: 'success' }]
|
||||
},
|
||||
question: {
|
||||
typeEnum: [{ key: 1, value: '单选题' }, { key: 2, value: '多选题' }, { key: 3, value: '判断题' }, { key: 4, value: '填空题' }, { key: 5, value: '简答题' }],
|
||||
answer: {
|
||||
doRightTag: [{ key: true, value: 'success' }, { key: false, value: 'danger' }, { key: null, value: 'warning' }],
|
||||
doRightEnum: [{ key: true, value: '正确' }, { key: false, value: '错误' }, { key: null, value: '待批改' }],
|
||||
doCompletedTag: [{ key: false, value: 'info' }, { key: true, value: 'success' }]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
40
source/vue/xzs-student/src/store/modules/exam.js
Normal file
40
source/vue/xzs-student/src/store/modules/exam.js
Normal file
@@ -0,0 +1,40 @@
|
||||
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 }) {
|
||||
subjectApi.list().then(re => {
|
||||
commit('setSubjects', re.response)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
setSubjects: (state, subjects) => {
|
||||
state.subjects = subjects
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
57
source/vue/xzs-student/src/store/modules/user.js
Normal file
57
source/vue/xzs-student/src/store/modules/user.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import Cookies from 'js-cookie'
|
||||
import userApi from '@/api/user'
|
||||
// initial state
|
||||
const state = {
|
||||
userName: Cookies.get('studentUserName'),
|
||||
userInfo: Cookies.get('studentUserInfo'),
|
||||
imagePath: Cookies.get('studentImagePath'),
|
||||
messageCount: 0
|
||||
}
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
initUserInfo ({ commit }) {
|
||||
userApi.getCurrentUser().then(re => {
|
||||
commit('setUserInfo', re.response)
|
||||
})
|
||||
},
|
||||
getUserMessageInfo ({ commit }) {
|
||||
userApi.getMessageCount().then(re => {
|
||||
commit('setMessageCount', re.response)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
setUserName (state, userName) {
|
||||
state.userName = userName
|
||||
Cookies.set('studentUserName', userName, { expires: 30 })
|
||||
},
|
||||
setUserInfo: (state, userInfo) => {
|
||||
state.userInfo = userInfo
|
||||
Cookies.set('studentUserInfo', userInfo, { expires: 30 })
|
||||
},
|
||||
setImagePath: (state, imagePath) => {
|
||||
state.imagePath = imagePath
|
||||
Cookies.set('studentImagePath', imagePath, { expires: 30 })
|
||||
},
|
||||
setMessageCount: (state, messageCount) => {
|
||||
state.messageCount = messageCount
|
||||
},
|
||||
messageCountSubtract: (state, num) => {
|
||||
state.messageCount = state.messageCount - num
|
||||
},
|
||||
clearLogin (state) {
|
||||
Cookies.remove('studentUserName')
|
||||
Cookies.remove('studentUserInfo')
|
||||
Cookies.remove('studentImagePath')
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
Reference in New Issue
Block a user