Commit 058d0999 authored by 张晨辰's avatar 张晨辰

feat: asset拖拽

parent d772678d
<template> <template>
<div class="zero-custom-picture" :style="`background-image:url(${properties.source}); background-size: contain;`"></div> <div class="zero-custom-picture"></div>
</template> </template>
<style> <style>
.zero-custom-picture { /* .zero-custom-picture {
height: 100%; height: 100%;
background-position: center; background-position: center;
} } */
</style> </style>
<script> <script>
......
...@@ -2,15 +2,7 @@ ...@@ -2,15 +2,7 @@
<el-slider class="zero-slider" v-model="swvalue" :min="min" :max="max" :step="step" show-input :show-input-controls="false" input-size="mini"></el-slider> <el-slider class="zero-slider" v-model="swvalue" :min="min" :max="max" :step="step" show-input :show-input-controls="false" input-size="mini"></el-slider>
</template> </template>
<style> <style>
.el-slider.zero-slider {
width: 180px;
}
.zero-slider .el-slider__runway.show-input {
width: 100px;
}
.zero-slider > .el-slider__input {
width: 60px;
}
/* .zero-slider > .el-slider__input > span { /* .zero-slider > .el-slider__input > span {
display: none; display: none;
} }
......
<template> <template>
<el-input disabled v-model="swvalue" @drop.native="drop(event)"></el-input> <el-input v-model="swvalue" @drop.native="drop" @dragover.native="dragOver"></el-input>
</template> </template>
<style> <style>
</style> </style>
<script> <script>
export default { export default {
...@@ -11,7 +10,7 @@ export default { ...@@ -11,7 +10,7 @@ export default {
}, },
data() { data() {
return { return {
swvalue: (this.value || '').split('/').pop() swvalue: this.value || ''
}; };
}, },
watch: { watch: {
...@@ -21,8 +20,14 @@ export default { ...@@ -21,8 +20,14 @@ export default {
}, },
methods: { methods: {
drop(e) { drop(e) {
console.log('native drop', e); if (this.$store.state.project.dragUUID) {
// debugger;
console.log('native drop', this.$store.state);
this.swvalue = `asset://${this.$store.state.project.dragUUID}`
}
},
dragOver(e) {
e.preventDefault();
} }
} }
}; };
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
* Created by rockyl on 2019-09-19. * Created by rockyl on 2019-09-19.
*/ */
//export const API_HOST = 'http://10.10.93.73:7777'; export const API_HOST = 'http://10.10.95.74:7777';
export const API_HOST = 'http://localhost:3002'; //export const API_HOST = 'http://localhost:3002';
export const UPLOAD_FILE_URL = API_HOST + '/api/uploadFile'; export const UPLOAD_FILE_URL = API_HOST + '/api/uploadFile';
export const PARSE_BUNDLE_URL = API_HOST + '/api/parsePSD'; export const PARSE_BUNDLE_URL = API_HOST + '/api/parsePSD';
......
...@@ -23,6 +23,8 @@ export const projectStore = { ...@@ -23,6 +23,8 @@ export const projectStore = {
}, },
activeComponent: {}, activeComponent: {},
activeIdList: [], activeIdList: [],
activeViews: '',
dragUUID: '',
dirty: false, dirty: false,
}, },
mutations: { mutations: {
...@@ -54,8 +56,8 @@ export const projectStore = { ...@@ -54,8 +56,8 @@ export const projectStore = {
* @param {*} id * @param {*} id
*/ */
activeComponent(state, item) { activeComponent(state, item) {
// debugger;
if (item !== state.activeComponent) { if (item !== state.activeComponent) {
// debugger;
state.activeComponent = item || state.activeComponent; state.activeComponent = item || state.activeComponent;
state.activeComponent.properties = state.activeComponent.properties || {}; state.activeComponent.properties = state.activeComponent.properties || {};
console.log('mutations activeComponent', state); console.log('mutations activeComponent', state);
...@@ -102,6 +104,14 @@ export const projectStore = { ...@@ -102,6 +104,14 @@ export const projectStore = {
} }
console.log('modifyComponent', state.activeComponent); console.log('modifyComponent', state.activeComponent);
}, },
/**
* assets拖拽
* @param {*} data
*/
assetDragStart(state, data) {
console.log('assetDragStart', data);
state.dragUUID = data.uuid;
},
modifyProject(state, ) { modifyProject(state, ) {
}, },
...@@ -195,10 +205,14 @@ export const projectStore = { ...@@ -195,10 +205,14 @@ export const projectStore = {
* 当前激活的组件 * 当前激活的组件
*/ */
activeComponent: state => { activeComponent: state => {
let _cmp = state.activeComponent || {} // if (state.activeComponent) {
console.log('activeComponent', _cmp); // let _cmp = state.activeComponent || {}
// console.log('activeComponent', _cmp);
return { ..._cmp, uuid: _cmp.uuid || generateUUID() } // return { ..._cmp, uuid: _cmp.uuid || generateUUID() }
// } else {
// return {};
// }
return state.activeComponent;
}, },
/** /**
* 当前激活的组件ID * 当前激活的组件ID
...@@ -210,12 +224,18 @@ export const projectStore = { ...@@ -210,12 +224,18 @@ export const projectStore = {
* 扁平化所有节点 * 扁平化所有节点
*/ */
componentList: state => { componentList: state => {
// debugger;
const flatten = arr => { const flatten = arr => {
return arr.reduce((flat, toFlat) => { return arr.reduce((flat, toFlat) => {
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); let _view = state.data.views.length ? [].concat(state.data.views[0]) : [];
if (state.activeViews) {
_view = state.data.views.filter(v => v.uuid === state.activeViews)
}
// debugger;
let result = flatten(_view);
// 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;
...@@ -263,13 +283,26 @@ export const projectStore = { ...@@ -263,13 +283,26 @@ export const projectStore = {
}, },
/** /**
* 选中节点 * 选中节点
* @param {*} param0 * @param {*} param
* @param {*} data * @param {*} data
*/ */
activeComponent({ commit }, data) { activeComponent({ commit, state }, data) {
console.log('actions activeComponent', data); console.log('actions activeComponent', data);
commit('activeComponent', data); let getTopView = node => {
if (node.parent && !node.parent.parent) {
return node;
} else {
return getTopView(node.parent);
}
}
let _view = getTopView(data.node);
if (_view && _view.data) {
state.activeViews = _view.data.uuid;
}
commit('activeComponent', data.data);
}, },
/** /**
* 修改属性 * 修改属性
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
@import "./home.scss"; @import "./home.scss";
@import "./editor.scss"; @import "./editor.scss";
@import "./playground.scss"; @import "./playground.scss";
@import "./inspector.scss";
@import "~element-ui/packages/theme-chalk/src/index.scss"; @import "~element-ui/packages/theme-chalk/src/index.scss";
......
.zero-inspector-form{
.el-input-number.el-input-number--mini,.el-select.el-select--mini{
width: 100%;
}
.el-slider.zero-slider {
width: 180px;
}
.zero-slider .el-slider__runway.show-input {
width: 100px;
}
.zero-slider > .el-slider__input {
width: 60px;
}
}
\ No newline at end of file
...@@ -49,6 +49,10 @@ const attrUnitMapper = { ...@@ -49,6 +49,10 @@ const attrUnitMapper = {
minHeight: 'px' minHeight: 'px'
}; };
// function getAssetByUUID(asset, uuid){
// return
// }
export const styles = { export const styles = {
getStyles(value, key) { getStyles(value, key) {
const attr = attrShortMapper[key] || changeCamle(key); const attr = attrShortMapper[key] || changeCamle(key);
...@@ -75,10 +79,15 @@ export const styles = { ...@@ -75,10 +79,15 @@ export const styles = {
* 根据Object类型的属性对象,生成dom中style属性可用的数据格式 * 根据Object类型的属性对象,生成dom中style属性可用的数据格式
* @param {*} obj * @param {*} obj
*/ */
getStylesFromObj(obj) { getStylesFromObj(obj, project) {
let resultObj = {}; let resultObj = {};
_.forIn(obj, (value, key) => { _.forIn(obj, (value, key) => {
if (key === 'source' && value.indexOf('asset://') === 0) {
let uuid = value.split('//')[1];
let asset = project.data.assets.find(a => a.uuid === uuid);
value = asset ? asset.url : '';
}
let _style = styles.getStyles(value, key); let _style = styles.getStyles(value, key);
if (!_style) { if (!_style) {
return; return;
...@@ -96,7 +105,7 @@ export const styles = { ...@@ -96,7 +105,7 @@ export const styles = {
* 根据组件数据,生成完整的style * 根据组件数据,生成完整的style
* @param {*} component * @param {*} component
*/ */
getComponentStyle(component) { getComponentStyle(component, project) {
let result = ''; let result = '';
// 根据组件类型,获取默认属性 // 根据组件类型,获取默认属性
...@@ -104,8 +113,8 @@ export const styles = { ...@@ -104,8 +113,8 @@ export const styles = {
defaultProps = _.omit(defaultProps, _.keys(component.properties)); defaultProps = _.omit(defaultProps, _.keys(component.properties));
defaultProps = _.mapValues(defaultProps, o => (o.value)); defaultProps = _.mapValues(defaultProps, o => (o.value));
let _cmpProps = styles.getStylesFromObj(component.properties); let _cmpProps = styles.getStylesFromObj(component.properties, project);
let _defaultProps = styles.getStylesFromObj(defaultProps); let _defaultProps = styles.getStylesFromObj(defaultProps, project);
_.forIn({ _.forIn({
..._defaultProps, ..._defaultProps,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<div class="file-item"> <div class="file-item">
<div class="icon"> <div class="icon">
<i v-if="!showThumbnail" draggable="true" class="file-icon" :class="fileIcon"></i> <i v-if="!showThumbnail" draggable="true" class="file-icon" :class="fileIcon"></i>
<img v-if="showThumbnail" draggable="true" class="thumbnail" :src="thumbnailUrl" alt="thumb" @dblclick="onDbclick()"> <img @dragstart="assetDragStart(data)" v-if="showThumbnail" draggable="true" class="thumbnail" :src="thumbnailUrl" alt="thumb" @dblclick="onDbclick()">
<div class="operate-bar"> <div class="operate-bar">
<el-button circle size="mini" type="success" icon="el-icon-edit" @dblclick.native.stop @click="onClickEdit"/> <el-button circle size="mini" type="success" icon="el-icon-edit" @dblclick.native.stop @click="onClickEdit"/>
<el-button circle size="mini" type="danger" icon="el-icon-delete" @dblclick.native.stop <el-button circle size="mini" type="danger" icon="el-icon-delete" @dblclick.native.stop
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
...mapMutations([ ...mapMutations([
'deleteAsset', 'deleteAsset',
'modifyAsset', 'modifyAsset',
'assetDragStart'
]), ]),
} }
} }
......
<template> <template>
<pane icon="el-icon-s-operation" :title="$t('panes.Inspector')"> <pane icon="el-icon-s-operation" :title="$t('panes.Inspector')">
<div class="zero-inspector-form"> <div class="zero-inspector-form">
<el-form ref="form" size="mini" v-if="activeComponent.name" :model="form" label-width="80px"> <el-form ref="form" size="mini" v-if="activeComponent.uuid" :model="form" label-width="80px">
<el-divider content-position="left">配置</el-divider> <el-divider content-position="left">配置</el-divider>
<el-form-item label="名称"> <el-form-item label="名称">
<el-input v-model="form.name" @input="v => handleChange('name', v)"></el-input> <el-input v-model="form.name" @input="v => handleChange('name', v)"></el-input>
......
...@@ -54,100 +54,97 @@ ...@@ -54,100 +54,97 @@
</template> </template>
<script> <script>
import {mapState, mapMutations, mapActions} from 'vuex'; import { mapState, mapMutations, mapActions } from 'vuex';
import Pane from '../../components/Pane'; import Pane from '../../components/Pane';
import {PARSE_BUNDLE_URL} from "../../config"; import { PARSE_BUNDLE_URL } from '../../config';
export default { export default {
name: 'Views', name: 'Views',
components: {Pane}, components: { Pane },
data() { data() {
return { return {
defaultProps: { defaultProps: {
children: 'children', children: 'children',
label: 'name' label: 'name'
} }
}; };
}, },
computed: { computed: {
importFileUrl() { importFileUrl() {
return PARSE_BUNDLE_URL; return PARSE_BUNDLE_URL;
}, },
...mapState({ ...mapState({
views: state => state.project.data.views views: state => state.project.data.views
}) })
}, },
methods: { methods: {
allowDrag(draggingNode) { allowDrag(draggingNode) {
return draggingNode.parent.parent; return draggingNode.parent.parent;
}, },
/** /**
* 点击左侧视图列表 * 点击左侧视图列表
*/ */
handleNodeClick(data) { handleNodeClick(data, node) {
this.$store.commit('activeComponent', data); this.$store.dispatch('activeComponent', { data, node });
}, },
toAddView() { toAddView() {
this.$prompt(this.$t('Input view name'), this.$t('Alert'), { this.$prompt(this.$t('Input view name'), this.$t('Alert'), {
confirmButtonText: this.$t('Confirm'), confirmButtonText: this.$t('Confirm'),
cancelButtonText: this.$t('Cancel'), cancelButtonText: this.$t('Cancel'),
inputPattern: /^.{1,64}$/, inputPattern: /^.{1,64}$/,
inputErrorMessage: this.$t('Invalid view name') inputErrorMessage: this.$t('Invalid view name')
}) })
.then(({value}) => { .then(({ value }) => {
this.addNode({ this.addNode({
name: value, name: value,
type: 'node' type: 'node'
}); });
}) })
.catch(() => { .catch(() => {});
}); },
}, toImportView() {},
toImportView() { selectNode(data, node, target) {},
}, onMoreMenu(command, data, node) {
selectNode(data, node, target) { switch (command) {
}, case 'delete':
onMoreMenu(command, data, node) { this.deleteNode({
switch (command) { node: data,
case 'delete': parentNode: node.parent.data
this.deleteNode({ });
node: data, break;
parentNode: node.parent.data case 'export':
}); this.exportView(data);
break; break;
case 'export': default:
this.exportView(data); if (command.startsWith('add_node_')) {
break; const type = command.substr('add_node_'.length);
default: this.addNode({
if (command.startsWith('add_node_')) { node: data,
const type = command.substr('add_node_'.length); type,
this.addNode({ name: 'node'
node: data, });
type, }
name: 'node' break;
}); }
} },
break; uploadFileSuccess(response, file) {
} if (response.success) {
}, console.log('upload success', response);
uploadFileSuccess(response, file) { const { view, assets } = response.data;
if (response.success) {
console.log('upload success', response);
const {view, assets} = response.data;
this.importView(view); this.importView(view);
this.importAssets(assets); this.importAssets(assets);
} else { } else {
this.uploadFileError(); this.uploadFileError();
} }
}, },
uploadFileError() { uploadFileError() {
console.log('upload error') console.log('upload error');
}, },
...mapMutations(['importView', 'importAssets', 'deleteNode', 'addNode']), ...mapMutations(['importView', 'importAssets', 'deleteNode', 'addNode']),
...mapActions(['exportView']), ...mapActions(['exportView'])
} }
}; };
</script> </script>
<style scoped> <style scoped>
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'; import { mapState, mapGetters } from 'vuex';
import { getComposedComponents } from '../../../utils/getComposedComponents'; import { getComposedComponents } from '../../../utils/getComposedComponents';
import { styles } from '../../../utils/common'; import { styles } from '../../../utils/common';
import properties from '../../../utils/properties'; import properties from '../../../utils/properties';
...@@ -139,6 +139,7 @@ export default { ...@@ -139,6 +139,7 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['project']),
...mapGetters(['activeComponentId']), ...mapGetters(['activeComponentId']),
active() { active() {
return this.activeComponentId === (this.componentData || {}).uuid; return this.activeComponentId === (this.componentData || {}).uuid;
...@@ -153,7 +154,7 @@ export default { ...@@ -153,7 +154,7 @@ export default {
styleObject() { styleObject() {
console.log('wrapper styleObject'); console.log('wrapper styleObject');
return styles.getComponentStyle(this.componentData); return styles.getComponentStyle(this.componentData, this.project);
}, },
position() { position() {
const componentData = this.componentData; const componentData = this.componentData;
......
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