feat: 修改文件页面样式

pull/105/head
zhengkunwang223 2023-01-31 14:02:29 +08:00 committed by zhengkunwang223
parent 71b17a0930
commit 5100865f7e
13 changed files with 514 additions and 586 deletions

View File

@ -6,7 +6,7 @@
<el-col :span="3"> <el-col :span="3">
<el-avatar shape="square" :size="180" :src="'data:image/png;base64,' + app.icon" /> <el-avatar shape="square" :size="180" :src="'data:image/png;base64,' + app.icon" />
</el-col> </el-col>
<el-col :span="20"> <el-col :span="18">
<div class="detail"> <div class="detail">
<div class="name"> <div class="name">
<span>{{ app.name }}</span> <span>{{ app.name }}</span>
@ -78,7 +78,7 @@
</el-col> </el-col>
</el-row> </el-row>
</div> </div>
<div v-loading="loadingDetail"> <div v-loading="loadingDetail" style="margin-left: -32px">
<v-md-preview :text="appDetail.readme"></v-md-preview> <v-md-preview :text="appDetail.readme"></v-md-preview>
</div> </div>
</template> </template>

View File

@ -1,21 +1,21 @@
<template> <template>
<el-dialog <el-drawer v-model="open" :before-close="handleClose" :close-on-click-modal="false" width="50%">
v-model="open" <template #header>
:before-close="handleClose" <DrawerHeader :header="$t('file.setRole')" :back="handleClose" />
:destroy-on-close="true" </template>
:close-on-click-modal="false"
:title="$t('file.setRole')" <el-row>
width="50%" <el-col :span="22" :offset="1">
@open="onOpen" <FileRole v-loading="loading" :mode="mode" @get-mode="getMode"></FileRole>
> </el-col>
<FileRole v-loading="loading" :mode="mode" @get-mode="getMode"></FileRole> </el-row>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button> <el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
<el-button type="primary" @click="submit()">{{ $t('commons.button.confirm') }}</el-button> <el-button type="primary" @click="submit()">{{ $t('commons.button.confirm') }}</el-button>
</span> </span>
</template> </template>
</el-dialog> </el-drawer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -26,33 +26,24 @@ import i18n from '@/lang';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import FileRole from '@/components/file-role/index.vue'; import FileRole from '@/components/file-role/index.vue';
const props = defineProps({ let open = ref(false);
open: {
type: Boolean,
default: false,
},
file: {
type: Object,
default: function () {
return {};
},
},
});
let form = ref<File.FileCreate>({ path: '', isDir: false, mode: 0o755 }); let form = ref<File.FileCreate>({ path: '', isDir: false, mode: 0o755 });
let loading = ref<Boolean>(false); let loading = ref<Boolean>(false);
let mode = ref('0755'); let mode = ref('0755');
const em = defineEmits(['close']); const em = defineEmits(['close']);
const handleClose = () => { const handleClose = () => {
open.value = false;
em('close', false); em('close', false);
}; };
const onOpen = () => { const acceptParams = (create: File.FileCreate) => {
const f = props.file as File.FileCreate; open.value = true;
form.value.isDir = f.isDir; form.value.isDir = create.isDir;
form.value.path = f.path; form.value.path = create.path;
mode.value = String(f.mode); form.value.isLink = false;
mode.value = String(create.mode);
}; };
const getMode = (val: number) => { const getMode = (val: number) => {
@ -70,4 +61,6 @@ const submit = async () => {
loading.value = false; loading.value = false;
}); });
}; };
defineExpose({ acceptParams });
</script> </script>

View File

