123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610 |
- <template>
- <div
- class="header-separate"
- v-if="judgeAnswer == 'standardAnswer' ? (userError ? true : false) : true"
- >
- <table>
- <colgroup>
- <col
- v-for="(item, i) in curQue.tableData.colsConfig.width"
- :key="`col-${i}`"
- :style="{ width: `${item.val}px` }"
- />
- </colgroup>
- <thead>
- <tr>
- <th
- v-for="({ text, english, type }, i) in curQue.tableData.headers"
- :key="`th-${i}`"
- >
- <div class="thead-content" :style="theadStyle">
- <span class="chs">{{ text }}</span>
- <span :class="[type === 'english' ? 'english' : 'pinyin']">
- {{ english }}
- </span>
- </div>
- </th>
- </tr>
- </thead>
- <tbody
- :style="{
- 'text-align': `${curQue.textAlign}`,
- }"
- >
- <tr v-for="(row, i) in curQue.tableData.body" :key="`tr-${i}`">
- <template v-for="(col, j) in row.content">
- <td
- v-if="tdIsShow(i, j)"
- :key="`td-${j}`"
- :colspan="col.colspan"
- :rowspan="col.rowspan"
- :class="[
- { underline: col.isUnderline },
- `${curQue.firstColAligin === 'center' ? 'col-center' : ''}`,
- judgeAnswer == 'standardAnswer' ? 'correct' : '',
- judgeAnswer == 'studentAnswer' || judgeAnswer == 'userAnswer'
- ? curQue.Bookanswer[i].content[j].userAnswerJudge
- ? curQue.Bookanswer[i].content[j].userAnswerJudge ==
- '[JUDGE##T##JUDGE]'
- ? 'correct'
- : 'error'
- : ''
- : '',
- ]"
- :style="{
- 'background-color': `${col.background}`,
- display: tdHeaderIsNone(i, j),
- }"
- >
- <div class="cell-wrap">
- <template v-if="col.type === 'content'">
- <span v-if="col.text.length > 0" class="content">
- {{ col.text }}
- </span>
- <template v-else>
- <el-input
- v-model="
- judgeAnswer == 'standardAnswer'
- ? col.answer
- : curQue.Bookanswer[i].content[j].answer
- "
- @blur="
- judgeAnswer == 'standardAnswer'
- ? (col.answer = col.answer.trim())
- : (curQue.Bookanswer[i].content[j].answer =
- curQue.Bookanswer[i].content[j].answer.trim())
- "
- type="textarea"
- :placeholder="`${isAnswerMode ? '' : '输入'}`"
- :disabled="isAnswerMode"
- :autosize="{ minRows: 1, maxRows: 6 }"
- @input="enterAnswer(i, j, 'input')"
- />
- </template>
- </template>
- <div
- v-else-if="col.type === 'pinyin'"
- class="sentence"
- :style="pinyinStyle"
- >
- <div>
- <span
- v-for="({ pinyin, chs }, k) in col.sentence_data
- .wordsList"
- :key="`${
- curQue.pinyinPosition === 'top' ||
- curQue.pinyinPosition === 'left'
- ? 'pinyin'
- : 'chs'
- }-${k}`"
- :class="[
- `${
- curQue.pinyinPosition === 'top' ||
- curQue.pinyinPosition === 'left'
- ? 'pinyin'
- : 'chs'
- }`,
- ]"
- >
- {{
- curQue.pinyinPosition === "top" ||
- curQue.pinyinPosition == "left"
- ? pinyin
- : chs
- }}
- </span>
- </div>
- <div>
- <span
- v-for="({ pinyin, chs }, k) in col.sentence_data
- .wordsList"
- :key="`${
- curQue.pinyinPosition === 'top' ||
- curQue.pinyinPosition === 'left'
- ? 'chs'
- : 'pinyin'
- }-${k}`"
- :class="[
- `${
- curQue.pinyinPosition === 'top' ||
- curQue.pinyinPosition === 'left'
- ? 'chs'
- : 'pinyin'
- }`,
- ]"
- >
- {{
- curQue.pinyinPosition === "top" ||
- curQue.pinyinPosition == "left"
- ? chs
- : pinyin
- }}
- </span>
- </div>
- </div>
- <div
- v-else-if="col.type === 'prePinyin'"
- :style="{
- 'flex-direction':
- col.prefixOrSuffix === 'prefix' ? 'row' : 'row-reverse',
- }"
- class="pre-pinyin"
- >
- <span>{{ col.message }}</span>
- <div
- class="right-pinyin"
- :style="{
- 'grid-template-columns': `repeat(${col.sentence_data.wordsList.length}, auto)`,
- }"
- >
- <span
- v-for="({ pinyin }, k) in col.sentence_data.wordsList"
- :key="`pre-pinyin-${k}`"
- class="pinyin"
- >
- {{ pinyin }}
- </span>
- <span
- v-for="({ pinyin, chs }, k) in col.sentence_data
- .wordsList"
- :key="`pre-chs-${k}`"
- class="chs"
- >
- {{ chs }}
- </span>
- </div>
- </div>
- <CrossTick
- v-if="col.isCross"
- :index="i"
- :indexs="j"
- :data="
- judgeAnswer == 'standardAnswer'
- ? col
- : curQue.Bookanswer[i].content[j]
- "
- :isAnswerMode="isAnswerMode"
- @enterAnswer="enterAnswer"
- />
- </div>
- </td>
- </template>
- </tr>
- </tbody>
- </table>
- </div>
- </template>
- <script>
- import CrossTick from "./CrossTick.vue";
- import AnswerTitle from "../../preview/components/AnswerTitle.vue";
- export default {
- components: { CrossTick, AnswerTitle },
- props: {
- curQue: {
- type: Object,
- required: true,
- },
- themeColor: {
- type: String,
- required: true,
- },
- judgeAnswer: {
- type: String,
- },
- },
- data() {
- return {
- isAnswerMode: false,
- userError: false,
- };
- },
- computed: {
- theadStyle() {
- const hp = this.curQue.headerEnglishPosition;
- if (hp === "top") {
- return {
- "flex-direction": "column-reverse",
- };
- }
- if (hp === "right") {
- return {
- "flex-direction": "row",
- "column-gap": "8px",
- };
- }
- if (hp === "bottom") {
- return {
- "flex-direction": "column",
- };
- }
- if (hp === "left") {
- return {
- "flex-direction": "row-reverse",
- "column-gap": "8px",
- };
- }
- },
- pinyinStyle() {
- let pyPos = this.curQue.pinyinPosition;
- if (pyPos === "left") {
- return {
- "column-gap": "16px",
- };
- }
- if (pyPos === "top") {
- return {
- "flex-direction": "column",
- };
- }
- if (pyPos === "right") {
- return {
- "column-gap": "16px",
- };
- }
- if (pyPos === "bottom") {
- return {
- "flex-direction": "column",
- };
- }
- },
- },
- created() {
- if (this.judgeAnswer) {
- this.isAnswerMode = true;
- }
- if (!this.curQue.Bookanswer) {
- let arr = [];
- this.curQue.tableData.body.forEach((item, i) => {
- arr.push({
- content: [],
- });
- item.content.forEach((items) => {
- arr[i].content.push({
- answer: "",
- CrossAnswer: "",
- userAnswerJudge:
- items.answer || items.isCross ? "[JUDGE##F##JUDGE]" : "",
- });
- });
- });
- this.$set(this.curQue, "Bookanswer", arr);
- } else {
- this.curQue.Bookanswer.forEach((item) => {
- item.content.forEach((item) => {
- if (item.userAnswerJudge == "[JUDGE##F##JUDGE]") {
- this.userError = true;
- return;
- }
- });
- });
- }
- },
- methods: {
- enterAnswer(i, j, type) {
- if (type == "input") {
- this.$forceUpdate();
- if (
- this.curQue.Bookanswer[i].content[j].answer.trim() ==
- this.curQue.tableData.body[i].content[j].answer
- ) {
- if (this.curQue.tableData.body[i].content[j].isCross) {
- if (
- this.curQue.Bookanswer[i].content[j].CrossAnswer ==
- this.curQue.tableData.body[i].content[j].CrossAnswer
- ) {
- this.curQue.Bookanswer[i].content[j].userAnswerJudge =
- "[JUDGE##T##JUDGE]";
- } else {
- this.curQue.Bookanswer[i].content[j].userAnswerJudge =
- "[JUDGE##F##JUDGE]";
- }
- } else {
- this.curQue.Bookanswer[i].content[j].userAnswerJudge =
- "[JUDGE##T##JUDGE]";
- }
- } else {
- if (this.curQue.tableData.body[i].content[j].answer) {
- this.curQue.Bookanswer[i].content[j].userAnswerJudge =
- "[JUDGE##F##JUDGE]";
- }
- }
- } else {
- if (
- this.curQue.Bookanswer[i].content[j].CrossAnswer ==
- this.curQue.tableData.body[i].content[j].CrossAnswer
- ) {
- if (this.curQue.tableData.body[i].content[j].answer) {
- if (
- this.curQue.Bookanswer[i].content[j].answer ==
- this.curQue.tableData.body[i].content[j].answer
- ) {
- this.curQue.Bookanswer[i].content[j].userAnswerJudge =
- "[JUDGE##T##JUDGE]";
- } else {
- this.curQue.Bookanswer[i].content[j].userAnswerJudge =
- "[JUDGE##F##JUDGE]";
- }
- } else {
- this.curQue.Bookanswer[i].content[j].userAnswerJudge =
- "[JUDGE##T##JUDGE]";
- }
- } else {
- this.curQue.Bookanswer[i].content[j].userAnswerJudge =
- "[JUDGE##F##JUDGE]";
- }
- }
- },
- // 控制首尾表格显隐
- tdHeaderIsNone(i, j) {
- let body = this.curQue.tableData.body;
- if (j !== 0 && j !== body[0].content.length - 1) return "table-cell";
- let col = 1;
- let colIndex = body[i].content.findIndex(({ colspan }, index) => {
- if (index > j) return false;
- let num = colspan === undefined ? 1 : Number(colspan);
- if (num > 1) {
- col = num;
- return false;
- }
- if (index === j && col > 1) return true;
- if (col > 0) col -= 1;
- return false;
- });
- let row = 1;
- let rowIndex = body.findIndex((item, index) => {
- let rowspan = item.content[j].rowspan;
- let num = rowspan === undefined ? 1 : Number(rowspan);
- if (num > 1) {
- row = num;
- return false;
- }
- if (index === i && row > 1) return true;
- if (row > 0) row -= 1;
- return false;
- });
- return rowIndex === -1 && colIndex === -1 ? "table-cell" : "none";
- },
- // rowspan colspan 控制td是否生成
- tdIsShow(i, j) {
- let body = this.curQue.tableData.body;
- if (j === 0) return true;
- let col = 1;
- let colIndex = body[i].content.findIndex(({ colspan }, index) => {
- if (index > j) return false;
- let num = colspan === undefined ? 1 : Number(colspan);
- if (num > 1) {
- col = num;
- return false;
- }
- if (index === j && col > 1) return true;
- if (col > 0) col -= 1;
- return false;
- });
- let row = 1;
- let rowIndex = body.findIndex((item, index) => {
- let rowspan = item.content[j].rowspan;
- let num = rowspan === undefined ? 1 : Number(rowspan);
- if (num > 1) {
- row = num;
- return false;
- }
- if (index === i && row > 1) return true;
- if (row > 0) row -= 1;
- return false;
- });
- return (
- colIndex === -1 && (rowIndex === -1 || j === body[0].content.length - 1)
- );
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .header-separate {
- width: 100%;
- margin-bottom: 16px;
- table {
- table-layout: fixed;
- font-size: 16px;
- border-collapse: separate;
- border-spacing: 6px 0;
- th {
- color: #4d4c51;
- font-weight: normal;
- background-color: #efeff9;
- padding: 4px 12px;
- border: 2px solid #afb4d1;
- .thead-content {
- display: flex;
- justify-content: center;
- .english {
- font-family: "robot";
- color: #000;
- }
- }
- }
- td {
- color: #474747;
- border-bottom: 1px solid transparent;
- padding: 4px 12px;
- min-height: 43px;
- height: 43px;
- .cell-wrap {
- display: flex;
- align-items: center;
- justify-content: space-between;
- .content {
- font-family: "FZJCGFKTK", "GB-PINYINOK-B", "robot";
- }
- }
- // 下划线
- &.underline {
- text-decoration: underline;
- }
- .sentence {
- display: flex;
- }
- // 前缀 + 拼音
- .pre-pinyin {
- display: flex;
- align-items: flex-end;
- .right-pinyin {
- margin-left: 4px;
- column-gap: 2px;
- text-align: center;
- display: grid;
- }
- }
- &:first-child {
- border-left: 2px solid transparent;
- border-bottom-width: 1px;
- border-image: linear-gradient(
- transparent 6px,
- #e7b576 6px,
- #e7b576 calc(100% - 6px),
- transparent calc(100% - 6px),
- transparent calc(100% - 2px),
- #cecece calc(100% - 2px)
- )
- 2;
- border-image-outset: 0 4px 0 0;
- &.col-center {
- text-align: center;
- }
- }
- &:not(:last-child) {
- position: relative;
- // 用 ::after 模拟中间边框
- &::after {
- content: "";
- position: absolute;
- top: 0;
- left: calc(100% + 2px);
- width: 2px;
- height: 100%;
- display: inline-block;
- background: repeating-linear-gradient(
- transparent,
- transparent 3px,
- #cecece 3px,
- #cecece 7px,
- transparent 7px
- );
- }
- }
- // 中间的底部边框用 ::before 模拟
- &:not(:first-child):not(:last-child)::before {
- content: "";
- position: absolute;
- top: 100%;
- left: 0;
- width: 100%;
- height: 1px;
- display: inline-block;
- background-color: #cecece;
- box-shadow: 2px 0 #cecece, -2px 0 #cecece;
- }
- &:last-child {
- border-right: 2px solid transparent;
- border-bottom-width: 1px;
- border-image: linear-gradient(
- transparent 6px,
- #e7b576 6px,
- #e7b576 calc(100% - 6px),
- transparent calc(100% - 6px),
- transparent calc(100% - 2px),
- #cecece calc(100% - 2px)
- )
- 2;
- border-image-outset: 0 0 0 4px;
- }
- }
- .pinyin {
- font-family: "GB-PINYINOK-B";
- }
- .chs {
- font-family: "FZJCGFKTK";
- }
- }
- }
- </style>
- <style lang="scss">
- .header-separate {
- .correct {
- .el-textarea.is-disabled .el-textarea__inner {
- color: #2ca767 !important;
- }
- .cross-tick {
- border-color: #2ca767 !important;
- .el-icon-check:before {
- color: #2ca767 !important;
- }
- .el-icon-close:before {
- color: #2ca767 !important;
- }
- }
- }
- .error {
- .el-textarea.is-disabled .el-textarea__inner {
- color: #ed342d !important;
- }
- .cross-tick {
- border-color: #ed342d !important;
- .el-icon-check:before {
- color: #ed342d !important;
- }
- .el-icon-close:before {
- color: #ed342d !important;
- }
- }
- }
- }
- </style>
|