Question.vue 6.24 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-21 11:00:14
 * @LastEditors: 纪泽龙 jizelong@qq.com
5
 * @LastEditTime: 2023-01-11 16:44:43
耿迪迪's avatar
耿迪迪 committed
6 7 8 9 10
 * @FilePath: /danger-manage-web/src/views/myLessons/components/Question.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="question flex">
11
    <div class="tips">{{ tipsArr[questionObj.topicType] }}</div>
耿迪迪's avatar
耿迪迪 committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    <div
      class="top"
      :class="{ flex: alignItemsCenter }"
      :style="{ alignItems: alignItemsCenter ? 'center' : '' }"
      ref="top"
    >
      <div class="text" ref="text">
        {{ questionObj.text }}
      </div>
      <div class="num">{{ nowQuestion + 1 }}</div>
    </div>
    <div class="middle">
      <div
        class="item flex"
        v-for="(item, index) in questionObj.question"
27
        :key="item + 'aas' + index"
耿迪迪's avatar
耿迪迪 committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41
      >
        <div class="letter">
          {{ letters[index] }}
        </div>
        <div class="">
          {{ item }}
        </div>
      </div>
    </div>

    <div class="bottom flex">
      <div class="change-wrapper flex">
        <div
          class="change"
42
          :class="{ active: letterActive.indexOf(index) >= 0 }"
耿迪迪's avatar
耿迪迪 committed
43 44
          @click="changeLetter(index)"
          v-for="(item, index) in questionObj.question"
45
          :key="item + 'a' + index"
耿迪迪's avatar
耿迪迪 committed
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        >
          {{ letters[index] }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
const letters = [
  "A",
  "B",
  "C",
  "D",
  "E",
  "F",
  "G",
  "H",
  "I",
  "J",
  "K",
  "L",
  "M",
  "N",
  "O",
  "P",
  "Q",
  "R",
  "S",
  "T",
  "U",
  "V",
  "W",
  "X",
  "Y",
  "Z",
];
export default {
  name: "question",
  props: {
    questionObj: {
      type: Object,
      default: () => {
        return {
          text: "asdfasdf",
          question: [
            "沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师沙发斯蒂芬大师",
            "沙发斯蒂芬大师",
            "沙发斯蒂芬大师",
            "沙发斯蒂芬大师",
            "沙发斯蒂芬大师",
          ],
        };
      },
    },
    nowQuestion: {
      type: Number,
    },
    index: {
      type: Number,
    },
    // 从外面传进来的选项,选择过的才有,没选择过的没有
    selectLetter: {
109 110
      type: [String, Number, Array],
      default: () => {
纪泽龙's avatar
纪泽龙 committed
111 112
        return [];
      },
耿迪迪's avatar
耿迪迪 committed
113 114 115 116 117 118 119 120
    },
  },
  data() {
    return {
      alignItemsCenter: false,
      // 如果传进来了,就是这个值,如果没有就是null,因为动画需要那个key的问题,会清空原始的盒子,所以要传一下值
      letterActive: this.selectLetter,
      letters,
121 122 123 124 125
      tipsArr: {
        1: "单选题",
        2: "多选题",
        3: "判断题",
      },
耿迪迪's avatar
耿迪迪 committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    };
  },
  mounted() {
    // console.log('123')
    // 每次都会更新,所以不需要watch 直接在这里面写 因为动画需要那个key的问题,会清空原始的盒子,所以要传一下值
    this.textCenter();
  },
  watch: {
    // 监听一下当前题目,调整一下位置
    // nowQuestion(value) {
    //   console.log('nowQuestion变化',value)
    //   this.$nextTick(() => {
    //     this.textCenter();
    //   });
    // },
  },
  methods: {
    textCenter() {
      let h1 = this.$refs.text?.offsetHeight;
      let h2 = this.$refs.top?.offsetHeight;
      // 如果text大于或者等于top,就出不居中,如果不小于top,就上下居中
      if (h2 <= h1) {
        this.alignItemsCenter = false;
      } else {
        this.alignItemsCenter = true;
      }
    },
    changeLetter(index) {
纪泽龙's avatar
纪泽龙 committed
154 155
      this.letterActive = [index];
      this.$emit("changeLetter", this.letterActive);
耿迪迪's avatar
耿迪迪 committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
      // this.$emit("changeLetter", this.letters[index]);
    },
  },
};
</script>
<style lang="scss" scoped>
.question {
  // position: absolute;
  // top: 0px;
  // display: inline-block;
  width: 100%;
  height: 370px;
  padding-bottom: 10px;
  border-bottom: 1px solid #bbbbbb;
  // background: red;
  flex-direction: column;
172 173 174 175 176 177 178 179 180 181 182 183 184
  position: relative;
  .tips {
    width: 80px;
    height: 24px;
    background: #1d84ff;
    font-size: 14px;
    color: #fff;
    position: absolute;
    top: -45px;
    left: 0px;
    text-align: center;
    line-height: 24px;
  }
耿迪迪's avatar
耿迪迪 committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
  .top {
    background: #f9f9f9;
    height: 54px;
    padding: 0px 10px 0px 43px;
    overflow-wrap: anywhere;
    // align-items: center;
    overflow-y: auto;
    position: relative;
    .text {
      font-size: 14px;
      text-indent: 2em;
    }
    .num {
      position: absolute;
      left: 0;
      width: 48px;
      height: 48px;
      top: 4px;
      background: #1d84ff;
      border-radius: 50%;
      text-align: center;
      line-height: 48px;
      font-size: 18px;
      color: #ffffff;
    }
  }
  .middle {
    flex: 1;
    // background: blue;
    overflow-y: auto;
    padding-left: 43px;
    padding-right: 10px;
    margin-bottom: 15px;
    .item {
      padding-top: 38px;
      width: 100%;
      overflow-wrap: anywhere;
      font-size: 14px;
      color: #101010;
      .letter {
        padding: 2px;
        margin-right: 10px;
        box-sizing: border-box;
      }
    }
  }
  .bottom {
    max-height: 70px;
    // background: black;
    padding-left: 43px;
    padding-right: 10px;
    overflow-y: auto;
    .change-wrapper {
      width: 756px;
      flex-wrap: wrap;
      margin: 0 auto;
      .change {
        width: 90px;
        height: 30px;
        background: #e8f4ff;
        color: #101010;
        border: 1px solid #a3d3ff;
        line-height: 30px;
        text-align: center;
        margin: 0 9px 5px;
        border-radius: 4px;
        cursor: pointer;
        &.active {
          background: #1d84ff;
          color: #ffffff;
          border: 1px solid #a3d3ff;
        }
        &:hover {
          background: rgba(29, 132, 255, 0.5);
          color: #ffffff;
        }
      }
    }
  }
}
</style>