2020-07-11 10:13:11 +09:00
|
|
|
<template>
|
2023-01-06 09:41:14 +09:00
|
|
|
<MkModalWindow
|
2022-07-01 16:43:38 +09:00
|
|
|
ref="dialog"
|
2020-11-25 21:31:34 +09:00
|
|
|
:width="450"
|
2020-10-17 20:12:00 +09:00
|
|
|
:can-close="false"
|
|
|
|
:with-ok-button="true"
|
|
|
|
:ok-button-disabled="false"
|
|
|
|
@click="cancel()"
|
|
|
|
@ok="ok()"
|
|
|
|
@close="cancel()"
|
|
|
|
@closed="$emit('closed')"
|
|
|
|
>
|
2020-07-11 10:13:11 +09:00
|
|
|
<template #header>
|
|
|
|
{{ title }}
|
|
|
|
</template>
|
2021-12-02 20:09:12 +09:00
|
|
|
|
|
|
|
<MkSpacer :margin-min="20" :margin-max="32">
|
2023-01-14 20:31:48 +09:00
|
|
|
<div class="_gaps_m">
|
2021-12-02 20:09:12 +09:00
|
|
|
<template v-for="item in Object.keys(form).filter(item => !form[item].hidden)">
|
2023-01-07 15:09:46 +09:00
|
|
|
<MkInput v-if="form[item].type === 'number'" v-model="values[item]" type="number" :step="form[item].step || 1">
|
2023-04-01 14:01:57 +09:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
|
2021-12-02 20:09:12 +09:00
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 15:09:46 +09:00
|
|
|
</MkInput>
|
|
|
|
<MkInput v-else-if="form[item].type === 'string' && !form[item].multiline" v-model="values[item]" type="text">
|
2023-04-01 14:01:57 +09:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
|
2021-12-02 20:09:12 +09:00
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 15:09:46 +09:00
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-else-if="form[item].type === 'string' && form[item].multiline" v-model="values[item]">
|
2023-04-01 14:01:57 +09:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
|
2021-12-02 20:09:12 +09:00
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 15:09:46 +09:00
|
|
|
</MkTextarea>
|
2023-01-07 14:59:54 +09:00
|
|
|
<MkSwitch v-else-if="form[item].type === 'boolean'" v-model="values[item]">
|
2021-12-02 20:09:12 +09:00
|
|
|
<span v-text="form[item].label || item"></span>
|
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 14:59:54 +09:00
|
|
|
</MkSwitch>
|
2023-01-07 15:09:46 +09:00
|
|
|
<MkSelect v-else-if="form[item].type === 'enum'" v-model="values[item]">
|
2023-04-01 14:01:57 +09:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
|
2021-12-02 20:09:12 +09:00
|
|
|
<option v-for="item in form[item].enum" :key="item.value" :value="item.value">{{ item.label }}</option>
|
2023-01-07 15:09:46 +09:00
|
|
|
</MkSelect>
|
|
|
|
<MkRadios v-else-if="form[item].type === 'radio'" v-model="values[item]">
|
2023-04-01 14:01:57 +09:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
|
2021-12-02 20:09:12 +09:00
|
|
|
<option v-for="item in form[item].options" :key="item.value" :value="item.value">{{ item.label }}</option>
|
2023-01-07 15:09:46 +09:00
|
|
|
</MkRadios>
|
|
|
|
<MkRange v-else-if="form[item].type === 'range'" v-model="values[item]" :min="form[item].min" :max="form[item].max" :step="form[item].step" :text-converter="form[item].textConverter">
|
2023-04-01 14:01:57 +09:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
|
2021-12-02 20:09:12 +09:00
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 15:09:46 +09:00
|
|
|
</MkRange>
|
2023-01-05 21:04:56 +09:00
|
|
|
<MkButton v-else-if="form[item].type === 'button'" @click="form[item].action($event, values)">
|
2021-12-02 20:09:12 +09:00
|
|
|
<span v-text="form[item].content || item"></span>
|
|
|
|
</MkButton>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
2023-01-06 09:41:14 +09:00
|
|
|
</MkModalWindow>
|
2020-07-11 10:13:11 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent } from 'vue';
|
2023-01-07 15:09:46 +09:00
|
|
|
import MkInput from './MkInput.vue';
|
|
|
|
import MkTextarea from './MkTextarea.vue';
|
2023-01-07 14:59:54 +09:00
|
|
|
import MkSwitch from './MkSwitch.vue';
|
2023-01-07 15:09:46 +09:00
|
|
|
import MkSelect from './MkSelect.vue';
|
|
|
|
import MkRange from './MkRange.vue';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkButton from './MkButton.vue';
|
2023-01-07 15:09:46 +09:00
|
|
|
import MkRadios from './MkRadios.vue';
|
2023-01-06 09:41:14 +09:00
|
|
|
import MkModalWindow from '@/components/MkModalWindow.vue';
|
2023-04-01 14:01:57 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2020-07-11 10:13:11 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-07-11 10:13:11 +09:00
|
|
|
components: {
|
2023-01-06 09:41:14 +09:00
|
|
|
MkModalWindow,
|
2023-01-07 15:09:46 +09:00
|
|
|
MkInput,
|
|
|
|
MkTextarea,
|
2023-01-07 14:59:54 +09:00
|
|
|
MkSwitch,
|
2023-01-07 15:09:46 +09:00
|
|
|
MkSelect,
|
|
|
|
MkRange,
|
2021-12-02 20:09:12 +09:00
|
|
|
MkButton,
|
2023-01-07 15:09:46 +09:00
|
|
|
MkRadios,
|
2020-07-11 10:13:11 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
form: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
emits: ['done'],
|
|
|
|
|
2020-07-11 10:13:11 +09:00
|
|
|
data() {
|
|
|
|
return {
|
2022-07-01 16:43:38 +09:00
|
|
|
values: {},
|
2023-04-01 14:01:57 +09:00
|
|
|
i18n,
|
2020-07-11 10:13:11 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
for (const item in this.form) {
|
2022-07-04 23:39:04 +09:00
|
|
|
this.values[item] = this.form[item].default ?? null;
|
2020-07-11 10:13:11 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
ok() {
|
2020-10-17 20:12:00 +09:00
|
|
|
this.$emit('done', {
|
2022-07-01 16:43:38 +09:00
|
|
|
result: this.values,
|
2020-10-17 20:12:00 +09:00
|
|
|
});
|
|
|
|
this.$refs.dialog.close();
|
2020-07-11 10:13:11 +09:00
|
|
|
},
|
2020-10-17 20:12:00 +09:00
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.$emit('done', {
|
2022-07-01 16:43:38 +09:00
|
|
|
canceled: true,
|
2020-10-17 20:12:00 +09:00
|
|
|
});
|
|
|
|
this.$refs.dialog.close();
|
2022-07-01 16:43:38 +09:00
|
|
|
},
|
|
|
|
},
|
2020-07-11 10:13:11 +09:00
|
|
|
});
|
|
|
|
</script>
|