index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. <th v-for="(num, i) in curQue.tableData.headers" :key="`th-${i}`">
  45. <el-input v-model="num.text">
  46. <template slot="prepend">文本</template>
  47. </el-input>
  48. <el-input v-model="num.english">
  49. <el-select
  50. slot="prepend"
  51. v-model="num.type"
  52. placeholder="请选择"
  53. >
  54. <el-option label="英文" value="english" />
  55. <el-option label="拼音" value="pinyin" />
  56. </el-select>
  57. </el-input>
  58. </th>
  59. </tr>
  60. </thead>
  61. <tbody>
  62. <tr v-for="(row, i) in curQue.tableData.body" :key="`tr-${i}`">
  63. <td v-for="(col, j) in row.content" :key="`td-${j}`">
  64. <el-button @click="edit(i, j)">编辑</el-button>
  65. </td>
  66. <td>
  67. <el-button size="mini" @click="deleteRow(i)">删除行</el-button>
  68. </td>
  69. </tr>
  70. <tr>
  71. <td
  72. v-for="(width, i) in curQue.tableData.colsConfig.width"
  73. :key="`width-${i}`"
  74. >
  75. <el-input v-model.number="width.val" size="mini">
  76. <template slot="prepend">宽度</template>
  77. </el-input>
  78. <el-button size="mini" @click="deleteCol(i)">删除列</el-button>
  79. </td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. </div>
  84. <CellEdit
  85. :visible="visible"
  86. :body="curQue.tableData.body"
  87. :cur-index="curIndex"
  88. @close="close"
  89. />
  90. </div>
  91. </template>
  92. <script>
  93. import CellEdit from "./components/CellEdit.vue";
  94. export default {
  95. components: { CellEdit },
  96. props: {
  97. curQue: {
  98. type: Object,
  99. default: () => {
  100. return {
  101. isFirst: true,
  102. type: "header_separate",
  103. name: "表头分离表格",
  104. pinyinPosition: "top",
  105. headerEnglishPosition: "top",
  106. firstColAligin: "center",
  107. textAlign: "center",
  108. tableData: {
  109. headers: [
  110. {
  111. text: "",
  112. type: "english",
  113. english: "",
  114. },
  115. {
  116. text: "",
  117. type: "english",
  118. english: "",
  119. },
  120. {
  121. text: "",
  122. type: "english",
  123. english: "",
  124. },
  125. ],
  126. body: [
  127. {
  128. content: [
  129. {
  130. type: "content",
  131. text: "",
  132. message: "",
  133. prefixOrSuffix: "prefix", // 前缀或后缀
  134. isUnderline: false, // 下划线
  135. background: "#fff", // 背景色
  136. isCross: false, // 勾叉
  137. rowspan: 1,
  138. colspan: 1,
  139. sentence_data: {
  140. type: "sentence_segword_chs",
  141. name: "句子分词",
  142. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  143. sentence: "", // 句子
  144. segList: [], // 分词结果
  145. seg_words: "",
  146. wordsList: [],
  147. },
  148. },
  149. {
  150. type: "content",
  151. text: "",
  152. message: "",
  153. prefixOrSuffix: "prefix",
  154. isUnderline: false,
  155. background: "#fff",
  156. isCross: false,
  157. rowspan: 1,
  158. colspan: 1,
  159. sentence_data: {
  160. type: "sentence_segword_chs",
  161. name: "句子分词",
  162. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  163. sentence: "", // 句子
  164. segList: [], // 分词结果
  165. seg_words: "",
  166. wordsList: [],
  167. },
  168. },
  169. {
  170. type: "content",
  171. text: "",
  172. message: "",
  173. prefixOrSuffix: "prefix",
  174. isUnderline: false,
  175. background: "#fff",
  176. isCross: false,
  177. rowspan: 1,
  178. colspan: 1,
  179. sentence_data: {
  180. type: "sentence_segword_chs",
  181. name: "句子分词",
  182. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  183. sentence: "", // 句子
  184. segList: [], // 分词结果
  185. seg_words: "",
  186. wordsList: [],
  187. },
  188. },
  189. ],
  190. },
  191. ],
  192. colsConfig: {
  193. width: [{ val: 100 }, { val: 100 }, { val: 100 }],
  194. },
  195. },
  196. };
  197. },
  198. },
  199. changeCurQue: {
  200. type: Function,
  201. required: true,
  202. },
  203. },
  204. data() {
  205. return {
  206. visible: false,
  207. curIndex: {
  208. col: 0,
  209. row: 0,
  210. },
  211. };
  212. },
  213. computed: {
  214. rows() {
  215. return this.curQue.tableData.body.length;
  216. },
  217. cols() {
  218. if (this.rows.length <= 0) return 0;
  219. return this.curQue.tableData.body[0].content.length;
  220. },
  221. },
  222. created() {
  223. if (this.curQue.isFirst) {
  224. this.curQue.isFirst = false;
  225. this.changeCurQue(this.curQue);
  226. }
  227. },
  228. methods: {
  229. addCol() {
  230. this.curQue.tableData.body.forEach(({ content }) => {
  231. content.push({
  232. type: "content",
  233. text: "",
  234. message: "",
  235. prefixOrSuffix: "prefix",
  236. isUnderline: false,
  237. background: "#fff",
  238. isCross: false,
  239. rowspan: 1,
  240. colspan: 1,
  241. sentence_data: {
  242. type: "sentence_segword_chs",
  243. name: "句子分词",
  244. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  245. sentence: "", // 句子
  246. segList: [], // 分词结果
  247. seg_words: "",
  248. wordsList: [],
  249. },
  250. });
  251. });
  252. this.curQue.tableData.headers.push({
  253. text: "",
  254. type: "english",
  255. english: "",
  256. });
  257. this.curQue.tableData.colsConfig.width.push({ val: 100 });
  258. },
  259. deleteCol(i) {
  260. this.$confirm("确定要删除此列吗?", "提示", {
  261. confirmButtonText: "确定",
  262. cancelButtonText: "取消",
  263. type: "warning",
  264. }).then(() => {
  265. this.curQue.tableData.body.forEach(({ content }) => {
  266. content.splice(i, 1);
  267. });
  268. this.curQue.tableData.headers.splice(i, 1);
  269. this.curQue.tableData.colsConfig.width.splice(i, 1);
  270. });
  271. },
  272. addRow() {
  273. let content = [];
  274. for (let i = 0; i < this.cols; i++) {
  275. content.push({
  276. type: "content",
  277. text: "",
  278. message: "", // 内容
  279. prefixOrSuffix: "prefix",
  280. isUnderline: false,
  281. background: "#fff",
  282. isCross: false,
  283. rowspan: 1,
  284. colspan: 1,
  285. sentence_data: {
  286. type: "sentence_segword_chs",
  287. name: "句子分词",
  288. pyPosition: "top", // top 拼音在上面;bottom 拼音在下面
  289. sentence: "", // 句子
  290. segList: [], // 分词结果
  291. seg_words: "",
  292. wordsList: [],
  293. },
  294. });
  295. }
  296. this.curQue.tableData.body.push({
  297. content,
  298. });
  299. },
  300. deleteRow(i) {
  301. this.$confirm("确定要删除此行吗?", "提示", {
  302. confirmButtonText: "确定",
  303. cancelButtonText: "取消",
  304. type: "warning",
  305. }).then(() => {
  306. if (this.rows <= 1) return this.$message.warning("必须留一行");
  307. this.curQue.tableData.body.splice(i, 1);
  308. });
  309. },
  310. edit(i, j) {
  311. this.curIndex = {
  312. col: j,
  313. row: i,
  314. };
  315. this.visible = true;
  316. },
  317. close() {
  318. this.visible = false;
  319. },
  320. },
  321. };
  322. </script>
  323. <style lang="scss" scoped>
  324. .header-separate {
  325. border: 1px solid #ccc;
  326. border-radius: 4px;
  327. padding: 8px 12px;
  328. &-options {
  329. > div {
  330. margin-bottom: 12px;
  331. }
  332. }
  333. &-preview {
  334. border-top: 1px solid #ccc;
  335. padding-top: 12px;
  336. .preview-table {
  337. border-collapse: collapse;
  338. th {
  339. .el-select {
  340. width: 80px;
  341. }
  342. }
  343. td,
  344. th {
  345. padding: 8px;
  346. .el-input {
  347. max-width: 220px;
  348. }
  349. }
  350. td {
  351. border: 1px solid #aaa;
  352. }
  353. th {
  354. border: 1px solid #aaa;
  355. }
  356. }
  357. }
  358. }
  359. </style>