utils.js 2.27 KB
import { API_SURVEY_MANAGE,API_SURVEY_QUFILLBLANK,
   API_SURVEY_QURADIO ,API_SURVEY_DELETE_BY_ID,API_SURVEY_QUCHECKBOX } from "@src/Api";

export default function uuid() {
  const s = [];
  const hexDigits = '0123456789abcdef';
  for (let i = 0; i < 36; i += 1) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = '4';
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
  const id = s.join('');
  return id;
}

export let switchEditor = (type) => {
  switch (type) {
    case 'radio':
      return {type:'quRadio',url:API_SURVEY_QURADIO.save};
    case 'dropdown':
      return '下拉题';
    case 'checkbox':
      return {type:'quCheckbox',url:API_SURVEY_QUCHECKBOX.save};
    case 'textarea':
      return '多行文本题';
    case 'text':
      return '单行文本题';
    case 'input':
      return {type:'input',url:API_SURVEY_QUFILLBLANK.save};
    default:
      return '错误';
  };
}

export let formatQuesData = (res = {}) => {
  if (res.questions && res.questions.length) {
    let editors = res.questions.map(k => {
      let qDetail = k.questionsDetail[0]
      return {
        ...qDetail,
        questionId: k.id,
        id:qDetail.id,
        quId:qDetail.quId || qDetail.id,
        type: k.type !=='fillblank' ? k.type : 'input',
        title: k.quTitle,
        required: k.isRequired ? true : false,
        remark: qDetail.isNote ? true : false, //是否有备注
        remarkText: qDetail.optionName, //备注内容
        options:qDetail.optionTitle ? JSON.parse(qDetail.optionTitle) :[],  //选项(只有radio,checkbox,select有,其余尽量给个空数组)
        rows: 1, //选项占的行数
        textareaHeight: 3, //多行文本高度
        maxLength: 50, //单行文本限制的字数
        otherOption: k.otherOption ? true : false, //是否有其他选项
        otherOptionForwards: k.otherOptionForwards, //”其他“项文本(前)
        otherOptionBackwards: k.otherOptionBackwards, //”其他“项文本(后)
        completionForwards: k.completionForwards, //填空题文本(前)
        completionBackwards: k.completionBackwards, //填空题文本(后)
        isEditor: false, //编辑状态还是已编辑状态
        isFirst: true, //是否是新创建的
        editorShake: "",
      }
    })
    return editors
  }

}