Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 缺陷修复回流 #466

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions server/src/modules/survey/__test/survey.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ describe('SurveyController', () => {
const reqBody = {
surveyId: surveyId.toString(),
configData: {
dataConf: {
dataList: [{ question: 'Test Question' }],
},
/* ... your config data here ... */
},
sessionId: 'mock-session-id',
Expand All @@ -159,6 +162,28 @@ describe('SurveyController', () => {
controller.updateConf(reqBody, { user: {} }),
).rejects.toThrow(HttpException);
});
it('should throw an error when missing question data', async () => {
const surveyId = new ObjectId();
const reqBody = {
surveyId: surveyId.toString(),
configData: {
dataConf: {
dataList: [], // Empty dataList
},
},
sessionId: 'mock-session-id',
};

try {
await controller.updateConf(reqBody, {
user: { username: 'testUser', _id: 'testUserId' },
surveyMeta: { _id: surveyId },
});
} catch (error) {
expect(error).toBeInstanceOf(HttpException);
expect(error.message).toBe('请添加题目后重新保存问卷');
}
});
});

describe('deleteSurvey', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export class DataStatisticController {

@Get('/aggregationStatis')
@HttpCode(200)
@UseGuards(SurveyGuard)
@SetMetadata('surveyId', 'query.surveyId')
@SetMetadata('surveyPermission', [SURVEY_PERMISSION.SURVEY_RESPONSE_MANAGE])
@UseGuards(Authentication)
async aggregationStatis(@Query() queryInfo: AggregationStatisDto) {
// 聚合统计
Expand Down
5 changes: 5 additions & 0 deletions server/src/modules/survey/controllers/survey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ export class SurveyController {
this.logger.error(error.message);
throw new HttpException('参数有误', EXCEPTION_CODE.PARAMETER_ERROR);
}
if(!surveyInfo?.configData?.dataConf?.dataList?.length){
this.logger.error('确少题目数据');
throw new HttpException('请添加题目后重新保存问卷', EXCEPTION_CODE.PARAMETER_ERROR);
}

const sessionId = value.sessionId;
const surveyId = value.surveyId;
const latestEditingOne = await this.sessionService.findLatestEditingOne({
Expand Down
11 changes: 9 additions & 2 deletions web/src/management/pages/analysis/components/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
v-for="item in props.tableData.listHead"
:key="item.field"
:prop="item.field"
:label="item.title"
:label="getContent(item.title)"
minWidth="200"
>
<template #header="scope">
Expand All @@ -23,7 +23,7 @@
@click="onPreviewImage"
@mouseover="onPopoverRefOver(scope, 'head')"
:ref="(el) => (popoverRefMap[scope.column.id] = el)"
v-html="item.title"
v-html="getContent(item.title) "
>
</span>
</div>
Expand Down Expand Up @@ -152,6 +152,13 @@ const onPreviewImage = (e) => {
display: flex;
align-items: center;
}
:deep(.table-row-head) {
display: inline-block;
max-width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
:deep(.el-table td.el-table__cell div) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<el-button type="primary" :loading="isPublishing" class="publish-btn" @click="handlePublish">
<span type="primary" :loading="isPublishing" class="publish-btn" @click="handlePublish">
发布
</el-button>
</span>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
Expand Down Expand Up @@ -124,12 +124,31 @@ const handlePublish = async () => {
}
}
</script>
<style lang="scss" scoped>
<style>
.publish-btn {
display: inline-flex;
justify-content: center;
align-items: center;
line-height: 1;
white-space: nowrap;
cursor: pointer;
color: #fff;
text-align: center;
box-sizing: border-box;
outline: none;
transition: .1s;
font-weight: 500;
vertical-align: middle;
background-color: #ffa600;
border: #ffa600;
border-color: #ffa600;
border-radius: 5px;
width: 100px;
font-size: 14px;
height: 36px;
line-height: 36px;
padding: 0;
font-size: 14px;
user-select: auto!important;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="option-handwrite">
<div class="option-header">
<div class="header-item flex-1">选项内容</div>
<div class="header-item w285">选项后增添输入框</div>
<div class="header-item w285" v-if="showOthers">选项后增添输入框</div>
</div>
<div>
<draggable :list="curOptions" handle=".drag-handle" itemKey="hash">
Expand All @@ -28,7 +28,7 @@
@blur="onBlur($event, index)"
></div>
</div>
<div class="oitem moreInfo lh36">
<div class="oitem moreInfo lh36" v-if="showOthers">
<el-switch
:modelValue="element.others"
@change="(val) => changeOptionOthers(val, element)"
Expand Down Expand Up @@ -56,7 +56,7 @@
<span class="add-option-item"> <i-ep-circlePlus class="icon" /> 添加新选项 </span>
</div>

<div class="add-option" @click="addOtherOption">
<div class="add-option" @click="addOtherOption" v-if="showOthers">
<span class="add-option-item"> <i-ep-circlePlus class="icon" /> 其他____ </span>
</div>
</div>
Expand All @@ -81,6 +81,7 @@ import 'element-plus/theme-chalk/src/message.scss'
import { useEditStore } from '@/management/stores/edit'
import { cleanRichText } from '@/common/xss'
import { cleanRichTextWithMediaTag } from '@/common/xss'
import { storeToRefs } from 'pinia'

export default {
name: 'OptionConfig',
Expand Down Expand Up @@ -112,6 +113,11 @@ export default {
},
textOptions() {
return this.curOptions.map((item) => cleanRichTextWithMediaTag(item.text))
},
showOthers() {
const editStore = useEditStore()
const { currentEditMeta } = storeToRefs(editStore)
return currentEditMeta.value?.editConfigure?.optionEditBar.configure.showOthers
}
},
components: {
Expand Down
24 changes: 22 additions & 2 deletions web/src/render/components/MainRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { watch } from 'vue'
import { storeToRefs } from 'pinia'

import MaterialGroup from './MaterialGroup.vue'
Expand All @@ -21,12 +21,32 @@ import { useSurveyStore } from '../stores/survey'

const surveyStore = useSurveyStore()
const questionStore = useQuestionStore()
const { renderData, needHideFields, showLogicHideFields, isFinallyPage } = storeToRefs(questionStore)

const renderData = computed(() => questionStore.renderData)

const { rules, formValues } = storeToRefs(surveyStore)

const handleChangeData = (data: any) => {
surveyStore.changeData(data)
}

// 在适当的地方调用 updatePageIndex 方法
watch(() => renderData.value, (value: any) => {
if(value.length ){
const displaylist = value[0].filter((item: any) => !needHideFields.value.includes(item.field))
if(displaylist.length === 0 && !isFinallyPage.value){
questionStore.addPageIndex()
}
}
})
watch(() => { return needHideFields.value.concat(showLogicHideFields.value) }, (value: any)=> {
if(renderData.value.length ){
const displaylist = renderData.value[0].filter((item: any) => !value.includes(item.field))
if(displaylist.length === 0 && !isFinallyPage.value){
questionStore.addPageIndex()
}
}
}, {
deep: true
})
</script>
10 changes: 10 additions & 0 deletions web/src/render/components/QuestionWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ const logicShow = computed(() => {
const result = showLogicEngine.value.match(props.moduleConfig.field, 'question', formValues.value)
return result === undefined ? true : result
})
watch(()=> logicShow.value, (value) => {
if(!value){
questionStore.addShowLogicHideFields([props.moduleConfig.field])
} else {
questionStore.removeShowLogicHideFields([props.moduleConfig.field])
}
}, {
immediate: true
})

// 跳转逻辑:题目是否需要跳过(隐藏)
const logicSkip = computed(() => {
return needHideFields.value.includes(props.moduleConfig.field)
Expand Down
18 changes: 17 additions & 1 deletion web/src/render/stores/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ export const useQuestionStore = defineStore('question', () => {
const pageIndex = ref(1) // 当前分页的索引
const changeField = ref(null)
const changeIndex = computed(() => {
if(!changeField.value || !questionData.value) return null
return questionData.value[changeField.value]?.index
})
const needHideFields = ref([])

// 题目列表
const questionList = computed(() => {
let index = 1
const hideMap = needHideFields.value.concat(showLogicHideFields.value)
return (
questionSeq.value &&
questionSeq.value.reduce((pre, item) => {
Expand All @@ -118,7 +120,7 @@ export const useQuestionStore = defineStore('question', () => {
item.forEach((questionKey) => {
const question = { ...questionData.value[questionKey] }
// 开启显示序号
if (question.showIndex) {
if (question.showIndex && !hideMap.includes(questionKey)) {
question.indexNumber = index++
}

Expand Down Expand Up @@ -202,6 +204,17 @@ export const useQuestionStore = defineStore('question', () => {
const removeNeedHideFields = (fields) => {
needHideFields.value = needHideFields.value.filter((field) => !fields.includes(field))
}
const showLogicHideFields = ref([])
const addShowLogicHideFields = (fields) => {
fields.forEach((field) => {
if (!showLogicHideFields.value.includes(field)) {
showLogicHideFields.value.push(field)
}
})
}
const removeShowLogicHideFields = (fields) => {
showLogicHideFields.value = showLogicHideFields.value.filter((field) => !fields.includes(field))
}
return {
questionData,
questionSeq,
Expand All @@ -222,6 +235,9 @@ export const useQuestionStore = defineStore('question', () => {
needHideFields,
addNeedHideFields,
removeNeedHideFields,
showLogicHideFields,
addShowLogicHideFields,
removeShowLogicHideFields,
getQuestionIndexByField
}
})
Loading