2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkModal ref="modal" @click="done(true)" @closed="$emit('closed')">
|
|
|
|
<div class="mk-dialog">
|
|
|
|
<div class="icon" v-if="icon">
|
2021-04-20 23:22:59 +09:00
|
|
|
<i :class="icon"></i>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
2020-10-25 11:29:10 +09:00
|
|
|
<div class="icon" v-else-if="!input && !select" :class="type">
|
2021-04-20 23:22:59 +09:00
|
|
|
<i v-if="type === 'success'" class="fas fa-check"></i>
|
|
|
|
<i v-else-if="type === 'error'" class="fas fa-times-circle"></i>
|
|
|
|
<i v-else-if="type === 'warning'" class="fas fa-exclamation-triangle"></i>
|
2021-04-23 12:17:04 +09:00
|
|
|
<i v-else-if="type === 'info'" class="fas fa-info-circle"></i>
|
2021-04-20 23:22:59 +09:00
|
|
|
<i v-else-if="type === 'question'" class="fas fa-question-circle"></i>
|
|
|
|
<i v-else-if="type === 'waiting'" class="fas fa-spinner fa-pulse"></i>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
2020-10-25 12:25:13 +09:00
|
|
|
<header v-if="title"><Mfm :text="title"/></header>
|
|
|
|
<div class="body" v-if="text"><Mfm :text="text"/></div>
|
2021-08-06 22:29:19 +09:00
|
|
|
<MkInput v-if="input" v-model="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown"></MkInput>
|
|
|
|
<MkSelect v-if="select" v-model="selectedValue" autofocus>
|
2020-10-17 20:12:00 +09:00
|
|
|
<template v-if="select.items">
|
|
|
|
<option v-for="item in select.items" :value="item.value">{{ item.text }}</option>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
2020-10-17 20:12:00 +09:00
|
|
|
<optgroup v-for="groupedItem in select.groupedItems" :label="groupedItem.label">
|
|
|
|
<option v-for="item in groupedItem.items" :value="item.value">{{ item.text }}</option>
|
|
|
|
</optgroup>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
2020-10-17 20:12:00 +09:00
|
|
|
</MkSelect>
|
|
|
|
<div class="buttons" v-if="(showOkButton || showCancelButton) && !actions">
|
2020-12-26 10:47:36 +09:00
|
|
|
<MkButton inline @click="ok" v-if="showOkButton" primary :autofocus="!input && !select">{{ (showCancelButton || input || select) ? $ts.ok : $ts.gotIt }}</MkButton>
|
|
|
|
<MkButton inline @click="cancel" v-if="showCancelButton || input || select">{{ $ts.cancel }}</MkButton>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
|
|
|
<div class="buttons" v-if="actions">
|
|
|
|
<MkButton v-for="action in actions" inline @click="() => { action.callback(); close(); }" :primary="action.primary" :key="action.text">{{ action.text }}</MkButton>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
|
|
|
</MkModal>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent } from 'vue';
|
2021-03-23 17:30:14 +09:00
|
|
|
import MkModal from '@client/components/ui/modal.vue';
|
|
|
|
import MkButton from '@client/components/ui/button.vue';
|
2021-09-30 00:50:45 +09:00
|
|
|
import MkInput from '@client/components/form/input.vue';
|
|
|
|
import MkSelect from '@client/components/form/select.vue';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-01-30 04:37:25 +09:00
|
|
|
components: {
|
2020-10-17 20:12:00 +09:00
|
|
|
MkModal,
|
2020-01-30 04:37:25 +09:00
|
|
|
MkButton,
|
|
|
|
MkInput,
|
|
|
|
MkSelect,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'info'
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
input: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
showOkButton: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
showCancelButton: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
cancelableByBgClick: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
emits: ['done', 'closed'],
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
inputValue: this.input && this.input.default ? this.input.default : null,
|
|
|
|
selectedValue: this.select ? this.select.default ? this.select.default : this.select.items ? this.select.items[0].value : this.select.groupedItems[0].items[0].value : null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
document.addEventListener('keydown', this.onKeydown);
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
beforeUnmount() {
|
2020-01-30 04:37:25 +09:00
|
|
|
document.removeEventListener('keydown', this.onKeydown);
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-10-17 20:12:00 +09:00
|
|
|
done(canceled, result?) {
|
|
|
|
this.$emit('done', { canceled, result });
|
|
|
|
this.$refs.modal.close();
|
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
async ok() {
|
|
|
|
if (!this.showOkButton) return;
|
|
|
|
|
2020-10-25 11:29:10 +09:00
|
|
|
const result =
|
|
|
|
this.input ? this.inputValue :
|
|
|
|
this.select ? this.selectedValue :
|
|
|
|
true;
|
|
|
|
this.done(false, result);
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
2020-10-17 20:12:00 +09:00
|
|
|
this.done(true);
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
onBgClick() {
|
|
|
|
if (this.cancelableByBgClick) {
|
|
|
|
this.cancel();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onKeydown(e) {
|
|
|
|
if (e.which === 27) { // ESC
|
|
|
|
this.cancel();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onInputKeydown(e) {
|
|
|
|
if (e.which === 13) { // Enter
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
this.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-dialog {
|
2020-10-17 20:12:00 +09:00
|
|
|
position: relative;
|
|
|
|
padding: 32px;
|
|
|
|
min-width: 320px;
|
|
|
|
max-width: 480px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
text-align: center;
|
|
|
|
background: var(--panel);
|
|
|
|
border-radius: var(--radius);
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
font-size: 32px;
|
|
|
|
|
|
|
|
&.success {
|
2020-11-01 22:09:16 +09:00
|
|
|
color: var(--success);
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
&.error {
|
2020-11-01 22:09:16 +09:00
|
|
|
color: var(--error);
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
&.warning {
|
2020-11-01 22:09:16 +09:00
|
|
|
color: var(--warn);
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> * {
|
|
|
|
display: block;
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
& + header {
|
|
|
|
margin-top: 16px;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> header {
|
|
|
|
margin: 0 0 8px 0;
|
|
|
|
font-weight: bold;
|
|
|
|
font-size: 20px;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
& + .body {
|
|
|
|
margin-top: 8px;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> .body {
|
|
|
|
margin: 16px 0 0 0;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> .buttons {
|
|
|
|
margin-top: 16px;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> * {
|
|
|
|
margin: 0 8px;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|