Skip to content

Commit

Permalink
fix(components): 修复打包失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lixin59 committed Dec 17, 2023
1 parent 70dfb6f commit a2d49a7
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions src/components/OmsTerminal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const OmsTerminal = ({ id, ws, onCloseTodo }: tProps) => {
for (let f = files.length - 1; f >= 0; f--) {
const fobj = files[f];
total_size += fobj.size;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
batch[f] = {
obj: fobj,
name: fobj.name,
Expand All @@ -74,6 +76,8 @@ const OmsTerminal = ({ id, ws, onCloseTodo }: tProps) => {
file_idx++;
return session.send_offer(cur_b).then(function after_send_offer(xfer) {
if (options.on_offer_response) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
options.on_offer_response(cur_b.obj, xfer);
}
if (xfer === undefined) {
Expand All @@ -91,29 +95,37 @@ const OmsTerminal = ({ id, ws, onCloseTodo }: tProps) => {
reader.onprogress = function reader_onprogress(e) {
// Some browsers (e.g., Chrome) give partial returns,
// while others (e.g., Firefox) don’t.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (e.target.result) {
piece = new Uint8Array(e.target.result, xfer.get_offset());
piece = new Uint8Array(e?.target?.result as ArrayBufferLike, xfer.get_offset());
// _check_aborted(session);
if (session.aborted()) {
throw new Zmodem.Error('aborted');
}
xfer.send(piece);
if (options.on_progress) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
options.on_progress(cur_b.obj, xfer, piece);
}
}
};
reader.onload = function reader_onload(e) {
piece = new Uint8Array(e.target.result, xfer, piece);
piece = new Uint8Array(e?.target?.result as ArrayBufferLike, xfer, piece);
// _check_aborted(session);
if (session.aborted()) {
throw new Zmodem.Error('aborted');
}
xfer.end(piece).then(function () {
if (options.on_progress && piece.length) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
options.on_progress(cur_b.obj, xfer, piece);
}
if (options.on_file_complete) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
options.on_file_complete(cur_b.obj, xfer);
}
// Resolve the current file-send promise with
Expand All @@ -123,6 +135,8 @@ const OmsTerminal = ({ id, ws, onCloseTodo }: tProps) => {
res(promise_callback());
});
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
reader.readAsArrayBuffer(cur_b.obj);
});
});
Expand Down Expand Up @@ -165,6 +179,8 @@ const OmsTerminal = ({ id, ws, onCloseTodo }: tProps) => {
console.log(`${obj.name} 上传成功`);
}
}).then(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
zsession?.close();
setUploadDialogVisible(false);
setUpLoading(false);
Expand All @@ -177,16 +193,16 @@ const OmsTerminal = ({ id, ws, onCloseTodo }: tProps) => {
}
};
// 上传文件弹框关闭
const handleCloseUpload = () => {
if (uploadLoading) {
console.log('====上传中无法关闭');
} else {
zsession?.close().then(() => {
// const upload = this.$refs.upload;
// upload.clearFiles();
});
}
};
// const handleCloseUpload = () => {
// if (uploadLoading) {
// console.log('====上传中无法关闭');
// } else {
// zsession?.close().then(() => {
// // const upload = this.$refs.upload;
// // upload.clearFiles();
// });
// }
// };

useEffect(() => {
// const ws = new WebSocket(wsUrl);
Expand Down Expand Up @@ -341,6 +357,8 @@ const OmsTerminal = ({ id, ws, onCloseTodo }: tProps) => {
// is actually not meant to be ZMODEM.
zsession = detection.confirm();
// 这里是监听上传事件
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (zsession?.type === 'send') {
// Send a group of files, e.g., from an <input>’s “.files”.
// There are events you can listen for here as well,
Expand All @@ -351,6 +369,8 @@ const OmsTerminal = ({ id, ws, onCloseTodo }: tProps) => {
setUploadDialogVisible(true);
} else {
// 这里监听下载事件
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
zsession.on('offer', (xfer) => {
// Do this if you don’t want the offered file.

Expand All @@ -373,10 +393,14 @@ const OmsTerminal = ({ id, ws, onCloseTodo }: tProps) => {
});
});
// 监听到下载完毕,关闭下载弹框
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
zsession.on('session_end', () => {
setPercentage(0);
setDownloadDialogVisible(false);
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
zsession.start();
}
};
Expand Down

0 comments on commit a2d49a7

Please sign in to comment.