From f8749dbb5c7b0e597bf7348fed2d9e57e0d9b1f9 Mon Sep 17 00:00:00 2001 From: Huangzhe Date: Mon, 31 Mar 2025 15:28:48 +0800 Subject: [PATCH] =?UTF-8?q?feat[preview]:=20=E6=8A=BD=E7=A6=BB=E7=9F=A9?= =?UTF-8?q?=E9=98=B5=E7=9A=84=E9=AA=8C=E8=AF=81=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 抽离 preview 矩阵的验证内容,多选矩阵的校验放到 PreviewMatrixCheckbox 内 - 添加新的错误提示支持 - 增加 矩阵 类型 - 添加矩阵测试文件 --- src/types/question.d.ts | 4 +- src/types/questions/matrixCheckbox.ts | 70 +++++++ .../components/Questions/MatrixCheckbox.vue | 8 +- .../components/Questions/MatrixQuestion.vue | 9 +- src/views/Survey/views/Preview/Index.vue | 83 +------- .../questions/PreviewMatrixCheckbox.vue | 43 +++-- .../questions/types/previewMatrix.ts | 2 + .../test/validateMatrixCheckbox.spec.ts | 179 ++++++++++++++++++ .../validate/validateMatrixCheckbox.ts | 117 ++++++++++++ src/views/Survey/views/Preview/js/language.js | 37 +++- 10 files changed, 451 insertions(+), 101 deletions(-) create mode 100644 src/types/questions/matrixCheckbox.ts create mode 100644 src/views/Survey/views/Preview/components/questions/types/previewMatrix.ts create mode 100644 src/views/Survey/views/Preview/components/questions/validate/test/validateMatrixCheckbox.spec.ts create mode 100644 src/views/Survey/views/Preview/components/questions/validate/validateMatrixCheckbox.ts diff --git a/src/types/question.d.ts b/src/types/question.d.ts index 1ea97c4..4b2590c 100644 --- a/src/types/question.d.ts +++ b/src/types/question.d.ts @@ -34,7 +34,7 @@ declare interface IQuestionOption { relation_last_scope: number; relation_first_scope: number; relation_question_index: number; - options?: questionOptionType[]; + options?: IMatrixCheckboxOption[]; } // 答案 config 类型 @@ -89,7 +89,7 @@ export declare interface IQuestion { stem?: string; other?: string; // options 列表项,第一个是默认 - list: questionOptionType[]; + list: questionOptionType[] | IQuestionOption[]; question_index?: number; question_type?: number; // 如果没有自定义类型,那么就直接用基础 config 类型 diff --git a/src/types/questions/matrixCheckbox.ts b/src/types/questions/matrixCheckbox.ts new file mode 100644 index 0000000..6bb77d8 --- /dev/null +++ b/src/types/questions/matrixCheckbox.ts @@ -0,0 +1,70 @@ +export declare interface IMatrixCheckboxConfig extends IBaseConfig { + /** 是否必选 (1-是 0-否) */ + is_required: 0 | 1; + /** 是否交换行列 */ + is_change_row_cell?: boolean; + /** 暂未得知 */ + quick_type: 0 | 1; + /** 每题选项数 */ + each_number: number; + /** 最大选择数 (空字符串表示无限制) */ + max_select: number | ''; + /** 最小选择数 (空字符串表示无限制) */ + min_select: number | ''; + /** 随机选择数量 */ + select_random: number; +} + +export declare interface IMatrixCheckboxOption { + /** 选项HTML内容 */ + option: string; + /** 是否为"其他"选项 (0-否 1-是) */ + is_other: 0 | 1; + /** 是否固定位置 (0-否 1-是) */ + is_fixed: 0 | 1; + /** 是否移除其他选项 (0-否 1-是) */ + is_remove_other: 0 | 1; + /** 层级深度 */ + level: number; + /** 选项唯一键 */ + option_key: string; + /** 选项索引(可能不连续) */ + option_index: string; + /** 选项编码 */ + option_code: string; + /** 选项配置 */ + option_config: IMatrixCheckboxOptionConfig; + /** 父选项索引 */ + parent_option_index: number; + /** 子选项(树形结构) */ + children: null; + /** 最小选择数 */ + min_select: number | string; +} + +export declare interface IMatrixCheckboxOptionConfig { + /** 选项类型 */ + type: number; + /** 关联价格 */ + price: number; + /** 标题 */ + title: string; + /** 渐变样式 */ + gradient: string; + /** 图片URL数组 */ + image_url: string[]; + /** 子区域配置 */ + child_area: null | { + // 根据实际业务补充具体结构 + area_type?: number; + coordinates?: number[]; + }; + /** 选项类型标记 */ + option_type: number; + /** 说明内容数组 */ + instructions: string[]; + /** 绑定商品ID */ + binding_goods_id: string; + /** 右侧限制内容(HTML) */ + limit_right_content: string; +} diff --git a/src/views/Design/components/Questions/MatrixCheckbox.vue b/src/views/Design/components/Questions/MatrixCheckbox.vue index 1c48316..933e0f5 100644 --- a/src/views/Design/components/Questions/MatrixCheckbox.vue +++ b/src/views/Design/components/Questions/MatrixCheckbox.vue @@ -9,13 +9,16 @@