questionare-generator-core
TypeScript icon, indicating that this package has built-in type declarations

1.13.1 • Public • Published

questionare-generator-core

问卷设计器的核心校验模块,提供完整的对JSON SCHEMA的校验功能


安装

使用npm进行安装

npm i questionare-generator-core

使用yarn进行安装

yarn add questionare-generator-core

引入

完整引入

完整引入提供全部题型和问卷的整体校验功能

import { jsonSchemaValidateError } from 'questionare-generator-core'

按需引入

按需引入可以使用qgc对象对单独的题目类型进行校验,在没有使用大量题目类型时有绝对的性能优势

import { qgc } from 'questionare-generator-core'

使用

完整引入的校验方式

import { jsonSchemaValidateError } from 'questionare-generator-core'

const testData = {
  questionImage: '',
  questionTitle: '问卷标题',
  questionRemark: '感谢您能抽出几分钟时间来参加本次答题,现在我们就马上开始吧!',
  isQuestionNumber: true,
  isQuestionType: true,
  data: [
    {
      id: 1,
      title: '请选择一个选项',
      type: 'single-choice',
      must: true,
      options: [{ label: '选项名称', value: 1 }, { label: '选项名称', value: 2 }]
    },
    {
      id: 2,
      title: '请选择一个或多个选项',
      type: 'multiple-choice',
      must: true,
      options: [{ label: '选项名称', value: 1 }, { label: '选项名称', value: 2 }]
    },
    {
      id: 3,
      title: '请选择一个或多个选项',
      type: 'multiple-choice',
      must: true,
      options: [{ label: '选项名称', value: 1 }, { label: '选项名称', value: 2 }]
    },
    {
      id: 4,
      title: '请填写本项内容',
      type: 'blanks-filling',
      must: true
    },
    {
      id: 5,
      title: '请给本项打分',
      type: 'scoring',
      must: true,
      fractionType: 5
    },
    {
      id: 6,
      title: '请给以下选项排序',
      type: 'ranking',
      must: false,
      options: [{ label: '选项名称', value: 1 }, { label: '选项名称', value: 2 }]
    }
  ]
}

const validate = () => {
  testData.data.forEach((item: any) => {
    jsonSchemaValidateError(item.type, [item])
  })
}

按需引入校验方式

import { qgc } from 'questionare-generator-core'

// 校验单选题
qgc.topicSingleChoiceValidate([{
  id: 3,
  title: '请选择一个或多个选项',
  type: 'multiple-choice',
  must: true,
  options: [{ label: '选项名称', value: 1 }, { label: '选项名称', value: 2 }]
}])

题型分类

分类名称 题型名称 参数名称
选择题 单选题 single-choice
选择题 多选题 multiple-choice
填空题 填空题 blanks-filling
打分题 打分题 scoring
排序题 排序题 ranking
比重题 比重题 proportion

问卷参数配置

名称 类型 说明 是否必传 默认值 可选值
questionTitle string 问卷标题 true - -
questionRemark string 问卷备注 true - -
questionImage string 问卷头部主题图片 true - -
data array 问卷题目数据 true - -
isQuestionNumber boolean 是否显示题号 true - true、false
isQuestionType boolean 是否现实题型 true - true、false

题型基础参数配置

基础参数配置

名称 类型 说明 是否必传 默认值 可选值 选项参数
title string 题目 true - - -
must boolean 是否必答(排序题和比重题只能传递false,因为排序题和比重题存在使用默认排序和比重为0的情况) true - true、false -
topicNum number 题号 false - - -
id number 题目id false - - -
type string 题型 true - - -

单选题和多选题特有参数配置

名称 类型 说明 是否必传 默认值 可选值 选项参数
options array 选项 true - - [{ label: 'first-option', value: 1 }, { label: 'second-option', value: 2 }]

排序题特有参数配置

名称 类型 说明 是否必传 默认值 可选值 选项参数
options array 选项 true - - [{ label: 'first-option', value: 1, order: 1 }, { label: 'second-option', value: 2, order: 2 }]

打分题特有参数配置

名称 类型 说明 是否必传 默认值 可选值
fractionType number 分数制 true 5 10

Package Sidebar

Install

npm i questionare-generator-core

Weekly Downloads

56

Version

1.13.1

License

MIT

Unpacked Size

144 kB

Total Files

48

Last publish

Collaborators

  • songjianet