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

View File

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

View File

@ -2,17 +2,17 @@ import { ref } from 'vue'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
export const useErrorInfo = defineStore('errorInfo', () => { export const useErrorInfo = defineStore('errorInfo', () => {
const errorInfo = ref( { const errorInfo = ref({
errorType: '', errorType: '',
errorMsg: '' errorMsg: ''
}) })
const setErrorInfo = ( { errorType, errorMsg }) => { const setErrorInfo = ({ errorType, errorMsg }) => {
errorInfo.value = { errorInfo.value = {
errorType, errorType,
errorMsg errorMsg
} }
}; }
return { return {
errorInfo, 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 { begTime, endTime, answerBegTime, answerEndTime } = baseConf
const { msgContent } = submitConf const { msgContent } = submitConf
const now = Date.now() const now = Date.now()
@ -104,7 +104,7 @@ export const useSurveyStore = defineStore('survey', () => {
const initSurvey = (option) => { const initSurvey = (option) => {
setEnterTime() setEnterTime()
if (!canFillQuestionnaire(option.baseConf)) { if (!canFillQuestionnaire(option.baseConf, option.submitConf)) {
return return
} }
@ -121,6 +121,7 @@ export const useSurveyStore = defineStore('survey', () => {
questionStore.questionData = questionData questionStore.questionData = questionData
questionStore.questionSeq = questionSeq questionStore.questionSeq = questionSeq
// 将数据设置到state上
rules.value = _rules rules.value = _rules
bannerConf.value = option.bannerConf bannerConf.value = option.bannerConf
baseConf.value = option.baseConf baseConf.value = option.baseConf
@ -134,6 +135,7 @@ export const useSurveyStore = defineStore('survey', () => {
questionStore.initVoteData() questionStore.initVoteData()
} }
// 用户输入或者选择后,更新表单数据
const changeData = (data) => { const changeData = (data) => {
let { key, value } = data let { key, value } = data
if (key in formValues.value) { if (key in formValues.value) {