2021-06-07 17:22:07 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="file-manage">
|
2021-09-08 17:55:57 +08:00
|
|
|
|
<el-dialog :title="title" v-model="dialogVisible" :show-close="true" :before-close="handleClose" width="800px">
|
2021-06-07 17:22:07 +08:00
|
|
|
|
<div class="toolbar">
|
|
|
|
|
|
<div style="float: right">
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-button v-auth="'machine:file:add'" type="primary" @click="add" icon="plus" size="small" plain>添加</el-button>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-table :data="fileTable" stripe style="width: 100%">
|
|
|
|
|
|
<el-table-column prop="name" label="名称" width>
|
|
|
|
|
|
<template #default="scope">
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-input v-model="scope.row.name" size="small" :disabled="scope.row.id != null" clearable></el-input>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column prop="name" label="类型" min-width="50px">
|
|
|
|
|
|
<template #default="scope">
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-select :disabled="scope.row.id != null" size="small" v-model="scope.row.type" style="width: 100px" placeholder="请选择">
|
2021-06-07 17:22:07 +08:00
|
|
|
|
<el-option v-for="item in enums.FileTypeEnum" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column prop="path" label="路径" width>
|
|
|
|
|
|
<template #default="scope">
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-input v-model="scope.row.path" :disabled="scope.row.id != null" size="small" clearable></el-input>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column label="操作" width>
|
|
|
|
|
|
<template #default="scope">
|
2022-01-19 15:10:17 +08:00
|
|
|
|
<el-button v-if="scope.row.id == null" @click="addFiles(scope.row)" type="success" icon="success-filled" size="small" plain
|
2021-06-07 17:22:07 +08:00
|
|
|
|
>确定</el-button
|
|
|
|
|
|
>
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-button v-if="scope.row.id != null" @click="getConf(scope.row)" type="primary" icon="tickets" size="small" plain
|
2021-06-07 17:22:07 +08:00
|
|
|
|
>查看</el-button
|
|
|
|
|
|
>
|
2021-06-09 16:58:57 +08:00
|
|
|
|
<el-button
|
|
|
|
|
|
v-auth="'machine:file:del'"
|
|
|
|
|
|
type="danger"
|
|
|
|
|
|
@click="deleteRow(scope.$index, scope.row)"
|
2022-01-12 16:00:31 +08:00
|
|
|
|
icon="delete"
|
|
|
|
|
|
size="small"
|
2021-06-09 16:58:57 +08:00
|
|
|
|
plain
|
|
|
|
|
|
>删除</el-button
|
|
|
|
|
|
>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
2022-05-12 10:34:16 +08:00
|
|
|
|
<el-row style="margin-top: 10px" type="flex" justify="end">
|
|
|
|
|
|
<el-pagination
|
|
|
|
|
|
small
|
|
|
|
|
|
style="text-align: center"
|
|
|
|
|
|
:total="total"
|
|
|
|
|
|
layout="prev, pager, next, total, jumper"
|
|
|
|
|
|
v-model:current-page="query.pageNum"
|
|
|
|
|
|
:page-size="query.pageSize"
|
|
|
|
|
|
@current-change="handlePageChange"
|
|
|
|
|
|
></el-pagination>
|
|
|
|
|
|
</el-row>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</el-dialog>
|
|
|
|
|
|
|
2022-09-07 11:18:47 +08:00
|
|
|
|
<el-dialog :title="tree.title" v-model="tree.visible" :close-on-click-modal="false" width="70%">
|
2022-02-09 10:41:48 +08:00
|
|
|
|
<el-progress
|
|
|
|
|
|
v-if="uploadProgressShow"
|
|
|
|
|
|
style="width: 90%; margin-left: 20px"
|
|
|
|
|
|
:text-inside="true"
|
|
|
|
|
|
:stroke-width="20"
|
|
|
|
|
|
:percentage="progressNum"
|
|
|
|
|
|
/>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
<div style="height: 45vh; overflow: auto">
|
2022-09-23 14:27:50 +08:00
|
|
|
|
<el-tree
|
|
|
|
|
|
v-if="tree.visible"
|
|
|
|
|
|
ref="fileTree"
|
|
|
|
|
|
:highlight-current="true"
|
|
|
|
|
|
:load="loadNode"
|
|
|
|
|
|
:props="props"
|
|
|
|
|
|
lazy
|
|
|
|
|
|
node-key="id"
|
|
|
|
|
|
:expand-on-click-node="true"
|
|
|
|
|
|
>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
<template #default="{ node, data }">
|
|
|
|
|
|
<span class="custom-tree-node">
|
2022-02-08 17:52:35 +08:00
|
|
|
|
<el-dropdown size="small" @visible-change="getFilePath(data, $event)" trigger="contextmenu">
|
2021-12-02 10:35:48 +08:00
|
|
|
|
<span class="el-dropdown-link">
|
|
|
|
|
|
<span v-if="data.type == 'd' && !node.expanded">
|
2022-01-28 11:30:11 +08:00
|
|
|
|
<SvgIcon name="folder" />
|
2021-12-02 10:35:48 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
<span v-if="data.type == 'd' && node.expanded">
|
2022-01-28 11:30:11 +08:00
|
|
|
|
<SvgIcon name="folder-opened" />
|
2021-12-02 10:35:48 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
<span v-if="data.type == '-'">
|
2022-01-28 11:30:11 +08:00
|
|
|
|
<SvgIcon name="document" />
|
2021-12-02 10:35:48 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
|
2022-09-28 21:40:59 +08:00
|
|
|
|
<span>
|
2021-12-02 10:35:48 +08:00
|
|
|
|
{{ node.label }}
|
2022-09-07 11:18:47 +08:00
|
|
|
|
</span>
|
2021-12-02 10:35:48 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
<template #dropdown>
|
|
|
|
|
|
<el-dropdown-menu>
|
2022-06-25 19:52:11 +08:00
|
|
|
|
<el-dropdown-item
|
|
|
|
|
|
@click="getFileContent(tree.folder.id, data.path)"
|
|
|
|
|
|
v-if="data.type == '-' && data.size < 1 * 1024 * 1024"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-link type="info" icon="view" :underline="false">查看</el-link>
|
2021-12-02 10:35:48 +08:00
|
|
|
|
</el-dropdown-item>
|
2022-02-08 17:52:35 +08:00
|
|
|
|
|
2022-07-04 20:21:24 +08:00
|
|
|
|
<span v-auth="'machine:file:write'">
|
|
|
|
|
|
<el-dropdown-item @click="showCreateFileDialog(node, data)" v-if="data.type == 'd'">
|
|
|
|
|
|
<el-link type="primary" icon="document" :underline="false" style="margin-left: 2px">新建</el-link>
|
|
|
|
|
|
</el-dropdown-item>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
2022-01-28 11:30:11 +08:00
|
|
|
|
<span v-auth="'machine:file:upload'">
|
|
|
|
|
|
<el-dropdown-item v-if="data.type == 'd'">
|
|
|
|
|
|
<el-upload
|
|
|
|
|
|
:before-upload="beforeUpload"
|
|
|
|
|
|
:on-success="uploadSuccess"
|
2022-02-08 17:52:35 +08:00
|
|
|
|
action=""
|
|
|
|
|
|
:http-request="getUploadFile"
|
2022-01-28 11:30:11 +08:00
|
|
|
|
:headers="{ token }"
|
|
|
|
|
|
:show-file-list="false"
|
|
|
|
|
|
name="file"
|
|
|
|
|
|
style="display: inline-block; margin-left: 2px"
|
|
|
|
|
|
>
|
2022-06-25 19:52:11 +08:00
|
|
|
|
<el-link icon="upload" :underline="false">上传</el-link>
|
2022-01-28 11:30:11 +08:00
|
|
|
|
</el-upload>
|
|
|
|
|
|
</el-dropdown-item>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span v-auth="'machine:file:write'">
|
2022-06-25 19:52:11 +08:00
|
|
|
|
<el-dropdown-item @click="downloadFile(node, data)" v-if="data.type == '-'">
|
|
|
|
|
|
<el-link type="primary" icon="download" :underline="false" style="margin-left: 2px">下载</el-link>
|
2022-01-28 11:30:11 +08:00
|
|
|
|
</el-dropdown-item>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span v-auth="'machine:file:rm'">
|
2022-06-25 19:52:11 +08:00
|
|
|
|
<el-dropdown-item @click="deleteFile(node, data)" v-if="!dontOperate(data)">
|
|
|
|
|
|
<el-link type="danger" icon="delete" :underline="false" style="margin-left: 2px">删除</el-link>
|
2022-01-28 11:30:11 +08:00
|
|
|
|
</el-dropdown-item>
|
|
|
|
|
|
</span>
|
2021-12-02 10:35:48 +08:00
|
|
|
|
</el-dropdown-menu>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dropdown>
|
2022-09-28 21:40:59 +08:00
|
|
|
|
<span style="display: inline-block" class="ml15">
|
|
|
|
|
|
<span style="color: #67c23a" v-if="data.type == '-'">[{{ formatFileSize(data.size) }}]</span>
|
|
|
|
|
|
<span v-if="data.mode" style="color: #67c23a"> [{{ data.mode }} {{ data.modTime }}]</span>
|
|
|
|
|
|
</span>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-tree>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
|
2022-07-04 20:21:24 +08:00
|
|
|
|
<el-dialog
|
|
|
|
|
|
:destroy-on-close="true"
|
|
|
|
|
|
title="新建文件"
|
|
|
|
|
|
v-model="createFileDialog.visible"
|
|
|
|
|
|
:before-close="closeCreateFileDialog"
|
|
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
|
top="5vh"
|
|
|
|
|
|
width="400px"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<el-form-item prop="name" label="名称:">
|
|
|
|
|
|
<el-input v-model.trim="createFileDialog.name" placeholder="请输入名称" auto-complete="off"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="type" label="类型:">
|
|
|
|
|
|
<el-radio-group v-model="createFileDialog.type">
|
|
|
|
|
|
<el-radio label="d" size="small">文件夹</el-radio>
|
|
|
|
|
|
<el-radio label="-" size="small">文件</el-radio>
|
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
2022-09-28 21:40:59 +08:00
|
|
|
|
<div>
|
2022-07-04 20:21:24 +08:00
|
|
|
|
<el-button @click="closeCreateFileDialog">关闭</el-button>
|
|
|
|
|
|
<el-button v-auth="'machine:file:write'" type="primary" @click="createFile">确定</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
|
2021-06-07 17:22:07 +08:00
|
|
|
|
<el-dialog
|
|
|
|
|
|
:destroy-on-close="true"
|
|
|
|
|
|
:title="fileContent.dialogTitle"
|
|
|
|
|
|
v-model="fileContent.contentVisible"
|
|
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
|
top="5vh"
|
|
|
|
|
|
width="70%"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<codemirror :can-change-mode="true" ref="cmEditor" v-model="fileContent.content" :language="fileContent.type" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<div class="dialog-footer">
|
2022-01-12 16:00:31 +08:00
|
|
|
|
<el-button @click="fileContent.contentVisible = false">关 闭</el-button>
|
2022-05-12 10:34:16 +08:00
|
|
|
|
<el-button v-auth="'machine:file:write'" type="primary" @click="updateContent">保 存</el-button>
|
2021-06-07 17:22:07 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
|
import { ref, toRefs, reactive, watch, defineComponent } from 'vue';
|
|
|
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
|
|
|
|
import { machineApi } from './api';
|
|
|
|
|
|
|
|
|
|
|
|
import { codemirror } from '@/components/codemirror';
|
|
|
|
|
|
import { getSession } from '@/common/utils/storage';
|
|
|
|
|
|
import enums from './enums';
|
|
|
|
|
|
import config from '@/common/config';
|
2022-07-04 20:21:24 +08:00
|
|
|
|
import { isTrue } from '@/common/assert';
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
|
name: 'FileManage',
|
|
|
|
|
|
components: {
|
|
|
|
|
|
codemirror,
|
|
|
|
|
|
},
|
|
|
|
|
|
props: {
|
|
|
|
|
|
visible: { type: Boolean },
|
|
|
|
|
|
machineId: { type: Number },
|
|
|
|
|
|
title: { type: String },
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
setup(props: any, { emit }) {
|
|
|
|
|
|
const addFile = machineApi.addConf;
|
|
|
|
|
|
const delFile = machineApi.delConf;
|
|
|
|
|
|
const updateFileContent = machineApi.updateFileContent;
|
|
|
|
|
|
const files = machineApi.files;
|
|
|
|
|
|
const fileTree: any = ref(null);
|
|
|
|
|
|
const token = getSession('token');
|
|
|
|
|
|
|
2022-07-04 20:21:24 +08:00
|
|
|
|
const folderType = 'd';
|
|
|
|
|
|
const fileType = '-';
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
|
|
|
|
|
const state = reactive({
|
2021-09-08 17:55:57 +08:00
|
|
|
|
dialogVisible: false,
|
2022-05-12 10:34:16 +08:00
|
|
|
|
query: {
|
|
|
|
|
|
id: 0,
|
|
|
|
|
|
pageNum: 1,
|
|
|
|
|
|
pageSize: 8,
|
|
|
|
|
|
},
|
2021-06-07 17:22:07 +08:00
|
|
|
|
form: {
|
|
|
|
|
|
id: null,
|
|
|
|
|
|
type: null,
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
remark: '',
|
|
|
|
|
|
},
|
2022-05-12 10:34:16 +08:00
|
|
|
|
total: 0,
|
2021-06-07 17:22:07 +08:00
|
|
|
|
fileTable: [] as any,
|
|
|
|
|
|
btnLoading: false,
|
|
|
|
|
|
fileContent: {
|
|
|
|
|
|
fileId: 0,
|
|
|
|
|
|
content: '',
|
|
|
|
|
|
contentVisible: false,
|
|
|
|
|
|
dialogTitle: '',
|
|
|
|
|
|
path: '',
|
|
|
|
|
|
type: 'shell',
|
|
|
|
|
|
},
|
|
|
|
|
|
tree: {
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
folder: { id: 0 },
|
|
|
|
|
|
node: {
|
|
|
|
|
|
childNodes: [],
|
|
|
|
|
|
},
|
|
|
|
|
|
resolve: {},
|
|
|
|
|
|
},
|
|
|
|
|
|
props: {
|
|
|
|
|
|
label: 'name',
|
|
|
|
|
|
children: 'zones',
|
|
|
|
|
|
isLeaf: 'leaf',
|
|
|
|
|
|
},
|
2022-02-08 17:52:35 +08:00
|
|
|
|
progressNum: 0,
|
|
|
|
|
|
uploadProgressShow: false,
|
|
|
|
|
|
dataObj: {
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
path: '',
|
|
|
|
|
|
type: '',
|
|
|
|
|
|
},
|
2022-07-04 20:21:24 +08:00
|
|
|
|
createFileDialog: {
|
|
|
|
|
|
visible: false,
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
type: folderType,
|
|
|
|
|
|
node: null as any,
|
|
|
|
|
|
},
|
2022-02-08 17:52:35 +08:00
|
|
|
|
file: null as any,
|
2021-06-07 17:22:07 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2022-09-23 14:27:50 +08:00
|
|
|
|
watch(props, async (newValue) => {
|
|
|
|
|
|
if (newValue.machineId && newValue.visible) {
|
|
|
|
|
|
await getFiles();
|
2021-06-07 17:22:07 +08:00
|
|
|
|
}
|
2021-09-08 17:55:57 +08:00
|
|
|
|
state.dialogVisible = newValue.visible;
|
2021-06-07 17:22:07 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const getFiles = async () => {
|
2022-05-12 10:34:16 +08:00
|
|
|
|
state.query.id = props.machineId;
|
|
|
|
|
|
const res = await files.request(state.query);
|
2021-06-07 17:22:07 +08:00
|
|
|
|
state.fileTable = res.list;
|
2022-05-12 10:34:16 +08:00
|
|
|
|
state.total = res.total;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handlePageChange = (curPage: number) => {
|
|
|
|
|
|
state.query.pageNum = curPage;
|
|
|
|
|
|
getFiles();
|
2021-06-07 17:22:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const add = () => {
|
|
|
|
|
|
// 往数组头部添加元素
|
|
|
|
|
|
state.fileTable = [{}].concat(state.fileTable);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const addFiles = async (row: any) => {
|
|
|
|
|
|
row.machineId = props.machineId;
|
|
|
|
|
|
await addFile.request(row);
|
|
|
|
|
|
ElMessage.success('添加成功');
|
|
|
|
|
|
getFiles();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const deleteRow = (idx: any, row: any) => {
|
|
|
|
|
|
if (row.id) {
|
|
|
|
|
|
ElMessageBox.confirm(`此操作将删除 [${row.name}], 是否继续?`, '提示', {
|
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
// 删除配置文件
|
|
|
|
|
|
delFile
|
|
|
|
|
|
.request({
|
|
|
|
|
|
machineId: props.machineId,
|
|
|
|
|
|
id: row.id,
|
|
|
|
|
|
})
|
2021-09-08 17:55:57 +08:00
|
|
|
|
.then(() => {
|
2022-05-12 10:34:16 +08:00
|
|
|
|
getFiles();
|
2021-06-07 17:22:07 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
state.fileTable.splice(idx, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getConf = (row: any) => {
|
|
|
|
|
|
if (row.type == 1) {
|
|
|
|
|
|
state.tree.folder = row;
|
|
|
|
|
|
state.tree.title = row.name;
|
|
|
|
|
|
loadNode(state.tree.node, state.tree.resolve);
|
|
|
|
|
|
state.tree.visible = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
getFileContent(row.id, row.path);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getFileContent = async (fileId: number, path: string) => {
|
|
|
|
|
|
const res = await machineApi.fileContent.request({
|
|
|
|
|
|
fileId,
|
|
|
|
|
|
path,
|
|
|
|
|
|
machineId: props.machineId,
|
|
|
|
|
|
});
|
|
|
|
|
|
state.fileContent.content = res;
|
|
|
|
|
|
state.fileContent.fileId = fileId;
|
|
|
|
|
|
state.fileContent.dialogTitle = path;
|
|
|
|
|
|
state.fileContent.path = path;
|
|
|
|
|
|
state.fileContent.type = getFileType(path);
|
|
|
|
|
|
state.fileContent.contentVisible = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getFileType = (path: string) => {
|
|
|
|
|
|
if (path.endsWith('.sh')) {
|
|
|
|
|
|
return 'shell';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (path.endsWith('js') || path.endsWith('json')) {
|
|
|
|
|
|
return 'javascript';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (path.endsWith('Dockerfile')) {
|
|
|
|
|
|
return 'dockerfile';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (path.endsWith('nginx.conf')) {
|
|
|
|
|
|
return 'nginx';
|
|
|
|
|
|
}
|
2022-04-10 10:41:14 +08:00
|
|
|
|
if (path.endsWith('sql')) {
|
|
|
|
|
|
return 'sql';
|
|
|
|
|
|
}
|
2021-06-07 17:22:07 +08:00
|
|
|
|
if (path.endsWith('yaml') || path.endsWith('yml')) {
|
|
|
|
|
|
return 'yaml';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (path.endsWith('xml') || path.endsWith('html')) {
|
|
|
|
|
|
return 'html';
|
|
|
|
|
|
}
|
|
|
|
|
|
return 'text';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const updateContent = async () => {
|
|
|
|
|
|
await updateFileContent.request({
|
|
|
|
|
|
content: state.fileContent.content,
|
|
|
|
|
|
id: state.fileContent.fileId,
|
|
|
|
|
|
path: state.fileContent.path,
|
|
|
|
|
|
machineId: props.machineId,
|
|
|
|
|
|
});
|
|
|
|
|
|
ElMessage.success('修改成功');
|
|
|
|
|
|
state.fileContent.contentVisible = false;
|
|
|
|
|
|
state.fileContent.content = '';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 关闭取消按钮触发的事件
|
|
|
|
|
|
*/
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
|
emit('update:machineId', null);
|
|
|
|
|
|
emit('cancel');
|
|
|
|
|
|
state.fileTable = [];
|
|
|
|
|
|
state.tree.folder = { id: 0 };
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 加载文件树节点
|
|
|
|
|
|
* @param {Object} node
|
|
|
|
|
|
* @param {Object} resolve
|
|
|
|
|
|
*/
|
|
|
|
|
|
const loadNode = async (node: any, resolve: any) => {
|
|
|
|
|
|
if (typeof resolve !== 'function') {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const folder: any = state.tree.folder;
|
|
|
|
|
|
if (node.level === 0) {
|
|
|
|
|
|
state.tree.node = node;
|
|
|
|
|
|
state.tree.resolve = resolve;
|
|
|
|
|
|
|
|
|
|
|
|
// let folder: any = this.tree.folder
|
|
|
|
|
|
const path = folder ? folder.path : '/';
|
|
|
|
|
|
return resolve([
|
|
|
|
|
|
{
|
|
|
|
|
|
name: path,
|
2022-07-04 20:21:24 +08:00
|
|
|
|
type: folderType,
|
2021-06-07 17:22:07 +08:00
|
|
|
|
path: path,
|
|
|
|
|
|
},
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let path;
|
|
|
|
|
|
const data = node.data;
|
|
|
|
|
|
// 只有在第一级节点时,name==path,即上述level==0时设置的
|
|
|
|
|
|
if (!data || data.name == data.path) {
|
|
|
|
|
|
path = folder.path;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
path = data.path;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const res = await machineApi.lsFile.request({
|
|
|
|
|
|
fileId: folder.id,
|
|
|
|
|
|
machineId: props.machineId,
|
|
|
|
|
|
path,
|
|
|
|
|
|
});
|
|
|
|
|
|
for (const file of res) {
|
|
|
|
|
|
const type = file.type;
|
2022-07-04 20:21:24 +08:00
|
|
|
|
if (type == fileType) {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
file.leaf = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return resolve(res);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-07-04 20:21:24 +08:00
|
|
|
|
const showCreateFileDialog = (node: any) => {
|
|
|
|
|
|
isTrue(node.expanded, '请先点击展开该节点后再创建');
|
|
|
|
|
|
state.createFileDialog.node = node;
|
|
|
|
|
|
state.createFileDialog.visible = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const createFile = async () => {
|
|
|
|
|
|
const node = state.createFileDialog.node;
|
|
|
|
|
|
console.log(node.data);
|
|
|
|
|
|
const name = state.createFileDialog.name;
|
|
|
|
|
|
const type = state.createFileDialog.type;
|
|
|
|
|
|
const path = node.data.path + '/' + name;
|
|
|
|
|
|
await machineApi.createFile.request({
|
|
|
|
|
|
machineId: props.machineId,
|
|
|
|
|
|
id: state.tree.folder.id,
|
|
|
|
|
|
path,
|
|
|
|
|
|
type,
|
|
|
|
|
|
});
|
|
|
|
|
|
fileTree.value.append({ name: name, path: path, type: type, leaf: type === fileType, size: 0 }, node);
|
|
|
|
|
|
closeCreateFileDialog();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const closeCreateFileDialog = () => {
|
|
|
|
|
|
state.createFileDialog.visible = false;
|
|
|
|
|
|
state.createFileDialog.node = null;
|
|
|
|
|
|
state.createFileDialog.name = '';
|
|
|
|
|
|
state.createFileDialog.type = folderType;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-06-07 17:22:07 +08:00
|
|
|
|
const deleteFile = (node: any, data: any) => {
|
|
|
|
|
|
const file = data.path;
|
|
|
|
|
|
ElMessageBox.confirm(`此操作将删除 [${file}], 是否继续?`, '提示', {
|
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
machineApi.rmFile
|
|
|
|
|
|
.request({
|
|
|
|
|
|
fileId: state.tree.folder.id,
|
|
|
|
|
|
path: file,
|
|
|
|
|
|
machineId: props.machineId,
|
|
|
|
|
|
})
|
2021-09-08 17:55:57 +08:00
|
|
|
|
.then(() => {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
ElMessage.success('删除成功');
|
|
|
|
|
|
fileTree.value.remove(node);
|
|
|
|
|
|
});
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
// skip
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const downloadFile = (node: any, data: any) => {
|
|
|
|
|
|
const a = document.createElement('a');
|
|
|
|
|
|
a.setAttribute(
|
|
|
|
|
|
'href',
|
|
|
|
|
|
`${config.baseApiUrl}/machines/${props.machineId}/files/${state.tree.folder.id}/read?type=1&path=${data.path}&token=${token}`
|
|
|
|
|
|
);
|
|
|
|
|
|
a.click();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-02-08 17:52:35 +08:00
|
|
|
|
const onUploadProgress = (progressEvent: any) => {
|
|
|
|
|
|
state.uploadProgressShow = true;
|
|
|
|
|
|
let complete = ((progressEvent.loaded / progressEvent.total) * 100) | 0;
|
|
|
|
|
|
state.progressNum = complete;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getUploadFile = (content: any) => {
|
|
|
|
|
|
const params = new FormData();
|
|
|
|
|
|
params.append('file', content.file);
|
|
|
|
|
|
params.append('path', state.dataObj.path);
|
|
|
|
|
|
params.append('machineId', props.machineId);
|
|
|
|
|
|
params.append('fileId', state.tree.folder.id as any);
|
|
|
|
|
|
params.append('token', token);
|
|
|
|
|
|
machineApi.uploadFile
|
|
|
|
|
|
.request(params, {
|
|
|
|
|
|
url: `${config.baseApiUrl}/machines/${props.machineId}/files/${state.tree.folder.id}/upload?token=${token}`,
|
|
|
|
|
|
headers: { 'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryF1uyUD0tWdqmJqpl' },
|
|
|
|
|
|
onUploadProgress: onUploadProgress,
|
|
|
|
|
|
baseURL: '',
|
2022-04-10 10:41:14 +08:00
|
|
|
|
timeout: 60 * 60 * 1000,
|
2022-02-08 17:52:35 +08:00
|
|
|
|
})
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
ElMessage.success('上传成功');
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
state.uploadProgressShow = false;
|
|
|
|
|
|
}, 3000);
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
state.uploadProgressShow = false;
|
|
|
|
|
|
});
|
2021-06-07 17:22:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const uploadSuccess = (res: any) => {
|
2021-11-11 15:56:02 +08:00
|
|
|
|
if (res.code !== 200) {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
ElMessage.error(res.msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-11-12 14:35:34 +08:00
|
|
|
|
const beforeUpload = (file: File) => {
|
2022-02-08 17:52:35 +08:00
|
|
|
|
state.file = file;
|
|
|
|
|
|
};
|
|
|
|
|
|
const getFilePath = (data: object, visible: boolean) => {
|
|
|
|
|
|
if (visible) {
|
|
|
|
|
|
state.dataObj = data as any;
|
|
|
|
|
|
}
|
2021-12-02 10:35:48 +08:00
|
|
|
|
};
|
2021-06-07 17:22:07 +08:00
|
|
|
|
const dontOperate = (data: any) => {
|
|
|
|
|
|
const path = data.path;
|
|
|
|
|
|
const ls = [
|
|
|
|
|
|
'/',
|
|
|
|
|
|
'//',
|
|
|
|
|
|
'/usr',
|
|
|
|
|
|
'/usr/',
|
|
|
|
|
|
'/usr/bin',
|
|
|
|
|
|
'/opt',
|
|
|
|
|
|
'/run',
|
|
|
|
|
|
'/etc',
|
|
|
|
|
|
'/proc',
|
|
|
|
|
|
'/var',
|
|
|
|
|
|
'/mnt',
|
|
|
|
|
|
'/boot',
|
|
|
|
|
|
'/dev',
|
|
|
|
|
|
'/home',
|
|
|
|
|
|
'/media',
|
|
|
|
|
|
'/root',
|
|
|
|
|
|
];
|
|
|
|
|
|
return ls.indexOf(path) != -1;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 格式化文件大小
|
|
|
|
|
|
* @param {*} value
|
|
|
|
|
|
*/
|
|
|
|
|
|
const formatFileSize = (size: any) => {
|
|
|
|
|
|
const value = Number(size);
|
|
|
|
|
|
if (size && !isNaN(value)) {
|
|
|
|
|
|
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'BB'];
|
|
|
|
|
|
let index = 0;
|
|
|
|
|
|
let k = value;
|
|
|
|
|
|
if (value >= 1024) {
|
|
|
|
|
|
while (k > 1024) {
|
|
|
|
|
|
k = k / 1024;
|
|
|
|
|
|
index++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return `${k.toFixed(2)}${units[index]}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
return '-';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
...toRefs(state),
|
|
|
|
|
|
fileTree,
|
|
|
|
|
|
enums,
|
|
|
|
|
|
token,
|
|
|
|
|
|
add,
|
|
|
|
|
|
getFiles,
|
2022-05-12 10:34:16 +08:00
|
|
|
|
handlePageChange,
|
2021-06-07 17:22:07 +08:00
|
|
|
|
addFiles,
|
|
|
|
|
|
deleteRow,
|
|
|
|
|
|
getConf,
|
|
|
|
|
|
getFileContent,
|
|
|
|
|
|
updateContent,
|
|
|
|
|
|
handleClose,
|
|
|
|
|
|
loadNode,
|
2022-07-04 20:21:24 +08:00
|
|
|
|
showCreateFileDialog,
|
|
|
|
|
|
closeCreateFileDialog,
|
|
|
|
|
|
createFile,
|
2021-06-07 17:22:07 +08:00
|
|
|
|
deleteFile,
|
|
|
|
|
|
downloadFile,
|
|
|
|
|
|
getUploadFile,
|
2021-11-12 14:35:34 +08:00
|
|
|
|
beforeUpload,
|
2022-02-08 17:52:35 +08:00
|
|
|
|
getFilePath,
|
2021-06-07 17:22:07 +08:00
|
|
|
|
uploadSuccess,
|
|
|
|
|
|
dontOperate,
|
|
|
|
|
|
formatFileSize,
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
</style>
|