@ -2,11 +2,11 @@
<el-dialog <el-dialog
v-model="open" v-model="open"
:title="$t('commons.button.edit')" :title="$t('commons.button.edit')"
@opened="onOpen"
:before-close="handleClose" :before-close="handleClose"
destroy-on-close destroy-on-close
width="70%" width="70%"
draggable draggable
@opened="onOpen"
> >
<div> <div>
<div v-loading="loading"> <div v-loading="loading">
@ -16,43 +16,38 @@
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button> <el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
<el-button type="primary" @click="save()">{{ $t('commons.button.confirm') }}</el-button> <el-button type="primary" @click="saveContent(true)">{{ $t('commons.button.confirm') }}</el-button>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { SaveFileContent } from '@/api/modules/files';
import i18n from '@/lang';
import { ElMessage } from 'element-plus';
import * as monaco from 'monaco-editor'; import * as monaco from 'monaco-editor';
import { reactive } from 'vue'; import { ref } from 'vue';
let editor: monaco.editor.IStandaloneCodeEditor | undefined; let editor: monaco.editor.IStandaloneCodeEditor | undefined;
const props = defineProps({ interface EditProps {
open: { language: string;
type: Boolean, content: string;
default: false, path: string;
}, name: string;
language: { }
type: String,
default: 'json',
},
content: {
type: String,
default: '',
},
loading: {
type: Boolean,
default: false,
},
});
let data = reactive({ let open = ref(false);
let loading = ref(false);
let language = ref('json');
let form = ref({
content: '', content: '',
language: '', path: '',
}); });
const em = defineEmits(['close', 'qsave', 'save']); const em = defineEmits(['close']);
const handleClose = () => { const handleClose = () => {
if (editor) { if (editor) {
@ -61,14 +56,6 @@ const handleClose = () => {
em('close', false); em('close', false);
}; };
const save = () => {
em('save', data.content);
};
const saveNotClose = () => {
em('qsave', data.content);
};
const initEditor = () => { const initEditor = () => {
if (editor) { if (editor) {
editor.dispose(); editor.dispose();
@ -76,26 +63,45 @@ const initEditor = () => {
const codeBox = document.getElementById('codeBox'); const codeBox = document.getElementById('codeBox');
editor = monaco.editor.create(codeBox as HTMLElement, { editor = monaco.editor.create(codeBox as HTMLElement, {
theme: 'vs-dark', //vs, hc-black, or vs-dark theme: 'vs-dark', //vs, hc-black, or vs-dark
value: data.content, value: form.value.content,
readOnly: false, readOnly: false,
automaticLayout: true, automaticLayout: true,
language: data.language, language: language.value,
folding: true, // folding: true, //
roundedSelection: false, // roundedSelection: false, //
}); });
editor.onDidChangeModelContent(() => { editor.onDidChangeModelContent(() => {
if (editor) { if (editor) {
data.content = editor.getValue(); form.value.content = editor.getValue();
} }
}); });
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, saveNotClose); editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, quickSave);
};
const quickSave = () => {
saveContent(false);
};
const saveContent = (closePage: boolean) => {
loading.value = true;
SaveFileContent(form.value).finally(() => {
loading.value = false;
open.value = !closePage;
ElMessage.success(i18n.global.t('commons.msg.updateSuccess'));
});
};
const acceptParams = (props: EditProps) => {
form.value.content = props.content;
form.value.path = props.path;
open.value = true;
}; };
const onOpen = () => { const onOpen = () => {
data.content = props.content;
data.language = props.language;
initEditor(); initEditor();
}; };
defineExpose({ acceptParams });
</script> </script>

View File

@ -1,52 +1,55 @@
<template> <template>
<el-dialog <el-drawer
v-model="open" v-model="open"
:title="title" :title="title"
:destroy-on-close="true" :destroy-on-close="true"
:close-on-click-modal="false" :close-on-click-modal="false"
:before-close="handleClose" :before-close="handleClose"
width="30%" size="50%"
@open="onOpen"
> >
<el-form <el-row>
ref="fileForm" <el-col :span="22" :offset="1">
label-position="left" <el-form
:model="form" ref="fileForm"
label-width="100px" label-position="top"
:rules="rules" :model="form"
v-loading="loading" label-width="100px"
> :rules="rules"
<el-form-item :label="$t('file.compressType')" prop="type"> v-loading="loading"
<el-select v-model="form.type"> >
<el-option v-for="item in options" :key="item" :label="item" :value="item" /> <el-form-item :label="$t('file.compressType')" prop="type">
</el-select> <el-select v-model="form.type">
</el-form-item> <el-option v-for="item in options" :key="item" :label="item" :value="item" />
<el-form-item :label="$t('file.name')" prop="name"> </el-select>
<el-input v-model="form.name"> </el-form-item>
<template #append>{{ extension }}</template> <el-form-item :label="$t('file.name')" prop="name">
</el-input> <el-input v-model="form.name">
</el-form-item> <template #append>{{ extension }}</template>
<el-form-item :label="$t('file.compressDst')" prop="dst"> </el-input>
<el-input v-model="form.dst" disabled> </el-form-item>
<template #append><FileList :path="props.dst" @choose="getLinkPath"></FileList></template> <el-form-item :label="$t('file.compressDst')" prop="dst">
</el-input> <el-input v-model="form.dst" disabled>
</el-form-item> <template #append><FileList :path="form.dst" @choose="getLinkPath"></FileList></template>
<el-form-item> </el-input>
<el-checkbox v-model="form.replace" :label="$t('file.replace')"></el-checkbox> </el-form-item>
</el-form-item> <el-form-item>
</el-form> <el-checkbox v-model="form.replace" :label="$t('file.replace')"></el-checkbox>
</el-form-item>
</el-form>
</el-col>
</el-row>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button> <el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
<el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button> <el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button>
</span> </span>
</template> </template>
</el-dialog> </el-drawer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import i18n from '@/lang'; import i18n from '@/lang';
import { computed, reactive, ref, toRefs } from 'vue'; import { computed, reactive, ref } from 'vue';
import { File } from '@/api/interface/file'; import { File } from '@/api/interface/file';
import { ElMessage, FormInstance, FormRules } from 'element-plus'; import { ElMessage, FormInstance, FormRules } from 'element-plus';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
@ -54,30 +57,12 @@ import { CompressExtention, CompressType } from '@/enums/files';
import { CompressFile } from '@/api/modules/files'; import { CompressFile } from '@/api/modules/files';
import FileList from '@/components/file-list/index.vue'; import FileList from '@/components/file-list/index.vue';
const props = defineProps({ interface CompressProps {
open: { files: Array<any>;
type: Boolean, dst: string;
default: false, name: string;
}, operate: string;
files: { }
type: Array,
default: function () {
return [];
},
},
type: {
type: String,
default: 'compress',
},
dst: {
type: String,
default: '',
},
name: {
type: String,
default: '',
},
});
const rules = reactive<FormRules>({ const rules = reactive<FormRules>({
type: [Rules.requiredSelect], type: [Rules.requiredSelect],
@ -85,18 +70,16 @@ const rules = reactive<FormRules>({
name: [Rules.requiredInput], name: [Rules.requiredInput],
}); });
const { open, files, type, dst, name } = toRefs(props);
const fileForm = ref<FormInstance>(); const fileForm = ref<FormInstance>();
let loading = ref(false); let loading = ref(false);
let form = ref<File.FileCompress>({ files: [], type: 'zip', dst: '', name: '', replace: false }); let form = ref<File.FileCompress>({ files: [], type: 'zip', dst: '', name: '', replace: false });
let options = ref<string[]>([]); let options = ref<string[]>([]);
let open = ref(false);
let title = ref('');
let operate = ref('compress');
const em = defineEmits(['close']); const em = defineEmits(['close']);
const title = computed(() => {
return i18n.global.t('file.' + type.value);
});
const extension = computed(() => { const extension = computed(() => {
return CompressExtention[form.value.type]; return CompressExtention[form.value.type];
}); });
@ -106,26 +89,13 @@ const handleClose = () => {
fileForm.value.resetFields(); fileForm.value.resetFields();
} }
em('close', open); em('close', open);
open.value = false;
}; };
const getLinkPath = (path: string) => { const getLinkPath = (path: string) => {
form.value.dst = path; form.value.dst = path;
}; };
const onOpen = () => {
form.value = {
dst: dst.value,
type: 'zip',
files: files.value as string[],
name: name.value,
replace: false,
};
options.value = [];
for (const t in CompressType) {
options.value.push(CompressType[t]);
}
};
const submit = async (formEl: FormInstance | undefined) => { const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return; if (!formEl) return;
await formEl.validate((valid) => { await formEl.validate((valid) => {
@ -146,4 +116,21 @@ const submit = async (formEl: FormInstance | undefined) => {
}); });
}); });
}; };
const acceptParams = (props: CompressProps) => {
form.value.files = props.files;
form.value.dst = props.dst;
form.value.name = props.name;
operate.value = props.operate;
options.value = [];
for (const t in CompressType) {
options.value.push(CompressType[t]);
}
open.value = true;
title.value = i18n.global.t('file.' + props.operate);
};
defineExpose({ acceptParams });
</script> </script>

View File

