Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cherry-markdown.js&cherry_markdown.js #947

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading