diff --git a/nezha-fronted/src/assets/css/components/charts/chart.scss b/nezha-fronted/src/assets/css/components/charts/chart.scss index f273319f1..e9cc99c9b 100644 --- a/nezha-fronted/src/assets/css/components/charts/chart.scss +++ b/nezha-fronted/src/assets/css/components/charts/chart.scss @@ -519,6 +519,18 @@ .chart-text-preview .ql-container.ql-snow { border: unset !important; } +.rich-text-container{ + .v-md-editor-preview{ + white-space: initial; + box-sizing: border-box; + padding: 12px 15px; + } + .v-md-copy-code-btn{ + display: none !important; + } +} + + .chart-table ,.chart-preview-dialog { .nz-table .el-table__row .custom-value .cell{ padding: 1px 0; diff --git a/nezha-fronted/src/assets/css/components/common/threshold/threshold.scss b/nezha-fronted/src/assets/css/components/common/threshold/threshold.scss index 49c28408b..ae303af57 100644 --- a/nezha-fronted/src/assets/css/components/common/threshold/threshold.scss +++ b/nezha-fronted/src/assets/css/components/common/threshold/threshold.scss @@ -1,5 +1,9 @@ .rich-text-editor { color: $--color-text-regular; + .ql-toolbar.ql-snow{ + padding: 7px; + height: 40px; + } .ql-toolbar { border: 1px solid $--border-color-light; } diff --git a/nezha-fronted/src/assets/css/components/common/v-md-editor.scss b/nezha-fronted/src/assets/css/components/common/v-md-editor.scss index d12b90ed9..e53380b96 100644 --- a/nezha-fronted/src/assets/css/components/common/v-md-editor.scss +++ b/nezha-fronted/src/assets/css/components/common/v-md-editor.scss @@ -44,4 +44,45 @@ background: $--alert-rule-background-color; } } +} + +.markdownEditor{ + box-sizing: border-box; + border-radius: 0; + border: 1px solid $--border-color-light; + box-shadow: none; + background: transparent; + .v-md-editor__toolbar{ + border-bottom: 1px solid $--border-color-light; + .v-md-editor__tooltip{ + display: none; + } + .v-md-editor__toolbar-item:hover,.v-md-editor__toolbar-item--active{ + background: transparent; + } + .v-md-editor__menu{ + background: $--background-color-empty; + border: 1px solid $--border-color-light; + .v-md-editor__menu-item{ + color: $--color-text-regular; + } + .v-md-editor__menu-item:hover{ + background: $--background-color-base; + } + } + } + .v-md-textarea-editor{ + &>textarea{ + padding: 12px 15px; + background: transparent; + color: $--color-text-regular; + font-family: menlo,Ubuntu Mono,consolas,Courier New,Microsoft Yahei,Hiragino Sans GB,WenQuanYi Micro Hei,sans-serif !important; + } + &>pre{ + padding: 12px 15px; + section{ + font-family: menlo,Ubuntu Mono,consolas,Courier New,Microsoft Yahei,Hiragino Sans GB,WenQuanYi Micro Hei,sans-serif !important; + } + } + } } \ No newline at end of file diff --git a/nezha-fronted/src/components/chart/chart/chartText.vue b/nezha-fronted/src/components/chart/chart/chartText.vue index fe643d347..4c416f32b 100644 --- a/nezha-fronted/src/components/chart/chart/chartText.vue +++ b/nezha-fronted/src/components/chart/chart/chartText.vue @@ -2,7 +2,8 @@
-
+ +
diff --git a/nezha-fronted/src/components/chart/markdownEditor.vue b/nezha-fronted/src/components/chart/markdownEditor.vue new file mode 100644 index 000000000..64477c2e4 --- /dev/null +++ b/nezha-fronted/src/components/chart/markdownEditor.vue @@ -0,0 +1,43 @@ + + + diff --git a/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue b/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue index f40f0c28a..d70dd92df 100644 --- a/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue +++ b/nezha-fronted/src/components/common/bottomBox/tabs/dashboardTab.vue @@ -473,6 +473,9 @@ export default { } } } + if (this.chart.type == 'text' && !this.chart.param.editorType) { + this.chart.param.editorType = 'richText' + } } else { this.rightBox.loading = true this.$get('visual/dashboard/chart/' + data.id).then(res => { @@ -536,6 +539,9 @@ export default { } } } + if (this.chart.type == 'text' && !this.chart.param.editorType) { + this.chart.param.editorType = 'richText' + } this.$nextTick(() => { this.$refs.addChartModal.isStable = 'stable' }) diff --git a/nezha-fronted/src/components/common/rightBox/chart/chartRightBox.vue b/nezha-fronted/src/components/common/rightBox/chart/chartRightBox.vue index 629cb782e..605e45e50 100644 --- a/nezha-fronted/src/components/common/rightBox/chart/chartRightBox.vue +++ b/nezha-fronted/src/components/common/rightBox/chart/chartRightBox.vue @@ -400,7 +400,11 @@ export default { varValue: '', result: 'show' }, - dataLink: [] + dataLink: [], + tooltip: { + mode: 'all', + sort: 'none' + } } } } diff --git a/nezha-fronted/src/components/common/rightBox/chart/otherChartConfig.vue b/nezha-fronted/src/components/common/rightBox/chart/otherChartConfig.vue index a3b3e5e1c..0446ee139 100644 --- a/nezha-fronted/src/components/common/rightBox/chart/otherChartConfig.vue +++ b/nezha-fronted/src/components/common/rightBox/chart/otherChartConfig.vue @@ -53,6 +53,20 @@ + + + + + + +
@@ -166,8 +180,9 @@ :isChart="true" /> - - + + + @@ -340,6 +355,7 @@ import publicConfig from '@/components/common/rightBox/chart/publicConfig' import chartTypeShow from '@/components/common/rightBox/chart/chartTypeShow' import richTextEditor from '@/components/chart/richTextEditor' +import markdownEditor from '@/components/chart/markdownEditor' import beforeMeta2d from '@/components/common/mixin/beforeMeta2d' import meta2dMain from '@/components/common/project/meta2d/meta2dMain' import { clearTopology } from '@/components/common/js/common' @@ -349,6 +365,7 @@ export default { mixins: [publicConfig, chartTypeShow], components: { richTextEditor, + markdownEditor, meta2dMain }, watch: { @@ -408,6 +425,10 @@ export default { } }, methods: { + editorTypeChange () { + this.chartConfig.param.text = '' + this.change() + }, init () { this.chartConfig = JSON.parse(JSON.stringify(this.params)) this.reloadTopo() @@ -451,7 +472,8 @@ export default { operator: 'equal', varValue: '', result: 'show' - } + }, + editorType: 'richText' } break case 'diagram': @@ -525,9 +547,13 @@ export default { this.topologyDialogChange(false, topo) }, textChange (val) { - const html = `
${val}
` - this.chartConfig.param.text = html - this.$refs.chartForm.validateField('param.text') + if (this.$lodash.get(this.chartConfig, 'param.editorType', 'richText') === 'richText') { + const html = `
${val}
` + this.chartConfig.param.text = html + } else { + this.chartConfig.param.text = val + } + this.$refs.chartForm && this.$refs.chartForm.validateField('param.text') this.change() }, reloadTopo () { diff --git a/nezha-fronted/src/components/page/dashboard/dashboard.vue b/nezha-fronted/src/components/page/dashboard/dashboard.vue index a75f114d5..2dc5c7561 100644 --- a/nezha-fronted/src/components/page/dashboard/dashboard.vue +++ b/nezha-fronted/src/components/page/dashboard/dashboard.vue @@ -648,6 +648,9 @@ export default { } } } + if (this.chart.type == 'text' && !this.chart.param.editorType) { + this.chart.param.editorType = 'richText' + } } else { this.rightBox.loading = true this.$get('visual/dashboard/chart/' + data.id).then(res => { @@ -711,6 +714,9 @@ export default { } } } + if (this.chart.type == 'text' && !this.chart.param.editorType) { + this.chart.param.editorType = 'richText' + } setTimeout(() => { this.$refs.addChartModal.isStable = 'stable' }) diff --git a/nezha-fronted/src/entrance/app/main.js b/nezha-fronted/src/entrance/app/main.js index 4712523f6..f741cb939 100644 --- a/nezha-fronted/src/entrance/app/main.js +++ b/nezha-fronted/src/entrance/app/main.js @@ -45,15 +45,20 @@ import htmlToPdf from '@/components/common/js/htmlToPdf' import mainMixin from '@/components/common/mixin/mainMixinFun' import introJS from 'intro.js' -// v-md-editor +// v-md-editor 预览组件 import VMdPreview from '@kangc/v-md-editor/lib/preview' import '@kangc/v-md-editor/lib/style/preview.css' import githubTheme from '@kangc/v-md-editor/lib/theme/github.js' import '@kangc/v-md-editor/lib/theme/style/github.css' -import hljs from 'highlight.js' // markdown支持代码复制 import createCopyCodePlugin from '@/components/common/copy-code/index' import '@/components/common/copy-code/copy-code.css' +// highlightjs +import hljs from 'highlight.js' +// markdown编辑器 +import VMdEditor from '@kangc/v-md-editor' +import '@kangc/v-md-editor/lib/style/base-editor.css' + VMdPreview.xss.extend({ // extend white list whiteList: { @@ -65,6 +70,10 @@ VMdPreview.use(githubTheme, { }) VMdPreview.use(createCopyCodePlugin()) Vue.use(VMdPreview) +VMdEditor.use(githubTheme, { + Hljs: hljs +}) +Vue.use(VMdEditor) // Pace.on("done", function() { // $self.isShowAuth = false;