@ -1,46 +1,54 @@
<template> <template>
<el-dialog <el-drawer
v-model="open" v-model="open"
:before-close="handleClose" :before-close="handleClose"
:destroy-on-close="true" :destroy-on-close="true"
:close-on-click-modal="false" :close-on-click-modal="false"
:title="$t('commons.button.create')" size="40%"
width="50%"
@open="onOpen"
> >
<el-form <template #header>
ref="fileForm" <DrawerHeader :header="$t('commons.button.create')" :back="handleClose" />
label-position="left" </template>
:model="addForm"
label-width="100px" <el-row>
:rules="rules" <el-col :span="22" :offset="1">
v-loading="loading" <el-form
> ref="fileForm"
<el-form-item :label="$t('file.path')" prop="path"><el-input v-model="getPath" disabled /></el-form-item> label-position="top"
<el-form-item :label="$t('file.name')" prop="name"><el-input v-model="addForm.name" /></el-form-item> :model="addForm"
<el-form-item v-if="!addForm.isDir"> label-width="100px"
<el-checkbox v-model="addForm.isLink" :label="$t('file.link')"></el-checkbox> :rules="rules"
</el-form-item> v-loading="loading"
<el-form-item :label="$t('file.linkType')" v-if="addForm.isLink" prop="linkType"> >
<el-radio-group v-model="addForm.isSymlink"> <el-form-item :label="$t('file.path')" prop="path">
<el-radio :label="true">{{ $t('file.softLink') }}</el-radio> <el-input v-model="getPath" disabled />
<el-radio :label="false">{{ $t('file.hardLink') }}</el-radio> </el-form-item>
</el-radio-group> <el-form-item :label="$t('file.name')" prop="name">
</el-form-item> <el-input v-model="addForm.name" />
<el-form-item v-if="addForm.isLink" :label="$t('file.linkPath')" prop="linkPath"> </el-form-item>
<el-input v-model="addForm.linkPath"> <el-form-item v-if="!addForm.isDir">
<template #append> <el-checkbox v-model="addForm.isLink" :label="$t('file.link')"></el-checkbox>
<FileList @choose="getLinkPath"></FileList> </el-form-item>
</template> <el-form-item :label="$t('file.linkType')" v-if="addForm.isLink" prop="linkType">
</el-input> <el-radio-group v-model="addForm.isSymlink">
</el-form-item> <el-radio :label="true">{{ $t('file.softLink') }}</el-radio>
<el-form-item> <el-radio :label="false">{{ $t('file.hardLink') }}</el-radio>
<el-checkbox v-if="addForm.isDir" v-model="setRole" :label="$t('file.setRole')"></el-checkbox> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item v-if="addForm.isLink" :label="$t('file.linkPath')" prop="linkPath">
<el-input v-model="addForm.linkPath">
<template #append>
<FileList @choose="getLinkPath"></FileList>
</template>
</el-input>
</el-form-item>
<el-form-item>
<el-checkbox v-if="addForm.isDir" v-model="setRole" :label="$t('file.setRole')"></el-checkbox>
</el-form-item>
</el-form>
<FileRole v-if="setRole" :mode="'0755'" @get-mode="getMode"></FileRole> <FileRole v-if="setRole" :mode="'0755'" @get-mode="getMode"></FileRole>
</el-form-item> </el-col>
</el-form> </el-row>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
@ -48,11 +56,11 @@
<el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button> <el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button>
</span> </span>
</template> </template>
</el-dialog> </el-drawer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { toRefs, ref, reactive, computed } from 'vue'; import { ref, reactive, computed } from 'vue';
import { File } from '@/api/interface/file'; import { File } from '@/api/interface/file';
import { ElMessage, FormInstance, FormRules } from 'element-plus'; import { ElMessage, FormInstance, FormRules } from 'element-plus';
import { CreateFile } from '@/api/modules/files'; import { CreateFile } from '@/api/modules/files';
@ -65,16 +73,18 @@ const fileForm = ref<FormInstance>();
let loading = ref(false); let loading = ref(false);
let setRole = ref(false); let setRole = ref(false);
const props = defineProps({ interface CreateProps {
open: Boolean, file: Object;
file: Object, }
const propData = ref<CreateProps>({
file: {},
}); });
const { open, file } = toRefs(props);
let addForm = reactive({ path: '', name: '', isDir: false, mode: 0o755, isLink: false, isSymlink: true, linkPath: '' }); let addForm = reactive({ path: '', name: '', isDir: false, mode: 0o755, isLink: false, isSymlink: true, linkPath: '' });
let open = ref(false);
const em = defineEmits(['close']); const em = defineEmits(['close']);
const handleClose = () => { const handleClose = () => {
open.value = false;
if (fileForm.value) { if (fileForm.value) {
fileForm.value.resetFields(); fileForm.value.resetFields();
} }
@ -126,16 +136,20 @@ const submit = async (formEl: FormInstance | undefined) => {
}); });
}; };
const onOpen = () => { const acceptParams = (create: File.FileCreate) => {
const f = file?.value as File.FileCreate; propData.value.file = create;
addForm.isDir = f.isDir; open.value = true;
addForm.path = f.path; addForm.isDir = create.isDir;
addForm.path = create.path;
addForm.name = ''; addForm.name = '';
addForm.isLink = false; addForm.isLink = false;
init(); init();
}; };
const init = () => { const init = () => {
setRole.value = false; setRole.value = false;
}; };
defineExpose({ acceptParams });
</script> </script>

View File

