Commit e32c628d authored by 张晨辰's avatar 张晨辰

feat: 数据处理

parent 5b53ad72
<template> <template>
<div class="zero-custom-picture" :style="`background-image:url(${properties.source.value}); background-size: contain;`"></div> <div class="zero-custom-picture" :style="`background-image:url(${properties.source}); background-size: contain;`"></div>
</template> </template>
<style> <style>
......
...@@ -36,8 +36,8 @@ export default { ...@@ -36,8 +36,8 @@ export default {
showPlaceholder() { showPlaceholder() {
return ( return (
!this.isTyping && !this.isTyping &&
typeof this.properties.text.value !== 'undefined' && typeof this.properties.text !== 'undefined' &&
!this.properties.text.value.replace(/\s|(&nbsp;)/g, '') !this.properties.text.replace(/\s|(&nbsp;)/g, '')
); );
}, },
addNBSP() { addNBSP() {
...@@ -45,7 +45,7 @@ export default { ...@@ -45,7 +45,7 @@ export default {
} }
}, },
created() { created() {
this.selfText = this.properties.text.value || this.selfText; this.selfText = this.properties.text || this.selfText;
} }
}; };
</script> </script>
<template> <template>
<div class="zero-custom-shape-rect-blue" :style="`background-color: ${properties.fillColor.value};border-width: ${properties.strokeWidth.value}px; border-color: ${properties.strokeColor.value};`"></div> <div class="zero-custom-shape-rect-blue" :style="`background-color: ${properties.fillColor};border-width: ${properties.strokeWidth}px; border-color: ${properties.strokeColor};`"></div>
</template> </template>
<style> <style>
......
...@@ -45,26 +45,25 @@ export const projectStore = { ...@@ -45,26 +45,25 @@ export const projectStore = {
Vue.set(localData, 'dataMapping', dataMapping || []); Vue.set(localData, 'dataMapping', dataMapping || []);
} }
} }
compoleteComponentData(state.data.views); // compoleteComponentData(state.data.views);
}, },
/** /**
* 激活组件 * 激活组件
* @param {*} state * @param {*} state
* @param {*} id * @param {*} id
*/ */
activeComponent(state, id) { activeComponent(state, item) {
// todo drag // todo drag
// if (state.cmpListDragging) { // if (state.cmpListDragging) {
// state.cmpListDragging = false; // state.cmpListDragging = false;
// return; // return;
// } // }
if (id !== state.activeComponent.id) { if (item !== state.activeComponent) {
const _active = this.getters.componentList.find(cmp => cmp.id === id); state.activeComponent = item || state.activeComponent;
state.activeComponent = _active || state.activeComponent;
} }
state.activeComponent = id; state.activeComponent = item;
state.activeIdList = [id]; // state.activeIdList = [id];
console.log('mutations activeComponent', state); console.log('mutations activeComponent', state);
}, },
modifyProject(state, ) { modifyProject(state, ) {
...@@ -169,10 +168,7 @@ export const projectStore = { ...@@ -169,10 +168,7 @@ export const projectStore = {
return flat.concat(toFlat.children ? flatten(toFlat.children).concat([toFlat]) : [toFlat]); return flat.concat(toFlat.children ? flatten(toFlat.children).concat([toFlat]) : [toFlat]);
}, []); }, []);
}; };
let result = flatten(state.data.views).map(v => { let result = flatten(state.data.views);
delete v.children;
return v;
});
// let result = state.data.views.flatMap(v => [v, v.children || []]) // let result = state.data.views.flatMap(v => [v, v.children || []])
console.log('componentList', result); console.log('componentList', result);
return result; return result;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
display: flex; display: flex;
flex: 1; flex: 1;
border-radius: 2px; border-radius: 2px;
position: relative;
} }
.title-bar { .title-bar {
......
...@@ -4,20 +4,24 @@ import { getComposedComponents } from './getComposedComponents'; ...@@ -4,20 +4,24 @@ import { getComposedComponents } from './getComposedComponents';
const composedComponents = getComposedComponents(); const composedComponents = getComposedComponents();
/**
* 初始化配置中的views数据
* @param {*} views
*/
export const compoleteComponentData = (views) => { export const compoleteComponentData = (views) => {
views.forEach(view => { views.forEach(view => {
view.id = view.id || guid(); // view.id = view.id || guid();
let _composedCmp = composedComponents[view.type]; // let _composedCmp = composedComponents[view.type];
view.component = _composedCmp.component.default; // // view.component = _composedCmp.component.default;
let _composedProps = _.cloneDeep(_composedCmp.properties); // 组件预设的属性,Object类型 // let _composedProps = _.cloneDeep(_composedCmp.properties); // 组件预设的属性,Object类型
let _viewProps = view.properties || {}; // 组件对象的具体属性,key:value // let _viewProps = view.properties || {}; // 组件对象的具体属性,key:value
let _keys = Object.keys(_viewProps); // let _keys = Object.keys(_viewProps);
_keys.forEach(k => { // _keys.forEach(k => {
_composedProps[k].value = _viewProps[k] // _composedProps[k].value = _viewProps[k]
}); // });
view.properties = _composedProps; // view.properties = _composedProps;
if (view.children) { if (view.children) {
compoleteComponentData(view.children); compoleteComponentData(view.children);
......
/**
* 获取customElement下的所有组件
*/
export const getComposedComponents = () => { export const getComposedComponents = () => {
// 去中心化; // 去中心化;
const context = require.context( const context = require.context(
......
...@@ -5,19 +5,19 @@ ...@@ -5,19 +5,19 @@
<el-form-item > <el-form-item >
<el-button @click="testGetter">test</el-button> <el-button @click="testGetter">test</el-button>
</el-form-item> </el-form-item>
<p>基础</p> <!-- <p>基础</p> -->
<el-divider></el-divider> <!-- <el-divider></el-divider> -->
<el-divider content-position="left">基础</el-divider>
<el-form-item label="类型"> <el-form-item label="类型">
<el-select v-model="activeComponent.type" placeholder="请选择类型"> <el-select v-model="activeComponent.type" placeholder="请选择类型">
<el-option v-for="cmp in componentsMap" :key="cmp.value" :label="cmp.label" :value="cmp.value"></el-option> <el-option v-for="cmp in componentsMap" :key="cmp.value" :label="cmp.label" :value="cmp.value"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<p>{{activeComponent.properties.groupName}}</p> <el-divider content-position="left">{{activeComponent.properties.groupName}}</el-divider>
<el-divider></el-divider>
<!-- <template v-for=""></template> --> <!-- <template v-for=""></template> -->
</el-form> </el-form>
</div> </div>
<div class="inspec-test" style="position: absolute;bottom: 0;font-size: 12px;background-color:#fff; width: 100%;height: 100px;" @click.native="testGetter"> <div class="inspec-test" style="word-break: break-all;position: absolute;bottom: 0;font-size: 12px;background-color:#fff; width: 100%;height: 100px;" @click.native="testGetter">
{{JSON.stringify(activeComponent.properties)}} {{JSON.stringify(activeComponent.properties)}}
</div> </div>
</pane> </pane>
...@@ -34,8 +34,7 @@ export default { ...@@ -34,8 +34,7 @@ export default {
components: { Pane }, components: { Pane },
data() { data() {
return { return {
componentsMap, componentsMap
sel: ''
}; };
}, },
computed: { computed: {
...@@ -70,5 +69,8 @@ export default { ...@@ -70,5 +69,8 @@ export default {
.el-form-item--mini.el-form-item { .el-form-item--mini.el-form-item {
margin-bottom: 10px; margin-bottom: 10px;
} }
.el-divider__text{
background-color: #e9e9e9;
}
} }
</style> </style>
\ No newline at end of file
...@@ -3,13 +3,11 @@ ...@@ -3,13 +3,11 @@
<div class="zero-draw-panel-container" > <div class="zero-draw-panel-container" >
<div class="zero-components-container" > <div class="zero-components-container" >
<div <div
v-if="item.id" :key="index"
:key="item.id" v-for="(item, index) in componentList"
:id="item.id" @click.exact="activeComponent(item)"
v-for="item in componentList" @click.shift.exact="changeActiveIdList(item)"
@click.exact="activeComponent(item.id)" @contextmenu.prevent="activeComponent(item)"
@click.shift.exact="changeActiveIdList(item.id)"
@contextmenu.prevent="activeComponent(item.id)"
> >
<wrapper :component-data="item"/> <wrapper :component-data="item"/>
</div> </div>
...@@ -28,11 +26,11 @@ import wrapper from './wrapper'; ...@@ -28,11 +26,11 @@ import wrapper from './wrapper';
export default { export default {
components: { wrapper }, components: { wrapper },
methods: { methods: {
activeComponent(id) { activeComponent(item) {
this.$store.dispatch('activeComponent', id); this.$store.dispatch('activeComponent', item);
}, },
changeActiveIdList(id) { changeActiveIdList(item) {
this.$store.commit('changeActiveIdList', id); this.$store.commit('changeActiveIdList', item);
} }
}, },
computed: { computed: {
......
...@@ -18,13 +18,20 @@ ...@@ -18,13 +18,20 @@
@input="handleInput" @input="handleInput"
@keyup.delete.prevent="changeEditRange" @keyup.delete.prevent="changeEditRange"
> >
<component :is="componentData.component" :is-typing="false" :properties="componentData.properties" /> <component :is="composedComponents[componentData.type].component.default" :is-typing="false" :properties="componentData.properties" />
</div> </div>
</vue-draggable-resizable> </vue-draggable-resizable>
</template> </template>
<script> <script>
import { getComposedComponents } from '../../../utils/getComposedComponents';
const composedComponents = getComposedComponents();
console.log('composedComponents', composedComponents);
export default { export default {
props: { props: {
from: { from: {
...@@ -35,6 +42,11 @@ export default { ...@@ -35,6 +42,11 @@ export default {
require: true require: true
} }
}, },
data() {
return {
composedComponents
}
},
methods: { methods: {
handleEnableInput() { handleEnableInput() {
// 处于编辑状态的组件不可进行 删除、移动、缩放操作 // 处于编辑状态的组件不可进行 删除、移动、缩放操作
...@@ -149,11 +161,14 @@ export default { ...@@ -149,11 +161,14 @@ export default {
}, },
position() { position() {
const componentData = this.componentData; const componentData = this.componentData;
console.log('componentData', componentData);
componentData.properties = componentData.properties || {};
return { return {
x: componentData.properties.left.value, x: componentData.properties.left || 0,
y: componentData.properties.top.value, y: componentData.properties.top || 0,
w: componentData.properties.width.value, w: componentData.properties.width || 10,
h: componentData.properties.height.value h: componentData.properties.height || 10
} }
// return !componentData // return !componentData
...@@ -196,9 +211,6 @@ export default { ...@@ -196,9 +211,6 @@ export default {
.vdr.isTyping { .vdr.isTyping {
cursor: text; cursor: text;
} }
/* .handle {
border-radius: 50%;
} */
.vdr.choosed-cmp > .handle { .vdr.choosed-cmp > .handle {
display: block !important; display: block !important;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment