Files
mixtape/zero.Web.UI/App/editor/editor.vue
T

90 lines
1.9 KiB
Vue
Raw Normal View History

2020-04-30 14:21:43 +02:00
<template>
<component v-if="loaded" :is="rootNode" class="editor">
2020-05-08 17:00:50 +02:00
<ui-tab v-if="hasTabs" class="ui-box" :label="component.params.name" v-for="(component, index) in components" :key="index">
<editor-component v-for="(child, index) in component.components" :key="index" v-model="model[child.params.field]" :component="child" />
2020-04-30 14:21:43 +02:00
</ui-tab>
2020-05-01 14:34:44 +02:00
<div v-if="!hasTabs" class="ui-box">
2020-05-08 17:00:50 +02:00
<editor-component v-for="(component, index) in components" :key="index" v-model="model[component.params.field]" :component="component" />
2020-05-01 14:34:44 +02:00
</div>
2020-04-30 14:21:43 +02:00
</component>
</template>
<script>
import Axios from 'axios';
import EditorComponent from 'zero/editor/editor-component';
export default {
name: 'uiEditor',
2020-05-01 14:34:44 +02:00
props: {
config: {
type: Object,
required: true
2020-05-02 12:20:22 +02:00
},
value: {
type: Object
2020-05-01 14:34:44 +02:00
}
},
2020-04-30 14:21:43 +02:00
components: { EditorComponent },
data: () => ({
loaded: false,
hasTabs: false,
2020-05-02 12:20:22 +02:00
model: {},
2020-04-30 14:21:43 +02:00
components: []
}),
computed: {
rootNode()
{
return this.hasTabs ? 'ui-tabs' : 'div';
}
},
2020-04-30 15:35:09 +02:00
watch: {
2020-05-01 14:34:44 +02:00
config: {
deep: true,
handler: function()
{
this.load();
}
},
2020-05-02 12:20:22 +02:00
value: {
deep: true,
handler: function (value)
{
this.model = value;
}
},
2020-04-30 15:35:09 +02:00
model: {
deep: true,
handler: function()
{
2020-05-01 14:34:44 +02:00
//console.info('change:editor')
//console.table(JSON.parse(JSON.stringify(this.model)));
2020-04-30 15:35:09 +02:00
}
}
},
2020-04-30 14:21:43 +02:00
created()
{
2020-05-01 14:34:44 +02:00
this.load();
},
methods: {
load()
2020-04-30 14:21:43 +02:00
{
2020-05-01 14:34:44 +02:00
if (!this.config.components)
{
return;
}
this.components = this.config.components;
2020-04-30 14:21:43 +02:00
this.hasTabs = this.components.length > 0 && this.components[0].method === 'tab';
this.loaded = true;
2020-05-01 14:34:44 +02:00
}
2020-04-30 14:21:43 +02:00
}
}
</script>