@ -1,44 +1,41 @@
<template> <template>
<div> <el-drawer
<el-dialog v-model="open"
v-model="open" :title="$t('file.deCompress')"
:title="$t('file.deCompress')" :destroy-on-close="true"
:destroy-on-close="true" :close-on-click-modal="false"
:close-on-click-modal="false" :before-close="handleClose"
:before-close="handleClose" size="30%"
width="30%" >
@open="onOpen" <el-form
ref="fileForm"
label-position="left"
:model="form"
label-width="100px"
:rules="rules"
v-loading="loading"
> >
<el-form <el-form-item :label="$t('file.name')">
ref="fileForm" <el-input v-model="name" disabled></el-input>
label-position="left" </el-form-item>
:model="form" <el-form-item :label="$t('file.deCompressDst')" prop="dst">
label-width="100px" <el-input v-model="form.dst" disabled>
:rules="rules" <template #append><FileList :path="form.dst" @choose="getLinkPath"></FileList></template>
v-loading="loading" </el-input>
> </el-form-item>
<el-form-item :label="$t('file.name')"> </el-form>
<el-input v-model="name" disabled></el-input> <template #footer>
</el-form-item> <span class="dialog-footer">
<el-form-item :label="$t('file.deCompressDst')" prop="dst"> <el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
<el-input v-model="form.dst" disabled> <el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button>
<template #append><FileList :path="props.dst" @choose="getLinkPath"></FileList></template> </span>
</el-input> </template>
</el-form-item> </el-drawer>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
<el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button>
</span>
</template>
</el-dialog>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import i18n from '@/lang'; import i18n from '@/lang';
import { reactive, ref, toRefs } from 'vue'; import { reactive, ref } from 'vue';
import { File } from '@/api/interface/file'; import { File } from '@/api/interface/file';
import { ElMessage, FormInstance, FormRules } from 'element-plus'; import { ElMessage, FormInstance, FormRules } from 'element-plus';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
@ -46,37 +43,23 @@ import { DeCompressFile } from '@/api/modules/files';
import { Mimetypes } from '@/global/mimetype'; import { Mimetypes } from '@/global/mimetype';
import FileList from '@/components/file-list/index.vue'; import FileList from '@/components/file-list/index.vue';
const props = defineProps({ interface CompressProps {
open: { files: Array<any>;
type: Boolean, dst: string;
default: false, name: string;
}, path: string;
dst: { mimeType: string;
type: String, }
default: '',
},
path: {
type: String,
default: '',
},
name: {
type: String,
default: '',
},
mimeType: {
type: String,
default: '',
},
});
const rules = reactive<FormRules>({ const rules = reactive<FormRules>({
dst: [Rules.requiredInput], dst: [Rules.requiredInput],
}); });
const { open, dst, path, name, mimeType } = toRefs(props);
const fileForm = ref<FormInstance>(); const fileForm = ref<FormInstance>();
let loading = ref(false); let loading = ref(false);
let form = ref<File.FileDeCompress>({ type: 'zip', dst: '', path: '' }); let form = ref<File.FileDeCompress>({ type: 'zip', dst: '', path: '' });
let open = ref(false);
let name = ref('');
const em = defineEmits(['close']); const em = defineEmits(['close']);
@ -84,6 +67,7 @@ const handleClose = () => {
if (fileForm.value) { if (fileForm.value) {
fileForm.value.resetFields(); fileForm.value.resetFields();
} }
open.value = false;
em('close', open); em('close', open);
}; };
@ -99,14 +83,6 @@ const getLinkPath = (path: string) => {
form.value.dst = path; form.value.dst = path;
}; };
const onOpen = () => {
form.value = {
dst: dst.value,
type: getFileType(mimeType.value),
path: path.value,
};
};
const submit = async (formEl: FormInstance | undefined) => { const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return; if (!formEl) return;
await formEl.validate((valid) => { await formEl.validate((valid) => {
@ -124,4 +100,14 @@ const submit = async (formEl: FormInstance | undefined) => {
}); });
}); });
}; };
const acceptParams = (props: CompressProps) => {
form.value.type = getFileType(props.mimeType);
form.value.dst = props.dst;
form.value.path = props.path;
name.value = props.name;
open.value = true;
};
defineExpose({ acceptParams });
</script> </script>

View File

@ -1,5 +1,5 @@
<template> <template>
<el-dialog v-model="open" :title="$t('file.info')" :column="1" width="30%"> <el-drawer v-model="open" :title="$t('file.info')" :column="1" width="30%">
<el-row> <el-row>
<el-col> <el-col>
<el-descriptions :column="1" border> <el-descriptions :column="1" border>
@ -16,7 +16,7 @@
</el-descriptions> </el-descriptions>
</el-col> </el-col>
</el-row> </el-row>
</el-dialog> </el-drawer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>

View File

@ -1,80 +1,70 @@
<template> <template>
<div> <el-drawer
<el-dialog v-model="open"
v-model="open" :title="$t('file.download')"
:title="$t('file.download')" :destroy-on-close="true"
:destroy-on-close="true" :close-on-click-modal="false"
:close-on-click-modal="false" :before-close="handleClose"
:before-close="handleClose" size="30%"
width="30%" >
@open="onOpen" <el-row>
> <el-col :span="11" :offset="1">
<el-form <el-form
ref="fileForm" ref="fileForm"
label-position="left" label-position="top"
:model="addForm" :model="addForm"
label-width="100px" label-width="100px"
:rules="rules" :rules="rules"
v-loading="loading" v-loading="loading"
> >
<el-form-item :label="$t('file.compressType')" prop="type"> <el-form-item :label="$t('file.compressType')" prop="type">
<el-select v-model="addForm.type"> <el-select v-model="addForm.type">
<el-option v-for="item in options" :key="item" :label="item" :value="item" /> <el-option v-for="item in options" :key="item" :label="item" :value="item" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item :label="$t('file.name')" prop="name"> <el-form-item :label="$t('file.name')" prop="name">
<el-input v-model="addForm.name"> <el-input v-model="addForm.name">
<template #append>{{ extension }}</template> <template #append>{{ extension }}</template>
</el-input> </el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> </el-col>
<span class="dialog-footer"> </el-row>
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button> <template #footer>
<el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button> <span class="dialog-footer">
</span> <el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
</template> <el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button>
</el-dialog> </span>
</div> </template>
</el-drawer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { FormInstance, FormRules } from 'element-plus'; import { FormInstance, FormRules } from 'element-plus';
import { CompressExtention, CompressType } from '@/enums/files'; import { CompressExtention, CompressType } from '@/enums/files';
import { computed, PropType, reactive, ref, toRefs } from 'vue'; import { computed, reactive, ref } from 'vue';
import { DownloadFile } from '@/api/modules/files'; import { DownloadFile } from '@/api/modules/files';
import { File } from '@/api/interface/file'; import { File } from '@/api/interface/file';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
const props = defineProps({ interface DownloadProps {
open: { paths: Array<string>;
type: Boolean, name: string;
default: false, }
},
paths: {
type: Array as PropType<string[]>,
default: function () {
return [];
},
},
name: {
type: String,
default: '',
},
});
const rules = reactive<FormRules>({ const rules = reactive<FormRules>({
name: [Rules.requiredInput], name: [Rules.requiredInput],
type: [Rules.requiredInput], type: [Rules.requiredInput],
}); });
const { open } = toRefs(props);
const fileForm = ref<FormInstance>(); const fileForm = ref<FormInstance>();
const options = ref<string[]>([]); const options = ref<string[]>([]);
let loading = ref(false); let loading = ref(false);
let open = ref(false);
const em = defineEmits(['close']); const em = defineEmits(['close']);
const handleClose = () => { const handleClose = () => {
open.value = false;
if (fileForm.value) { if (fileForm.value) {
fileForm.value.resetFields(); fileForm.value.resetFields();
} }
@ -91,18 +81,18 @@ const extension = computed(() => {
return CompressExtention[addForm.value.type]; return CompressExtention[addForm.value.type];
}); });
const onOpen = () => { // const onOpen = () => {
addForm.value = { // addForm.value = {
type: 'zip', // type: 'zip',
paths: props.paths, // paths: props.paths,
name: props.name, // name: props.name,
}; // };
console.log(addForm); // console.log(addForm);
options.value = []; // options.value = [];
for (const t in CompressType) { // for (const t in CompressType) {
options.value.push(CompressType[t]); // options.value.push(CompressType[t]);
} // }
}; // };
const submit = async (formEl: FormInstance | undefined) => { const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return; if (!formEl) return;
@ -130,4 +120,16 @@ const submit = async (formEl: FormInstance | undefined) => {
}); });
}); });
}; };
const acceptParams = (props: DownloadProps) => {
addForm.value.paths = props.paths;
addForm.value.name = props.name;
addForm.value.type = 'zip';
options.value = [];
for (const t in CompressType) {
options.value.push(CompressType[t]);
}
open.value = true;
};
defineExpose({ acceptParams });
</script> </script>

