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>
|
2024-05-15 12:32:57 +00:00
|
|
|
<script setup lang="ts">
|
2024-08-12 11:43:55 +00:00
|
|
|
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'
|
2024-07-10 06:41:36 +00:00
|
|
|
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-08-14 09:59:51 +00:00
|
|
|
|
2024-06-14 11:20:36 +00:00
|
|
|
const route = useRoute()
|
2024-07-10 06:41:36 +00:00
|
|
|
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,
|
2024-08-06 09:30:12 +00:00
|
|
|
submitConf,
|
2024-08-06 11:33:11 +00:00
|
|
|
pageConf
|
2024-08-06 09:30:12 +00:00
|
|
|
}
|
|
|
|
|
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-05-15 12:32:57 +00:00
|
|
|
|
2024-06-14 11:20:36 +00:00
|
|
|
document.title = data.title
|
2024-05-15 12:32:57 +00:00
|
|
|
|
2024-07-10 06:41:36 +00:00
|
|
|
surveyStore.setSurveyPath(surveyPath)
|
2024-07-19 10:55:22 +00:00
|
|
|
surveyStore.initSurvey(questionData)
|
2024-08-14 09:59:51 +00:00
|
|
|
surveyStore.initShowLogicEngine(logicConf?.showLogicConf)
|
|
|
|
surveyStore.initJumpLogicEngine(logicConf.jumpLogicConf)
|
2024-05-15 12:32:57 +00:00
|
|
|
} else {
|
2024-06-14 11:20:36 +00:00
|
|
|
throw new Error(res.errmsg)
|
2024-05-15 12:32:57 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-14 11:20:36 +00:00
|
|
|
onMounted(() => {
|
|
|
|
const surveyId = route.params.surveyId
|
|
|
|
console.log({ surveyId })
|
2024-07-10 06:41:36 +00:00
|
|
|
surveyStore.setSurveyPath(surveyId)
|
2024-06-14 11:20:36 +00:00
|
|
|
getDetail(surveyId as string)
|
|
|
|
})
|
|
|
|
|
2024-08-12 11:43:55 +00:00
|
|
|
watch(
|
|
|
|
() => route.query.t,
|
|
|
|
() => {
|
|
|
|
location.reload()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-06-14 11:20:36 +00:00
|
|
|
const getDetail = async (surveyPath: string) => {
|
|
|
|
const alert = useCommandComponent(AlertDialog)
|
2024-05-15 12:32:57 +00:00
|
|
|
|
|
|
|
try {
|
2024-06-14 11:20:36 +00:00
|
|
|
if (surveyPath.length > 8) {
|
|
|
|
const res: any = await getPreviewSchema({ surveyPath })
|
|
|
|
loadData(res, surveyPath)
|
2024-05-15 12:32:57 +00:00
|
|
|
} 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) {
|
2024-05-15 12:32:57 +00:00
|
|
|
console.log(error)
|
2024-06-14 11:20:36 +00:00
|
|
|
alert({ title: error.message || '获取问卷失败' })
|
2024-05-09 12:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|