fix: render错误数据不同步问题

This commit is contained in:
sudoooooo 2024-07-22 17:18:37 +08:00
parent 6b7b3a12d8
commit 9afd1d1c7c
4 changed files with 46 additions and 40 deletions

View File

@ -30,7 +30,7 @@
</template>
<script setup>
import { computed, ref, watch, toRefs } from 'vue'
import { ref, watch, toRefs } from 'vue'
import communalLoader from '@materials/communals/communalLoader.js'
import MaterialGroup from '@/management/pages/edit/components/MaterialGroup.vue'
import { storeToRefs } from 'pinia'
@ -47,12 +47,12 @@ const mainOperation = ref(null)
const materialGroup = ref(null)
const { bannerConf, submitConf, skinConf } = toRefs(schema)
const autoScrollData = computed(() => {
return {
currentEditOne: currentEditOne.value,
len: questionDataList.value.length
}
})
// const autoScrollData = computed(() => {
// return {
// currentEditOne: currentEditOne.value,
// len: questionDataList.value.length
// }
// })
const handleChange = (data) => {
if (currentEditOne.value === null) {
@ -108,22 +108,24 @@ watch(
}
)
watch(autoScrollData, (newVal) => {
const { currentEditOne } = newVal
if (typeof currentEditOne === 'number') {
setTimeout(() => {
const field = questionDataList.value?.[currentEditOne]?.field
if (field) {
const questionModule = materialGroup.value?.getQuestionRefByField(field)
if (questionModule && questionModule.$el) {
questionModule.$el.scrollIntoView({
behavior: 'smooth'
})
}
}
}, 0)
}
})
//
//
// watch(autoScrollData, (newVal) => {
// const { currentEditOne } = newVal
// if (typeof currentEditOne === 'number') {
// setTimeout(() => {
// const field = questionDataList.value?.[currentEditOne]?.field
// if (field) {
// const questionModule = materialGroup.value?.getQuestionRefByField(field)
// if (questionModule && questionModule.$el) {
// questionModule.$el.scrollIntoView({
// behavior: 'smooth'
// })
// }
// }
// }, 0)
// }
// })
</script>
<style lang="scss" scoped>

View File

@ -2,16 +2,17 @@
<div class="result-page-wrap">
<div class="result-page">
<div class="page-content">
<img class="img" :src="errorImageUrl" />
<img class="img" :src="errorImage" />
<div class="msg" v-html="errorMsg"></div>
</div>
<LogoIcon :logo-conf="logoConf" :readonly="true" />
</div>
</div>
</template>
<script setup lang="ts">
<script setup>
import { computed } from 'vue'
// @ts-ignore
import { storeToRefs } from 'pinia'
import communalLoader from '@materials/communals/communalLoader.js'
import { useErrorInfo } from '../stores/errorInfo'
import { useSurveyStore } from '../stores/survey'
@ -19,20 +20,21 @@ import { useSurveyStore } from '../stores/survey'
const LogoIcon = communalLoader.loadComponent('LogoIcon')
const surveyStore = useSurveyStore()
const { errorInfo } = useErrorInfo()
const errorImageUrl = computed(() => {
const errorType = errorInfo?.errorType
const imageMap = {
const errorStore = useErrorInfo()
const { errorInfo } = storeToRefs(errorStore)
const imageMap = {
overTime: '/imgs/icons/overtime.webp',
default: '/imgs/icons/error.webp'
}
}
return imageMap[errorType as 'overTime'] || imageMap.default
const errorImage = computed(() => {
const errorType = errorInfo.value.errorType
return imageMap[errorType] || imageMap.default
})
const errorMsg = computed(() => {
return errorInfo?.errorMsg || '提交失败'
return errorInfo.value.errorMsg || '提交失败'
})
const logoConf = computed(() => surveyStore.bottomConf || {})
</script>

View File

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

View File

@ -61,7 +61,7 @@ export const useSurveyStore = defineStore('survey', () => {
}
}
const canFillQuestionnaire = (baseConf) => {
const canFillQuestionnaire = (baseConf, submitConf) => {
const { begTime, endTime, answerBegTime, answerEndTime } = baseConf
const { msgContent } = submitConf
const now = Date.now()
@ -104,7 +104,7 @@ export const useSurveyStore = defineStore('survey', () => {
const initSurvey = (option) => {
setEnterTime()
if (!canFillQuestionnaire(option.baseConf)) {
if (!canFillQuestionnaire(option.baseConf, option.submitConf)) {
return
}
@ -121,6 +121,7 @@ export const useSurveyStore = defineStore('survey', () => {
questionStore.questionData = questionData
questionStore.questionSeq = questionSeq
// 将数据设置到state上
rules.value = _rules
bannerConf.value = option.bannerConf
baseConf.value = option.baseConf
@ -134,6 +135,7 @@ export const useSurveyStore = defineStore('survey', () => {
questionStore.initVoteData()
}
// 用户输入或者选择后,更新表单数据
const changeData = (data) => {
let { key, value } = data
if (key in formValues.value) {