当前位置:   article > 正文

常用项目插件_vue sql编辑器组件

vue sql编辑器组件

1、前端可以进行复制文字操作的插件   clipboard

npm install clipboard --save

2、 写sql语句高亮的插件 代码编辑器功能 sql语言格式化sql-formatter 搭配使用

vue2-ace-editor         sql-formatter

安装

npm install vue2-ace-editor --save
npm install sql-formatter --save

封装组件

  1. <div class="editor-box">
  2. <ace
  3. ref="editor"
  4. :value="content"
  5. @init="initEditor"
  6. :lang="lang"
  7. :height="height === 0 ? '100%' : height"
  8. :theme="theme"
  9. :options="options"
  10. width="100%"
  11. v-bind="config">
  12. </ace>
  13. </div>
  14. <script>
  15. import ace from 'vue2-ace-editor'
  16. export default {
  17. name: 'SqlEditor',
  18. components: {
  19. ace
  20. },
  21. props: {
  22. content: {
  23. type: String,
  24. default: ''
  25. },
  26. height: {
  27. type: Number,
  28. default: 0
  29. },
  30. readOnly: {
  31. type: Boolean,
  32. default: false
  33. },
  34. theme: {
  35. type: String,
  36. default: 'monokai'
  37. },
  38. lang: {
  39. type: String,
  40. default: 'sql'
  41. },
  42. config: {
  43. type: Object,
  44. default: () => {
  45. return {
  46. font_size: 16,
  47. sql_atom: true
  48. }
  49. }
  50. }
  51. },
  52. computed: {
  53. options () {
  54. if (this.readOnly) {
  55. return {
  56. enableBasicAutocompletion: true,
  57. enableSnippets: true,
  58. enableLiveAutocompletion: this.config.sql_atom,
  59. showPrintMargin: false,
  60. fontSize: this.config.font_size,
  61. readOnly: true
  62. }
  63. }
  64. return {
  65. enableBasicAutocompletion: true,
  66. enableSnippets: true,
  67. enableLiveAutocompletion: this.config.sql_atom,
  68. showPrintMargin: false,
  69. fontSize: this.config.font_size
  70. }
  71. }
  72. },
  73. created () {
  74. },
  75. methods: {
  76. initEditor (editor) {
  77. require('brace/ext/language_tools')
  78. // 设置语言
  79. require('brace/mode/sql')
  80. require('brace/snippets/sql')
  81. // 设置主题 按需加载
  82. require('brace/theme/monokai')
  83. require('brace/theme/chrome')
  84. require('brace/theme/crimson_editor')
  85. // 监听值的变化
  86. editor.getSession().on('change', val => {
  87. this.$emit('change', editor.getValue())
  88. })
  89. }
  90. }
  91. }
  92. </script>

组件使用

  1. import Editor from '@/components/common/Editor.vue'
  2. <editor
  3. ref="editors"
  4. :content="value"
  5. :theme="'crimson_editor'"
  6. :config="config"
  7. @change="editorChange">
  8. </editor>

sql语言格式化sql-formatter

  1. import { format } from 'sql-formatter'
  2. // 方法
  3. formatter () {
  4. const editor = this.$refs.editor.editor
  5. const content = editor.getValue()
  6. const formatContent = format(content)
  7. editor.setValue(formatContent)
  8. }

3、vue写终端的插件

vue-web-terminal  适用于vue2

npm install vue-web-terminal@2.0.0 --save

 

 

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

闽ICP备14008679号