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-06-14 11:20:36 +00:00
|
|
|
import { onMounted } from 'vue'
|
2024-05-15 12:32:57 +00:00
|
|
|
import { useStore } from 'vuex'
|
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-06-14 11:20:36 +00:00
|
|
|
import AlertDialog from '../components/AlertDialog.vue'
|
|
|
|
import { initRuleEngine } from '@/render/hooks/useRuleEngine.js'
|
2024-05-15 12:32:57 +00:00
|
|
|
const store = useStore()
|
2024-06-14 11:20:36 +00:00
|
|
|
const route = useRoute()
|
|
|
|
const loadData = (res: any, surveyPath: string) => {
|
|
|
|
if (res.code === 200) {
|
|
|
|
const data = res.data
|
|
|
|
const {
|
|
|
|
bannerConf,
|
|
|
|
baseConf,
|
|
|
|
bottomConf,
|
|
|
|
dataConf,
|
|
|
|
skinConf,
|
|
|
|
submitConf,
|
|
|
|
logicConf
|
|
|
|
} = data.code
|
|
|
|
const questionData = {
|
|
|
|
bannerConf,
|
|
|
|
baseConf,
|
|
|
|
bottomConf,
|
|
|
|
dataConf,
|
|
|
|
skinConf,
|
|
|
|
submitConf
|
|
|
|
}
|
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-06-14 11:20:36 +00:00
|
|
|
store.commit('setSurveyPath', surveyPath)
|
|
|
|
store.dispatch('init', questionData)
|
|
|
|
initRuleEngine(logicConf?.showLogicConf)
|
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 })
|
|
|
|
store.commit('setSurveyPath', surveyId)
|
|
|
|
getDetail(surveyId as string)
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
|
|
|
store.dispatch('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>
|