解决方案见文末
jQuery环境是正常的
如下的js导出
JQ环境使用:
var up = new fcup({
id: "upid", // 绑定id
url: "/api/cloudrive/userFile/upchunkFile", // url地址
checkurl: "/api/cloudrive/userFile/isUpload", // 检查上传url地址
//type: "jpg,png,jpeg,gif", // 限制上传类型,为空不限制
shardsize: "8", // 每次分片大小,单位为M,默认1M
minsize: '', // 最小文件上传M数,单位为M,默认为无
maxsize: "20000", // 上传文件最大M数,单位为M,默认200M
// headers: {"version": "fcup-v2.0"}, // 附加的文件头,默认为null, 请注意指定header头时将不能进行跨域操作
apped_data: subData, //每次上传的附加数据
// 定义错误信息
errormsg: {
1000: "未找到上传id",
1001: "类型不允许上传",
1002: "上传文件过小",
1003: "上传文件过大",
1004: "上传请求超时"
},
// 错误提示
error: function (msg) {
alert(msg);
},
// 初始化事件
start: function () {
Progress(0);
},
// 等待上传事件,可以用来loading
beforeSend: function () {
console.log('等待请求中');
},
// 上传进度事件
progress: function (num, other) {
Progress(num);
console.log(num);
console.log('上传进度' + num);
console.log("上传类型" + other.type);
console.log("已经上传" + other.current);
console.log("剩余上传" + other.surplus);
console.log("已用时间" + other.usetime);
console.log("预计时间" + other.totaltime);
},
// 检查地址回调,用于判断文件是否存在,类型,当前上传的片数等操作
checksuccess: function (res) {
res = res ? eval('(' + res + ')') : '';
if (res.code == 200) {
var data = res.data;
// 秒传存储
if (data.status == 1) {
Progress(100);
bootbox.alert('秒传完成!');
modal.hide();
//刷新
DriveFileManager.refresh();
return false;
}
// 已经上传
if (data.status == 2) {
// 起始上传的切片要从1开始
var fileIndex = data.fileIndex ? data.fileIndex : 1;
// 设置上传切片的起始位置
up.setshard(fileIndex);
// 如果接口没有错误,必须要返回true,才不会终止上传
return true;
}
if (data.status == 4) {
//从0开始上传
return true;
}
} else {
bootbox.alert(res.message);
return false;
}
},
// 上传成功回调,回调会根据切片循环,要终止上传循环,必须要return false,成功的情况下要始终返回true;
success: function (res) {
res = res ? eval('(' + res + ')') : '';
if (res.code == 200) {
// 如果接口没有错误,必须要返回true,才不会终止上传循环
if (res.data.status == 2) {
bootbox.alert("上传完成!");
modal.hide();
//刷新
DriveFileManager.refresh();
}
return true;
} else {
bootbox.alert(res.message);
return false;
}
}
});
Vue cli3使用import引入
使用时仍然使用JQ的方式时,对象指向的是
SparkMD5,也就是
所以要在VUE中使用 fcup 方法,我将这个方法,改为了
export const fcup = function(config)
的形式
改造如下: