xiaoju-survey/web/src/render/pages/IndexPage.vue

85 lines
2.0 KiB
Vue
Raw Normal View History

2024-05-09 12:34:24 +00:00
<template>
2024-06-14 11:20:36 +00:00
<router-view></router-view>
2024-05-09 12:34:24 +00:00
</template>
<script setup lang="ts">
import { onMounted, watch } from 'vue'
2024-06-14 11:20:36 +00:00
import { useRoute } from 'vue-router'
2024-05-09 12:34:24 +00:00
2024-06-14 11:20:36 +00:00
import { getPublishedSurveyInfo, getPreviewSchema } from '../api/survey'
2024-05-09 12:34:24 +00:00
import useCommandComponent from '../hooks/useCommandComponent'
import { useSurveyStore } from '../stores/survey'
2024-05-09 12:34:24 +00:00
2024-06-14 11:20:36 +00:00
import AlertDialog from '../components/AlertDialog.vue'
2024-06-14 11:20:36 +00:00
const route = useRoute()
const surveyStore = useSurveyStore()
2024-06-14 11:20:36 +00:00
const loadData = (res: any, surveyPath: string) => {
if (res.code === 200) {
const data = res.data
2024-08-06 11:33:11 +00:00
const {
bannerConf,
baseConf,
bottomConf,
dataConf,
skinConf,
submitConf,
logicConf,
pageConf
} = data.code
2024-06-14 11:20:36 +00:00
const questionData = {
bannerConf,
baseConf,
bottomConf,
dataConf,
skinConf,
submitConf,
2024-08-06 11:33:11 +00:00
pageConf
}
2024-08-06 11:33:11 +00:00
if (!pageConf || pageConf?.length == 0) {
questionData.pageConf = [dataConf.dataList.length]
2024-06-14 11:20:36 +00:00
}
2024-06-14 11:20:36 +00:00
document.title = data.title
surveyStore.setSurveyPath(surveyPath)
surveyStore.initSurvey(questionData)
surveyStore.initShowLogicEngine(logicConf?.showLogicConf)
surveyStore.initJumpLogicEngine(logicConf.jumpLogicConf)
} else {
2024-06-14 11:20:36 +00:00
throw new Error(res.errmsg)
}
}
2024-06-14 11:20:36 +00:00
onMounted(() => {
const surveyId = route.params.surveyId
console.log({ surveyId })
surveyStore.setSurveyPath(surveyId)
2024-06-14 11:20:36 +00:00
getDetail(surveyId as string)
})
watch(
() => route.query.t,
() => {
location.reload()
}
)
2024-06-14 11:20:36 +00:00
const getDetail = async (surveyPath: string) => {
const alert = useCommandComponent(AlertDialog)
try {
2024-06-14 11:20:36 +00:00
if (surveyPath.length > 8) {
const res: any = await getPreviewSchema({ surveyPath })
loadData(res, surveyPath)
} else {
2024-06-14 11:20:36 +00:00
const res: any = await getPublishedSurveyInfo({ surveyPath })
loadData(res, surveyPath)
2024-07-10 07:30:39 +00:00
surveyStore.getEncryptInfo()
2024-05-09 12:34:24 +00:00
}
2024-06-14 11:20:36 +00:00
} catch (error: any) {
console.log(error)
2024-06-14 11:20:36 +00:00
alert({ title: error.message || '获取问卷失败' })
2024-05-09 12:34:24 +00:00
}
}
</script>