Hangar/frontend/components/modals/HangarModal.vue

96 lines
2.7 KiB
Vue
Raw Normal View History

2021-03-18 07:55:48 +08:00
<template>
<v-dialog v-model="dialog" :max-width="maxWidth" @input="$emit('open')">
<template #activator="props">
<slot name="activator" v-bind="props" />
</template>
<v-card>
<v-card-title>{{ title }}</v-card-title>
<v-card-text>
2021-03-28 14:03:13 +08:00
<v-form v-if="!noForm" ref="modalForm" v-model="validForm">
2021-03-18 07:55:48 +08:00
<slot />
</v-form>
2021-03-28 14:03:13 +08:00
<slot v-else />
2021-03-18 07:55:48 +08:00
</v-card-text>
<v-card-actions class="justify-end">
<v-btn text :color="closeColor" @click.stop="close">
{{ closeLabel || $t('general.close') }}
</v-btn>
2021-03-18 07:55:48 +08:00
<slot name="other-btns" />
2021-05-17 08:29:02 +08:00
<v-btn :color="submitColor" :disabled="(!noForm && !validForm) || submitDisabled" :loading="loading" @click.stop="submit0">
2021-03-28 14:03:13 +08:00
{{ submitLabel || $t('general.submit') }}
2021-03-18 07:55:48 +08:00
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script lang="ts">
import { Component, Prop } from 'nuxt-property-decorator';
import { PropType } from 'vue';
import { TranslateResult } from 'vue-i18n';
import { HangarFormModal } from '~/components/mixins';
@Component
export default class HangarModal extends HangarFormModal {
@Prop({ type: String, default: '500' })
maxWidth!: string;
@Prop({ type: String as PropType<TranslateResult>, required: true })
title!: TranslateResult;
2021-05-17 08:29:02 +08:00
@Prop({ type: String as PropType<TranslateResult> })
closeLabel!: TranslateResult | null;
@Prop({ type: String, default: 'warning' })
closeColor!: string;
2021-03-28 14:03:13 +08:00
@Prop({ type: String as PropType<TranslateResult> })
submitLabel!: TranslateResult | null;
2021-03-18 07:55:48 +08:00
2021-05-17 08:29:02 +08:00
@Prop({ type: String, default: 'success' })
submitColor!: string;
2021-03-18 07:55:48 +08:00
@Prop({ type: Function as PropType<() => Promise<void>>, required: true })
submit!: () => Promise<void>;
@Prop({ type: Boolean, default: false })
submitDisabled!: boolean;
2021-03-28 14:03:13 +08:00
@Prop({ type: Boolean, default: false })
noForm!: boolean;
2021-03-18 07:55:48 +08:00
$refs!: {
modalForm: any;
};
2021-05-17 08:29:02 +08:00
open() {
this.dialog = true;
}
2021-03-18 07:55:48 +08:00
close() {
2021-03-28 14:03:13 +08:00
if (!this.noForm) {
this.$refs.modalForm.reset();
}
2021-03-18 07:55:48 +08:00
this.dialog = false;
this.$emit('close');
}
submit0() {
this.loading = true;
this.submit()
.then(() => {
this.dialog = false;
2021-03-28 14:03:13 +08:00
if (!this.noForm) {
this.$refs.modalForm.reset();
}
2021-03-18 07:55:48 +08:00
})
.finally(() => {
this.loading = false;
});
}
}
</script>
<style lang="scss" scoped></style>