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

154 lines
4.9 KiB
Vue
Raw Normal View History

2022-08-25 17:54:52 +08:00
<template>
2023-01-31 14:02:29 +08:00
<el-drawer
2022-08-25 17:54:52 +08:00
v-model="open"
:before-close="handleClose"
2022-12-01 17:34:19 +08:00
:destroy-on-close="true"
:close-on-click-modal="false"
2023-01-31 14:02:29 +08:00
size="40%"
2022-08-25 17:54:52 +08:00
>
2023-01-31 14:02:29 +08:00
<template #header>
<DrawerHeader :header="$t('commons.button.create')" :back="handleClose" />
</template>
<el-row>
<el-col :span="22" :offset="1">
<el-form
ref="fileForm"
label-position="top"
:model="addForm"
label-width="100px"
:rules="rules"
v-loading="loading"
>
<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">
2023-02-09 14:31:05 +08:00
<template #prepend>
2023-01-31 14:02:29 +08:00
<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>
2023-01-31 14:02:29 +08:00
</el-col>
</el-row>
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>
2023-01-31 14:02:29 +08:00
</el-drawer>
2022-08-25 17:54:52 +08:00
</template>
<script setup lang="ts">
2023-01-31 18:52:07 +08:00
import DrawerHeader from '@/components/drawer-header/index.vue';
2023-01-31 14:02:29 +08:00
import { 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';
2022-09-16 16:00:49 +08:00
import { Rules } from '@/global/form-rules';
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
2023-01-31 14:02:29 +08:00
interface CreateProps {
file: Object;
}
const propData = ref<CreateProps>({
file: {},
2022-08-25 17:54:52 +08:00
});
let addForm = reactive({ path: '', name: '', isDir: false, mode: 0o755, isLink: false, isSymlink: true, linkPath: '' });
2023-01-31 14:02:29 +08:00
let open = ref(false);
2022-08-25 17:54:52 +08:00
const em = defineEmits(['close']);
const handleClose = () => {
2023-01-31 14:02:29 +08:00
open.value = false;
2022-09-06 15:46:46 +08:00
if (fileForm.value) {
fileForm.value.resetFields();
}
2022-08-25 17:54:52 +08:00
em('close', open);
};
const rules = reactive<FormRules>({
2022-12-23 14:50:28 +08:00
name: [Rules.requiredInput, Rules.linuxName],
2022-09-03 18:41:52 +08:00
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;
});
});
};
2023-01-31 14:02:29 +08:00
const acceptParams = (create: File.FileCreate) => {
propData.value.file = create;
open.value = true;
addForm.isDir = create.isDir;
addForm.path = create.path;
addForm.name = '';
addForm.isLink = false;
2023-01-31 14:02:29 +08:00
init();
};
const init = () => {
setRole.value = false;
2022-08-25 17:54:52 +08:00
};
2023-01-31 14:02:29 +08:00
defineExpose({ acceptParams });
2022-08-25 17:54:52 +08:00
</script>