Skip to content

Commit 8ef7fbb

Browse files
committed
Feature: 编辑器加载失败可以手动触发重新加载
1 parent ece21b6 commit 8ef7fbb

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

upupor-web/src/main/resources/static/js/cv.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -380,25 +380,38 @@ let cherryConfig = {
380380
* 加载不同的编辑器js,初始化是同一个
381381
*/
382382
function initEditor(isComment){
383-
if(isComment){
384-
_height = '400px';
385-
_defaultModel = 'editOnly';
386-
}
383+
try{
384+
$("#editor_load_failure").hide();
385+
$("#editor_loading").show();
387386

388-
let config = Object.assign({}, cherryConfig);
389-
window.editor = new Cherry(config);
387+
if(isComment){
388+
_height = '400px';
389+
_defaultModel = 'editOnly';
390+
}
390391

391-
let mdValue = getElementValue("md_value");
392-
let htmlValue = getElementValue("html_value");
392+
let config = Object.assign({}, cherryConfig);
393+
window.editor = new Cherry(config);
393394

394-
if(cvIsNull(mdValue) && !cvIsNull(htmlValue)){
395-
// 将html转为markdown
396-
mdValue = window.editor.engine.makeMarkdown(htmlValue);
397-
}
395+
let mdValue = getElementValue("md_value");
396+
let htmlValue = getElementValue("html_value");
397+
398+
if(cvIsNull(mdValue) && !cvIsNull(htmlValue)){
399+
// 将html转为markdown
400+
mdValue = window.editor.engine.makeMarkdown(htmlValue);
401+
}
398402

399-
if(!cvIsNull(mdValue)){
400-
window.editor.setMarkdown(mdValue);
403+
if(!cvIsNull(mdValue)){
404+
window.editor.setMarkdown(mdValue);
405+
}
406+
}catch (e) {
407+
$("#editor_load_failure").show();
408+
$("#editor_loading").hide();
401409
}
410+
411+
}
412+
413+
function reloadEditor(isComment) {
414+
$.cvLoadBootstrapRichText(isComment)
402415
}
403416

404417

upupor-web/src/main/resources/templates/editor/editor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
</div>
7171
<div class="form-group mb-3">
7272
<div class="col-lg-12">
73-
<div th:replace="fragments/comment::loading_editor"></div>
73+
<div th:replace="fragments/comment::loading_editor(false)"></div>
7474
<!--编辑器-->
7575
<input type="hidden" id="md_value" th:value="${editorIndexDto?.content?.contentExtend?.markdownContent}" />
7676
<input type="hidden" id="html_value" th:value="${editorIndexDto?.content?.contentExtend?.detailContent}" />

upupor-web/src/main/resources/templates/fragments/comment.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@
3030
xmlns:th="http://www.thymeleaf.org">
3131
<body>
3232

33-
<div th:fragment="loading_editor">
33+
<div th:fragment="loading_editor(isComment)">
3434
<div class="text-center" id="comment_loading">
35-
<div class="spinner-grow text-primary" role="status"></div>
36-
<p class="text-black-50">编辑器加载中...</p>
37-
<p class="text-black-50 small">注: 因最小维护成本需要(eg.最低带宽,无CDN等),编辑器加载可能需要15秒左右,请耐心等待</p>
35+
<div id="editor_loading">
36+
<div class="spinner-grow text-primary" role="status"></div>
37+
<p class="text-black-50">编辑器加载中...</p>
38+
<p class="text-black-50 small">注: 因最小维护成本需要(eg.最低带宽,无CDN等),编辑器加载可能需要15秒左右,请耐心等待</p>
39+
</div>
40+
<p class="text-danger" style="display:none;" id="editor_load_failure">
41+
<button class="btn btn-danger btn-sm" th:onclick="reloadEditor([[${isComment}]])">编辑器加载失败,重新加载</button>
42+
</p>
3843
</div>
3944
</div>
4045

4146
<div th:fragment="comment_box(targetId,source,text)">
4247
<div>
43-
<div th:replace="fragments/comment::loading_editor"></div>
48+
<div th:replace="fragments/comment::loading_editor(true)"></div>
4449
<div th:replace="fragments/editor::upupor-editor-progress"></div>
4550
<div id="vcr_editor" style="height: 300px; overflow:hidden"></div>
4651
<input type="hidden" id="reply_to_user" />

0 commit comments

Comments
 (0)