Giter VIP home page Giter VIP logo

sojump-api's Introduction

questionnaire-editor(问卷编辑器API)

Tech Stack

  • express
  • mysql

sojump-api's People

Contributors

auxior avatar ileostar avatar

Stargazers

 avatar

Watchers

 avatar

sojump-api's Issues

stat 接口

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 },
        ],
      },
    },
  ]
}

question 接口

question 接口

const getQuestionList = require('./data/getQuestionList')
const getComponentList = require('./data/getComponentList')

module.exports = [
  {
    // 获取单个问卷信息
    url: '/api/question/:id',
    method: 'get',
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
          title: Random.ctitle(),
          desc: '问卷描述',
          js: '',
          css: '',
          isDeleted: false,
          isPublished: true,
          componentList: getComponentList(),
        },
      }
    },
  },
  {
    // 创建问卷
    url: '/api/question',
    method: 'post',
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      }
    },
  },
  {
    // 获取(查询)问卷列表
    url: '/api/question',
    method: 'get',
    response(ctx) {
      const { url = '', query = {} } = ctx
      const isDeleted = url.indexOf('isDeleted=true') >= 0
      const isStar = url.indexOf('isStar=true') >= 0
      const pageSize = parseInt(query.pageSize) || 10

      return {
        errno: 0,
        data: {
          list: getQuestionList({ len: pageSize, isDeleted, isStar }), // 当前页
          total: 100, // 总数,用于分页
        },
      }
    },
  },
  {
    // 更新问卷
    url: '/api/question/:id',
    method: 'patch',
    response() {
      return {
        errno: 0,
      }
    },
  },
  {
    // 复制问卷
    url: '/api/question/duplicate/:id',
    method: 'post',
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      }
    },
  },
  {
    // 批量彻底删除
    url: '/api/question',
    method: 'delete',
    response() {
      return {
        errno: 0,
      }
    },
  },
]

function getQuestionList()

function getQuestionList(opt = {}) {
  const { len = 10, isDeleted = false, isStar = false } = opt
  const list = []
  for (let i = 0; i < len; i++) {
    list.push({
      _id: Random.id(),
      title: Random.ctitle(),
      isPublished: Random.boolean(),
      isStar,
      answerCount: Random.natural(50, 100),
      createdAt: Random.datetime(),
      isDeleted, // 假删除
    })
  }
  return list
}

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 },
        ],
      },
    },
  ]
}

user 接口

user 接口

module.exports = [
  {
    // 获取用户信息
    url: '/api/user/info',
    method: 'get',
    response() {
      return {
        errno: 0,
        data: {
          username: Random.title(),
          nickname: Random.cname(),
        },
      }
    },
  },
  {
    // 注册
    url: '/api/user/register',
    method: 'post',
    response() {
      return {
        errno: 0,
      }
    },
  },
  {
    // 登录
    url: '/api/user/login',
    method: 'post',
    response() {
      return {
        errno: 0,
        data: {
          token: Random.word(20),
        },
      }
    },
  },
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.