feat: errorInfo to pinia (#353)

This commit is contained in:
yoruponder 2024-07-17 20:11:41 +08:00 committed by GitHub
parent 7ff691471b
commit bd603eccfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 5 deletions

View File

@ -14,13 +14,17 @@ import { computed } from 'vue'
import { useStore } from 'vuex' import { useStore } from 'vuex'
// @ts-ignore // @ts-ignore
import communalLoader from '@materials/communals/communalLoader.js' import communalLoader from '@materials/communals/communalLoader.js'
import { useErrorInfo } from '../stores/errorInfo'
const LogoIcon = communalLoader.loadComponent('LogoIcon') const LogoIcon = communalLoader.loadComponent('LogoIcon')
const store = useStore() const store = useStore()
const {errorInfo} = useErrorInfo();
const errorImageUrl = computed(() => { const errorImageUrl = computed(() => {
const errorType = store.state?.errorInfo?.errorType // const errorType = store.state?.errorInfo?.errorType
const errorType = errorInfo?.errorType
const imageMap = { const imageMap = {
overTime: '/imgs/icons/overtime.webp', overTime: '/imgs/icons/overtime.webp',
default: '/imgs/icons/error.webp' default: '/imgs/icons/error.webp'
@ -29,7 +33,10 @@ const errorImageUrl = computed(() => {
return imageMap[errorType as 'overTime'] || imageMap.default return imageMap[errorType as 'overTime'] || imageMap.default
}) })
const errorMsg = computed(() => store.state?.errorInfo?.errorMsg || '提交失败') // const errorMsg = computed(() => store.state?.errorInfo?.errorMsg || '')
const errorMsg = computed(() => {
return errorInfo?.errorMsg || '提交失败'
})
const logoConf = computed(() => store.state?.bottomConf || {}) const logoConf = computed(() => store.state?.bottomConf || {})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -8,6 +8,7 @@ import adapter from '../adapter'
import { RuleMatch } from '@/common/logicEngine/RulesMatch' import { RuleMatch } from '@/common/logicEngine/RulesMatch'
import { useSurveyStore } from '@/render/stores/survey' import { useSurveyStore } from '@/render/stores/survey'
import { useQuestionStore } from '@/render/stores/question' import { useQuestionStore } from '@/render/stores/question'
import { useErrorInfo } from '@/render/stores/errorInfo'
/** /**
* CODE_MAP不从management引入在dev阶段会导致B端 router被加载进而导致C端路由被添加 baseUrl: /management * CODE_MAP不从management引入在dev阶段会导致B端 router被加载进而导致C端路由被添加 baseUrl: /management
*/ */
@ -23,13 +24,20 @@ export default {
init({ commit }, { bannerConf, baseConf, bottomConf, dataConf, skinConf, submitConf }) { init({ commit }, { bannerConf, baseConf, bottomConf, dataConf, skinConf, submitConf }) {
const surveyStore = useSurveyStore() const surveyStore = useSurveyStore()
const questionStore = useQuestionStore() const questionStore = useQuestionStore()
const { setErrorInfo } = useErrorInfo()
surveyStore.setEnterTime() surveyStore.setEnterTime()
const { begTime, endTime, answerBegTime, answerEndTime } = baseConf const { begTime, endTime, answerBegTime, answerEndTime } = baseConf
const { msgContent } = submitConf const { msgContent } = submitConf
const now = Date.now() const now = Date.now()
if (now < new Date(begTime).getTime()) { if (now < new Date(begTime).getTime()) {
router.push({ name: 'errorPage' }) router.push({ name: 'errorPage' })
commit('setErrorInfo', { // commit('setErrorInfo', {
// errorType: 'overTime',
// errorMsg: `<p>问卷未到开始填写时间,暂时无法进行填写<p/>
// <p>开始时间为: ${begTime}</p>`
// })
setErrorInfo({
errorType: 'overTime', errorType: 'overTime',
errorMsg: `<p>问卷未到开始填写时间,暂时无法进行填写<p/> errorMsg: `<p>问卷未到开始填写时间,暂时无法进行填写<p/>
<p>开始时间为: ${begTime}</p>` <p>开始时间为: ${begTime}</p>`
@ -37,7 +45,11 @@ export default {
return return
} else if (now > new Date(endTime).getTime()) { } else if (now > new Date(endTime).getTime()) {
router.push({ name: 'errorPage' }) router.push({ name: 'errorPage' })
commit('setErrorInfo', { // commit('setErrorInfo', {
// errorType: 'overTime',
// errorMsg: msgContent.msg_9001 || '您来晚了,感谢支持问卷~'
// })
setErrorInfo({
errorType: 'overTime', errorType: 'overTime',
errorMsg: msgContent.msg_9001 || '您来晚了,感谢支持问卷~' errorMsg: msgContent.msg_9001 || '您来晚了,感谢支持问卷~'
}) })
@ -49,7 +61,12 @@ export default {
const momentEndTime = moment(`${todayStr} ${answerEndTime}`) const momentEndTime = moment(`${todayStr} ${answerEndTime}`)
if (momentNow.isBefore(momentStartTime) || momentNow.isAfter(momentEndTime)) { if (momentNow.isBefore(momentStartTime) || momentNow.isAfter(momentEndTime)) {
router.push({ name: 'errorPage' }) router.push({ name: 'errorPage' })
commit('setErrorInfo', { // commit('setErrorInfo', {
// errorType: 'overTime',
// errorMsg: `<p>不在答题时间范围内,暂时无法进行填写<p/>
// <p>答题时间为: ${answerBegTime} ~ ${answerEndTime}</p>`
// })
setErrorInfo({
errorType: 'overTime', errorType: 'overTime',
errorMsg: `<p>不在答题时间范围内,暂时无法进行填写<p/> errorMsg: `<p>不在答题时间范围内,暂时无法进行填写<p/>
<p>答题时间为: ${answerBegTime} ~ ${answerEndTime}</p>` <p>答题时间为: ${answerBegTime} ~ ${answerEndTime}</p>`

View File

@ -0,0 +1,22 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useErrorInfo = defineStore('errorInfo', () => {
const errorInfo = ref( {
errorType: '',
errorMsg: ''
})
const setErrorInfo = ( { errorType, errorMsg }) => {
errorInfo.value = {
errorType,
errorMsg
}
};
return {
errorInfo,
setErrorInfo
}
})