Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gsw945 authored Jun 11, 2024
2 parents 6fa1db9 + 66cd615 commit 5326ea0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 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
5 changes: 3 additions & 2 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,8 +630,8 @@ function myFileUpload(file, callback) {
},
success: function (data) {
layer.close(layerIndex);
if (data[0].errcode != 0) {
layer.msg(data.message);
if (data[0].errcode !== 0) {
layer.msg(data[0].message);
} else {
callback(data[0].url); // 假设返回的 JSON 中包含上传文件的 URL,调用回调函数并传入 URL
}
Expand Down

0 comments on commit 5326ea0

Please sign in to comment.