Skip to content

Commit

Permalink
update cherry-markdown.js&cherry_markdown.js (#947)
Browse files Browse the repository at this point in the history
* update images upload

* modify js res.url

* add froala

* froala-editor.js

* update cherry-markdown&cherry_markdown.js
  • Loading branch information
3xxx authored Jun 11, 2024
1 parent 0ce6c5b commit 66cd615
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
15 changes: 10 additions & 5 deletions static/cherry/cherry-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -21811,22 +21811,26 @@
function handleUpload(editor) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'image';
var accept = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '*';
var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
// var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
// type为上传文件类型 image|video|audio|pdf|word
var input = document.createElement('input');
input.type = 'file';
input.id = 'fileUpload';
input.value = '';
input.style.display = 'none';
input.accept = accept; // document.body.appendChild(input);
input.multiple = 'multiple';

input.addEventListener('change', function (event) {
// @ts-ignore
var _event$target$files = _slicedToArray(event.target.files, 1),
file = _event$target$files[0]; // 文件上传后的回调函数可以由调用方自己实现


// var _event$target$files = _slicedToArray(event.target.files, 1),
// file = _event$target$files[0]; // 文件上传后的回调函数可以由调用方自己实现
// 3xxx 20240607
let files = event.target.files;
for (let i = 0; i < files.length; i++) {
var file = files[i]
editor.options.fileUpload(file, function (url) {
var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

// 文件上传的默认回调行数,调用方可以完全不使用该函数
Expand Down Expand Up @@ -21866,6 +21870,7 @@

editor.editor.doc.replaceSelection(code);
});
}
});
input.click();
}
Expand Down
7 changes: 4 additions & 3 deletions static/js/cherry_markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ function myFileUpload(file, callback) {
$.ajax({
url: window.fileUploadURL, // 确保此 URL 是文件上传 API 的正确 URL
type: "POST",
async: false, // 3xxx 20240609这里修改为同步,保证cherry批量上传图片时,插入的图片名称是正确的,否则,插入的图片名称都是最后一个名称
dataType: "json",
data: formData,
processData: false, // 必须设置为 false,因为数据是 FormData 对象,不需要对数据进行序列化处理
Expand All @@ -629,10 +630,10 @@ function myFileUpload(file, callback) {
},
success: function (data) {
layer.close(layerIndex);
if (data.errcode !== 0) {
layer.msg(data.message);
if (data[0].errcode !== 0) {
layer.msg(data[0].message);
} else {
callback(data.url); // 假设返回的 JSON 中包含上传文件的 URL,调用回调函数并传入 URL
callback(data[0].url); // 假设返回的 JSON 中包含上传文件的 URL,调用回调函数并传入 URL
}
}
});
Expand Down

0 comments on commit 66cd615

Please sign in to comment.