View File

@ -5,7 +5,7 @@
<el-button :icon="Refresh" circle @click="search" /> <el-button :icon="Refresh" circle @click="search" />
</el-col> </el-col>
<el-col :span="22"> <el-col :span="22">
<div style="background-color: #ffffff"> <div class="path">
<BreadCrumbs> <BreadCrumbs>
<BreadCrumbItem @click="jump(-1)" :right="paths.length == 0">/</BreadCrumbItem> <BreadCrumbItem @click="jump(-1)" :right="paths.length == 0">/</BreadCrumbItem>
<BreadCrumbItem <BreadCrumbItem
@ -23,7 +23,7 @@
<LayoutContent :title="$t('file.file')" v-loading="loading"> <LayoutContent :title="$t('file.file')" v-loading="loading">
<template #toolbar> <template #toolbar>
<el-dropdown @command="handleCreate"> <el-dropdown @command="handleCreate">
<el-button type="primary" icon="Plus"> <el-button type="primary">
{{ $t('commons.button.create') }} {{ $t('commons.button.create') }}
<el-icon class="el-icon--right"><arrow-down /></el-icon> <el-icon class="el-icon--right"><arrow-down /></el-icon>
</el-button> </el-button>
@ -114,55 +114,24 @@
</ComplexTable> </ComplexTable>
</template> </template>
<CreateFile :open="filePage.open" :file="filePage.createForm" @close="closeCreate"></CreateFile> <CreateFile ref="createRef" @close="search" />
<ChangeRole :open="modePage.open" :file="modePage.modeForm" @close="closeMode"></ChangeRole> <ChangeRole ref="roleRef" @close="search" />
<Compress <Compress ref="compressRef" @close="search" />
:open="compressPage.open" <Decompress ref="deCompressRef" @close="search" />
:files="compressPage.files" <CodeEditor ref="codeEditorRef" @close="search" />
:dst="compressPage.dst" <FileRename ref="renameRef" @close="search" />
:name="compressPage.name" <Upload ref="uploadRef" @close="search" />
@close="closeCompress" <Wget ref="wgetRef" @close="closeWget" />
></Compress> <Move ref="moveRef" @close="search" />
<Decompress <Download ref="downloadRef" @close="search" />
:open="deCompressPage.open" <Process :open="processPage.open" @close="closeProcess" />
:dst="deCompressPage.dst" <Detail ref="detailRef" />
:path="deCompressPage.path"
:name="deCompressPage.name"
:mimeType="deCompressPage.mimeType"
@close="closeDeCompress"
></Decompress>
<CodeEditor
:open="editorPage.open"
:language="'json'"
:content="editorPage.content"
:loading="editorPage.loading"
@close="closeCodeEditor"
@qsave="quickSave"
@save="saveContent"
></CodeEditor>
<FileRename
:open="renamePage.open"
:path="renamePage.path"
:oldName="renamePage.oldName"
@close="closeRename"
></FileRename>
<Upload :open="uploadPage.open" :path="uploadPage.path" @close="closeUpload"></Upload>
<Wget :open="wgetPage.open" :path="wgetPage.path" @close="closeWget"></Wget>
<Move :open="movePage.open" :oldPaths="movePage.oldPaths" :type="movePage.type" @close="clodeMove"></Move>
<Download
:open="downloadPage.open"
:paths="downloadPage.paths"
:name="downloadPage.name"
@close="closeDownload"
></Download>
<Process :open="processPage.open" @close="closeProcess"></Process>
<Detail ref="detailRef"></Detail>
</LayoutContent> </LayoutContent>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, reactive, ref } from '@vue/runtime-core'; import { onMounted, reactive, ref } from '@vue/runtime-core';
import { GetFilesList, DeleteFile, GetFileContent, SaveFileContent, ComputeDirSize } from '@/api/modules/files'; import { GetFilesList, DeleteFile, GetFileContent, ComputeDirSize } from '@/api/modules/files';
import { computeSize, dateFormat, getIcon, getRandomStr } from '@/utils/util'; import { computeSize, dateFormat, getIcon, getRandomStr } from '@/utils/util';
import { File } from '@/api/interface/file'; import { File } from '@/api/interface/file';
import { useDeleteData } from '@/hooks/use-delete-data'; import { useDeleteData } from '@/hooks/use-delete-data';
@ -195,19 +164,29 @@ let req = reactive({ path: '/', expand: true, showHidden: false, page: 1, pageSi
let loading = ref(false); let loading = ref(false);
const paths = ref<string[]>([]); const paths = ref<string[]>([]);
const filePage = reactive({ open: false, createForm: { path: '/', isDir: false, mode: 0o755 } }); const fileCreate = reactive({ path: '/', isDir: false, mode: 0o755 });
const modePage = reactive({ open: false, modeForm: { path: '/', isDir: false, mode: 0o755 } }); const fileCompress = reactive({ files: [''], name: '', dst: '', operate: 'compress' });
const compressPage = reactive({ open: false, files: [''], name: '', dst: '' }); const fileDeCompress = reactive({ path: '', name: '', dst: '', mimeType: '' });
const deCompressPage = reactive({ open: false, path: '', name: '', dst: '', mimeType: '' }); const fileEdit = reactive({ content: '', path: '', name: '' });
const editorPage = reactive({ open: false, content: '', loading: false });
const codeReq = reactive({ path: '', expand: false, page: 1, pageSize: 100 }); const codeReq = reactive({ path: '', expand: false, page: 1, pageSize: 100 });
const uploadPage = reactive({ open: false, path: '' }); const fileUpload = reactive({ path: '' });
const renamePage = reactive({ open: false, path: '', oldName: '' }); const fileRename = reactive({ path: '', oldName: '' });
const wgetPage = reactive({ open: false, path: '' }); const fileWget = reactive({ path: '' });
const movePage = reactive({ open: false, oldPaths: [''], type: '' }); const fileMove = reactive({ oldPaths: [''], type: '' });
const downloadPage = reactive({ open: false, paths: [''], name: '' }); const fileDownload = reactive({ paths: [''], name: '' });
const processPage = reactive({ open: false }); const processPage = reactive({ open: false });
const createRef = ref();
const roleRef = ref();
const detailRef = ref(); const detailRef = ref();
const compressRef = ref();
const deCompressRef = ref();
const codeEditorRef = ref();
const renameRef = ref();
const uploadRef = ref();
const wgetRef = ref();
const moveRef = ref();
const downloadRef = ref();
const paginationConfig = reactive({ const paginationConfig = reactive({
currentPage: 1, currentPage: 1,
@ -269,12 +248,12 @@ const jump = async (index: number) => {
}; };
const handleCreate = (commnad: string) => { const handleCreate = (commnad: string) => {
filePage.createForm.path = req.path; fileCreate.path = req.path;
filePage.createForm.isDir = false; fileCreate.isDir = false;
if (commnad === 'dir') { if (commnad === 'dir') {
filePage.createForm.isDir = true; fileCreate.isDir = true;
} }
filePage.open = true; createRef.value.acceptParams(fileCreate);
}; };
const delFile = async (row: File.File | null) => { const delFile = async (row: File.File | null) => {
@ -304,39 +283,24 @@ const getIconName = (extension: string) => {
return getIcon(extension); return getIcon(extension);
}; };
const closeCreate = () => {
filePage.open = false;
search();
};
const openMode = (item: File.File) => { const openMode = (item: File.File) => {
modePage.modeForm = item; roleRef.value.acceptParams(item);
modePage.open = true;
};
const closeMode = () => {
modePage.open = false;
search();
}; };
const openCompress = (items: File.File[]) => { const openCompress = (items: File.File[]) => {
compressPage.open = true;
const paths = []; const paths = [];
for (const item of items) { for (const item of items) {
paths.push(item.path); paths.push(item.path);
} }
compressPage.files = paths; fileCompress.files = paths;
if (paths.length === 1) { if (paths.length === 1) {
compressPage.name = items[0].name; fileCompress.name = items[0].name;
} else { } else {
compressPage.name = getRandomStr(6); fileCompress.name = getRandomStr(6);
} }
compressPage.dst = req.path; fileCompress.dst = req.path;
};
const closeCompress = () => { compressRef.value.acceptParams(fileCompress);
compressPage.open = false;
search();
}; };
const openDeCompress = (item: File.File) => { const openDeCompress = (item: File.File) => {
@ -345,48 +309,36 @@ const openDeCompress = (item: File.File) => {
return; return;
} }
deCompressPage.open = true; fileDeCompress.name = item.name;
deCompressPage.name = item.name; fileDeCompress.path = item.path;
deCompressPage.path = item.path; fileDeCompress.dst = req.path;
deCompressPage.dst = req.path; fileDeCompress.mimeType = item.mimeType;
deCompressPage.mimeType = item.mimeType;
};
const closeDeCompress = () => { deCompressRef.value.acceptParams(fileDeCompress);
deCompressPage.open = false;
search();
}; };
const openCodeEditor = (row: File.File) => { const openCodeEditor = (row: File.File) => {
codeReq.path = row.path; codeReq.path = row.path;
codeReq.expand = true; codeReq.expand = true;
GetFileContent(codeReq).then((res) => { GetFileContent(codeReq).then((res) => {
editorPage.content = res.data.content; fileEdit.content = res.data.content;
editorPage.open = true; fileEdit.path = res.data.path;
fileEdit.name = res.data.name;
codeEditorRef.value.acceptParams(fileEdit);
}); });
}; };
const closeCodeEditor = () => {
editorPage.open = false;
};
const openUpload = () => { const openUpload = () => {
uploadPage.open = true; fileUpload.path = req.path;
uploadPage.path = req.path; uploadRef.value.acceptParams(fileUpload);
};
const closeUpload = () => {
uploadPage.open = false;
search();
}; };
const openWget = () => { const openWget = () => {
wgetPage.open = true; fileWget.path = req.path;
wgetPage.path = req.path; wgetRef.value.acceptParams(fileWget);
}; };
const closeWget = (submit: any) => { const closeWget = (submit: any) => {
wgetPage.open = false;
search(); search();
if (submit) { if (submit) {
openProcess(); openProcess();
@ -402,29 +354,19 @@ const closeProcess = () => {
}; };
const openRename = (item: File.File) => { const openRename = (item: File.File) => {
renamePage.open = true; fileRename.path = req.path;
renamePage.path = req.path; fileRename.oldName = item.name;
renamePage.oldName = item.name; renameRef.value.acceptParams(fileRename);
};
const closeRename = () => {
renamePage.open = false;
search();
}; };
const openMove = (type: string) => { const openMove = (type: string) => {
movePage.type = type; fileMove.type = type;
const oldpaths = []; const oldpaths = [];
for (const s of selects.value) { for (const s of selects.value) {
oldpaths.push(s['path']); oldpaths.push(s['path']);
} }
movePage.oldPaths = oldpaths; fileMove.oldPaths = oldpaths;
movePage.open = true; moveRef.value.acceptParams(fileMove);
};
const clodeMove = () => {
movePage.open = false;
search();
}; };
const openDownload = () => { const openDownload = () => {
@ -432,31 +374,31 @@ const openDownload = () => {
for (const s of selects.value) { for (const s of selects.value) {
paths.push(s['path']); paths.push(s['path']);
} }
downloadPage.paths = paths; fileDownload.paths = paths;
downloadPage.name = getRandomStr(6); fileDownload.name = getRandomStr(6);
downloadPage.open = true; downloadRef.value.acceptParams(fileDownload);
}; };
const closeDownload = () => { // const closeDownload = () => {
downloadPage.open = false; // downloadPage.open = false;
search(); // search();
}; // };
const saveContent = (content: string) => { // const saveContent = (content: string) => {
editorPage.loading = true; // editorPage.loading = true;
SaveFileContent({ path: codeReq.path, content: content }).finally(() => { // SaveFileContent({ path: codeReq.path, content: content }).finally(() => {
editorPage.loading = false; // editorPage.loading = false;
editorPage.open = false; // editorPage.open = false;
ElMessage.success(i18n.global.t('commons.msg.updateSuccess')); // ElMessage.success(i18n.global.t('commons.msg.updateSuccess'));
}); // });
}; // };
const quickSave = (content: string) => { // const quickSave = (content: string) => {
editorPage.loading = true; // editorPage.loading = true;
SaveFileContent({ path: codeReq.path, content: content }).finally(() => { // SaveFileContent({ path: codeReq.path, content: content }).finally(() => {
editorPage.loading = false; // editorPage.loading = false;
ElMessage.success(i18n.global.t('commons.msg.updateSuccess')); // ElMessage.success(i18n.global.t('commons.msg.updateSuccess'));
}); // });
}; // };
const openDetail = (row: File.File) => { const openDetail = (row: File.File) => {
detailRef.value.acceptParams({ path: row.path }); detailRef.value.acceptParams({ path: row.path });
@ -508,8 +450,7 @@ onMounted(() => {
<style> <style>
.path { .path {
height: 30px; background-color: #ffffff;
margin-bottom: 5px;
} }
.search-button { .search-button {

View File

@ -1,12 +1,11 @@
<template> <template>
<el-dialog <el-drawer
v-model="open" v-model="open"
:title="title" :title="title"
:destroy-on-close="true" :destroy-on-close="true"
:close-on-click-modal="false" :close-on-click-modal="false"
:before-close="handleClose" :before-close="handleClose"
width="30%" size="30%"
@open="onOpen"
> >
<el-form <el-form
ref="fileForm" ref="fileForm"
@ -30,7 +29,7 @@
</el-button> </el-button>
</span> </span>
</template> </template>
</el-dialog> </el-drawer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -38,32 +37,21 @@ import { MoveFile } from '@/api/modules/files';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
import i18n from '@/lang'; import i18n from '@/lang';
import { ElMessage, FormInstance, FormRules } from 'element-plus'; import { ElMessage, FormInstance, FormRules } from 'element-plus';
import { toRefs, ref, reactive, PropType, computed } from 'vue'; import { ref, reactive, computed } from 'vue';
import FileList from '@/components/file-list/index.vue'; import FileList from '@/components/file-list/index.vue';
const props = defineProps({ interface MoveProps {
open: { oldPaths: Array<string>;
type: Boolean, type: string;
default: false, }
},
oldPaths: {
type: Array as PropType<string[]>,
default: () => {
return [];
},
},
type: {
type: String,
default: '',
},
});
const { open } = toRefs(props);
const fileForm = ref<FormInstance>(); const fileForm = ref<FormInstance>();
const loading = ref(false); const loading = ref(false);
let open = ref(false);
let type = ref('cut');
const title = computed(() => { const title = computed(() => {
if (props.type === 'cut') { if (type.value === 'cut') {
return i18n.global.t('file.move'); return i18n.global.t('file.move');
} else { } else {
return i18n.global.t('file.copy'); return i18n.global.t('file.copy');
@ -83,6 +71,7 @@ const rules = reactive<FormRules>({
const em = defineEmits(['close']); const em = defineEmits(['close']);
const handleClose = () => { const handleClose = () => {
open.value = false;
if (fileForm.value) { if (fileForm.value) {
fileForm.value.resetFields(); fileForm.value.resetFields();
} }
@ -111,8 +100,12 @@ const submit = async (formEl: FormInstance | undefined) => {
}); });
}; };
const onOpen = () => { const acceptParams = (props: MoveProps) => {
addForm.oldPaths = props.oldPaths; addForm.oldPaths = props.oldPaths;
addForm.type = props.type; addForm.type = props.type;
type.value = props.type;
open.value = true;
}; };
defineExpose({ acceptParams });
</script> </script>

View File

@ -1,53 +1,50 @@
<template> <template>
<el-dialog v-model="open" :before-close="handleClose" :title="$t('file.setRole')" width="30%" @open="onOpen"> <el-drawer v-model="open" :before-close="handleClose" :title="$t('file.rename')" size="30%">
<el-form <el-row>
ref="fileForm" <el-col :span="22" :offset="1">
label-position="left" <el-form
:model="addForm" ref="fileForm"
label-width="100px" label-position="top"
:rules="rules" :model="addForm"
v-loading="loading" label-width="100px"
> :rules="rules"
<el-form-item :label="$t('file.path')" prop="path"> v-loading="loading"
<el-input v-model="props.path" disabled /> >
</el-form-item> <el-form-item :label="$t('file.path')" prop="path">
<el-form-item :label="$t('file.name')" prop="newName"><el-input v-model="addForm.newName" /></el-form-item> <el-input v-model="addForm.path" disabled />
</el-form> </el-form-item>
<el-form-item :label="$t('file.name')" prop="newName">
<el-input v-model="addForm.newName" />
</el-form-item>
</el-form>
</el-col>
</el-row>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button> <el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
<el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button> <el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button>
</span> </span>
</template> </template>
</el-dialog> </el-drawer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { RenameRile } from '@/api/modules/files'; import { RenameRile } from '@/api/modules/files';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
import { ElMessage, FormInstance, FormRules } from 'element-plus'; import { ElMessage, FormInstance, FormRules } from 'element-plus';
import { reactive, ref, toRefs } from 'vue'; import { reactive, ref } from 'vue';
import { File } from '@/api/interface/file'; import { File } from '@/api/interface/file';
import i18n from '@/lang'; import i18n from '@/lang';
const props = defineProps({ interface RenameProps {
open: { path: string;
type: Boolean, oldName: string;
default: false, }
},
oldName: {
type: String,
default: '',
},
path: {
type: String,
default: '',
},
});
const { open } = toRefs(props);
const fileForm = ref<FormInstance>(); const fileForm = ref<FormInstance>();
const loading = ref(false); const loading = ref(false);
let open = ref(false);
const oldName = ref('');
const addForm = reactive({ const addForm = reactive({
newName: '', newName: '',
@ -60,6 +57,7 @@ const rules = reactive<FormRules>({
const em = defineEmits(['close']); const em = defineEmits(['close']);
const handleClose = () => { const handleClose = () => {
open.value = false;
if (fileForm.value) { if (fileForm.value) {
fileForm.value.resetFields(); fileForm.value.resetFields();
} }
@ -78,8 +76,8 @@ const submit = async (formEl: FormInstance | undefined) => {
let addItem = {}; let addItem = {};
Object.assign(addItem, addForm); Object.assign(addItem, addForm);
addItem['oldName'] = getPath(props.path, props.oldName); addItem['oldName'] = getPath(addForm.path, oldName.value);
addItem['newName'] = getPath(props.path, addForm.newName); addItem['newName'] = getPath(addForm.path, addForm.newName);
loading.value = true; loading.value = true;
RenameRile(addItem as File.FileRename) RenameRile(addItem as File.FileRename)
.then(() => { .then(() => {
@ -92,7 +90,12 @@ const submit = async (formEl: FormInstance | undefined) => {
}); });
}; };
const onOpen = () => { const acceptParams = (props: RenameProps) => {
oldName.value = props.oldName;
addForm.newName = props.oldName; addForm.newName = props.oldName;
addForm.path = props.path;
open.value = true;
}; };
defineExpose({ acceptParams });
</script> </script>

View File

@ -1,5 +1,5 @@
<template> <template>
<el-dialog v-model="open" :title="$t('file.upload')" :before-close="handleClose" width="30%" :file-list="files"> <el-drawer v-model="open" :title="$t('file.upload')" :before-close="handleClose" size="40%" :file-list="files">
<el-upload <el-upload
action="#" action="#"
:auto-upload="false" :auto-upload="false"
@ -21,7 +21,7 @@
</el-button> </el-button>
</span> </span>
</template> </template>
</el-dialog> </el-drawer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -30,24 +30,20 @@ import { ElMessage, UploadFile, UploadFiles, UploadInstance } from 'element-plus
import { UploadFileData } from '@/api/modules/files'; import { UploadFileData } from '@/api/modules/files';
import i18n from '@/lang'; import i18n from '@/lang';
const props = defineProps({ interface UploadProps {
open: { path: string;
type: Boolean, }
default: false,
},
path: {
type: String,
default: '',
},
});
const uploadRef = ref<UploadInstance>(); const uploadRef = ref<UploadInstance>();
const files = ref(); const files = ref();
const loading = ref(false); const loading = ref(false);
let uploadPrecent = ref(0); let uploadPrecent = ref(0);
let open = ref(false);
let path = ref();
const em = defineEmits(['close']); const em = defineEmits(['close']);
const handleClose = () => { const handleClose = () => {
open.value = false;
uploadRef.value!.clearFiles(); uploadRef.value!.clearFiles();
em('close', false); em('close', false);
}; };
@ -70,7 +66,7 @@ const submit = () => {
formData.append('file', file.raw); formData.append('file', file.raw);
} }
} }
formData.append('path', props.path); formData.append('path', path.value);
loading.value = true; loading.value = true;
UploadFileData(formData, { onUploadProgress: onProcess }) UploadFileData(formData, { onUploadProgress: onProcess })
.then(() => { .then(() => {
@ -81,4 +77,11 @@ const submit = () => {
loading.value = false; loading.value = false;
}); });
}; };
const acceptParams = (props: UploadProps) => {
path.value = props.path;
open.value = true;
};
defineExpose({ acceptParams });
</script> </script>

View File

@ -1,34 +1,38 @@
<template> <template>
<el-dialog v-model="open" :before-close="handleClose" :title="$t('file.download')" width="30%" @open="onOpen"> <el-drawer v-model="open" :before-close="handleClose" :title="$t('file.download')" size="50%">
<el-form <el-row>
ref="fileForm" <el-col :span="22" :offset="1">
label-position="left" <el-form
:model="addForm" ref="fileForm"
label-width="100px" label-position="top"
:rules="rules" :model="addForm"
v-loading="loading" label-width="100px"
> :rules="rules"
<el-form-item :label="$t('file.downloadUrl')" prop="url"> v-loading="loading"
<el-input v-model="addForm.url" @input="getFileName" /> >
</el-form-item> <el-form-item :label="$t('file.downloadUrl')" prop="url">
<el-form-item :label="$t('file.path')" prop="path"> <el-input v-model="addForm.url" @input="getFileName" />
<el-input v-model="addForm.path" disabled> </el-form-item>
<template #append><FileList :path="path" @choose="getPath"></FileList></template> <el-form-item :label="$t('file.path')" prop="path">
</el-input> <el-input v-model="addForm.path" disabled>
</el-form-item> <template #append><FileList :path="addForm.path" @choose="getPath"></FileList></template>
<el-form-item :label="$t('file.name')" prop="name"> </el-input>
<el-input v-model="addForm.name"></el-input> </el-form-item>
</el-form-item> <el-form-item :label="$t('file.name')" prop="name">
</el-form> <el-input v-model="addForm.name"></el-input>
</el-form-item>
</el-form>
</el-col>
</el-row>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="handleClose(false)" :disabled="loading">{{ $t('commons.button.cancel') }}</el-button> <el-button @click="handleClose()" :disabled="loading">{{ $t('commons.button.cancel') }}</el-button>
<el-button type="primary" @click="submit(fileForm)" :disabled="loading"> <el-button type="primary" @click="submit(fileForm)" :disabled="loading">
{{ $t('commons.button.confirm') }} {{ $t('commons.button.confirm') }}
</el-button> </el-button>
</span> </span>
</template> </template>
</el-dialog> </el-drawer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -36,22 +40,17 @@ import { WgetFile } from '@/api/modules/files';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
import i18n from '@/lang'; import i18n from '@/lang';
import { ElMessage, FormInstance, FormRules } from 'element-plus'; import { ElMessage, FormInstance, FormRules } from 'element-plus';
import { reactive, ref, toRefs } from 'vue'; import { reactive, ref } from 'vue';
import FileList from '@/components/file-list/index.vue'; import FileList from '@/components/file-list/index.vue';
const props = defineProps({ interface WgetProps {
open: { path: string;
type: Boolean, }
default: false,
},
path: {
type: String,
default: '',
},
});
const { open } = toRefs(props);
const fileForm = ref<FormInstance>(); const fileForm = ref<FormInstance>();
const loading = ref(false); const loading = ref(false);
let open = ref(false);
let submitData = ref(false);
const rules = reactive<FormRules>({ const rules = reactive<FormRules>({
name: [Rules.requiredInput], name: [Rules.requiredInput],
@ -67,15 +66,12 @@ const addForm = reactive({
const em = defineEmits(['close']); const em = defineEmits(['close']);
const handleClose = (submit: boolean) => { const handleClose = () => {
if (fileForm.value) { if (fileForm.value) {
fileForm.value.resetFields(); fileForm.value.resetFields();
} }
if (submit != true) { open.value = false;
em('close', false); em('close', submitData);
} else {
em('close', true);
}
}; };
const getPath = (path: string) => { const getPath = (path: string) => {
@ -92,7 +88,8 @@ const submit = async (formEl: FormInstance | undefined) => {
WgetFile(addForm) WgetFile(addForm)
.then(() => { .then(() => {
ElMessage.success(i18n.global.t('file.downloadStart')); ElMessage.success(i18n.global.t('file.downloadStart'));
handleClose(true); submitData.value = true;
handleClose();
}) })
.finally(() => { .finally(() => {
loading.value = false; loading.value = false;
@ -105,7 +102,10 @@ const getFileName = (url: string) => {
addForm.name = paths[paths.length - 1]; addForm.name = paths[paths.length - 1];
}; };
const onOpen = () => { const acceptParams = (props: WgetProps) => {
addForm.path = props.path; addForm.path = props.path;
open.value = true;
}; };
defineExpose({ acceptParams });
</script> </script>