调查问卷题目选项增加必填设置
This commit is contained in:
@@ -38,6 +38,15 @@ public class QsvSubject extends BaseModel implements Serializable {
|
|||||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否必须作答;新题默认必填,历史空值由答题页面按必填兼容。
|
||||||
|
*/
|
||||||
|
@Column
|
||||||
|
@Comment("是否必填")
|
||||||
|
@ColDefine(type = ColType.BOOLEAN)
|
||||||
|
@Default("1")
|
||||||
|
private Boolean required = true;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@Comment("正确答案")
|
@Comment("正确答案")
|
||||||
@ColDefine(type = ColType.MYSQL_JSON)
|
@ColDefine(type = ColType.MYSQL_JSON)
|
||||||
|
|||||||
@@ -48,6 +48,17 @@ const subjectForm = {
|
|||||||
<!-- </el-option>-->
|
<!-- </el-option>-->
|
||||||
</el-select>
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
是否必填:
|
||||||
|
<el-select
|
||||||
|
:value="subject.required"
|
||||||
|
@change="subjectRequiredChange(subject, $event)"
|
||||||
|
placeholder="请选择是否必填"
|
||||||
|
style="width: 200px;">
|
||||||
|
<el-option label="必填" :value="true"></el-option>
|
||||||
|
<el-option label="非必填" :value="false"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
<div v-if="subject.type === 'checkbox'">
|
<div v-if="subject.type === 'checkbox'">
|
||||||
最大选择数:
|
最大选择数:
|
||||||
<el-input-number v-model="subject.maxMulti" placeholder="最多可选数量"></el-input-number>
|
<el-input-number v-model="subject.maxMulti" placeholder="最多可选数量"></el-input-number>
|
||||||
@@ -355,7 +366,11 @@ const subjectForm = {
|
|||||||
})
|
})
|
||||||
$.post("/platform/qsv/activity/listSubjects", {activityId: id}).then((res) => {
|
$.post("/platform/qsv/activity/listSubjects", {activityId: id}).then((res) => {
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
this.subjects = res.data
|
// 旧题未设置必填属性时沿用必填规则,已设置的非必填值保持不变。
|
||||||
|
res.data.forEach((subject) => {
|
||||||
|
this.$set(subject, "required", subject.required !== false)
|
||||||
|
})
|
||||||
|
this.$set(this, "subjects", res.data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -373,6 +388,8 @@ const subjectForm = {
|
|||||||
title: "",
|
title: "",
|
||||||
hint: "",
|
hint: "",
|
||||||
type: "radio",
|
type: "radio",
|
||||||
|
// 手工新增题目默认必填,允许在题目类型右侧切换为非必填。
|
||||||
|
required: true,
|
||||||
score: 0,
|
score: 0,
|
||||||
displayDate: "",
|
displayDate: "",
|
||||||
options: [
|
options: [
|
||||||
@@ -394,6 +411,11 @@ const subjectForm = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// subject 为当前题目,required 为下拉框返回的布尔值;响应式更新必填设置,不返回结果。
|
||||||
|
subjectRequiredChange(subject, required) {
|
||||||
|
this.$set(subject, "required", required)
|
||||||
|
},
|
||||||
|
|
||||||
//题目类型切换
|
//题目类型切换
|
||||||
subjectTypeChange(subject, subjectIndex) {
|
subjectTypeChange(subject, subjectIndex) {
|
||||||
if (subject.type === 'text') {
|
if (subject.type === 'text') {
|
||||||
@@ -615,6 +637,8 @@ const subjectForm = {
|
|||||||
// 更新导入题目的序号
|
// 更新导入题目的序号
|
||||||
importedQuestions.forEach((question, index) => {
|
importedQuestions.forEach((question, index) => {
|
||||||
question.sortNum = startSortNum + index;
|
question.sortNum = startSortNum + index;
|
||||||
|
// 文本导入没有必填配置时默认必填,保留明确的非必填设置。
|
||||||
|
this.$set(question, "required", question.required !== false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 将导入的题目添加到现有题目列表
|
// 将导入的题目添加到现有题目列表
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ layout("/layouts/platform_h5.html"){
|
|||||||
|
|
||||||
<div v-if="!answerRecord.isFinish">
|
<div v-if="!answerRecord.isFinish">
|
||||||
<div v-for="(subject, index) in subjects" :key="index" class="subject">
|
<div v-for="(subject, index) in subjects" :key="index" class="subject">
|
||||||
<p>{{index+1}}、{{ subject.title }}</p>
|
<!-- 必填标识与提交校验一致,旧题未配置时默认必填。 -->
|
||||||
|
<p><span v-if="subject.required !== false" style="color: #ee0a24; margin-right: 4px;" aria-label="必填">*</span>{{index+1}}、{{ subject.title }}</p>
|
||||||
<div class="tag">
|
<div class="tag">
|
||||||
<van-tag v-if="subject.type === 'checkbox'" type="primary" size="large">多选</van-tag>
|
<van-tag v-if="subject.type === 'checkbox'" type="primary" size="large">多选</van-tag>
|
||||||
<van-tag v-if="subject.type === 'radio'" type="primary" size="large">单选</van-tag>
|
<van-tag v-if="subject.type === 'radio'" type="primary" size="large">单选</van-tag>
|
||||||
@@ -261,6 +262,10 @@ layout("/layouts/platform_h5.html"){
|
|||||||
//提示那些题没有作答
|
//提示那些题没有作答
|
||||||
for (let i = 0; i < this.subjects.length; i++) {
|
for (let i = 0; i < this.subjects.length; i++) {
|
||||||
let subject = this.subjects[i]
|
let subject = this.subjects[i]
|
||||||
|
// 明确设置非必填的题目允许留空,旧题缺失该属性时仍须作答。
|
||||||
|
if (subject.required === false) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
//["radio", "checkbox"].includes(subject.type) &&
|
//["radio", "checkbox"].includes(subject.type) &&
|
||||||
if (!subject.userSelectOptionIds || subject.userSelectOptionIds.length === 0) {
|
if (!subject.userSelectOptionIds || subject.userSelectOptionIds.length === 0) {
|
||||||
this.$toast.fail("第" + (i + 1) + "题未做答")
|
this.$toast.fail("第" + (i + 1) + "题未做答")
|
||||||
|
|||||||
@@ -92,7 +92,8 @@ layout("/layouts/platform_h5.html"){
|
|||||||
<h2 class="title">{{ activity.title }}</h2>
|
<h2 class="title">{{ activity.title }}</h2>
|
||||||
<div v-if="!isFinished">
|
<div v-if="!isFinished">
|
||||||
<div v-for="(subject, index) in visibleSubjects" :key="subject.id" class="subject">
|
<div v-for="(subject, index) in visibleSubjects" :key="subject.id" class="subject">
|
||||||
<p>{{index+1}}、{{ subject.title }}</p>
|
<!-- 必填标识与提交校验一致,旧题未配置时默认必填。 -->
|
||||||
|
<p><span v-if="subject.required !== false" style="color: #ee0a24; margin-right: 4px;" aria-label="必填">*</span>{{index+1}}、{{ subject.title }}</p>
|
||||||
<div class="tag">
|
<div class="tag">
|
||||||
<van-tag v-if="subject.type === 'checkbox'" type="primary" size="large">多选</van-tag>
|
<van-tag v-if="subject.type === 'checkbox'" type="primary" size="large">多选</van-tag>
|
||||||
<van-tag v-if="subject.type === 'radio'" type="primary" size="large">单选</van-tag>
|
<van-tag v-if="subject.type === 'radio'" type="primary" size="large">单选</van-tag>
|
||||||
@@ -341,6 +342,10 @@ layout("/layouts/platform_h5.html"){
|
|||||||
//提示那些题没有作答
|
//提示那些题没有作答
|
||||||
for (let i = 0; i < this.visibleSubjects.length; i++) {
|
for (let i = 0; i < this.visibleSubjects.length; i++) {
|
||||||
const subject = this.visibleSubjects[i]
|
const subject = this.visibleSubjects[i]
|
||||||
|
// 仅校验可见的必填题;旧题属性缺失或为空时仍按必填处理。
|
||||||
|
if (subject.required === false) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (["radio", "checkbox"].includes(subject.type)) {
|
if (["radio", "checkbox"].includes(subject.type)) {
|
||||||
if (!subject.userSelectOptionIds || subject.userSelectOptionIds.length === 0) {
|
if (!subject.userSelectOptionIds || subject.userSelectOptionIds.length === 0) {
|
||||||
this.$toast.fail("第" + (i + 1) + "题未做答")
|
this.$toast.fail("第" + (i + 1) + "题未做答")
|
||||||
|
|||||||
Reference in New Issue
Block a user