index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <div class="header-separate">
  3. <table>
  4. <colgroup>
  5. <col
  6. v-for="(item, i) in curQue.tableData.colsConfig.width"
  7. :key="`col-${i}`"
  8. :style="{ width: `${item.val}px` }"
  9. />
  10. </colgroup>
  11. <thead>
  12. <tr>
  13. <th
  14. v-for="({ text, english, type }, i) in curQue.tableData.headers"
  15. :key="`th-${i}`"
  16. >
  17. <div class="thead-content" :style="theadStyle">
  18. <span class="chs">{{ text }}</span>
  19. <span :class="[type === 'english' ? 'english' : 'pinyin']">
  20. {{ english }}
  21. </span>
  22. </div>
  23. </th>
  24. </tr>
  25. </thead>
  26. <tbody
  27. :style="{
  28. 'text-align': `${curQue.textAlign}`,
  29. }"
  30. >
  31. <tr v-for="(row, i) in curQue.tableData.body" :key="`tr-${i}`">
  32. <template v-for="(col, j) in row.content">
  33. <td
  34. v-if="tdIsShow(i, j)"
  35. :key="`td-${j}`"
  36. :colspan="col.colspan"
  37. :rowspan="col.rowspan"
  38. :class="[
  39. { underline: col.isUnderline },
  40. `${curQue.firstColAligin === 'center' ? 'col-center' : ''}`,
  41. ]"
  42. :style="{
  43. 'background-color': `${col.background}`,
  44. display: tdHeaderIsNone(i, j),
  45. }"
  46. >
  47. <div class="cell-wrap">
  48. <template v-if="col.type === 'content'">
  49. <span v-if="col.text.length > 0" class="content">
  50. {{ col.text }}
  51. </span>
  52. <template v-else>
  53. <el-input
  54. v-model="col.answer"
  55. type="textarea"
  56. :placeholder="`${isAnswerMode ? '' : '输入'}`"
  57. :disabled="isAnswerMode"
  58. :autosize="{ minRows: 1, maxRows: 6 }"
  59. @input="enterAnswer(i, j, $event)"
  60. />
  61. </template>
  62. </template>
  63. <div
  64. v-else-if="col.type === 'pinyin'"
  65. class="sentence"
  66. :style="pinyinStyle"
  67. >
  68. <div>
  69. <span
  70. v-for="({ pinyin, chs }, k) in col.sentence_data
  71. .wordsList"
  72. :key="`${
  73. curQue.pinyinPosition === 'top' ||
  74. curQue.pinyinPosition === 'left'
  75. ? 'pinyin'
  76. : 'chs'
  77. }-${k}`"
  78. :class="[
  79. `${
  80. curQue.pinyinPosition === 'top' ||
  81. curQue.pinyinPosition === 'left'
  82. ? 'pinyin'
  83. : 'chs'
  84. }`,
  85. ]"
  86. >
  87. {{
  88. curQue.pinyinPosition === "top" ||
  89. curQue.pinyinPosition == "left"
  90. ? pinyin
  91. : chs
  92. }}
  93. </span>
  94. </div>
  95. <div>
  96. <span
  97. v-for="({ pinyin, chs }, k) in col.sentence_data
  98. .wordsList"
  99. :key="`${
  100. curQue.pinyinPosition === 'top' ||
  101. curQue.pinyinPosition === 'left'
  102. ? 'chs'
  103. : 'pinyin'
  104. }-${k}`"
  105. :class="[
  106. `${
  107. curQue.pinyinPosition === 'top' ||
  108. curQue.pinyinPosition === 'left'
  109. ? 'chs'
  110. : 'pinyin'
  111. }`,
  112. ]"
  113. >
  114. {{
  115. curQue.pinyinPosition === "top" ||
  116. curQue.pinyinPosition == "left"
  117. ? chs
  118. : pinyin
  119. }}
  120. </span>
  121. </div>
  122. </div>
  123. <div
  124. v-else-if="col.type === 'prePinyin'"
  125. :style="{
  126. 'flex-direction':
  127. col.prefixOrSuffix === 'prefix' ? 'row' : 'row-reverse',
  128. }"
  129. class="pre-pinyin"
  130. >
  131. <span>{{ col.message }}</span>
  132. <div
  133. class="right-pinyin"
  134. :style="{
  135. 'grid-template-columns': `repeat(${col.sentence_data.wordsList.length}, auto)`,
  136. }"
  137. >
  138. <span
  139. v-for="({ pinyin }, k) in col.sentence_data.wordsList"
  140. :key="`pre-pinyin-${k}`"
  141. class="pinyin"
  142. >
  143. {{ pinyin }}
  144. </span>
  145. <span
  146. v-for="({ pinyin, chs }, k) in col.sentence_data
  147. .wordsList"
  148. :key="`pre-chs-${k}`"
  149. class="chs"
  150. >
  151. {{ chs }}
  152. </span>
  153. </div>
  154. </div>
  155. <CrossTick v-if="col.isCross" />
  156. </div>
  157. </td>
  158. </template>
  159. </tr>
  160. </tbody>
  161. </table>
  162. </div>
  163. </template>
  164. <script>
  165. import CrossTick from "./CrossTick.vue";
  166. export default {
  167. components: { CrossTick },
  168. props: {
  169. curQue: {
  170. type: Object,
  171. required: true,
  172. },
  173. themeColor: {
  174. type: String,
  175. required: true,
  176. },
  177. },
  178. data() {
  179. return {
  180. isAnswerMode: false,
  181. };
  182. },
  183. computed: {
  184. theadStyle() {
  185. const hp = this.curQue.headerEnglishPosition;
  186. if (hp === "top") {
  187. return {
  188. "flex-direction": "column-reverse",
  189. };
  190. }
  191. if (hp === "right") {
  192. return {
  193. "flex-direction": "row",
  194. "column-gap": "8px",
  195. };
  196. }
  197. if (hp === "bottom") {
  198. return {
  199. "flex-direction": "column",
  200. };
  201. }
  202. if (hp === "left") {
  203. return {
  204. "flex-direction": "row-reverse",
  205. "column-gap": "8px",
  206. };
  207. }
  208. },
  209. pinyinStyle() {
  210. let pyPos = this.curQue.pinyinPosition;
  211. if (pyPos === "left") {
  212. return {
  213. "column-gap": "16px",
  214. };
  215. }
  216. if (pyPos === "top") {
  217. return {
  218. "flex-direction": "column",
  219. };
  220. }
  221. if (pyPos === "right") {
  222. return {
  223. "column-gap": "16px",
  224. };
  225. }
  226. if (pyPos === "bottom") {
  227. return {
  228. "flex-direction": "column",
  229. };
  230. }
  231. },
  232. },
  233. created() {
  234. const Bookanswer = this.curQue.Bookanswer;
  235. if (Bookanswer) {
  236. this.isAnswerMode = true;
  237. for (const key in Bookanswer) {
  238. let { col, row, value } = Bookanswer[key];
  239. this.curQue.tableData.body[col].content[row].answer = value;
  240. }
  241. } else {
  242. this.$set(this.curQue, "Bookanswer", {});
  243. }
  244. },
  245. methods: {
  246. enterAnswer(i, j, value) {
  247. this.curQue.Bookanswer[`${i}-${j}`] = {
  248. col: i,
  249. row: j,
  250. value,
  251. };
  252. },
  253. // 控制首尾表格显隐
  254. tdHeaderIsNone(i, j) {
  255. let body = this.curQue.tableData.body;
  256. if (j !== 0 && j !== body[0].content.length - 1) return "table-cell";
  257. let col = 1;
  258. let colIndex = body[i].content.findIndex(({ colspan }, index) => {
  259. if (index > j) return false;
  260. let num = colspan === undefined ? 1 : Number(colspan);
  261. if (num > 1) {
  262. col = num;
  263. return false;
  264. }
  265. if (index === j && col > 1) return true;
  266. if (col > 0) col -= 1;
  267. return false;
  268. });
  269. let row = 1;
  270. let rowIndex = body.findIndex((item, index) => {
  271. let rowspan = item.content[j].rowspan;
  272. let num = rowspan === undefined ? 1 : Number(rowspan);
  273. if (num > 1) {
  274. row = num;
  275. return false;
  276. }
  277. if (index === i && row > 1) return true;
  278. if (row > 0) row -= 1;
  279. return false;
  280. });
  281. return rowIndex === -1 && colIndex === -1 ? "table-cell" : "none";
  282. },
  283. // rowspan colspan 控制td是否生成
  284. tdIsShow(i, j) {
  285. let body = this.curQue.tableData.body;
  286. if (j === 0) return true;
  287. let col = 1;
  288. let colIndex = body[i].content.findIndex(({ colspan }, index) => {
  289. if (index > j) return false;
  290. let num = colspan === undefined ? 1 : Number(colspan);
  291. if (num > 1) {
  292. col = num;
  293. return false;
  294. }
  295. if (index === j && col > 1) return true;
  296. if (col > 0) col -= 1;
  297. return false;
  298. });
  299. let row = 1;
  300. let rowIndex = body.findIndex((item, index) => {
  301. let rowspan = item.content[j].rowspan;
  302. let num = rowspan === undefined ? 1 : Number(rowspan);
  303. if (num > 1) {
  304. row = num;
  305. return false;
  306. }
  307. if (index === i && row > 1) return true;
  308. if (row > 0) row -= 1;
  309. return false;
  310. });
  311. return (
  312. colIndex === -1 && (rowIndex === -1 || j === body[0].content.length - 1)
  313. );
  314. },
  315. },
  316. };
  317. </script>
  318. <style lang="scss" scoped>
  319. .header-separate {
  320. width: 100%;
  321. margin-bottom: 16px;
  322. table {
  323. table-layout: fixed;
  324. font-size: 16px;
  325. border-collapse: separate;
  326. border-spacing: 6px 0;
  327. th {
  328. color: #4d4c51;
  329. font-weight: normal;
  330. background-color: #efeff9;
  331. padding: 4px 12px;
  332. border: 2px solid #afb4d1;
  333. .thead-content {
  334. display: flex;
  335. justify-content: center;
  336. .english {
  337. font-family: "robot";
  338. color: #000;
  339. }
  340. }
  341. }
  342. td {
  343. color: #474747;
  344. border-bottom: 1px solid transparent;
  345. padding: 4px 12px;
  346. min-height: 43px;
  347. height: 43px;
  348. .cell-wrap {
  349. display: flex;
  350. align-items: center;
  351. justify-content: space-between;
  352. .content {
  353. font-family: "FZJCGFKTK", "GB-PINYINOK-B", "robot";
  354. }
  355. }
  356. // 下划线
  357. &.underline {
  358. text-decoration: underline;
  359. }
  360. .sentence {
  361. display: flex;
  362. }
  363. // 前缀 + 拼音
  364. .pre-pinyin {
  365. display: flex;
  366. align-items: flex-end;
  367. .right-pinyin {
  368. margin-left: 4px;
  369. column-gap: 2px;
  370. text-align: center;
  371. display: grid;
  372. }
  373. }
  374. &:first-child {
  375. border-left: 2px solid transparent;
  376. border-bottom-width: 1px;
  377. border-image: linear-gradient(
  378. transparent 6px,
  379. #e7b576 6px,
  380. #e7b576 calc(100% - 6px),
  381. transparent calc(100% - 6px),
  382. transparent calc(100% - 2px),
  383. #cecece calc(100% - 2px)
  384. )
  385. 2;
  386. border-image-outset: 0 4px 0 0;
  387. &.col-center {
  388. text-align: center;
  389. }
  390. }
  391. &:not(:last-child) {
  392. position: relative;
  393. // 用 ::after 模拟中间边框
  394. &::after {
  395. content: "";
  396. position: absolute;
  397. top: 0;
  398. left: calc(100% + 2px);
  399. width: 2px;
  400. height: 100%;
  401. display: inline-block;
  402. background: repeating-linear-gradient(
  403. transparent,
  404. transparent 3px,
  405. #cecece 3px,
  406. #cecece 7px,
  407. transparent 7px
  408. );
  409. }
  410. }
  411. // 中间的底部边框用 ::before 模拟
  412. &:not(:first-child):not(:last-child)::before {
  413. content: "";
  414. position: absolute;
  415. top: 100%;
  416. left: 0;
  417. width: 100%;
  418. height: 1px;
  419. display: inline-block;
  420. background-color: #cecece;
  421. box-shadow: 2px 0 #cecece, -2px 0 #cecece;
  422. }
  423. &:last-child {
  424. border-right: 2px solid transparent;
  425. border-bottom-width: 1px;
  426. border-image: linear-gradient(
  427. transparent 6px,
  428. #e7b576 6px,
  429. #e7b576 calc(100% - 6px),
  430. transparent calc(100% - 6px),
  431. transparent calc(100% - 2px),
  432. #cecece calc(100% - 2px)
  433. )
  434. 2;
  435. border-image-outset: 0 0 0 4px;
  436. }
  437. }
  438. .pinyin {
  439. font-family: "GB-PINYINOK-B";
  440. }
  441. .chs {
  442. font-family: "FZJCGFKTK";
  443. }
  444. }
  445. }
  446. </style>