Skip to content

Commit 3765cbb

Browse files
committed
将TAB选择UI改为下拉选择;解决预览视图中最后一个元素存在下边距的问题;
1 parent 2e72d96 commit 3765cbb

File tree

6 files changed

+55
-84
lines changed

6 files changed

+55
-84
lines changed

src/components/components.vue

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<section>
33
<mu-content-block style="display:flex;">
4-
<mu-select-field :value="activeTab" @change="handleTabChange" autoWidth>
4+
<mu-select-field :value="activeUI" @change="handleTabChange" autoWidth>
55
<mu-menu-item title="Muse-UI" value="Muse-UI">
66
</mu-menu-item>
77
<mu-menu-item title="Mint-UI" value="Mint-UI">
@@ -15,7 +15,7 @@
1515
</mu-select-field>
1616
<mu-sub-header style="white-space:nowrap;">- 组件</mu-sub-header>
1717
</mu-content-block>
18-
<div v-if="activeTab === 'Muse-UI'">
18+
<div v-if="activeUI === 'Muse-UI'">
1919
<ul class="components-list">
2020
<!-- 导航栏 -->
2121
<li draggable="true" @dragstart="dragStart" data-name="App Bar">
@@ -122,7 +122,7 @@
122122
-->
123123
</ul>
124124
</div>
125-
<div v-if="activeTab === 'Mint-UI'">
125+
<div v-if="activeUI === 'Mint-UI'">
126126
<ul class="components-list">
127127
<li draggable="true" @dragstart="dragStart" data-name="Header">
128128
<mt-header fixed title="Header"></mt-header>
@@ -132,7 +132,7 @@
132132
</li>
133133
</ul>
134134
</div>
135-
<div v-if="activeTab === 'iView-UI'">
135+
<div v-if="activeUI === 'iView-UI'">
136136
<ul class="components-list">
137137
<!--
138138
<li draggable="true" @dragstart="dragStart" data-name="Header">
@@ -141,7 +141,7 @@
141141
-->
142142
</ul>
143143
</div>
144-
<div v-if="activeTab === 'Element-UI'">
144+
<div v-if="activeUI === 'Element-UI'">
145145
<ul class="components-list">
146146
<!--
147147
<li draggable="true" @dragstart="dragStart" data-name="Header">
@@ -150,7 +150,7 @@
150150
-->
151151
</ul>
152152
</div>
153-
<div v-if="activeTab==='Common'">
153+
<div v-if="activeUI==='Common'">
154154
<ul class="components-list">
155155
<li draggable="true" @dragstart="dragStart" data-name="Text">
156156
<mu-icon value="text_fields" style="vertical-align:middle;" /> 文本
@@ -176,16 +176,14 @@ import museUiList from './list/muse-ui'
176176
export default {
177177
name: 'components',
178178
data() {
179-
return {
180-
activeTab: 'Muse-UI'
181-
}
179+
return {}
182180
},
183181
mounted() {
184182
185183
},
186184
methods: {
187185
handleTabChange(val) {
188-
this.activeTab = val
186+
this.activeUI = val
189187
},
190188
getComponent(e) {
191189
if (!e)
@@ -203,11 +201,23 @@ export default {
203201
let componentName = e.target.getAttribute('data-name')
204202
let info = {
205203
name: componentName,
206-
ui: this.activeTab
204+
ui: this.activeUI
207205
}
208206
e.dataTransfer.setData('info', JSON.stringify(info))
209207
}
210208
},
209+
computed: {
210+
activeUI: {
211+
get() {
212+
return this.$store.state.activeUI
213+
},
214+
set(val) {
215+
this.$store.commit('setState', {
216+
activeUI: val
217+
})
218+
}
219+
}
220+
},
211221
components: {
212222
...museUiList
213223
}

src/components/preview.vue

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<section class="preview" @dragover="dragOver" @drop="drop">
33
<!-- CODE视图 -->
4-
<mu-paper class="sound-code">
5-
<div class="sound-code-bar">
4+
<mu-paper class="preview-head">
5+
<div class="bar">
66
<mu-sub-header style="display:inline;">{{showType}}</mu-sub-header>
77
<mu-icon-button style="float:right;" icon="fullscreen" tooltip="全屏" @click="fullScreen" />
88
<mu-icon-button style="float:right;" icon="delete" tooltip="清空" @click="empty" />
@@ -14,7 +14,7 @@
1414
<mu-icon-button style="float:right;" icon="code" tooltip="查看代码" @click="showCode" />
1515
<mu-icon-button v-if="$store.state.backupComponents.length" style="float:right;" icon="undo" tooltip="撤销" @click="undo" />
1616
</div>
17-
<mu-content-block :class="{'sound-code-content':true,'active':showType!=='预览'}">
17+
<mu-content-block :class="{'content':true,'active':showType!=='预览'}">
1818
<pre v-show="showType==='CODE'" v-highlightjs="getSource(components)"><code class="html"></code></pre>
1919
<textarea v-show="showType==='编辑样式'" class="css-editor" placeholder=".vue-layout{ ... }" v-model="css"></textarea>
2020
</mu-content-block>
@@ -395,7 +395,7 @@ export default {
395395
if (placeholder)
396396
placeholder.parentElement.removeChild(placeholder)
397397
},
398-
selectedSlot(){
398+
selectedSlot() {
399399
// 必需,勿删,会在ondrop中被重写
400400
},
401401
getSource(components) { //预览视图中所有组件的代码
@@ -569,15 +569,15 @@ export default {
569569
components = components.concat(copiedComponents)
570570
this.$store.commit('setState', {
571571
components,
572-
copiedComponents: []//粘贴后清除剪切板
572+
copiedComponents: [] //粘贴后清除剪切板
573573
})
574574
let topComponent = this.getParentComponent(components[index])
575575
let topIndex = components.findIndex(c => c.info.id === topComponent.info.id)
576576
components[topIndex].template = getTemplate(components[topIndex].info, components[topIndex].attributes, components[topIndex].slots).template
577577
//因为getTemplate中需要最新的components,所以提交两次状态
578578
this.$store.commit('setState', {
579579
components,
580-
copiedComponents: []//粘贴后清除剪切板
580+
copiedComponents: [] //粘贴后清除剪切板
581581
})
582582
this.fresh()
583583
})
@@ -649,10 +649,10 @@ export default {
649649
650650
.preview-area {
651651
overflow: auto;
652-
padding-top: 48px;
653652
position: relative;
654653
height: inherit;
655654
z-index: 0;
655+
padding-bottom: 100px;
656656
}
657657
658658
.preview-tip {
@@ -663,27 +663,31 @@ export default {
663663
z-index: -1;
664664
}
665665
666-
.sound-code {
667-
position: absolute;
666+
.preview-head {
668667
width: 100%;
669668
top: 0;
670669
z-index: 2;
671-
}
672-
673-
.sound-code-bar {
674-
background-color: @grey100;
675-
}
676-
677-
.sound-code-content {
678-
height: 0;
679-
overflow: auto;
680-
transition: all .2s;
681-
padding-top: 0;
682-
padding-bottom: 0;
683-
margin-top: 0;
684-
margin-bottom: 0;
685-
background-color: @grey50;
686-
user-select: text;
670+
.bar {
671+
background-color: @grey100;
672+
}
673+
.content {
674+
height: 0;
675+
overflow: auto;
676+
transition: all .2s;
677+
padding-top: 0;
678+
padding-bottom: 0;
679+
margin-top: 0;
680+
margin-bottom: 0;
681+
background-color: @grey50;
682+
user-select: text;
683+
code {
684+
background: none;
685+
font-family: Consolas, Liberation Mono, Menlo, Courier, monospace;
686+
}
687+
}
688+
.content.active {
689+
height: 95vh;
690+
}
687691
}
688692
689693
.css-editor {
@@ -695,15 +699,6 @@ export default {
695699
overflow: auto;
696700
}
697701
698-
.sound-code-content code {
699-
background: none;
700-
font-family: Consolas, Liberation Mono, Menlo, Courier, monospace;
701-
}
702-
703-
.sound-code-content.active {
704-
height: 95vh;
705-
}
706-
707702
.preview-mobile {
708703
position: absolute;
709704
width: 375px;
@@ -719,10 +714,4 @@ export default {
719714
width: 100%;
720715
}
721716
</style>
722-
<style>
723-
/*预览视图底部预留空间 方便操作 */
724717

725-
.preview-area > *:nth-last-child(1) {
726-
margin-bottom: 100px;
727-
}
728-
</style>

src/components/preview_mobile.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ section {
3131
width: 100%;
3232
height: 100vh;
3333
background-color: @grey50;
34-
margin-top: 48px;
3534
}
3635
</style>

src/components/template/Mint-UI/Header.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ var handle = function(_attr, _slots) {
55
title: {
66
type: 'text',
77
value: 'title'
8+
},
9+
fixed:{
10+
type:'boolean',
11+
value:false
812
}
913
},
1014
slots = {

src/components/template/README.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +0,0 @@
1-
如何拓展UI可视化组件?
2-
==
3-
4-
1. 如果是新增的UI,先在main.js中引入,然后在`./src/components/template`路径下,创建对应的UI的文件夹(如果没有);
5-
2. copy已有的类似组件。假设你要拓展mint-ui的导航栏组件,你可以直接复制muse-ui的导航栏(`./src/components/template/Muse-UI/App Bar.js`)到Mint-UI目录中,修改文件名为Header.js、以及其中的部分代码即可:
6-
![此处输入图片的描述][1]
7-
主要就是修改红框部分的内容,attributes和slots参照UI文档的API,template改成对应组件的标签名,当然每个UI、每个组件都不同,有的只需要稍作修改,有的则需要改很多。
8-
每次属性视图上触发的属性更新,都会让handle函数执行一遍,并传入新的属性、嵌套以及组件的信息,然后返回拼凑的新模板,重新挂载到预览视图。**属性可视化编辑的功能就是这么实现的。**
9-
10-
3. header.js完成后,在`./src/components/template/Mint-UI/index.js`中引入,
11-
![此处输入图片的描述][2]
12-
图中的键名的写法,是因为有的键名包含空格,比如"App Bar",为了直观和便于维护,命名都是与UI官方文档相同。
13-
14-
4. 再将添加的Header组件添加到组件列表视图即可。
15-
16-
>
17-
<li draggable="true" @dragstart="dragStart" data-name="Header">
18-
<mt-header fixed title="Header"></mt-header>
19-
</li>
20-
21-
22-
li标签包裹的元素,就是显示在组件列表视图的元素,其中li的data-name的值必须与上一步骤中保存的键名相同。
23-
24-
到此,一个mint-ui导航栏组件的可视化就拓展完成了。
25-
26-
完结,撒花。
27-
28-
29-
30-
31-
[1]: https://raw.githubusercontent.com/jaweii/Vue-Layout/master/docs/images/App%20Bar1.png
32-
[2]: https://raw.githubusercontent.com/jaweii/Vue-Layout/master/docs/images/Header%201.png

src/store/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const store = new Vuex.Store({
2222
components: '25'
2323
}],
2424
css: '', //用户编辑的自定义css字符串
25+
activeUI:'Muse-UI',
2526
currentComponent: {}, //预览视图的选中组件
2627
components: [], //预览视图的组件树
2728
backupComponents: [],//删除组件时备份的

0 commit comments

Comments
 (0)