🔨 优化 sftp 回调逻辑.

This commit is contained in:
lijiahang
2024-02-12 00:49:05 +08:00
parent c723eb4ac3
commit 7926f304ff
4 changed files with 42 additions and 18 deletions

View File

@@ -72,7 +72,7 @@ public enum InputTypeEnum {
*/ */
SFTP_LIST("ls", SFTP_LIST("ls",
SftpListHandler.class, SftpListHandler.class,
new String[]{"type", "sessionId", "path"}, new String[]{"type", "sessionId", "showHiddenFile", "path"},
SftpListRequest.class), SftpListRequest.class),

View File

@@ -17,17 +17,19 @@
</span> </span>
</a-tooltip> </a-tooltip>
<!-- 当前路径 --> <!-- 当前路径 -->
<div class="sftp-path-wrapper" <div class="sftp-path-container"
@click="setPathEditable(true)"> @click="setPathEditable(true)">
<!-- 路径输入框 --> <!-- 路径输入框 -->
<div v-if="pathEditable"> <div v-if="pathEditable">
<a-input v-model="pathInput" <a-input v-model="pathInput"
ref="pathInputRef"
size="mini"
placeholder="文件夹路径" placeholder="文件夹路径"
allow-clear allow-clear
@press-enter="doChangePath" /> @press-enter="doChangePath" />
</div> </div>
<!-- 路径视图 --> <!-- 路径视图 -->
<a-breadcrumb v-else> <a-breadcrumb class="sftp-path-wrapper" v-else>
<!-- 根目录 --> <!-- 根目录 -->
<a-breadcrumb-item class="sftp-path-unit" <a-breadcrumb-item class="sftp-path-unit"
@click.stop="loadFileList('/')"> @click.stop="loadFileList('/')">
@@ -82,7 +84,7 @@
arrow-class="terminal-tooltip-content" arrow-class="terminal-tooltip-content"
content="刷新"> content="刷新">
<span class="click-icon-wrapper header-action-icon" <span class="click-icon-wrapper header-action-icon"
@click="loadFileList"> @click="loadFileList()">
<icon-refresh /> <icon-refresh />
</span> </span>
</a-tooltip> </a-tooltip>
@@ -140,14 +142,15 @@
</span> </span>
</a-tooltip> </a-tooltip>
<!-- 复制 FIXME 不行就删除 --> <!-- 复制 FIXME 不行就删除 -->
<a-tooltip position="top" <a-tooltip v-if="false"
position="top"
:mini="true" :mini="true"
:overlay-inverse="true" :overlay-inverse="true"
:auto-fix-position="false" :auto-fix-position="false"
content-class="terminal-tooltip-content" content-class="terminal-tooltip-content"
arrow-class="terminal-tooltip-content" arrow-class="terminal-tooltip-content"
content="复制"> content="复制">
<span v-if="false" class="click-icon-wrapper header-action-icon"> <span class="click-icon-wrapper header-action-icon">
<icon-copy /> <icon-copy />
</span> </span>
</a-tooltip> </a-tooltip>
@@ -202,7 +205,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { PathAnalysis } from '@/utils/file'; import type { PathAnalysis } from '@/utils/file';
import type { ISftpSession } from '../../types/terminal.type'; import type { ISftpSession } from '../../types/terminal.type';
import { ref, watch } from 'vue'; import { nextTick, ref, watch } from 'vue';
import { getParentPath, getPathAnalysis } from '@/utils/file'; import { getParentPath, getPathAnalysis } from '@/utils/file';
const props = defineProps<{ const props = defineProps<{
@@ -217,6 +220,7 @@
const analysisPaths = ref<Array<PathAnalysis>>([]); const analysisPaths = ref<Array<PathAnalysis>>([]);
const pathEditable = ref(false); const pathEditable = ref(false);
const pathInput = ref(''); const pathInput = ref('');
const pathInputRef = ref();
// 监听路径变化 // 监听路径变化
watch(() => props.currentPath, (path) => { watch(() => props.currentPath, (path) => {
@@ -236,6 +240,12 @@
const setPathEditable = (editable: boolean) => { const setPathEditable = (editable: boolean) => {
pathEditable.value = editable; pathEditable.value = editable;
pathInput.value = editable ? props.currentPath : ''; pathInput.value = editable ? props.currentPath : '';
// 自动聚焦
nextTick(() => {
if (editable) {
pathInputRef.value?.focus();
}
});
}; };
// 执行修改目录 // 执行修改目录
@@ -262,26 +272,30 @@
// 创建文件 // 创建文件
const createFile = () => { const createFile = () => {
// openModal(true, "props.currentPath") // openModal(true, "props.currentPath")
console.log(props.currentPath);
}; };
// 创建文件夹 // 创建文件夹
const createDir = () => { const createDir = () => {
// openModal(false, "props.currentPath") // openModal(false, "props.currentPath")
console.log(props.currentPath);
}; };
// 删除选中文件 // 删除选中文件
const deleteSelectFiles = () => { const deleteSelectFiles = () => {
// confirm // confirm
console.log(props.selectedFiles);
}; };
// 上传文件 // 上传文件
const uploadFile = () => { const uploadFile = () => {
// openModal("props.currentPath") // openModal("props.currentPath")
console.log(props.currentPath);
}; };
// 下载文件 // 下载文件
const downloadFile = () => { const downloadFile = () => {
console.log(props.selectedFiles);
}; };
// FIXME 图标宽度提成变量 // FIXME 图标宽度提成变量
@@ -312,11 +326,10 @@
} }
} }
.sftp-path-wrapper { .sftp-path-container {
background: var(--color-fill-2); background: var(--color-fill-2);
width: 100%; width: 100%;
border-radius: 2px; border-radius: 2px;
padding: 1px 6px;
overflow: hidden; overflow: hidden;
:deep(.sftp-path-unit) { :deep(.sftp-path-unit) {
@@ -326,6 +339,10 @@
color: rgb(var(--arcoblue-6)); color: rgb(var(--arcoblue-6));
} }
} }
.sftp-path-wrapper {
padding: 0 6px 1px 6px;
}
} }
.header-action-icon { .header-action-icon {

View File

@@ -121,19 +121,14 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { TableData } from '@arco-design/web-vue/es/table/interface'; import type { TableData } from '@arco-design/web-vue/es/table/interface';
import type { SftpFile } from '../../types/terminal.type'; import type { SftpFile, ISftpSession } from '../../types/terminal.type';
import { ref } from 'vue'; import { ref, computed } from 'vue';
import { useRowSelection } from '@/types/table'; import { useRowSelection } from '@/types/table';
import { dateFormat } from '@/utils'; import { dateFormat } from '@/utils';
import columns from './types/table.columns'; import columns from './types/table.columns';
import useCopy from '@/hooks/copy'; import useCopy from '@/hooks/copy';
import { FILE_TYPE } from '../../types/terminal.const'; import { FILE_TYPE } from '../../types/terminal.const';
import type { ISftpSession } from '../../types/terminal.type';
import useLoading from '@/hooks/loading';
import { useCacheStore } from '@/store';
import { computed } from 'vue/dist/vue';
const props = defineProps<{ const props = defineProps<{
session: ISftpSession | undefined; session: ISftpSession | undefined;
list: Array<SftpFile>; list: Array<SftpFile>;
@@ -177,20 +172,24 @@
// 删除文件 // 删除文件
const deleteFile = (path: string) => { const deleteFile = (path: string) => {
// confirm // confirm
console.log(path);
}; };
// 下载文件 // 下载文件
const downloadFile = (path: string) => { const downloadFile = (path: string) => {
console.log(path);
}; };
// 移动文件 // 移动文件
const moveFile = (path: string) => { const moveFile = (path: string) => {
// openModal('path') // openModal('path')
console.log(path);
}; };
// 文件提权 // 文件提权
const chmodFile = (path: string, attr: string) => { const chmodFile = (path: string, attr: string) => {
// openModal('path','mod') // openModal('path','mod')
console.log(path, attr);
}; };

View File

@@ -127,6 +127,14 @@ export const parse = (payload: string) => {
export const format = (protocol: Protocol, payload: InputPayload) => { export const format = (protocol: Protocol, payload: InputPayload) => {
payload.type = protocol.type; payload.type = protocol.type;
return protocol.template return protocol.template
.map(i => payload[i] || '') .map(i => getPayloadValueString(payload[i]))
.join(SEPARATOR); .join(SEPARATOR);
}; };
// 获取默认值
export const getPayloadValueString = (value: unknown): any => {
if (value === undefined || value === null) {
return '';
}
return value;
};