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

64 lines
1.7 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">
2024-06-14 11:20:36 +00:00
import { onMounted } from 'vue'
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'
import { initRuleEngine } from '@/render/hooks/useRuleEngine.js'
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-07-10 07:30:39 +00:00
const { bannerConf, baseConf, bottomConf, dataConf, skinConf, submitConf, logicConf } =
data.code
2024-06-14 11:20:36 +00:00
const questionData = {
bannerConf,
baseConf,
bottomConf,
dataConf,
skinConf,
submitConf
}
2024-06-14 11:20:36 +00:00
document.title = data.title
surveyStore.setSurveyPath(surveyPath)
surveyStore.initSurvey(questionData)
2024-06-14 11:20:36 +00:00
initRuleEngine(logicConf?.showLogicConf)
} 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)
})
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>