2024-05-09 12:34:24 +00:00
|
|
|
<template>
|
|
|
|
<div class="index">
|
2024-05-21 13:31:55 +00:00
|
|
|
<ProgressBar />
|
2024-05-15 12:32:57 +00:00
|
|
|
<div class="wrapper" ref="boxRef">
|
2024-05-29 13:59:13 +00:00
|
|
|
<HeaderContent :bannerConf="bannerConf" :readonly="true" />
|
2024-05-09 12:34:24 +00:00
|
|
|
<div class="content">
|
2024-05-29 13:59:13 +00:00
|
|
|
<MainTitle :bannerConf="bannerConf" :readonly="true"></MainTitle>
|
2024-05-15 12:32:57 +00:00
|
|
|
<MainRenderer ref="mainRef"></MainRenderer>
|
2024-05-29 13:59:13 +00:00
|
|
|
<SubmitButton
|
|
|
|
:validate="validate"
|
|
|
|
:submitConf="submitConf"
|
|
|
|
:readonly="true"
|
|
|
|
:renderData="renderData"
|
|
|
|
@submit="handleSubmit"
|
|
|
|
></SubmitButton>
|
|
|
|
<LogoIcon :logo-conf="logoConf" :readonly="true" />
|
2024-05-09 12:34:24 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2024-05-15 12:32:57 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed, ref } from 'vue'
|
|
|
|
import { useStore } from 'vuex'
|
2024-05-29 13:59:13 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import communalLoader from '@materials/communals/communalLoader.js'
|
2024-05-09 12:34:24 +00:00
|
|
|
import MainRenderer from '../components/MainRenderer.vue'
|
|
|
|
import AlertDialog from '../components/AlertDialog.vue'
|
|
|
|
import ConfirmDialog from '../components/ConfirmDialog.vue'
|
2024-05-21 13:31:55 +00:00
|
|
|
import ProgressBar from '../components/ProgressBar.vue'
|
2024-05-09 12:34:24 +00:00
|
|
|
|
|
|
|
import { submitForm } from '../api/survey'
|
|
|
|
import encrypt from '../utils/encrypt'
|
|
|
|
|
|
|
|
import useCommandComponent from '../hooks/useCommandComponent'
|
|
|
|
|
2024-05-15 12:32:57 +00:00
|
|
|
interface Props {
|
2024-05-15 12:34:56 +00:00
|
|
|
questionInfo?: any
|
|
|
|
isMobile?: boolean
|
2024-05-15 12:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
withDefaults(defineProps<Props>(), {
|
|
|
|
questionInfo: {},
|
2024-05-15 12:34:56 +00:00
|
|
|
isMobile: false
|
2024-05-15 12:32:57 +00:00
|
|
|
})
|
|
|
|
|
2024-05-29 13:59:13 +00:00
|
|
|
const HeaderContent = communalLoader.loadComponent('HeaderContent')
|
|
|
|
const MainTitle = communalLoader.loadComponent('MainTitle')
|
|
|
|
const SubmitButton = communalLoader.loadComponent('SubmitButton')
|
|
|
|
const LogoIcon = communalLoader.loadComponent('LogoIcon')
|
|
|
|
|
2024-05-15 12:32:57 +00:00
|
|
|
const mainRef = ref<any>()
|
|
|
|
const boxRef = ref<HTMLElement>()
|
|
|
|
|
|
|
|
const alert = useCommandComponent(AlertDialog)
|
|
|
|
const confirm = useCommandComponent(ConfirmDialog)
|
|
|
|
|
|
|
|
const store = useStore()
|
|
|
|
|
2024-05-29 13:59:13 +00:00
|
|
|
const bannerConf = computed(() => store.state?.bannerConf || {})
|
2024-05-15 12:32:57 +00:00
|
|
|
const renderData = computed(() => store.getters.renderData)
|
2024-05-29 13:59:13 +00:00
|
|
|
const submitConf = computed(() => store.state?.submitConf || {})
|
|
|
|
const logoConf = computed(() => store.state?.bottomConf || {})
|
2024-06-11 08:04:00 +00:00
|
|
|
const surveyPath = computed(() => store.state?.surveyPath || '')
|
2024-05-15 12:32:57 +00:00
|
|
|
|
|
|
|
const validate = (cbk: (v: boolean) => void) => {
|
|
|
|
const index = 0
|
|
|
|
mainRef.value.$refs.formGroup[index].validate(cbk)
|
|
|
|
}
|
|
|
|
|
|
|
|
const normalizationRequestBody = () => {
|
|
|
|
const enterTime = store.state.enterTime
|
|
|
|
const encryptInfo = store.state.encryptInfo
|
2024-05-29 14:04:44 +00:00
|
|
|
const formValues = store.state.formValues
|
2024-05-15 12:32:57 +00:00
|
|
|
|
|
|
|
const result: any = {
|
2024-06-11 08:04:00 +00:00
|
|
|
surveyPath: surveyPath.value,
|
2024-05-29 14:04:44 +00:00
|
|
|
data: JSON.stringify(formValues),
|
2024-05-15 12:32:57 +00:00
|
|
|
difTime: Date.now() - enterTime,
|
|
|
|
clientTime: Date.now()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encryptInfo?.encryptType) {
|
|
|
|
result.encryptType = encryptInfo?.encryptType
|
|
|
|
result.data = encrypt[result.encryptType as 'rsa']({
|
|
|
|
data: result.data,
|
|
|
|
secretKey: encryptInfo?.data?.secretKey
|
|
|
|
})
|
|
|
|
if (encryptInfo?.data?.sessionId) {
|
|
|
|
result.sessionId = encryptInfo.data.sessionId
|
2024-05-09 12:34:24 +00:00
|
|
|
}
|
2024-05-15 12:32:57 +00:00
|
|
|
} else {
|
|
|
|
result.data = JSON.stringify(result.data)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
const submitSurver = async () => {
|
2024-06-11 08:04:00 +00:00
|
|
|
if (surveyPath.value.length > 8) {
|
|
|
|
store.commit('setRouter', 'successPage')
|
|
|
|
return
|
|
|
|
}
|
2024-05-15 12:32:57 +00:00
|
|
|
try {
|
|
|
|
const params = normalizationRequestBody()
|
|
|
|
const res: any = await submitForm(params)
|
|
|
|
if (res.code === 200) {
|
|
|
|
store.commit('setRouter', 'successPage')
|
|
|
|
} else {
|
|
|
|
alert({
|
|
|
|
title: res.errmsg || '提交失败'
|
|
|
|
})
|
2024-05-09 12:34:24 +00:00
|
|
|
}
|
2024-05-15 12:32:57 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.log(error)
|
|
|
|
}
|
|
|
|
}
|
2024-05-09 12:34:24 +00:00
|
|
|
|
2024-05-15 12:32:57 +00:00
|
|
|
const handleSubmit = () => {
|
|
|
|
const confirmAgain = store.state.submitConf.confirmAgain
|
|
|
|
const { again_text, is_again } = confirmAgain
|
|
|
|
|
|
|
|
if (is_again) {
|
|
|
|
confirm({
|
|
|
|
title: again_text,
|
|
|
|
onConfirm: async () => {
|
|
|
|
try {
|
|
|
|
submitSurver()
|
2024-05-15 12:34:56 +00:00
|
|
|
} catch (error) {
|
2024-05-15 12:32:57 +00:00
|
|
|
console.log(error)
|
|
|
|
} finally {
|
|
|
|
confirm.close()
|
2024-05-09 12:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-15 12:32:57 +00:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
submitSurver()
|
2024-05-09 12:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.index {
|
|
|
|
min-height: 100%;
|
2024-05-29 13:59:13 +00:00
|
|
|
|
2024-05-09 12:34:24 +00:00
|
|
|
.wrapper {
|
|
|
|
min-height: 100%;
|
|
|
|
background-color: var(--primary-background-color);
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2024-05-29 13:59:13 +00:00
|
|
|
|
2024-05-09 12:34:24 +00:00
|
|
|
.content {
|
|
|
|
flex: 1;
|
|
|
|
margin: 0 0.3rem;
|
|
|
|
background: rgba(255, 255, 255, var(--opacity));
|
|
|
|
border-radius: 8px 8px 0 0;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|