⚡ 优化文件下载逻辑.
This commit is contained in:
@@ -77,6 +77,7 @@
|
||||
arrow-class="terminal-tooltip-content"
|
||||
content="编辑内容">
|
||||
<a-button class="icon-button row-action-icon"
|
||||
:disabled="editorLoading"
|
||||
@click="editFile(record)">
|
||||
<icon-edit />
|
||||
</a-button>
|
||||
@@ -158,6 +159,7 @@
|
||||
session?: ISftpSession;
|
||||
list: Array<SftpFile>;
|
||||
loading: boolean;
|
||||
editorLoading: boolean;
|
||||
selectedFiles: Array<string>;
|
||||
}>();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
:session="session"
|
||||
:list="fileList"
|
||||
:loading="tableLoading"
|
||||
:editor-loading="editorLoading"
|
||||
@load-file="loadFiles"
|
||||
@edit-file="editFile"
|
||||
@delete-file="deleteFile"
|
||||
@@ -70,6 +71,8 @@
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import { openSftpCreateModalKey, openSftpMoveModalKey, openSftpChmodModalKey, openSftpUploadModalKey } from '../../types/const';
|
||||
import { getSftpFileContent, setSftpFileContent } from '@/api/asset/host-sftp';
|
||||
import { isString } from '@/utils/is';
|
||||
import SftpTableHeader from './sftp-table-header.vue';
|
||||
import SftpTable from './sftp-table.vue';
|
||||
import SftpEditorHeader from './sftp-editor-header.vue';
|
||||
@@ -135,8 +138,7 @@
|
||||
// 编辑器保存
|
||||
const editorSave = () => {
|
||||
setEditorLoading(true);
|
||||
const value = editorRef.value?.getValue() || '';
|
||||
session.value?.setContent(editorFilePath.value, value);
|
||||
session.value?.setContent(editorFilePath.value);
|
||||
};
|
||||
|
||||
// 关闭编辑器
|
||||
@@ -231,24 +233,47 @@
|
||||
};
|
||||
|
||||
// 接收获取文件内容响应
|
||||
const resolveSftpGetContent = (path: string, result: string, msg: string, content: string) => {
|
||||
const resolveSftpGetContent = (result: string, msg: string, token: string) => {
|
||||
setTableLoading(false);
|
||||
setEditorLoading(false);
|
||||
// 检查结果
|
||||
if (!checkResult(result, msg)) {
|
||||
return;
|
||||
}
|
||||
editorRef.value?.setValue(content);
|
||||
setEditorLoading(true);
|
||||
editorRef.value?.setValue('');
|
||||
// 读取文件
|
||||
getSftpFileContent(token).then(async ({ data }) => {
|
||||
if (isString(data)) {
|
||||
// 成功为 string
|
||||
editorRef.value?.setValue(data || '');
|
||||
} else {
|
||||
// 失败为 object
|
||||
Message.error((data as any).msg || '读取失败');
|
||||
}
|
||||
setEditorLoading(false);
|
||||
}).catch(() => {
|
||||
setEditorLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
// 接收修改文件内容响应
|
||||
const resolveSftpSetContent = (result: string, msg: string) => {
|
||||
const resolveSftpSetContent = (result: string, msg: string, token: string) => {
|
||||
setEditorLoading(false);
|
||||
// 检查结果
|
||||
if (!checkResult(result, msg)) {
|
||||
return;
|
||||
}
|
||||
Message.success('保存成功');
|
||||
setEditorLoading(true);
|
||||
// 获取文本
|
||||
const value = editorRef.value?.getValue() || '';
|
||||
// 保存
|
||||
setSftpFileContent(token, value).then(() => {
|
||||
setEditorLoading(false);
|
||||
Message.success('保存成功');
|
||||
}).catch(() => {
|
||||
setEditorLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
// 接收下载文件夹展开文件响应
|
||||
|
||||
@@ -144,11 +144,10 @@ export default class SftpSession extends BaseSession implements ISftpSession {
|
||||
};
|
||||
|
||||
// 修改内容
|
||||
setContent(path: string, content: string) {
|
||||
setContent(path: string) {
|
||||
this.channel.send(InputProtocol.SFTP_SET_CONTENT, {
|
||||
sessionId: this.sessionId,
|
||||
path,
|
||||
content
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -177,17 +177,17 @@ export default class TerminalOutputProcessor implements ITerminalOutputProcessor
|
||||
}
|
||||
|
||||
// 处理 SFTP 获取文件内容
|
||||
processSftpGetContent({ sessionId, path, result, msg, content }: OutputPayload): void {
|
||||
processSftpGetContent({ sessionId, result, msg, token }: OutputPayload): void {
|
||||
// 获取会话
|
||||
const session = this.sessionManager.getSession<ISftpSession>(sessionId);
|
||||
session && session.resolver.resolveSftpGetContent(path, result, msg, content);
|
||||
session && session.resolver.resolveSftpGetContent(result, msg, token);
|
||||
}
|
||||
|
||||
// 处理 SFTP 修改文件内容
|
||||
processSftpSetContent({ sessionId, result, msg }: OutputPayload) {
|
||||
processSftpSetContent({ sessionId, result, msg, token }: OutputPayload) {
|
||||
// 获取会话
|
||||
const session = this.sessionManager.getSession<ISftpSession>(sessionId);
|
||||
session && session.resolver.resolveSftpSetContent(result, msg);
|
||||
session && session.resolver.resolveSftpSetContent(result, msg, token);
|
||||
}
|
||||
|
||||
// 根据类型处理操作
|
||||
|
||||
@@ -323,7 +323,7 @@ export interface ISftpSession extends ITerminalSession {
|
||||
// 获取内容
|
||||
getContent: (path: string) => void;
|
||||
// 修改内容
|
||||
setContent: (path: string, content: string) => void;
|
||||
setContent: (path: string) => void;
|
||||
}
|
||||
|
||||
// sftp 会话接收器定义
|
||||
@@ -349,9 +349,9 @@ export interface ISftpSessionResolver {
|
||||
// 接收下载文件夹展开文件响应
|
||||
resolveDownloadFlatDirectory: (currentPath: string, result: string, msg: string, list: Array<SftpFile>) => void;
|
||||
// 接收获取文件内容响应
|
||||
resolveSftpGetContent: (path: string, result: string, msg: string, content: string) => void;
|
||||
resolveSftpGetContent: (result: string, msg: string, token: string) => void;
|
||||
// 接收修改文件内容响应
|
||||
resolveSftpSetContent: (result: string, msg: string) => void;
|
||||
resolveSftpSetContent: (result: string, msg: string, token: string) => void;
|
||||
}
|
||||
|
||||
// sftp 文件
|
||||
|
||||
Reference in New Issue
Block a user