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-29 15:26:36 +08:00
|
|
|
<el-form ref="fileForm" label-position="left" :model="form" label-width="100px" :rules="rules">
|
|
|
|
<el-form-item :label="$t('file.path')"> <el-input v-model="getPath" disabled /></el-form-item>
|
|
|
|
<el-form-item :label="$t('file.name')"> <el-input v-model="name" /></el-form-item>
|
2022-08-26 17:35:14 +08:00
|
|
|
<el-checkbox v-model="isLink" :label="$t('file.link')"></el-checkbox>
|
2022-08-25 17:54:52 +08:00
|
|
|
</el-form>
|
2022-08-26 17:35:14 +08:00
|
|
|
<el-checkbox v-model="setRole" :label="$t('file.setRole')"></el-checkbox>
|
2022-08-29 15:26:36 +08:00
|
|
|
<FileRole v-if="setRole" :mode="'0755'" @get-mode="getMode"></FileRole>
|
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-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);
|
|
|
|
let isLink = ref(false);
|
|
|
|
let name = ref('');
|
|
|
|
let path = ref('');
|
2022-08-25 17:54:52 +08:00
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
open: Boolean,
|
|
|
|
file: Object,
|
|
|
|
});
|
|
|
|
const { open, file } = toRefs(props);
|
|
|
|
let form = ref<File.FileCreate>({ path: '', isDir: false, mode: 0o755 });
|
|
|
|
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-26 17:35:14 +08:00
|
|
|
const getMode = (val: number) => {
|
|
|
|
form.value.mode = val;
|
|
|
|
};
|
|
|
|
|
2022-08-29 15:26:36 +08:00
|
|
|
let getPath = computed(() => {
|
|
|
|
return path.value + '/' + name.value;
|
|
|
|
});
|
|
|
|
|
2022-08-25 17:54:52 +08:00
|
|
|
const submit = async (formEl: FormInstance | undefined) => {
|
|
|
|
if (!formEl) return;
|
|
|
|
await formEl.validate((valid) => {
|
|
|
|
if (!valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
loading.value = true;
|
2022-08-29 15:26:36 +08:00
|
|
|
form.value.path = getPath.value;
|
2022-08-25 17:54:52 +08:00
|
|
|
CreateFile(form.value)
|
|
|
|
.then(() => {
|
|
|
|
ElMessage.success(i18n.global.t('commons.msg.createSuccess'));
|
|
|
|
handleClose();
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
loading.value = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onOpen = () => {
|
|
|
|
const f = file?.value as File.FileCreate;
|
|
|
|
form.value.isDir = f.isDir;
|
|
|
|
form.value.path = f.path;
|
2022-08-29 15:26:36 +08:00
|
|
|
path.value = f.path;
|
|
|
|
name.value = '';
|
2022-08-25 17:54:52 +08:00
|
|
|
};
|
|
|
|
</script>
|