Skip to content

stat 接口 #3

@Auxior

Description

@Auxior

stat 接口

const getStatList = require('./data/getStatList')

module.exports = [
  // 答卷列表
  {
    url: '/api/stat/:questionId',
    method: 'get',
    response() {
      return {
        errno: 0,
        data: {
          total: 100, // 分页
          list: getStatList(),
        },
      }
    },
  },
  // 获取单个组件的统计数据汇总
  {
    url: '/api/stat/:questionId/:componentId',
    method: 'get',
    response() {
      return {
        errno: 0,
        data: {
          stat: [
            { name: '选项1', count: 20 },
            { name: '选项2', count: 10 },
            { name: '选项3', count: 25 },
          ],
        },
      }
    },
  },
]

function getStatList()

function getStatList(len = 10) {
  const componentList = getComponentList()

  const res = []

  for (let i = 0; i < len; i++) {
    // 一个用户的答卷
    const stat = {
      _id: Random.id(),
    }

    // 增加各个组件的 id value
    componentList.forEach((c) => {
      const { fe_id, type, props } = c

      switch (type) {
        case 'questionInput':
          stat[fe_id] = Random.ctitle()
          break
        case 'questionTextarea':
          stat[fe_id] = Random.ctitle()
          break
        case 'questionRadio':
          stat[fe_id] = props.options[0].text
          break
        case 'questionCheckbox':
          stat[fe_id] = `${props.list[0].text},${props.list[1].text}`
          break
      }
    })

    res.push(stat)
  }

  return res
}

function getComponentList()

function getComponentList() {
  return [
    // Info
    {
      fe_id: 'c1', // 注意,由于统计页,左侧和中间需要数据完全一直,所以要写死 fe_id ,不能用 Random.id()
      type: 'questionInfo', // 组件类型,不能重复,前后端统一好
      title: '问卷信息',
      isHidden: false,
      isLocked: false,
      props: { title: '问卷标题', desc: '问卷描述...' },
    },
    // Title
    {
      fe_id: 'c2',
      type: 'questionTitle', // 组件类型,不能重复,前后端统一好
      title: '标题',
      isHidden: false,
      isLocked: false,
      props: { text: '个人信息调研', level: 1, isCenter: false },
    },
    // Input
    {
      fe_id: 'c3',
      type: 'questionInput',
      title: '输入框1',
      isHidden: false,
      isLocked: false,
      props: { title: '你的姓名', placeholder: '请输入姓名...' },
    },
    // Input
    {
      fe_id: 'c4',
      type: 'questionInput',
      title: '输入框2',
      isHidden: false,
      isLocked: false,
      props: { title: '你的电话', placeholder: '请输入电话...' },
    },
    // Textarea
    {
      fe_id: 'c5',
      type: 'questionTextarea',
      title: '多行输入',
      isHidden: false,
      isLocked: false,
      props: { title: '你的爱好', placeholder: '请输入...' },
    },
    // Paragraph
    {
      fe_id: 'c6',
      type: 'questionParagraph',
      title: '段落',
      isHidden: false,
      isLocked: false,
      props: { text: '一行段落1\n一行段落2', isCenter: false },
    },
    // Radio
    {
      fe_id: 'c7',
      type: 'questionRadio',
      title: '单选',
      isHidden: false,
      isLocked: false,
      props: {
        title: '单选标题',
        isVertical: false,
        options: [
          { value: 'item1', text: '选项1' },
          { value: 'item2', text: '选项2' },
          { value: 'item3', text: '选项3' },
        ],
        value: '',
      },
    },
    // Checkbox
    {
      fe_id: 'c8',
      type: 'questionCheckbox',
      title: '多选',
      isHidden: false,
      isLocked: false,
      props: {
        title: '多选标题',
        isVertical: false,
        list: [
          { value: 'item1', text: '选项1', checked: true },
          { value: 'item2', text: '选项2', checked: false },
          { value: 'item3', text: '选项3', checked: false },
        ],
      },
    },
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions