Skip to content

Commit

Permalink
feat: C端增加重新填写入口, didi#182
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangchunfu committed Aug 10, 2024
1 parent 0702858 commit b4893a7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
48 changes: 37 additions & 11 deletions web/src/render/pages/IndexPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
<router-view></router-view>
</template>
<script setup lang="ts">
import { onMounted } from 'vue'
import { onMounted, watch } from 'vue'
import { useRoute } from 'vue-router'
import { getPublishedSurveyInfo, getPreviewSchema } from '../api/survey'
import useCommandComponent from '../hooks/useCommandComponent'
import { useSurveyStore } from '../stores/survey'
import { useQuestionStore } from '../stores/question'
import AlertDialog from '../components/AlertDialog.vue'
import { initRuleEngine } from '@/render/hooks/useRuleEngine.js'
const route = useRoute()
const surveyId = route.params.surveyId
const isPreview = surveyId.length > 8
const surveyStore = useSurveyStore()
const questionStore = useQuestionStore()
let questionData
const loadData = (res: any, surveyPath: string) => {
if (res.code === 200) {
const data = res.data
Expand All @@ -26,7 +32,7 @@ const loadData = (res: any, surveyPath: string) => {
logicConf,
pageConf
} = data.code
const questionData = {
questionData = {
bannerConf,
baseConf,
bottomConf,
Expand All @@ -50,24 +56,44 @@ const loadData = (res: any, surveyPath: string) => {
}
}
onMounted(() => {
const surveyId = route.params.surveyId
console.log({ surveyId })
surveyStore.setSurveyPath(surveyId)
getDetail(surveyId as string)
})
watch(
() => route.query.t,
() => {
// location.reload()
reAnswer()
}
)
// 重新答题
function reAnswer() {
surveyStore.setEnterTime()
if (!surveyStore.canFillQuestionnaire(questionData!.baseConf, questionData!.submitConf)) {
return
}
// 重置数据
for (const key in surveyStore.formValues) {
;(surveyStore.formValues as Record<string, string>)[key] = ''
}
// 重置页码
questionStore.pageIndex = 1
// 重置加密
if (!isPreview) surveyStore.getEncryptInfo()
}
const getDetail = async (surveyPath: string) => {
const alert = useCommandComponent(AlertDialog)
try {
if (surveyPath.length > 8) {
const res: any = await getPreviewSchema({ surveyPath })
loadData(res, surveyPath)
} else {
const res: any = await getPublishedSurveyInfo({ surveyPath })
loadData(res, surveyPath)
surveyStore.getEncryptInfo()
}
const getInfoData = isPreview ? getPreviewSchema : getPublishedSurveyInfo
const res: any = await getInfoData({ surveyPath })
loadData(res, surveyPath)
if (!isPreview) surveyStore.getEncryptInfo()
} catch (error: any) {
console.log(error)
alert({ title: error.message || '获取问卷失败' })
Expand Down
20 changes: 20 additions & 0 deletions web/src/render/pages/SuccessPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
<div class="result-content">
<img src="/imgs/icons/success.webp" />
<div class="msg" v-html="successMsg"></div>
<router-link
:to="{
name: 'renderPage',
query: {
t: new Date().getTime()
}
}"
replace
class="reset-link"
>
重新填写
</router-link>
</div>
<LogoIcon :logo-conf="logoConf" :readonly="true" />
</div>
Expand Down Expand Up @@ -65,5 +77,13 @@ const successMsg = computed(() => {
font-weight: 500;
margin-top: 0.15rem;
}
.reset-link {
margin-top: 0.24rem;
font-size: 0.27rem;
color: #5094f0;
text-decoration: underline;
display: block;
}
}
</style>
3 changes: 2 additions & 1 deletion web/src/render/stores/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export const useSurveyStore = defineStore('survey', () => {
setWhiteData,
setSurveyPath,
setEnterTime,
getEncryptInfo
getEncryptInfo,
canFillQuestionnaire
}
})

0 comments on commit b4893a7

Please sign in to comment.