index.js 2.22 KB
Newer Older
duanledexianxianxian's avatar
sync  
duanledexianxianxian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
import React, { useState } from 'react';
import router from 'umi/router';

import styles from './index.less';
import config from '@/config';
import { Button } from 'antd-mobile';
import classNames from 'classNames';
import Option from './option';
const Index = ({ type = 0, analysis, title, total, no, rightAnswer, optionList = [] }) => {
  const [isShowAnswer, setIsShowAnswer] = useState(false);
  const [options, setOptions] = useState(optionList);

  const showAnswer = () => {
    setIsShowAnswer(true);
  };

  const goSubmitAnalysis = () => {
    router.push('/exam/question/submit/analysis/0');
  };

  const selectOption = () => {};

  const handleSelect = (id, isSelected) => {
    options.forEach(item => {
      if(type===0){
        item.isSelected = false;
      }
      if (id === item.id) item.isSelected = isSelected;
      
    });
    setOptions([...options]);
  };

  /**
   * 渲染选项
   */
  const renderOption = () => {
    return options.map((item, index) => {
      return <Option {...item} isShowAnswer={isShowAnswer} onSelect={handleSelect} />;
    });
  };

  return (
    <div className={styles.root}>
      <div className={styles.content}>
        <div className={styles.title}>
          {no}/{total}、{title}
        </div>
        <div className={styles.options}>{renderOption()}</div>
        {isShowAnswer && (
          <div className={styles.answer}>
            <div className={styles.rightAnswer}>正确答案为{rightAnswer}</div>
            <div className={styles.analysis}>
              <span>题型解析</span>:{analysis}
            </div>
            <div className={styles.goAnalysis} onClick={goSubmitAnalysis}>
              我要解析
            </div>
          </div>
        )}
        {!isShowAnswer && (
          <div className={styles.submit}>
            <Button type="primary" onClick={showAnswer}>
              查看答案
            </Button>
          </div>
        )}
      </div>
      <div className={styles.action}>
        <div className={styles.pre}>上一题</div>
        <div className={styles.input}>
          跳转到
          <input type="text" />
        </div>
        <div className={styles.next}>下一题</div>
      </div>
    </div>
  );
};

export default Index;