Pages: Implement radio button

This commit is contained in:
syuilo 2019-07-10 18:30:51 +09:00
parent a59ab79da0
commit feec5e88fc
7 changed files with 108 additions and 2 deletions

View file

@ -2066,6 +2066,13 @@ pages:
variable: "送信する変数" variable: "送信する変数"
no-variable: "なし" no-variable: "なし"
radioButton: "選択肢"
_radioButton:
name: "変数名"
title: "タイトル"
values: "改行で区切った選択肢"
default: "デフォルト値"
script: script:
categories: categories:
flow: "制御" flow: "制御"

View file

@ -32,6 +32,12 @@ export function collectPageVars(content) {
type: 'number', type: 'number',
value: 0 value: 0
}); });
} else if (x.type === 'radioButton') {
pageVars.push({
name: x.name,
type: 'string',
value: x.default || ''
});
} else if (x.children) { } else if (x.children) {
collect(x.children); collect(x.children);
} }

View file

@ -16,10 +16,11 @@ import XIf from './page.if.vue';
import XTextarea from './page.textarea.vue'; import XTextarea from './page.textarea.vue';
import XPost from './page.post.vue'; import XPost from './page.post.vue';
import XCounter from './page.counter.vue'; import XCounter from './page.counter.vue';
import XRadioButton from './page.radio-button.vue';
export default Vue.extend({ export default Vue.extend({
components: { components: {
XText, XSection, XImage, XButton, XNumberInput, XTextInput, XTextareaInput, XTextarea, XPost, XSwitch, XIf, XCounter XText, XSection, XImage, XButton, XNumberInput, XTextInput, XTextareaInput, XTextarea, XPost, XSwitch, XIf, XCounter, XRadioButton
}, },
props: { props: {

View file

@ -0,0 +1,37 @@
<template>
<div>
<div>{{ script.interpolate(value.title) }}</div>
<ui-radio v-for="x in value.values" v-model="v" :value="x" :key="x">{{ x }}</ui-radio>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
props: {
value: {
required: true
},
script: {
required: true
}
},
data() {
return {
v: this.value.default,
};
},
watch: {
v() {
this.script.aiScript.updatePageVar(this.value.name, this.v);
this.script.eval();
}
}
});
</script>
<style lang="stylus" scoped>
</style>

View file

@ -0,0 +1,53 @@
<template>
<x-container @remove="() => $emit('remove')" :draggable="true">
<template #header><fa :icon="faBolt"/> {{ $t('blocks.radioButton') }}</template>
<section style="padding: 0 16px 16px 16px;">
<ui-input v-model="value.name"><template #prefix><fa :icon="faMagic"/></template><span>{{ $t('blocks._radioButton.name') }}</span></ui-input>
<ui-input v-model="value.title"><span>{{ $t('blocks._radioButton.title') }}</span></ui-input>
<ui-textarea v-model="values"><span>{{ $t('blocks._radioButton.values') }}</span></ui-textarea>
<ui-input v-model="value.default"><span>{{ $t('blocks._radioButton.default') }}</span></ui-input>
</section>
</x-container>
</template>
<script lang="ts">
import Vue from 'vue';
import { faBolt, faMagic } from '@fortawesome/free-solid-svg-icons';
import i18n from '../../../../../i18n';
import XContainer from '../page-editor.container.vue';
export default Vue.extend({
i18n: i18n('pages'),
components: {
XContainer
},
props: {
value: {
required: true
},
},
data() {
return {
values: '',
faBolt, faMagic
};
},
watch: {
values() {
Vue.set(this.value, 'values', this.values.split('\n'));
}
},
created() {
if (this.value.name == null) Vue.set(this.value, 'name', '');
if (this.value.title == null) Vue.set(this.value, 'title', '');
if (this.value.values == null) Vue.set(this.value, 'values', []);
this.values = this.value.values.join('\n');
},
});
</script>

View file

@ -19,10 +19,11 @@ import XSwitch from './els/page-editor.el.switch.vue';
import XIf from './els/page-editor.el.if.vue'; import XIf from './els/page-editor.el.if.vue';
import XPost from './els/page-editor.el.post.vue'; import XPost from './els/page-editor.el.post.vue';
import XCounter from './els/page-editor.el.counter.vue'; import XCounter from './els/page-editor.el.counter.vue';
import XRadioButton from './els/page-editor.el.radio-button.vue';
export default Vue.extend({ export default Vue.extend({
components: { components: {
XDraggable, XSection, XText, XImage, XButton, XTextarea, XTextInput, XTextareaInput, XNumberInput, XSwitch, XIf, XPost, XCounter XDraggable, XSection, XText, XImage, XButton, XTextarea, XTextInput, XTextareaInput, XNumberInput, XSwitch, XIf, XPost, XCounter, XRadioButton
}, },
props: { props: {

View file

@ -342,6 +342,7 @@ export default Vue.extend({
label: this.$t('input-blocks'), label: this.$t('input-blocks'),
items: [ items: [
{ value: 'button', text: this.$t('blocks.button') }, { value: 'button', text: this.$t('blocks.button') },
{ value: 'radioButton', text: this.$t('blocks.radioButton') },
{ value: 'textInput', text: this.$t('blocks.textInput') }, { value: 'textInput', text: this.$t('blocks.textInput') },
{ value: 'textareaInput', text: this.$t('blocks.textareaInput') }, { value: 'textareaInput', text: this.$t('blocks.textareaInput') },
{ value: 'numberInput', text: this.$t('blocks.numberInput') }, { value: 'numberInput', text: this.$t('blocks.numberInput') },