2022-08-25 17:54:52 +08:00
|
|
|
<template>
|
|
|
|
<el-dialog
|
|
|
|
v-model="open"
|
|
|
|
:before-close="handleClose"
|
|
|
|
:title="$t('commons.button.create')"
|
|
|
|
width="30%"
|
|
|
|
@open="onOpen"
|
|
|
|
v-loading="loading"
|
|
|
|
>
|
2022-08-31 16:00:51 +08:00
|
|
|
<el-form ref="fileForm" label-position="left" :model="addForm" label-width="100px" :rules="rules">
|
2022-08-30 17:59:59 +08:00
|
|
|
<el-form-item :label="$t('file.path')" prop="path"> <el-input v-model="getPath" disabled /></el-form-item>
|
2022-08-31 16:00:51 +08:00
|
|
|
<el-form-item :label="$t('file.name')" prop="name"> <el-input v-model="addForm.name" /></el-form-item>
|
|
|
|
<el-form-item v-if="!addForm.isDir">
|
|
|
|
<el-checkbox v-model="addForm.isLink" :label="$t('file.link')"></el-checkbox
|
|
|
|
></el-form-item>
|
|
|
|
<el-form-item :label="$t('file.linkType')" v-if="addForm.isLink" prop="linkType">
|
|
|
|
<el-radio-group v-model="addForm.isSymlink">
|
|
|
|
<el-radio :label="true">{{ $t('file.softLink') }}</el-radio>
|
|
|
|
<el-radio :label="false">{{ $t('file.hardLink') }}</el-radio>
|
|
|
|
</el-radio-group>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item v-if="addForm.isLink" :label="$t('file.linkPath')" prop="linkPath">
|
2022-08-31 18:03:47 +08:00
|
|
|
<el-input v-model="addForm.linkPath">
|
|
|
|
<template #append>
|
|
|
|
<FileList @choose="getLinkPath"></FileList>
|
|
|
|
</template>
|
|
|
|
</el-input>
|
|
|
|
</el-form-item>
|
2022-08-31 16:00:51 +08:00
|
|
|
<el-form-item>
|
|
|
|
<el-checkbox v-if="addForm.isDir" v-model="setRole" :label="$t('file.setRole')"></el-checkbox>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item>
|
|
|
|
<FileRole v-if="setRole" :mode="'0755'" @get-mode="getMode"></FileRole>
|
|
|
|
</el-form-item>
|
2022-08-25 17:54:52 +08:00
|
|
|
</el-form>
|
2022-08-31 16:00:51 +08:00
|
|
|
|
2022-08-25 17:54:52 +08:00
|
|
|
<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>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-08-29 15:26:36 +08:00
|
|
|
import { toRefs, ref, reactive, computed } from 'vue';
|
2022-08-25 17:54:52 +08:00
|
|
|
import { File } from '@/api/interface/file';
|
2022-08-29 15:26:36 +08:00
|
|
|
import { ElMessage, FormInstance, FormRules } from 'element-plus';
|
2022-08-25 17:54:52 +08:00
|
|
|
import { CreateFile } from '@/api/modules/files';
|
|
|
|
import i18n from '@/lang';
|
2022-08-26 17:35:14 +08:00
|
|
|
import FileRole from '@/components/file-role/index.vue';
|
2022-08-29 15:26:36 +08:00
|
|
|
import { Rules } from '@/global/form-rues';
|
2022-08-31 18:03:47 +08:00
|
|
|
import FileList from '@/components/file-list/index.vue';
|
2022-08-25 17:54:52 +08:00
|
|
|
|
|
|
|
const fileForm = ref<FormInstance>();
|
2022-08-29 15:26:36 +08:00
|
|
|
let loading = ref(false);
|
|
|
|
let setRole = ref(false);
|
2022-08-25 17:54:52 +08:00
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
open: Boolean,
|
|
|
|
file: Object,
|
|
|
|
});
|
|
|
|
const { open, file } = toRefs(props);
|
2022-08-31 16:00:51 +08:00
|
|
|
|
|
|
|
let addForm = reactive({ path: '', name: '', isDir: false, mode: 0o755, isLink: false, isSymlink: true, linkPath: '' });
|
|
|
|
|
2022-08-25 17:54:52 +08:00
|
|
|
const em = defineEmits(['close']);
|
|
|
|
const handleClose = () => {
|
|
|
|
em('close', open);
|
|
|
|
};
|
|
|
|
|
2022-08-29 15:26:36 +08:00
|
|
|
const rules = reactive<FormRules>({
|
|
|
|
name: [Rules.required],
|
2022-08-30 17:59:59 +08:00
|
|
|
path: [Rules.required],
|
2022-08-31 16:00:51 +08:00
|
|
|
isSymlink: [Rules.required],
|
|
|
|
linkPath: [Rules.required],
|
2022-08-29 15:26:36 +08:00
|
|
|
});
|
|
|
|
|
2022-08-26 17:35:14 +08:00
|
|
|
const getMode = (val: number) => {
|
2022-08-31 16:00:51 +08:00
|
|
|
addForm.mode = val;
|
2022-08-26 17:35:14 +08:00
|
|
|
};
|
|
|
|
|
2022-08-29 15:26:36 +08:00
|
|
|
let getPath = computed(() => {
|
2022-09-01 19:02:33 +08:00
|
|
|
if (addForm.path.endsWith('/')) {
|
2022-08-31 16:00:51 +08:00
|
|
|
return addForm.path + addForm.name;
|
2022-08-30 17:59:59 +08:00
|
|
|
} else {
|
2022-08-31 16:00:51 +08:00
|
|
|
return addForm.path + '/' + addForm.name;
|
2022-08-30 17:59:59 +08:00
|
|
|
}
|
2022-08-29 15:26:36 +08:00
|
|
|
});
|
|
|
|
|
2022-08-31 18:03:47 +08:00
|
|
|
const getLinkPath = (path: string) => {
|
|
|
|
addForm.linkPath = path;
|
|
|
|
};
|
|
|
|
|
2022-08-25 17:54:52 +08:00
|
|
|
const submit = async (formEl: FormInstance | undefined) => {
|
|
|
|
if (!formEl) return;
|
|
|
|
await formEl.validate((valid) => {
|
|
|
|
if (!valid) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-31 16:00:51 +08:00
|
|
|
|
|
|
|
let addItem = {};
|
|
|
|
Object.assign(addItem, addForm);
|
|
|
|
addItem['path'] = getPath.value;
|
2022-08-25 17:54:52 +08:00
|
|
|
loading.value = true;
|
2022-08-31 16:00:51 +08:00
|
|
|
CreateFile(addItem as File.FileCreate)
|
2022-08-25 17:54:52 +08:00
|
|
|
.then(() => {
|
|
|
|
ElMessage.success(i18n.global.t('commons.msg.createSuccess'));
|
|
|
|
handleClose();
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
loading.value = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onOpen = () => {
|
|
|
|
const f = file?.value as File.FileCreate;
|
2022-08-31 16:00:51 +08:00
|
|
|
addForm.isDir = f.isDir;
|
|
|
|
addForm.path = f.path;
|
|
|
|
addForm.name = '';
|
|
|
|
addForm.isLink = false;
|
|
|
|
init();
|
|
|
|
};
|
|
|
|
|
|
|
|
const init = () => {
|
|
|
|
setRole.value = false;
|
2022-08-25 17:54:52 +08:00
|
|
|
};
|
|
|
|
</script>
|