TableExhibitionQuery.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div class="table-query">
  3. <div>
  4. <el-button type="primary" @click="openCodeDialog">查看代码</el-button>
  5. <el-button type="primary" @click="handleClipboard(srcTableCode, $event)">
  6. 复制代码
  7. </el-button>
  8. </div>
  9. <el-dialog destroy-on-close title="查看代码" :visible.sync="dialogVisible">
  10. <textarea v-show="false" ref="code" v-model="srcTableCode"></textarea>
  11. <span slot="footer" class="dialog-footer">
  12. <el-button @click="dialogVisible = false">取 消</el-button>
  13. <el-button
  14. type="primary"
  15. @click="closeCodeDialog(srcTableCode, $event)"
  16. >
  17. 复制代码
  18. </el-button>
  19. </span>
  20. </el-dialog>
  21. </div>
  22. </template>
  23. <script>
  24. import { mapGetters } from "vuex";
  25. import clipboard from "@/utils/clipboard";
  26. import CodeMirror from "codemirror";
  27. export default {
  28. props: {
  29. headers: {
  30. type: Array,
  31. required: true,
  32. },
  33. },
  34. data() {
  35. return {
  36. dialogVisible: false,
  37. };
  38. },
  39. computed: {
  40. ...mapGetters({ srcTableCode: "table/srcTableCode" }),
  41. },
  42. methods: {
  43. handleClipboard(text, event) {
  44. clipboard(text, event);
  45. },
  46. openCodeDialog() {
  47. this.dialogVisible = true;
  48. setTimeout(() => {
  49. CodeMirror.fromTextArea(this.$refs.code, {
  50. lineNumbers: true,
  51. gutters: ["CodeMirror-lint-markers"],
  52. theme: "rubyblue",
  53. autoRefresh: true,
  54. lint: true,
  55. });
  56. }, 0);
  57. },
  58. closeCodeDialog(text, event) {
  59. this.handleClipboard(text, event);
  60. this.dialogVisible = false;
  61. },
  62. },
  63. };
  64. </script>
  65. <style lang="scss" scoped>
  66. .table-query {
  67. display: flex;
  68. justify-content: flex-end;
  69. height: 45px;
  70. ::v-deep {
  71. .CodeMirror {
  72. height: auto;
  73. min-height: calc(100vh - 420px);
  74. }
  75. }
  76. }
  77. </style>