不在组别内的扫描调查问卷二维码优化

This commit is contained in:
2026-10-22 17:05:06 +08:00
parent 3f51f5ebc4
commit f20bccc1ee
@@ -83,8 +83,12 @@ layout("/layouts/platform_h5.html"){
</style>
<div id="app" v-cloak>
<van-nav-bar title="问卷调查" left-arrow @click-left="historyBack" placeholder fixed></van-nav-bar>
<div class="container" :style="{'padding-bottom': answerRecord.isFinish ? 0 : '84px'}">
<van-nav-bar title="问卷调查" left-arrow @click-left="onBack" placeholder fixed></van-nav-bar>
<van-loading v-if="tableLoading" vertical style="padding: 40px 0">正在加载问卷</van-loading>
<van-empty v-else-if="loadError" :description="loadError">
<van-button type="primary" @click="onBack">返回首页</van-button>
</van-empty>
<div v-else-if="surveyReady" class="container" :style="{'padding-bottom': answerRecord.isFinish ? 0 : '84px'}">
<h2 class="title">{{ activity.title }}</h2>
<div v-if="!isFinished">
<div v-for="(subject, index) in visibleSubjects" :key="subject.id" class="subject">
@@ -149,7 +153,10 @@ layout("/layouts/platform_h5.html"){
remainingTime: 0,
isFinished: false,
answerRecord: {},
answerRecordId: null
answerRecordId: null,
tableLoading: false,
surveyReady: false,
loadError: ""
}
},
@@ -173,29 +180,69 @@ layout("/layouts/platform_h5.html"){
},
methods: {
//获取活动、题目
listSubjects() {
this.$axios.post("/platform/h5/qsv/survey/subjects", { activityId: this.id }).then((res) => {
if (res.code === 0) {
this.activity = res.data.activity
this.subjects = res.data.subjects
this.answerRecordId = res.data.answerRecordId
this.getAnswerRecord()
}
})
//失败页直接替换为首页,避免扫码认证历史将用户再次带回无权参与的问卷。
onBack() {
if (this.loadError) {
window.h5PopupHistory.clear().then(() => {
window.location.replace("/platform/h5/home")
})
return
}
this.historyBack()
},
//获取回答记录
//error 为接口业务错误或网络异常;持久展示提示,并禁止空问卷提交。
onLoadError(error) {
this.$set(this, "surveyReady", false)
this.$set(this, "loadError", (error && (error.msg || error.message)) || "问卷加载失败,请返回首页后重试")
},
//activityId 传扫码地址中的 id;成功返回活动、题目及答题记录 ID,再加载历史答案。
listSubjects() {
this.$set(this, "tableLoading", true)
this.$set(this, "surveyReady", false)
this.$set(this, "loadError", "")
return this.$axios.post("/platform/h5/qsv/survey/subjects", { activityId: this.id })
.then((res) => {
if (res.code !== 0 || !res.data || !res.data.activity || !res.data.answerRecordId || !Array.isArray(res.data.subjects)) {
throw new Error(res.msg || "问卷数据不完整,请返回首页后重试")
}
this.$set(this, "activity", res.data.activity)
this.$set(this, "subjects", res.data.subjects)
this.$set(this, "answerRecordId", res.data.answerRecordId)
return this.getAnswerRecord()
})
.catch((error) => {
this.onLoadError(error)
})
.finally(() => {
this.$set(this, "tableLoading", false)
})
},
//answerRecordId 传题目接口返回的记录 ID;答案回显完成后才允许展示和提交问卷。
getAnswerRecord() {
this.$axios.post("/platform/h5/qsv/survey/answerRecord", { answerRecordId: this.answerRecordId }).then((res) => {
if (res.code === 0) {
this.answerRecord = res.data
this.$set(this, "tableLoading", true)
this.$set(this, "surveyReady", false)
return this.$axios.post("/platform/h5/qsv/survey/answerRecord", { answerRecordId: this.answerRecordId })
.then((res) => {
if (res.code !== 0 || !res.data) {
throw new Error(res.msg || "答题记录加载失败,请返回首页后重试")
}
this.$set(this, "answerRecord", res.data)
if (this.answerRecord.isFinish) {
this.$toast.success("您已完成该调查")
}
this.initAnswer()
}
})
this.$set(this, "loadError", "")
this.$set(this, "surveyReady", true)
})
.catch((error) => {
this.onLoadError(error)
})
.finally(() => {
this.$set(this, "tableLoading", false)
})
},
//直接回填答案数据,隐藏题没有组件引用,也能安全完成历史答卷回显。
@@ -281,6 +328,10 @@ layout("/layouts/platform_h5.html"){
//手动提交
onSubmit() {
//范围校验失败、加载未完成或已提交时,不发送无效答卷。
if (!this.surveyReady || this.tableLoading || this.loadError || !this.answerRecordId || this.answerRecord.isFinish) {
return
}
const endTime = this.activity.endTime
if (this.isEnd) {
this.$toast("调查已结束")
@@ -307,6 +358,10 @@ layout("/layouts/platform_h5.html"){
//自动提交
autoSubmit(loading = null) {
//同时保护直接调用入口,避免绕过按钮状态提交空记录。
if (!this.surveyReady || this.tableLoading || this.loadError || !this.answerRecordId || this.answerRecord.isFinish) {
return
}
this.$axios
.post("/platform/h5/qsv/survey/submitAnswer", {
answer: JSON.stringify({
@@ -337,8 +392,10 @@ layout("/layouts/platform_h5.html"){
created() {
const id = GetQueryString("id")
if (id) {
this.id = id
this.$set(this, "id", id)
this.listSubjects()
} else {
this.onLoadError({ msg: "问卷链接缺少活动信息,请返回首页" })
}
}
})