From b8f387eb9905f6aa88e5c59e7f555ff8f315c5ba Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Fri, 13 Sep 2024 11:35:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87ech?= =?UTF-8?q?arts=5Frander=E6=A0=87=E7=AD=BE=20=E6=B8=B2=E6=9F=93=E5=9B=BE?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/components/markdown/EchartsRander.vue | 76 ++++++++++++++++++++ ui/src/components/markdown/MdRenderer.vue | 44 +++++++++++- 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 ui/src/components/markdown/EchartsRander.vue diff --git a/ui/src/components/markdown/EchartsRander.vue b/ui/src/components/markdown/EchartsRander.vue new file mode 100644 index 000000000..dffcc6de0 --- /dev/null +++ b/ui/src/components/markdown/EchartsRander.vue @@ -0,0 +1,76 @@ + + + diff --git a/ui/src/components/markdown/MdRenderer.vue b/ui/src/components/markdown/MdRenderer.vue index 3323d8730..76ab43fa4 100644 --- a/ui/src/components/markdown/MdRenderer.vue +++ b/ui/src/components/markdown/MdRenderer.vue @@ -10,7 +10,10 @@ {{ item.content }} - + { @@ -64,8 +68,9 @@ const md_view_list = computed(() => { return md_img_list[Math.floor(index / 2)] } }) - return split_html_rander(split_quick_question(result)) + return split_echarts_rander(split_html_rander(split_quick_question(result))) }) + const split_quick_question = (result: Array) => { return result .map((item) => split_quick_question_(item)) @@ -133,6 +138,41 @@ const split_html_rander_ = (source: string, type: string) => { }) return result } + +const split_echarts_rander = (result: Array) => { + return result + .map((item) => split_echarts_rander_(item.content, item.type)) + .reduce((x: any, y: any) => { + return [...x, ...y] + }, []) +} + +const split_echarts_rander_ = (source: string, type: string) => { + const temp_md_quick_question_list = source.match(/[\d\D]*?<\/echarts_rander>/g) + const md_quick_question_list = temp_md_quick_question_list + ? temp_md_quick_question_list.filter((i) => i) + : [] + const split_quick_question_value = source + .split(/[\d\D]*?<\/echarts_rander>/g) + .filter((item) => item !== undefined) + .filter((item) => !md_quick_question_list?.includes(item)) + const result = Array.from( + { length: md_quick_question_list.length + split_quick_question_value.length }, + (v, i) => i + ).map((index) => { + if (index % 2 == 0) { + return { type: type, content: split_quick_question_value[Math.floor(index / 2)] } + } else { + return { + type: 'echarts_rander', + content: md_quick_question_list[Math.floor(index / 2)] + .replace('', '') + .replace('', '') + } + } + }) + return result +}