index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <div class="header-separate">
  3. <div class="header-separate-options">
  4. <div>
  5. 表头英文位置:
  6. <el-radio v-model="curQue.headerEnglishPosition" label="top">
  7. </el-radio>
  8. <el-radio v-model="curQue.headerEnglishPosition" label="right">
  9. </el-radio>
  10. <el-radio v-model="curQue.headerEnglishPosition" label="bottom">
  11. </el-radio>
  12. <el-radio v-model="curQue.headerEnglishPosition" label="left">
  13. </el-radio>
  14. </div>
  15. <div>
  16. 单元格拼音位置:
  17. <el-radio v-model="curQue.pinyinPosition" label="top">上</el-radio>
  18. <el-radio v-model="curQue.pinyinPosition" label="right">右</el-radio>
  19. <el-radio v-model="curQue.pinyinPosition" label="bottom">下</el-radio>
  20. <el-radio v-model="curQue.pinyinPosition" label="left">左</el-radio>
  21. </div>
  22. <div>
  23. 首列对齐方式:
  24. <el-radio v-model="curQue.firstColAligin" label="center">居中</el-radio>
  25. <el-radio v-model="curQue.firstColAligin" label="follow">
  26. 跟随内容
  27. </el-radio>
  28. </div>
  29. <div>
  30. 内容对齐方式:
  31. <el-radio v-model="curQue.textAlign" label="left">左对齐</el-radio>
  32. <el-radio v-model="curQue.textAlign" label="center">居中</el-radio>
  33. <el-radio v-model="curQue.textAlign" label="right">右对齐</el-radio>
  34. </div>
  35. <div>
  36. <el-button @click="addCol">增加一列</el-button>
  37. <el-button @click="addRow">增加一行</el-button>
  38. </div>
  39. </div>
  40. <div class="header-separate-preview">
  41. <table class="preview-table">
  42. <thead>
  43. <tr>
  44. <td></td>
  45. <td
  46. v-for="(item, k) in curQue.tableData.colsConfig.width"
  47. :key="`tfoot-${k}`"
  48. >
  49. 第{{k+1}}列
  50. </td>
  51. <td></td>
  52. </tr>
  53. <tr>
  54. <th></th>
  55. <th v-for="(num, i) in curQue.tableData.headers" :key="`th-${i}`">
  56. <el-input v-model="num.text">
  57. <template slot="prepend">文本</template>
  58. </el-input>
  59. <el-input v-model="num.english">
  60. <el-select
  61. slot="prepend"
  62. v-model="num.type"
  63. placeholder="请选择"
  64. >
  65. <el-option label="英文" value="english" />
  66. <el-option label="拼音" value="pinyin" />
  67. </el-select>
  68. </el-input>
  69. </th>
  70. <th></th>
  71. </tr>
  72. </thead>
  73. <tbody>
  74. <tr v-for="(row, i) in curQue.tableData.body" :key="`tr-${i}`">
  75. <td width="60">第{{i+1}}行</td>
  76. <td v-for="(col, j) in row.content" :key="`td-${j}`">
  77. <p>{{col.message+' '+col.text+' '+col.sentence_data.sentence}}</p>
  78. <template v-if="col.mulText">
  79. <ul
  80. class="option-detail-detail"
  81. v-for="(dItem, dIndex) in col.mulText.detail"
  82. :key="'ddItem' + dIndex"
  83. >
  84. <li
  85. v-for="(ddItem, ddIndex) in dItem.detail"
  86. :key="'ddItem' + dIndex + ddIndex"
  87. >
  88. <span
  89. :class="[
  90. ddItem.config.wordPadding.indexOf('left') > -1
  91. ? 'dleft'
  92. : '',
  93. ddItem.config.wordPadding.indexOf('right') > -1
  94. ? 'dright'
  95. : '',
  96. !ddItem.sentence ? 'placeholder' : '',
  97. ]"
  98. >{{ ddItem.sentence }}</span
  99. >
  100. </li>
  101. </ul>
  102. </template>
  103. <el-button @click="edit(i, j)">编辑</el-button>
  104. </td>
  105. <td>
  106. <el-button size="mini" @click="deleteRow(i)">删除行</el-button>
  107. </td>
  108. </tr>
  109. <tr>
  110. <td></td>
  111. <td
  112. v-for="(width, i) in curQue.tableData.colsConfig.width"
  113. :key="`width-${i}`"
  114. >
  115. <el-input v-model.number="width.val" size="mini">
  116. <template slot="prepend">宽度</template>
  117. </el-input>
  118. <el-button size="mini" @click="deleteCol(i)">删除列</el-button>
  119. </td>
  120. <td></td>
  121. </tr>
  122. </tbody>
  123. </table>
  124. </div>
  125. <CellEdit
  126. :visible="visible"
  127. :body="curQue.tableData.body"
  128. :cur-index="curIndex"
  129. @close="close"
  130. />
  131. </div>
  132. </template>
  133. <script>
  134. import CellEdit from "./components/CellEdit.vue";
  135. export default {
  136. components: { CellEdit },
  137. props: {
  138. curQue: {
  139. type: Object,
  140. default: () => {
  141. return {
  142. isFirst: true,
  143. type: "header_separate",
  144. name: "表头分离表格",
  145. pinyinPosition: "top",
  146. headerEnglishPosition: "top",
  147. firstColAligin: "center",
  148. textAlign: "center",
  149. tableData: {
  150. headers: [
  151. {
  152. text: "",
  153. type: "english",
  154. english: "",
  155. },
  156. {
  157. text: "",
  158. type: "english",
  159. english: "",
  160. },
  161. {
  162. text: "",
  163. type: "english",
  164. english: "",
  165. },
  166. ],
  167. body: [
  168. {
  169. content: [
  170. {
  171. type: "content",
  172. text: "",
  173. message: "",
  174. prefixOrSuffix: "prefix", // 前缀或后缀
  175. isUnderline: false, // 下划线
  176. background: "#fff", // 背景色
  177. isCross: false, // 勾叉
  178. answer: "",
  179. CrossAnswer: "normal",
  180. rowspan: 1,
  181. colspan: 1,
  182. sentence_data: {
  183. type: "sentence_segword_chs",
  184. name: "句子分词",
  185. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  186. sentence: "", // 句子
  187. segList: [], // 分词结果
  188. seg_words: "",
  189. wordsList: [],
  190. },
  191. mulText:{
  192. correct: {
  193. completeInput: ""
  194. },
  195. detail: [],
  196. input_Isexample: false,
  197. }
  198. },
  199. {
  200. type: "content",
  201. text: "",
  202. message: "",
  203. prefixOrSuffix: "prefix",
  204. isUnderline: false,
  205. background: "#fff",
  206. isCross: false,
  207. answer: "",
  208. CrossAnswer: "normal",
  209. rowspan: 1,
  210. colspan: 1,
  211. sentence_data: {
  212. type: "sentence_segword_chs",
  213. name: "句子分词",
  214. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  215. sentence: "", // 句子
  216. segList: [], // 分词结果
  217. seg_words: "",
  218. wordsList: [],
  219. },
  220. mulText:{
  221. correct: {
  222. completeInput: ""
  223. },
  224. detail: [],
  225. input_Isexample: false,
  226. }
  227. },
  228. {
  229. type: "content",
  230. text: "",
  231. message: "",
  232. prefixOrSuffix: "prefix",
  233. isUnderline: false,
  234. background: "#fff",
  235. isCross: false,
  236. answer: "",
  237. CrossAnswer: "normal",
  238. rowspan: 1,
  239. colspan: 1,
  240. sentence_data: {
  241. type: "sentence_segword_chs",
  242. name: "句子分词",
  243. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  244. sentence: "", // 句子
  245. segList: [], // 分词结果
  246. seg_words: "",
  247. wordsList: [],
  248. },
  249. mulText:{
  250. correct: {
  251. completeInput: ""
  252. },
  253. detail: [],
  254. input_Isexample: false,
  255. }
  256. },
  257. ],
  258. },
  259. ],
  260. colsConfig: {
  261. width: [{ val: 100 }, { val: 100 }, { val: 100 }],
  262. },
  263. },
  264. };
  265. },
  266. },
  267. changeCurQue: {
  268. type: Function,
  269. required: true,
  270. },
  271. },
  272. data() {
  273. return {
  274. visible: false,
  275. curIndex: {
  276. col: 0,
  277. row: 0,
  278. },
  279. };
  280. },
  281. computed: {
  282. rows() {
  283. return this.curQue.tableData.body.length;
  284. },
  285. cols() {
  286. if (this.rows.length <= 0) return 0;
  287. return this.curQue.tableData.body[0].content.length;
  288. },
  289. },
  290. created() {
  291. if (this.curQue.isFirst) {
  292. this.curQue.isFirst = false;
  293. this.changeCurQue(this.curQue);
  294. }
  295. },
  296. methods: {
  297. addCol() {
  298. this.curQue.tableData.body.forEach(({ content }) => {
  299. content.push({
  300. type: "content",
  301. text: "",
  302. message: "",
  303. prefixOrSuffix: "prefix",
  304. isUnderline: false,
  305. background: "#fff",
  306. isCross: false,
  307. rowspan: 1,
  308. colspan: 1,
  309. sentence_data: {
  310. type: "sentence_segword_chs",
  311. name: "句子分词",
  312. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  313. sentence: "", // 句子
  314. segList: [], // 分词结果
  315. seg_words: "",
  316. wordsList: [],
  317. },
  318. mulText:{
  319. correct: {
  320. completeInput: ""
  321. },
  322. detail: [],
  323. input_Isexample: false,
  324. }
  325. });
  326. });
  327. this.curQue.tableData.headers.push({
  328. text: "",
  329. type: "english",
  330. english: "",
  331. });
  332. this.curQue.tableData.colsConfig.width.push({ val: 100 });
  333. },
  334. deleteCol(i) {
  335. this.$confirm("确定要删除此列吗?", "提示", {
  336. confirmButtonText: "确定",
  337. cancelButtonText: "取消",
  338. type: "warning",
  339. }).then(() => {
  340. this.curQue.tableData.body.forEach(({ content }) => {
  341. content.splice(i, 1);
  342. });
  343. this.curQue.tableData.headers.splice(i, 1);
  344. this.curQue.tableData.colsConfig.width.splice(i, 1);
  345. });
  346. },
  347. addRow() {
  348. let content = [];
  349. for (let i = 0; i < this.cols; i++) {
  350. content.push({
  351. type: "content",
  352. text: "",
  353. message: "", // 内容
  354. prefixOrSuffix: "prefix",
  355. isUnderline: false,
  356. background: "#fff",
  357. isCross: false,
  358. rowspan: 1,
  359. colspan: 1,
  360. sentence_data: {
  361. type: "sentence_segword_chs",
  362. name: "句子分词",
  363. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  364. sentence: "", // 句子
  365. segList: [], // 分词结果
  366. seg_words: "",
  367. wordsList: [],
  368. },
  369. mulText:{
  370. correct: {
  371. completeInput: ""
  372. },
  373. detail: [],
  374. input_Isexample: false,
  375. }
  376. });
  377. }
  378. this.curQue.tableData.body.push({
  379. content,
  380. });
  381. },
  382. deleteRow(i) {
  383. this.$confirm("确定要删除此行吗?", "提示", {
  384. confirmButtonText: "确定",
  385. cancelButtonText: "取消",
  386. type: "warning",
  387. }).then(() => {
  388. if (this.rows <= 1) return this.$message.warning("必须留一行");
  389. this.curQue.tableData.body.splice(i, 1);
  390. });
  391. },
  392. edit(i, j) {
  393. this.curIndex = {
  394. col: j,
  395. row: i,
  396. };
  397. this.visible = true;
  398. },
  399. close() {
  400. this.visible = false;
  401. },
  402. },
  403. };
  404. </script>
  405. <style lang="scss" scoped>
  406. .header-separate {
  407. border: 1px solid #ccc;
  408. border-radius: 4px;
  409. padding: 8px 12px;
  410. &-options {
  411. > div {
  412. margin-bottom: 12px;
  413. }
  414. }
  415. &-preview {
  416. border-top: 1px solid #ccc;
  417. padding-top: 12px;
  418. .preview-table {
  419. border-collapse: collapse;
  420. th {
  421. .el-select {
  422. width: 80px;
  423. }
  424. }
  425. td,
  426. th {
  427. padding: 8px;
  428. .el-input {
  429. max-width: 220px;
  430. }
  431. }
  432. td {
  433. border: 1px solid #aaa;
  434. }
  435. th {
  436. border: 1px solid #aaa;
  437. }
  438. }
  439. }
  440. .option-detail-detail {
  441. clear: both;
  442. overflow: hidden;
  443. margin-bottom: 10px;
  444. > li {
  445. float: left;
  446. > span {
  447. float: left;
  448. &.dleft {
  449. padding-left: 4px;
  450. }
  451. &.dright{
  452. padding-right: 4px;
  453. }
  454. }
  455. }
  456. > i {
  457. float: left;
  458. }
  459. }
  460. }
  461. </style>