123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- <template>
- <div class="config-table">
- <table
- :style="{
- 'box-shadow': `${
- curQue.isShadow ? '4px 4px 4px rgba(0, 0, 0, 0.3)' : ''
- }`,
- border: `${curQue.marginHighlight ? '1.1px solid #949494' : ''}`,
- }"
- >
- <colgroup>
- <col
- v-for="(col, i) in curQue.tableData.colsConfig.width"
- :key="`col-${i}`"
- :style="{ width: `${col.val}px` }"
- />
- </colgroup>
- <caption v-if="curQue.isTitle">
- {{
- curQue.title
- }}
- </caption>
- <thead>
- <tr
- v-for="({ content }, i) in curQue.tableData.headers"
- :key="`thead-${i}`"
- :style="{
- 'background-color': `${curQue.headerBgColor}`,
- }"
- >
- <template v-for="({ text, colspan, rowspan }, j) in content">
- <th
- v-if="thIsShow(i, j)"
- :key="`th-${i}-${j}`"
- :colspan="colspan"
- :rowspan="rowspan"
- >
- {{ text }}
- </th>
- </template>
- </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-${i}-${j}`"
- :colspan="col.colspan"
- :rowspan="col.rowspan"
- :class="[{ underline: col.isUnderline }]"
- :style="{ 'background-color': `${col.background}` }"
- >
- <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="col.answer"
- type="textarea"
- :placeholder="`${isAnswerMode ? '' : '输入'}`"
- :disabled="isAnswerMode"
- :autosize="{ minRows: 1, maxRows: 6 }"
- @input="enterAnswer(i, j, $event)"
- />
- </template>
- </template>
- <div v-else-if="col.type === 'preContent'" class="preContent">
- <span>{{ col.prefix }}</span>
- <template v-if="col.text.length > 0">
- {{ col.text }}
- </template>
- <template v-else>
- <el-input
- v-model="col.answer"
- type="textarea"
- :placeholder="`${isAnswerMode ? '' : '输入'}`"
- :disabled="isAnswerMode"
- :autosize="{ minRows: 1, maxRows: 6 }"
- @input="enterAnswer(i, j, $event)"
- />
- </template>
- </div>
- <div
- v-else-if="
- col.type === 'pinyin' || col.type === 'twoAnnotation'
- "
- 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>
- <span
- v-if="
- col.type === 'twoAnnotation' &&
- (curQue.pinyinPosition === 'right' ||
- curQue.pinyinPosition === 'bottom')
- "
- class="english"
- >
- ({{ col.text }})
- </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>
- <span
- v-if="
- col.type === 'twoAnnotation' &&
- (curQue.pinyinPosition === 'top' ||
- curQue.pinyinPosition === 'left')
- "
- class="english"
- >
- ({{ col.text }})
- </span>
- </div>
- </div>
- <div v-else-if="col.type === 'prePinyin'" class="pre-pinyin">
- <span>{{ col.prefix }}</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" />
- </div>
- </td>
- </template>
- </tr>
- </tbody>
- </table>
- </div>
- </template>
- <script>
- import CrossTick from "./HeaderSparate/CrossTick.vue";
- export default {
- components: { CrossTick },
- props: {
- curQue: {
- type: Object,
- required: true,
- },
- themeColor: {
- type: String,
- required: true,
- },
- },
- data() {
- return {
- isAnswerMode: false,
- };
- },
- computed: {
- 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() {
- const Bookanswer = this.curQue.Bookanswer;
- if (Bookanswer) {
- this.isAnswerMode = true;
- for (const key in Bookanswer) {
- let { col, row, value } = Bookanswer[key];
- this.curQue.tableData.body[col].content[row].answer = value;
- }
- } else {
- this.$set(this.curQue, "Bookanswer", {});
- }
- },
- methods: {
- enterAnswer(i, j, value) {
- this.curQue.Bookanswer[`${i}-${j}`] = {
- col: i,
- row: j,
- value,
- };
- },
- // th 是否生成
- thIsShow(i, j) {
- let headers = this.curQue.tableData.headers;
- let col = 1;
- let colIndex = headers[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 = headers.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;
- },
- // rowspan colspan 控制td是否生成
- tdIsShow(i, j) {
- let body = this.curQue.tableData.body;
- 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;
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .config-table {
- width: 100%;
- margin-bottom: 16px;
- table {
- table-layout: fixed;
- font-size: 16px;
- color: #404040;
- border-collapse: collapse;
- caption {
- font-size: 20px;
- color: #000;
- font-weight: bold;
- line-height: 1.95;
- }
- th {
- font-family: "FZJCGFKTK", "GB-PINYINOK-B", "robot";
- }
- th,
- td {
- font-weight: normal;
- border: 1px solid #e6e6e6;
- padding: 8px 12px;
- }
- .thead-merge {
- display: flex;
- justify-content: space-evenly;
- }
- .preContent {
- font-family: "FZJCGFKTK", "GB-PINYINOK-B", "robot";
- display: flex;
- align-items: center;
- ::v-deep .el-textarea__inner {
- padding-top: 2px;
- }
- }
- td {
- // min-height: 51px;
- // height: 51px;
- .cell-wrap {
- display: flex;
- align-items: center;
- justify-content: space-between;
- .content {
- font-family: "FZJCGFKTK", "GB-PINYINOK-B", "robot";
- }
- }
- .content {
- font-family: "FZJCGFKTK", "GB-PINYINOK-B", "robot";
- }
- .sentence {
- display: flex;
- .english {
- font-family: "robot";
- opacity: 0.6;
- }
- }
- .pinyin {
- font-family: "GB-PINYINOK-B";
- opacity: 0.6;
- }
- .chs {
- font-family: "FZJCGFKTK";
- }
- // 下划线
- &.underline {
- text-decoration: underline;
- }
- // 前缀 + 拼音
- .pre-pinyin {
- display: flex;
- align-items: flex-end;
- .right-pinyin {
- margin-left: 4px;
- column-gap: 2px;
- text-align: center;
- display: grid;
- }
- }
- }
- }
- }
- </style>
|