1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-09 10:00:06 +08:00

461 lines
15 KiB
Vue
Raw Normal View History

2022-08-17 17:46:49 +08:00
<template>
2023-01-30 10:10:40 +08:00
<el-row>
<el-col :span="2">
<el-button :icon="Back" @click="jump(paths.length - 2)" circle :disabled="paths.length == 0" />
<el-button :icon="Refresh" circle @click="search" />
</el-col>
<el-col :span="22">
2023-01-31 14:02:29 +08:00
<div class="path">
2023-01-30 10:10:40 +08:00
<BreadCrumbs>
<BreadCrumbItem @click="jump(-1)" :right="paths.length == 0">/</BreadCrumbItem>
<BreadCrumbItem
v-for="(item, key) in paths"
:key="key"
@click="jump(key)"
:right="key == paths.length - 1"
2022-08-24 17:34:21 +08:00
>
2023-01-30 10:10:40 +08:00
{{ item }}
</BreadCrumbItem>
</BreadCrumbs>
</div>
</el-col>
</el-row>
<LayoutContent :title="$t('file.file')" v-loading="loading">
<template #toolbar>
<el-dropdown @command="handleCreate">
2023-01-31 14:02:29 +08:00
<el-button type="primary">
2023-01-30 10:10:40 +08:00
{{ $t('commons.button.create') }}
<el-icon class="el-icon--right"><arrow-down /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="dir">
<svg-icon iconName="p-file-folder"></svg-icon>
{{ $t('file.dir') }}
</el-dropdown-item>
<el-dropdown-item command="file">
<svg-icon iconName="p-file-normal"></svg-icon>
{{ $t('file.file') }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<el-button plain @click="openUpload" style="margin-left: 10px">{{ $t('file.upload') }}</el-button>
<el-button plain @click="openWget">{{ $t('file.remoteFile') }}</el-button>
<el-button plain @click="openMove('copy')" :disabled="selects.length === 0">
{{ $t('file.copy') }}
</el-button>
<el-button plain @click="openMove('cut')" :disabled="selects.length === 0">
{{ $t('file.move') }}
</el-button>
<el-button plain @click="openCompress(selects)" :disabled="selects.length === 0">
{{ $t('file.compress') }}
</el-button>
<el-button plain @click="openDownload" :disabled="selects.length === 0">
{{ $t('file.download') }}
</el-button>
<div class="search-button">
<el-input
clearable
@clear="search()"
suffix-icon="Search"
@keyup.enter="search()"
@blur="search()"
:placeholder="$t('commons.button.search')"
></el-input>
</div>
</template>
<template #main>
<ComplexTable :pagination-config="paginationConfig" v-model:selects="selects" :data="data" @search="search">
<el-table-column type="selection" width="55" />
<el-table-column :label="$t('commons.table.name')" min-width="250" fix show-overflow-tooltip>
<template #default="{ row }">
<svg-icon v-if="row.isDir" className="table-icon" iconName="p-file-folder"></svg-icon>
<svg-icon v-else className="table-icon" :iconName="getIconName(row.extension)"></svg-icon>
<el-link :underline="false" @click="open(row)">{{ row.name }}</el-link>
<span v-if="row.isSymlink">-> {{ row.linkPath }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('file.mode')" prop="mode">
<template #default="{ row }">
<el-link :underline="false" @click="openMode(row)">{{ row.mode }}</el-link>
</template>
</el-table-column>
<el-table-column :label="$t('file.user')" prop="user" show-overflow-tooltip></el-table-column>
<el-table-column :label="$t('file.group')" prop="group"></el-table-column>
<el-table-column :label="$t('file.size')" prop="size">
<template #default="{ row }">
<span v-if="row.isDir">
<el-button type="primary" link small @click="getDirSize(row)">
<span v-if="row.dirSize == undefined">
{{ $t('file.calculate') }}
</span>
<span v-else>{{ getFileSize(row.dirSize) }}</span>
2022-09-09 11:20:02 +08:00
</el-button>
2023-01-30 10:10:40 +08:00
</span>
<span v-else>{{ getFileSize(row.size) }}</span>
2022-08-19 16:02:58 +08:00
</template>
2023-01-30 10:10:40 +08:00
</el-table-column>
<el-table-column
:label="$t('file.updateTime')"
prop="modTime"
:formatter="dateFormat"
min-width="150"
show-overflow-tooltip
></el-table-column>
<fu-table-operations
:ellipsis="1"
:buttons="buttons"
:label="$t('commons.table.operate')"
fixed="right"
fix
/>
</ComplexTable>
</template>
2023-01-31 14:02:29 +08:00
<CreateFile ref="createRef" @close="search" />
<ChangeRole ref="roleRef" @close="search" />
<Compress ref="compressRef" @close="search" />
<Decompress ref="deCompressRef" @close="search" />
<CodeEditor ref="codeEditorRef" @close="search" />
<FileRename ref="renameRef" @close="search" />
<Upload ref="uploadRef" @close="search" />
<Wget ref="wgetRef" @close="closeWget" />
<Move ref="moveRef" @close="search" />
<Download ref="downloadRef" @close="search" />
<Process :open="processPage.open" @close="closeProcess" />
<Detail ref="detailRef" />
2022-08-19 16:02:58 +08:00
</LayoutContent>
2022-08-17 17:46:49 +08:00
</template>
2022-08-19 16:02:58 +08:00
<script setup lang="ts">
2022-08-25 18:48:03 +08:00
import { onMounted, reactive, ref } from '@vue/runtime-core';
2023-01-31 14:02:29 +08:00
import { GetFilesList, DeleteFile, GetFileContent, ComputeDirSize } from '@/api/modules/files';
2023-01-16 15:55:53 +08:00
import { computeSize, dateFormat, getIcon, getRandomStr } from '@/utils/util';
2022-09-06 17:48:49 +08:00
import { File } from '@/api/interface/file';
import { useDeleteData } from '@/hooks/use-delete-data';
import { ElMessage } from 'element-plus';
2022-08-19 16:02:58 +08:00
import LayoutContent from '@/layout/layout-content.vue';
import ComplexTable from '@/components/complex-table/index.vue';
import i18n from '@/lang';
import BreadCrumbs from '@/components/bread-crumbs/index.vue';
import BreadCrumbItem from '@/components/bread-crumbs/bread-crumbs-item.vue';
2022-08-31 13:59:02 +08:00
import CreateFile from './create/index.vue';
import ChangeRole from './change-role/index.vue';
import Compress from './compress/index.vue';
import Decompress from './decompress/index.vue';
2022-09-03 18:41:52 +08:00
import Upload from './upload/index.vue';
2022-09-06 10:35:35 +08:00
import FileRename from './rename/index.vue';
2022-09-01 19:02:33 +08:00
import CodeEditor from './code-editor/index.vue';
2022-09-06 17:48:49 +08:00
import Wget from './wget/index.vue';
2022-09-06 10:35:35 +08:00
import Move from './move/index.vue';
2022-09-06 17:48:49 +08:00
import Download from './download/index.vue';
2022-09-09 18:39:56 +08:00
import { Mimetypes } from '@/global/mimetype';
2022-09-14 19:09:39 +08:00
import Process from './process/index.vue';
2022-12-04 15:29:55 +08:00
import Detail from './detail/index.vue';
2022-12-27 15:36:09 +08:00
import { useRouter } from 'vue-router';
2023-01-30 10:10:40 +08:00
import { Back, Refresh } from '@element-plus/icons-vue';
2022-08-24 17:34:21 +08:00
2022-12-27 15:36:09 +08:00
const router = useRouter();
2022-09-06 17:48:49 +08:00
const data = ref();
let selects = ref<any>([]);
2022-09-15 10:44:43 +08:00
let req = reactive({ path: '/', expand: true, showHidden: false, page: 1, pageSize: 100 });
let loading = ref(false);
2022-09-06 17:48:49 +08:00
const paths = ref<string[]>([]);
2022-08-24 17:34:21 +08:00
2023-01-31 14:02:29 +08:00
const fileCreate = reactive({ path: '/', isDir: false, mode: 0o755 });
const fileCompress = reactive({ files: [''], name: '', dst: '', operate: 'compress' });
const fileDeCompress = reactive({ path: '', name: '', dst: '', mimeType: '' });
const fileEdit = reactive({ content: '', path: '', name: '' });
2022-09-15 10:44:43 +08:00
const codeReq = reactive({ path: '', expand: false, page: 1, pageSize: 100 });
2023-01-31 14:02:29 +08:00
const fileUpload = reactive({ path: '' });
const fileRename = reactive({ path: '', oldName: '' });
const fileWget = reactive({ path: '' });
const fileMove = reactive({ oldPaths: [''], type: '' });
const fileDownload = reactive({ paths: [''], name: '' });
2022-09-14 19:09:39 +08:00
const processPage = reactive({ open: false });
2023-01-31 14:02:29 +08:00
const createRef = ref();
const roleRef = ref();
2022-12-04 15:29:55 +08:00
const detailRef = ref();
2023-01-31 14:02:29 +08:00
const compressRef = ref();
const deCompressRef = ref();
const codeEditorRef = ref();
const renameRef = ref();
const uploadRef = ref();
const wgetRef = ref();
const moveRef = ref();
const downloadRef = ref();
2022-08-30 17:59:59 +08:00
2022-08-19 16:02:58 +08:00
const paginationConfig = reactive({
currentPage: 1,
2022-09-15 10:44:43 +08:00
pageSize: 100,
2022-08-19 16:02:58 +08:00
total: 0,
});
const search = async () => {
2022-08-24 11:10:50 +08:00
loading.value = true;
req.page = paginationConfig.currentPage;
2022-09-15 10:44:43 +08:00
req.pageSize = paginationConfig.pageSize;
2022-08-24 17:34:21 +08:00
await GetFilesList(req)
2022-08-24 11:10:50 +08:00
.then((res) => {
2022-09-15 10:44:43 +08:00
paginationConfig.total = res.data.itemTotal;
2022-08-24 11:10:50 +08:00
data.value = res.data.items;
req.path = res.data.path;
const pathArray = req.path.split('/');
paths.value = [];
for (const p of pathArray) {
if (p != '') {
paths.value.push(p);
}
}
2022-08-24 11:10:50 +08:00
})
.finally(() => {
loading.value = false;
});
};
const open = async (row: File.File) => {
if (row.isDir) {
const name = row.name;
paths.value.push(name);
2022-09-01 19:02:33 +08:00
if (req.path.endsWith('/')) {
req.path = req.path + name;
} else {
req.path = req.path + '/' + name;
}
search();
2022-09-01 19:02:33 +08:00
} else {
openCodeEditor(row);
2022-08-24 11:10:50 +08:00
}
};
const jump = async (index: number) => {
let path = '/';
if (index != -1) {
const jPaths = paths.value.slice(0, index + 1);
for (let i in jPaths) {
2022-09-06 17:48:49 +08:00
if (path.endsWith('/')) {
path = path + jPaths[i];
} else {
path = path + '/' + jPaths[i];
}
2022-08-24 11:10:50 +08:00
}
}
req.path = path;
search();
2022-08-19 16:02:58 +08:00
};
2022-08-25 17:54:52 +08:00
const handleCreate = (commnad: string) => {
2023-01-31 14:02:29 +08:00
fileCreate.path = req.path;
fileCreate.isDir = false;
2022-08-25 17:54:52 +08:00
if (commnad === 'dir') {
2023-01-31 14:02:29 +08:00
fileCreate.isDir = true;
2022-08-25 17:54:52 +08:00
}
2023-01-31 14:02:29 +08:00
createRef.value.acceptParams(fileCreate);
2022-08-25 17:54:52 +08:00
};
2022-08-25 18:48:03 +08:00
const delFile = async (row: File.File | null) => {
2022-12-02 10:59:07 +08:00
await useDeleteData(DeleteFile, row as File.FileDelete, 'commons.msg.delete');
search();
2022-08-25 18:48:03 +08:00
};
const getFileSize = (size: number) => {
return computeSize(size);
};
const getDirSize = async (row: any) => {
const req = {
path: row.path,
};
loading.value = true;
await ComputeDirSize(req)
.then(async (res) => {
row.dirSize = res.data.size;
})
.finally(() => {
loading.value = false;
});
};
2022-09-09 18:27:50 +08:00
const getIconName = (extension: string) => {
return getIcon(extension);
};
const openMode = (item: File.File) => {
2023-01-31 14:02:29 +08:00
roleRef.value.acceptParams(item);
};
2022-09-06 17:48:49 +08:00
const openCompress = (items: File.File[]) => {
const paths = [];
for (const item of items) {
paths.push(item.path);
}
2023-01-31 14:02:29 +08:00
fileCompress.files = paths;
2022-09-06 17:48:49 +08:00
if (paths.length === 1) {
2023-01-31 14:02:29 +08:00
fileCompress.name = items[0].name;
2022-09-06 17:48:49 +08:00
} else {
2023-01-31 14:02:29 +08:00
fileCompress.name = getRandomStr(6);
2022-09-06 17:48:49 +08:00
}
2023-01-31 14:02:29 +08:00
fileCompress.dst = req.path;
2022-08-30 17:59:59 +08:00
2023-01-31 14:02:29 +08:00
compressRef.value.acceptParams(fileCompress);
2022-08-30 17:59:59 +08:00
};
2022-08-31 13:59:02 +08:00
const openDeCompress = (item: File.File) => {
2022-09-09 18:39:56 +08:00
if (Mimetypes.get(item.mimeType) == undefined) {
ElMessage.warning(i18n.global.t('file.canNotDeCompress'));
return;
}
2023-01-31 14:02:29 +08:00
fileDeCompress.name = item.name;
fileDeCompress.path = item.path;
fileDeCompress.dst = req.path;
fileDeCompress.mimeType = item.mimeType;
2022-08-31 13:59:02 +08:00
2023-01-31 14:02:29 +08:00
deCompressRef.value.acceptParams(fileDeCompress);
2022-08-31 13:59:02 +08:00
};
2022-09-01 19:02:33 +08:00
const openCodeEditor = (row: File.File) => {
codeReq.path = row.path;
codeReq.expand = true;
GetFileContent(codeReq).then((res) => {
2023-01-31 14:02:29 +08:00
fileEdit.content = res.data.content;
fileEdit.path = res.data.path;
fileEdit.name = res.data.name;
codeEditorRef.value.acceptParams(fileEdit);
2022-09-01 19:02:33 +08:00
});
};
2022-09-03 18:41:52 +08:00
const openUpload = () => {
2023-01-31 14:02:29 +08:00
fileUpload.path = req.path;
uploadRef.value.acceptParams(fileUpload);
2022-09-03 18:41:52 +08:00
};
2022-09-06 17:48:49 +08:00
const openWget = () => {
2023-01-31 14:02:29 +08:00
fileWget.path = req.path;
wgetRef.value.acceptParams(fileWget);
2022-09-05 16:25:26 +08:00
};
2022-09-14 19:09:39 +08:00
const closeWget = (submit: any) => {
search();
2022-09-14 19:09:39 +08:00
if (submit) {
openProcess();
}
};
const openProcess = () => {
processPage.open = true;
};
const closeProcess = () => {
processPage.open = false;
2022-09-05 16:25:26 +08:00
};
2022-09-03 22:22:40 +08:00
const openRename = (item: File.File) => {
2023-01-31 14:02:29 +08:00
fileRename.path = req.path;
fileRename.oldName = item.name;
renameRef.value.acceptParams(fileRename);
2022-09-03 22:22:40 +08:00
};
2022-09-06 10:35:35 +08:00
const openMove = (type: string) => {
2023-01-31 14:02:29 +08:00
fileMove.type = type;
2022-09-06 10:35:35 +08:00
const oldpaths = [];
for (const s of selects.value) {
oldpaths.push(s['path']);
}
2023-01-31 14:02:29 +08:00
fileMove.oldPaths = oldpaths;
moveRef.value.acceptParams(fileMove);
2022-09-06 10:35:35 +08:00
};
2022-09-06 17:48:49 +08:00
const openDownload = () => {
const paths = [];
for (const s of selects.value) {
paths.push(s['path']);
}
2023-01-31 14:02:29 +08:00
fileDownload.paths = paths;
fileDownload.name = getRandomStr(6);
downloadRef.value.acceptParams(fileDownload);
};
// const closeDownload = () => {
// downloadPage.open = false;
// search();
// };
// const saveContent = (content: string) => {
// editorPage.loading = true;
// SaveFileContent({ path: codeReq.path, content: content }).finally(() => {
// editorPage.loading = false;
// editorPage.open = false;
// ElMessage.success(i18n.global.t('commons.msg.updateSuccess'));
// });
// };
// const quickSave = (content: string) => {
// editorPage.loading = true;
// SaveFileContent({ path: codeReq.path, content: content }).finally(() => {
// editorPage.loading = false;
// ElMessage.success(i18n.global.t('commons.msg.updateSuccess'));
// });
// };
2022-09-01 19:02:33 +08:00
2022-12-04 15:29:55 +08:00
const openDetail = (row: File.File) => {
detailRef.value.acceptParams({ path: row.path });
};
2022-08-25 18:48:03 +08:00
const buttons = [
{
label: i18n.global.t('file.open'),
click: open,
},
{
label: i18n.global.t('file.mode'),
click: openMode,
},
{
2022-08-31 13:59:02 +08:00
label: i18n.global.t('file.compress'),
2022-09-06 17:48:49 +08:00
click: (row: File.File) => {
openCompress([row]);
},
},
2022-08-31 13:59:02 +08:00
{
label: i18n.global.t('file.deCompress'),
click: openDeCompress,
2022-09-09 18:39:56 +08:00
disabled: (row: File.File) => {
return row.isDir;
},
2022-08-31 13:59:02 +08:00
},
{
label: i18n.global.t('file.rename'),
2022-09-03 22:22:40 +08:00
click: openRename,
},
{
label: i18n.global.t('commons.button.delete'),
2022-08-25 18:48:03 +08:00
click: delFile,
},
{
label: i18n.global.t('file.info'),
2022-12-04 15:29:55 +08:00
click: openDetail,
},
];
2022-12-04 15:29:55 +08:00
onMounted(() => {
2022-12-27 15:36:09 +08:00
if (router.currentRoute.value.query.path) {
req.path = String(router.currentRoute.value.query.path);
}
2022-12-04 15:29:55 +08:00
search();
});
2022-08-19 16:02:58 +08:00
</script>
<style>
.path {
2023-01-31 14:02:29 +08:00
background-color: #ffffff;
2022-08-19 16:02:58 +08:00
}
2023-01-30 10:10:40 +08:00
.search-button {
float: right;
display: inline;
}
2022-08-19 16:02:58 +08:00
</style>