2020-07-11 01:13:11 +00:00
|
|
|
<template>
|
2020-10-17 11:12:00 +00:00
|
|
|
<XModalWindow ref="dialog"
|
2020-11-25 12:31:34 +00:00
|
|
|
:width="450"
|
2020-10-17 11:12:00 +00:00
|
|
|
:can-close="false"
|
|
|
|
:with-ok-button="true"
|
|
|
|
:ok-button-disabled="false"
|
|
|
|
@click="cancel()"
|
|
|
|
@ok="ok()"
|
|
|
|
@close="cancel()"
|
|
|
|
@closed="$emit('closed')"
|
|
|
|
>
|
2020-07-11 01:13:11 +00:00
|
|
|
<template #header>
|
|
|
|
{{ title }}
|
|
|
|
</template>
|
2020-11-25 12:31:34 +00:00
|
|
|
<FormBase class="xkpnjxcv">
|
|
|
|
<template v-for="item in Object.keys(form).filter(item => !form[item].hidden)">
|
|
|
|
<FormInput v-if="form[item].type === 'number'" v-model:value="values[item]" type="number" :step="form[item].step || 1">
|
2020-12-26 01:47:36 +00:00
|
|
|
<span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ $ts.optional }})</span>
|
2020-07-29 15:35:07 +00:00
|
|
|
<template v-if="form[item].description" #desc>{{ form[item].description }}</template>
|
2020-11-25 12:31:34 +00:00
|
|
|
</FormInput>
|
|
|
|
<FormInput v-else-if="form[item].type === 'string' && !form[item].multiline" v-model:value="values[item]" type="text">
|
2020-12-26 01:47:36 +00:00
|
|
|
<span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ $ts.optional }})</span>
|
2020-07-29 15:35:07 +00:00
|
|
|
<template v-if="form[item].description" #desc>{{ form[item].description }}</template>
|
2020-11-25 12:31:34 +00:00
|
|
|
</FormInput>
|
|
|
|
<FormTextarea v-else-if="form[item].type === 'string' && form[item].multiline" v-model:value="values[item]">
|
2020-12-26 01:47:36 +00:00
|
|
|
<span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ $ts.optional }})</span>
|
2020-07-29 15:35:07 +00:00
|
|
|
<template v-if="form[item].description" #desc>{{ form[item].description }}</template>
|
2020-11-25 12:31:34 +00:00
|
|
|
</FormTextarea>
|
|
|
|
<FormSwitch v-else-if="form[item].type === 'boolean'" v-model:value="values[item]">
|
2020-07-29 15:35:07 +00:00
|
|
|
<span v-text="form[item].label || item"></span>
|
|
|
|
<template v-if="form[item].description" #desc>{{ form[item].description }}</template>
|
2020-11-25 12:31:34 +00:00
|
|
|
</FormSwitch>
|
|
|
|
<FormSelect v-else-if="form[item].type === 'enum'" v-model:value="values[item]">
|
2020-12-26 01:47:36 +00:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ $ts.optional }})</span></template>
|
2020-11-25 12:31:34 +00:00
|
|
|
<option v-for="item in form[item].enum" :value="item.value" :key="item.value">{{ item.label }}</option>
|
|
|
|
</FormSelect>
|
2021-07-19 14:30:45 +00:00
|
|
|
<FormRadios v-else-if="form[item].type === 'radio'" v-model="values[item]">
|
|
|
|
<template #desc><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ $ts.optional }})</span></template>
|
|
|
|
<option v-for="item in form[item].options" :value="item.value" :key="item.value">{{ item.label }}</option>
|
|
|
|
</FormRadios>
|
2020-11-25 12:31:34 +00:00
|
|
|
<FormRange v-else-if="form[item].type === 'range'" v-model:value="values[item]" :min="form[item].mim" :max="form[item].max" :step="form[item].step">
|
2020-12-26 01:47:36 +00:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ $ts.optional }})</span></template>
|
2020-11-25 12:31:34 +00:00
|
|
|
<template v-if="form[item].description" #desc>{{ form[item].description }}</template>
|
|
|
|
</FormRange>
|
|
|
|
<FormButton v-else-if="form[item].type === 'button'" @click="form[item].action($event, values)">
|
|
|
|
<span v-text="form[item].content || item"></span>
|
|
|
|
</FormButton>
|
|
|
|
</template>
|
|
|
|
</FormBase>
|
2020-10-17 11:12:00 +00:00
|
|
|
</XModalWindow>
|
2020-07-11 01:13:11 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 11:12:00 +00:00
|
|
|
import { defineComponent } from 'vue';
|
2021-03-23 08:30:14 +00:00
|
|
|
import XModalWindow from '@client/components/ui/modal-window.vue';
|
2020-11-25 12:31:34 +00:00
|
|
|
import FormBase from './form/base.vue';
|
|
|
|
import FormInput from './form/input.vue';
|
|
|
|
import FormTextarea from './form/textarea.vue';
|
|
|
|
import FormSwitch from './form/switch.vue';
|
|
|
|
import FormSelect from './form/select.vue';
|
|
|
|
import FormRange from './form/range.vue';
|
|
|
|
import FormButton from './form/button.vue';
|
2021-07-19 14:30:45 +00:00
|
|
|
import FormRadios from './form/radios.vue';
|
2020-07-11 01:13:11 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2020-07-11 01:13:11 +00:00
|
|
|
components: {
|
2020-10-17 11:12:00 +00:00
|
|
|
XModalWindow,
|
2020-11-25 12:31:34 +00:00
|
|
|
FormBase,
|
|
|
|
FormInput,
|
|
|
|
FormTextarea,
|
|
|
|
FormSwitch,
|
|
|
|
FormSelect,
|
|
|
|
FormRange,
|
|
|
|
FormButton,
|
2021-07-19 14:30:45 +00:00
|
|
|
FormRadios,
|
2020-07-11 01:13:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
form: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
emits: ['done'],
|
|
|
|
|
2020-07-11 01:13:11 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
values: {}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
for (const item in this.form) {
|
2020-10-17 11:12:00 +00:00
|
|
|
this.values[item] = this.form[item].hasOwnProperty('default') ? this.form[item].default : null;
|
2020-07-11 01:13:11 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
ok() {
|
2020-10-17 11:12:00 +00:00
|
|
|
this.$emit('done', {
|
|
|
|
result: this.values
|
|
|
|
});
|
|
|
|
this.$refs.dialog.close();
|
2020-07-11 01:13:11 +00:00
|
|
|
},
|
2020-10-17 11:12:00 +00:00
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.$emit('done', {
|
|
|
|
canceled: true
|
|
|
|
});
|
|
|
|
this.$refs.dialog.close();
|
|
|
|
}
|
2020-07-11 01:13:11 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.xkpnjxcv {
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2020-07-11 01:13:11 +00:00
|
|
|
}
|
|
|
|
</style>
|