Skip to content

Commit

Permalink
支持IE10
Browse files Browse the repository at this point in the history
  • Loading branch information
longjinwen committed Jan 9, 2020
1 parent a2ccce4 commit 0c90c31
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
1 change: 1 addition & 0 deletions 2.xSrc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Date: 2020/1/4
* Time: 3:32 下午
*/
import './polyfill';

import UploadFile from './upload';

Expand Down
34 changes: 34 additions & 0 deletions 2.xSrc/polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @description 解决IE不认识 Object.assign 的问题
* @description2 采用自 https://developer.mozilla.org/zh-CN/
* */

if (typeof Object.assign != 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, 'assign', {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}

var to = Object(target);

for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];

if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
7 changes: 4 additions & 3 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// 队列延迟发送,可用于调试,默认0(ms)
delay: 0,
// 切片大小(M),建议不要太小,默认10
chunkSile: 20,
chunkSile: 1,
})
.appendHeader({
header1: 'header 1',
Expand Down Expand Up @@ -54,6 +54,7 @@
// console.log(taskParam);
// console.log('queue');
// console.log(queue);
// 队列
// queue 使用方法 https://github.com/8696/js-queue
// 例1:
if (xhr.status === 200) {
Expand All @@ -63,11 +64,11 @@
queue.next();
} else {
// 重新提交当前块
queue.again();
// queue.again();
}
} else {
// 重新提交当前块
queue.again();
// queue.again();
}
},
// 队列中的最后一次响应
Expand Down
2 changes: 1 addition & 1 deletion dist/simple-upload-slice-file.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/simple-upload-slice-file.min.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ app.use(staticFiles(path.resolve(__dirname, '../dist')));

app.use(async (ctx, next) => {
ctx.set('Access-Control-Allow-Origin', '*');
ctx.set('Access-Control-Allow-Headers', '*');
ctx.set('Access-Control-Allow-Headers', '*');
ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
ctx.set('Access-Control-Allow-Headers', 'header1, header2'); // IE 不能用*
ctx.set('Access-Control-Allow-Methods', '*');
if (ctx.method === 'OPTIONS') {
ctx.body = '';
} else {
Expand Down Expand Up @@ -62,7 +61,7 @@ async function getFileMd5(file) {

router.post('/upload', async (ctx) => {

await sleep();
// await sleep();
// console.log(ctx.request.files.file);
// console.log(ctx.request.body);
// console.log(ctx.request.query);
Expand All @@ -80,10 +79,11 @@ router.post('/upload', async (ctx) => {
if (Number(ctx.request.query['task-total-slice']) === Number(ctx.request.query['task-order'])) {
// 合并(也可以每次提交在进行合并)
let newFile = path.resolve(taskDir, ctx.request.query['task-id'] + suffix);

fs.readdirSync(taskDir).forEach(fileName => {
fs.readdirSync(taskDir).sort((a, b) => {
return a.split('.')[0] - b.split('.')[0];
}).forEach(fileName => {
console.log(fileName);
let filePath = path.resolve(taskDir, fileName);
console.log(filePath);
//
fs.appendFileSync(newFile, fs.readFileSync(filePath));
fs.unlinkSync(filePath);
Expand Down

0 comments on commit 0c90c31

Please sign in to comment.