1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-22 17:59:17 +08:00

131 lines
4.2 KiB
Vue
Raw Normal View History

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"
>
<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>
<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">
<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-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-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">
import { toRefs, ref, reactive, computed } from 'vue';
2022-08-25 17:54:52 +08:00
import { File } from '@/api/interface/file';
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';
import { Rules } from '@/global/form-rues';
import FileList from '@/components/file-list/index.vue';
2022-08-25 17:54:52 +08:00
const fileForm = ref<FormInstance>();
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);
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);
};
const rules = reactive<FormRules>({
2022-09-03 18:41:52 +08:00
name: [Rules.requiredInput],
path: [Rules.requiredInput],
isSymlink: [Rules.requiredInput],
linkPath: [Rules.requiredInput],
});
2022-08-26 17:35:14 +08:00
const getMode = (val: number) => {
addForm.mode = val;
2022-08-26 17:35:14 +08:00
};
let getPath = computed(() => {
2022-09-01 19:02:33 +08:00
if (addForm.path.endsWith('/')) {
return addForm.path + addForm.name;
2022-08-30 17:59:59 +08:00
} else {
return addForm.path + '/' + addForm.name;
2022-08-30 17:59:59 +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;
}
let addItem = {};
Object.assign(addItem, addForm);
addItem['path'] = getPath.value;
2022-08-25 17:54:52 +08:00
loading.value = true;
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;
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>