当前位置:   article > 正文

【sgCreateTableData】自定义小工具:敏捷开发→自动化生成表格数据数组[基于el-table]

【sgCreateTableData】自定义小工具:敏捷开发→自动化生成表格数据数组[基于el-table]

6aba114194844c62b8bf03cba32ba571.gif

源码

  1. <template>
  2. <!--
  3. 前往https://blog.csdn.net/qq_37860634/article/details/136141769
  4. 查看使用说明
  5. -->
  6. <div :class="$options.name">
  7. <div class="sg-head">表格数据生成工具</div>
  8. <div class="sg-container">
  9. <div class="sg-start">
  10. <div style="margin-bottom: 10px">字段中文名</div>
  11. <el-input
  12. style="margin-bottom: 10px"
  13. type="textarea"
  14. :placeholder="`请粘贴字段中文名`"
  15. v-model="textareaValue1"
  16. :rows="30"
  17. show-word-limit
  18. />
  19. <el-button type="primary" @click="createResult">生成表格数据</el-button>
  20. </div>
  21. <div class="sg-center"></div>
  22. <div class="sg-end">
  23. <div style="margin-bottom: 10px">生成结果</div>
  24. <el-input
  25. style="margin-bottom: 10px"
  26. type="textarea"
  27. :placeholder="`请复制结果`"
  28. v-model="textareaValue2"
  29. :rows="30"
  30. show-word-limit
  31. />
  32. <el-button type="primary" @click="copyResult">复制</el-button>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import pinyin from "@/js/pinyin";
  39. export default {
  40. name: "sgCreateTableData",
  41. data() {
  42. return {
  43. textareaValue1: "",
  44. textareaValue2: "",
  45. };
  46. },
  47. watch: {
  48. textareaValue1(newValue, oldValue) {
  49. newValue && this.createResult(newValue);
  50. },
  51. },
  52. methods: {
  53. createResult(d) {
  54. let texts = this.textareaValue1
  55. .split("\n")
  56. .map((v) => v.split("\t").join("").trim());
  57. texts = texts.filter((v, i, ar) => v !== ``);
  58. let rowData = {};
  59. texts.map((v) => {
  60. let cn_col = v;
  61. let py_col = pinyin.getCamelChars(v);
  62. rowData[py_col] = cn_col;
  63. });
  64. let data = [...Array(5)].map((v) => {
  65. return Object.assign({}, { ID: this.$g.UUID() }, rowData);
  66. });
  67. this.textareaValue2 = JSON.stringify(data, null, 2);
  68. this.copyResult(); //自动复制生成结果
  69. },
  70. copyResult(d) {
  71. this.$g.copy(this.textareaValue2, true);
  72. },
  73. },
  74. };
  75. </script>
  76. <style lang="scss" scoped>
  77. .sgCreateTableData {
  78. width: 100%;
  79. height: 100%;
  80. position: absolute;
  81. box-sizing: border-box;
  82. padding: 20px;
  83. .sg-head {
  84. display: flex;
  85. // justify-content: center;
  86. align-items: center;
  87. font-size: 24px;
  88. font-weight: bold;
  89. color: #409eff;
  90. margin-bottom: 10px;
  91. }
  92. .sg-container {
  93. display: flex;
  94. flex-wrap: nowrap;
  95. & > .sg-start {
  96. width: calc(50% - 20px);
  97. flex-shrink: 0;
  98. }
  99. & > .sg-center {
  100. display: flex;
  101. justify-content: center;
  102. align-items: center;
  103. flex-grow: 1;
  104. margin: 0 10px;
  105. font-size: 24px;
  106. color: #409eff;
  107. font-weight: bold;
  108. }
  109. & > .sg-end {
  110. width: calc(50% - 20px);
  111. flex-shrink: 0;
  112. }
  113. >>> textarea {
  114. max-height: revert;
  115. height: calc(100vh - 200px);
  116. word-wrap: break-word;
  117. word-break: break-all;
  118. white-space: break-spaces;
  119. }
  120. }
  121. }
  122. </style>

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/126777
推荐阅读