File size: 3,738 Bytes
8ede856 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | <template>
<v-dialog v-model="showDialog" max-width="450px">
<v-card>
<v-card-title>
<v-icon class="mr-2">mdi-folder-plus</v-icon>
{{ labels.title }}
</v-card-title>
<v-card-text>
<v-form ref="form" v-model="formValid">
<v-text-field v-model="formData.name" :label="mergedLabels.nameLabel"
:rules="[(v: any) => !!v || mergedLabels.nameRequired]" variant="outlined"
density="comfortable" autofocus class="mb-3" />
<v-textarea v-model="formData.description" :label="labels.descriptionLabel" variant="outlined"
rows="3" density="comfortable" hide-details />
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn variant="text" @click="closeDialog">
{{ labels.cancelButton }}
</v-btn>
<v-btn color="primary" variant="flat" @click="submitForm" :loading="loading" :disabled="!formValid">
{{ labels.createButton }}
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script lang="ts">
import { defineComponent, type PropType } from 'vue';
import type { CreateFolderData } from './types';
interface DefaultLabels {
title: string;
nameLabel: string;
descriptionLabel: string;
nameRequired: string;
cancelButton: string;
createButton: string;
}
const defaultLabels: DefaultLabels = {
title: '创建文件夹',
nameLabel: '名称',
descriptionLabel: '描述',
nameRequired: '请输入文件夹名称',
cancelButton: '取消',
createButton: '创建'
};
export default defineComponent({
name: 'BaseCreateFolderDialog',
props: {
modelValue: {
type: Boolean,
default: false
},
parentFolderId: {
type: String as PropType<string | null>,
default: null
},
labels: {
type: Object as PropType<Partial<DefaultLabels>>,
default: () => ({})
}
},
emits: ['update:modelValue', 'create'],
data() {
return {
formValid: false,
loading: false,
formData: {
name: '',
description: ''
}
};
},
computed: {
showDialog: {
get(): boolean {
return this.modelValue;
},
set(value: boolean) {
this.$emit('update:modelValue', value);
}
},
mergedLabels(): DefaultLabels {
return { ...defaultLabels, ...this.labels };
}
},
watch: {
modelValue(newValue: boolean) {
if (newValue) {
this.resetForm();
}
}
},
methods: {
resetForm() {
this.formData = {
name: '',
description: ''
};
if (this.$refs.form) {
(this.$refs.form as any).resetValidation();
}
},
closeDialog() {
this.showDialog = false;
},
async submitForm() {
if (!this.formValid) return;
const data: CreateFolderData = {
name: this.formData.name,
description: this.formData.description || undefined,
parent_id: this.parentFolderId
};
this.$emit('create', data);
},
setLoading(value: boolean) {
this.loading = value;
}
}
});
</script>
|