-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.html
92 lines (87 loc) · 3.86 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>easyUpload.js</title>
<link rel="stylesheet" href="./dist/easy_upload.min.css">
</head>
<body>
<div id="easy1" class="easy-upload"></div>
<div id="easy2" class="easy-upload" style="margin-top: 30px;"></div>
<script src="./dist/easyUpload.min.js "></script>
<script>
easyUpload({
easyId: 'easy1',
action: 'https://jsonplaceholder.typicode.com/posts/',
accept: '.jpg,.png,.gif,.docx',
maxSize: 1, //单位MB
showLoading: true,
setRequestHeader: function(xhr) {
xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
},
setRequestHeader: function (xhr) {
xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
//和原生xhr配置api保持一致
},
buildSendData: function (file) {
// var formData = new FormData(); // 发送格式为formData时
// formData.append('name', file.file)
// return formData;
// return file.base64; //发送格式为base64时
return null; //发送空数据,用于测试。默认return null
},
checkSuccessCode: function (xhr) {
if (/error/.test(xhr.responseText.toLowerCase())) { //这里判断仅仅用于测试,具体看项目
return false;
} else {
return true;
} //默认return tue
},
uploadStart: function (self) {
// 文件队列上传前的回调函数,传入唯一参数'self'是当前插件实例
console.log('上传开始,现在的队列是', self.files)
},
uploadEnd: function (self) {
// 文件队列上传完成后的回调函数,传入唯一参数'self'是当前插件实例
console.log('上传完成了,现在的队列是', self.files)
}
});
//创建另个一实例如下
easyUpload({
easyId: 'easy2',
action: 'https://jsonplaceholder.typicode.com/posts/',
accept: '.jpg,.png,.gif,.docx',
maxSize: 3, //单位MB
showLoading: true,
setRequestHeader: function (xhr) {
xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
//和原生xhr配置api保持一致
},
buildSendData: function (file) {
// var formData = new FormData(); // 发送格式为formData时
// formData.append('name', file.file)
// return formData;
// return file.base64; //发送格式为base64时
return null; //发送空数据,用于测试。默认return null
},
checkSuccessCode: function (xhr) {
if (/error/.test(xhr.responseText.toLowerCase())) { //这里判断仅仅用于测试,具体看项目
return false;
} else {
return true;
} //默认return ture
},
uploadStart: function (self) {
// 文件队列上传前的回调函数,传入唯一参数'self'是当前插件实例
console.log('上传开始,现在的队列是', self.files)
},
uploadEnd: function (self) {
// 文件队列上传完成后的回调函数,传入唯一参数'self'是当前插件实例
console.log('上传完成了,现在的队列是', self.files)
}
});
</script>
</body>
</html>