2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-07-11 03:13:11 +02:00
|
|
|
<template>
|
2023-01-06 01:41:14 +01:00
|
|
|
<MkModalWindow
|
2022-07-01 09:43:38 +02:00
|
|
|
ref="dialog"
|
2020-11-25 13:31:34 +01:00
|
|
|
:width="450"
|
2023-05-19 06:58:09 +02:00
|
|
|
:canClose="false"
|
|
|
|
:withOkButton="true"
|
|
|
|
:okButtonDisabled="false"
|
2020-10-17 13:12:00 +02:00
|
|
|
@click="cancel()"
|
|
|
|
@ok="ok()"
|
|
|
|
@close="cancel()"
|
|
|
|
@closed="$emit('closed')"
|
|
|
|
>
|
2020-07-11 03:13:11 +02:00
|
|
|
<template #header>
|
|
|
|
{{ title }}
|
|
|
|
</template>
|
2021-12-02 12:09:12 +01:00
|
|
|
|
2023-05-19 06:58:09 +02:00
|
|
|
<MkSpacer :marginMin="20" :marginMax="32">
|
2024-01-03 05:42:09 +01:00
|
|
|
<div v-if="Object.keys(form).filter(item => !form[item].hidden).length > 0" class="_gaps_m">
|
2021-12-02 12:09:12 +01:00
|
|
|
<template v-for="item in Object.keys(form).filter(item => !form[item].hidden)">
|
2023-01-07 07:09:46 +01:00
|
|
|
<MkInput v-if="form[item].type === 'number'" v-model="values[item]" type="number" :step="form[item].step || 1">
|
2023-04-01 07:01:57 +02: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 12:09:12 +01:00
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkInput>
|
2023-12-14 05:11:23 +01:00
|
|
|
<MkInput v-else-if="form[item].type === 'string' && !form[item].multiline" v-model="values[item]" type="text" :mfmAutocomplete="form[item].treatAsMfm">
|
2023-04-01 07:01:57 +02: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 12:09:12 +01:00
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkInput>
|
2023-12-14 05:11:23 +01:00
|
|
|
<MkTextarea v-else-if="form[item].type === 'string' && form[item].multiline" v-model="values[item]" :mfmAutocomplete="form[item].treatAsMfm" :mfmPreview="form[item].treatAsMfm">
|
2023-04-01 07:01:57 +02: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 12:09:12 +01:00
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkTextarea>
|
2023-01-07 06:59:54 +01:00
|
|
|
<MkSwitch v-else-if="form[item].type === 'boolean'" v-model="values[item]">
|
2021-12-02 12:09:12 +01:00
|
|
|
<span v-text="form[item].label || item"></span>
|
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 06:59:54 +01:00
|
|
|
</MkSwitch>
|
2023-01-07 07:09:46 +01:00
|
|
|
<MkSelect v-else-if="form[item].type === 'enum'" v-model="values[item]">
|
2023-04-01 07:01:57 +02:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
|
2024-01-30 11:53:53 +01:00
|
|
|
<option v-for="option in form[item].enum" :key="option.value" :value="option.value">{{ option.label }}</option>
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkSelect>
|
|
|
|
<MkRadios v-else-if="form[item].type === 'radio'" v-model="values[item]">
|
2023-04-01 07:01:57 +02:00
|
|
|
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
|
2024-01-30 11:53:53 +01:00
|
|
|
<option v-for="option in form[item].options" :key="option.value" :value="option.value">{{ option.label }}</option>
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkRadios>
|
2023-05-19 06:58:09 +02:00
|
|
|
<MkRange v-else-if="form[item].type === 'range'" v-model="values[item]" :min="form[item].min" :max="form[item].max" :step="form[item].step" :textConverter="form[item].textConverter">
|
2023-04-01 07:01:57 +02: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 12:09:12 +01:00
|
|
|
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkRange>
|
2023-01-05 13:04:56 +01:00
|
|
|
<MkButton v-else-if="form[item].type === 'button'" @click="form[item].action($event, values)">
|
2021-12-02 12:09:12 +01:00
|
|
|
<span v-text="form[item].content || item"></span>
|
|
|
|
</MkButton>
|
|
|
|
</template>
|
|
|
|
</div>
|
2024-01-03 05:42:09 +01:00
|
|
|
<div v-else class="_fullinfo">
|
|
|
|
<img :src="infoImageUrl" class="_ghost"/>
|
|
|
|
<div>{{ i18n.ts.nothing }}</div>
|
|
|
|
</div>
|
2021-12-02 12:09:12 +01:00
|
|
|
</MkSpacer>
|
2023-01-06 01:41:14 +01:00
|
|
|
</MkModalWindow>
|
2020-07-11 03:13:11 +02:00
|
|
|
</template>
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { reactive, shallowRef } from 'vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkInput from './MkInput.vue';
|
|
|
|
import MkTextarea from './MkTextarea.vue';
|
2023-01-07 06:59:54 +01:00
|
|
|
import MkSwitch from './MkSwitch.vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkSelect from './MkSelect.vue';
|
|
|
|
import MkRange from './MkRange.vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkButton from './MkButton.vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkRadios from './MkRadios.vue';
|
2023-01-06 01:41:14 +01:00
|
|
|
import MkModalWindow from '@/components/MkModalWindow.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { i18n } from '@/i18n.js';
|
2024-01-03 05:42:09 +01:00
|
|
|
import { infoImageUrl } from '@/instance.js';
|
2020-07-11 03:13:11 +02:00
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
title: string;
|
|
|
|
form: any;
|
|
|
|
}>();
|
2020-07-11 03:13:11 +02:00
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'done', v: {
|
|
|
|
canceled?: boolean;
|
|
|
|
result?: any;
|
|
|
|
}): void;
|
2024-01-30 11:53:53 +01:00
|
|
|
(ev: 'closed'): void;
|
2023-05-14 05:23:39 +02:00
|
|
|
}>();
|
2020-07-11 03:13:11 +02:00
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
const dialog = shallowRef<InstanceType<typeof MkModalWindow>>();
|
|
|
|
const values = reactive({});
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
for (const item in props.form) {
|
|
|
|
values[item] = props.form[item].default ?? null;
|
|
|
|
}
|
2020-07-11 03:13:11 +02:00
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
function ok() {
|
|
|
|
emit('done', {
|
|
|
|
result: values,
|
|
|
|
});
|
2024-01-30 11:53:53 +01:00
|
|
|
dialog.value?.close();
|
2023-05-14 05:23:39 +02:00
|
|
|
}
|
2020-07-11 03:13:11 +02:00
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
function cancel() {
|
|
|
|
emit('done', {
|
|
|
|
canceled: true,
|
|
|
|
});
|
2024-01-30 11:53:53 +01:00
|
|
|
dialog.value?.close();
|
2023-05-14 05:23:39 +02:00
|
|
|
}
|
2020-07-11 03:13:11 +02:00
|
|
|
</script>
|