浏览代码

:art: fix 改进功能

Vanessa 1 年之前
父节点
当前提交
0346f19d83
共有 3 个文件被更改,包括 8 次插入0 次删除
  1. 1 0
      CHANGELOG.md
  2. 4 0
      src/index.ts
  3. 3 0
      src/ts/util/addScript.ts

+ 1 - 0
CHANGELOG.md

@@ -14,6 +14,7 @@
 
 ### v3.9.8 / 2023-12
 
+* [多语言加载失败后给出相关提示](https://github.com/Vanessa219/vditor/issues/1531) `改进功能`
 * [导出 PDF 时 CDN 配置不生效](https://github.com/Vanessa219/vditor/pull/1529) `修复缺陷`
 * [sv 模式中在脚注下方输入文本出现渲染错误](https://github.com/Vanessa219/vditor/issues/1518) `修复缺陷`
 * [KaTeX 渲染支持 macros](https://github.com/Vanessa219/vditor/issues/1519) `引入特性`

+ 4 - 0
src/index.ts

@@ -82,6 +82,10 @@ class Vditor extends VditorMethod {
                 });
                 addScript(`${mergedOptions.cdn}/dist/js/i18n/${mergedOptions.lang}.js`, i18nScriptID).then(() => {
                     this.init(id as HTMLElement, mergedOptions);
+                }).catch(error => {
+                    const tip = new Tip();
+                    document.body.appendChild(tip.element);
+                    tip.show(`GET ${mergedOptions.cdn}/dist/js/i18n/${mergedOptions.lang}.js net::ERR_ABORTED 404 (Not Found)`, 0)
                 });
             }
         } else {

+ 3 - 0
src/ts/util/addScript.ts

@@ -26,6 +26,9 @@ export const addScript = (path: string, id: string) => {
         scriptElement.async = true;
         // 循环调用时 Chrome 不会重复请求 js
         document.head.appendChild(scriptElement);
+        scriptElement.onerror = (event) => {
+            reject(event);
+        }
         scriptElement.onload = () => {
             if (document.getElementById(id)) {
                 // 循环调用需清除 DOM 中的 script 标签