From 5addb707ee67445442f22949f0e6680b3ee33054 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Mon, 19 Feb 2024 00:35:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4=20tui-edit?= =?UTF-8?q?or=20i18n=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.vue | 8 +-- .../src/components/markdown/tui-editor.vue | 69 +++++++++++++++---- frontend/src/i18n/index.ts | 8 +-- frontend/src/i18n/locales/en.json | 2 +- .../i18n/locales/{zh-Hans.json => zh-CN.json} | 2 +- frontend/src/stores/globalConfig.ts | 2 +- frontend/src/views/MainView.vue | 5 +- 7 files changed, 69 insertions(+), 27 deletions(-) rename frontend/src/i18n/locales/{zh-Hans.json => zh-CN.json} (96%) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index cc1a41d..42e78bb 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -19,7 +19,7 @@ watch(locale,(value)=>{ if(elementUIConfig.supportLocale[value]){ elementUIConfig.locale = elementUIConfig.supportLocale[value] } else { - elementUIConfig.locale = elementUIConfig.supportLocale["zh-Hans"] + elementUIConfig.locale = elementUIConfig.supportLocale["zh-CN"] } }, { immediate: true @@ -85,7 +85,7 @@ document.body.addEventListener("click", function (event) { -
+
import '@toast-ui/editor/dist/toastui-editor.css'; -import {onMounted, reactive, ref} from "vue"; +import type {Ref} from "vue"; +import {onMounted, reactive, ref, watch} from "vue"; import Editor from "@toast-ui/editor"; import Prism from 'prismjs' import codeSyntaxHighlight from '@toast-ui/editor-plugin-code-syntax-highlight' import chart from "@toast-ui/editor-plugin-chart" import tableMergedCell from "@toast-ui/editor-plugin-table-merged-cell" import uml from "@toast-ui/editor-plugin-uml" +import "@toast-ui/editor/dist/i18n/zh-cn"; +import {useI18n} from "vue-i18n"; + const chartOptions = { minWidth: 100, @@ -15,27 +19,62 @@ const chartOptions = { maxHeight: 300 }; +const {locale} = useI18n() + const editorRef = ref() -onMounted(() => { - const editor = new Editor({ +function initEditor(editorRef:Ref){ + let editor = new Editor({ el: editorRef.value, - language: 'en-US', + // language: 'en-US', + language: locale.value, previewStyle: 'vertical', - height: '80vh', + height: '85vh', initialValue: "", - plugins: [[chart, chartOptions], [codeSyntaxHighlight, {highlighter: Prism}], tableMergedCell, uml] - }); + plugins: [ + [chart, chartOptions], + [codeSyntaxHighlight, {highlighter: Prism}], + tableMergedCell, + uml, + ], + useCommandShortcut: true, + usageStatistics: true, + hideModeSwitch: false, + toolbarItems: [ + ['heading', 'bold', 'italic', 'strike'], + ['hr', 'quote'], + ['ul', 'ol', 'task', 'indent', 'outdent'], + ['table', 'image', 'link'], + ['code', 'codeblock'], + ['scrollSync'], + ] + }) + + // const viewer = Editor.factory({ + // el: editorRef.value, + // viewer: true, + // height: '500px', + // initialValue: "", + // plugins: [[chart, chartOptions], [codeSyntaxHighlight, { highlighter: Prism }], tableMergedCell, uml] + // }); + + return editor; +} + +onMounted(() => { + console.log("locale.value",locale.value) + let editor = initEditor(editorRef); + watch(locale, value => { + let markdown = editor.getMarkdown() + editor.destroy() + + editor = initEditor(editorRef); + editor.setMarkdown(markdown) + }) }) -// const viewer = Editor.factory({ -// el: document.querySelector('#viewer'), -// viewer: true, -// height: '500px', -// initialValue: "", -// plugins: [[chart, chartOptions], [codeSyntaxHighlight, { highlighter: Prism }], tableMergedCell, uml] -// }); + // // const defaultOptions = reactive({ // minHeight: '600px', @@ -60,7 +99,7 @@ const ctx = reactive({