forked from vincentzyc/form-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhome.vue
More file actions
188 lines (182 loc) · 6.27 KB
/
home.vue
File metadata and controls
188 lines (182 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<template>
<div class="home">
<Header />
<el-container>
<div class="form-edit-wrapper flex">
<el-aside style="min-width:300px;width:20vw">
<div class="components-list">
<div class="widget-cate">基础类组件</div>
<draggable
tag="ul"
:list="basicComponents"
:group="{ name:'widget', pull:'clone',put:false}"
:sort="false"
ghostClass="ghost"
>
<li class="form-edit-widget-label" v-for="(item, index) in basicComponents" :key="index">
<a>{{item.name}}</a>
</li>
</draggable>
<div class="widget-cate">图片类组件</div>
<draggable
tag="ul"
:list="imgComponents"
:group="{ name:'widget', pull:'clone',put:false}"
:sort="false"
ghostClass="ghost"
>
<li class="form-edit-widget-label" v-for="(item, index) in imgComponents" :key="index">
<a>{{item.name}}</a>
</li>
</draggable>
<div class="widget-cate">辅助类组件</div>
<draggable
tag="ul"
:list="assistComponents"
:group="{ name:'widget', pull:'clone',put:false}"
:sort="false"
ghostClass="ghost"
>
<li class="form-edit-widget-label" v-for="(item, index) in assistComponents" :key="index">
<a>{{item.name}}</a>
</li>
</draggable>
<div class="widget-cate">高级组件</div>
<draggable
tag="ul"
:list="advancedComponents"
:group="{ name:'widget', pull:'clone',put:false}"
filter=".disdraggable"
:sort="false"
ghostClass="ghost"
>
<li
class="form-edit-widget-label"
:class="{disdraggable:disFormList}"
v-for="(item, index) in advancedComponents"
:key="index"
>
<a :style="{cursor:disFormList?'no-drop':'move'}">{{item.name}}</a>
</li>
</draggable>
</div>
</el-aside>
<el-container class="center-container" direction="vertical">
<el-header class="btn-bar" style="height: 45px;">
<el-button type="text" size="medium" icon="el-icon-refresh" @click="handleReset()" class="mg-r15">重置</el-button>
<el-button type="text" size="medium" icon="el-icon-view" @click="handlePreview()" class="mg-r15">预览</el-button>
<el-button type="text" size="medium" icon="el-icon-document" @click="handleSave()" class="mg-r15">保存</el-button>
</el-header>
<el-main>
<widget-form></widget-form>
</el-main>
</el-container>
<el-aside class="widget-config-container" style="min-width:300px;width:20vw">
<el-container>
<el-header height="45px" class="flex">
<div
class="config-tab flex-auto"
:class="{active: configTab=='widget'}"
@click="handleConfigSelect('widget')"
>字段属性</div>
<div
class="config-tab flex-auto"
:class="{active: configTab=='page'}"
@click="handleConfigSelect('page')"
>页面属性</div>
</el-header>
<el-main class="config-content">
<widget-config v-show="configTab=='widget'"></widget-config>
<page-config v-show="configTab=='page'"></page-config>
</el-main>
</el-container>
</el-aside>
</div>
</el-container>
</div>
</template>
<script>
import { mapState } from 'vuex';
import Draggable from 'vuedraggable'
import Header from '@/components/header'
import WidgetConfig from '@/components/widget-config'
import PageConfig from '@/components/page-config'
import WidgetForm from '@/components/widget-form'
import allWidget from '@/assets/js/widget.js'
import pageConfigData from '@/assets/js/page-config.js'
export default {
name: 'form-design',
components: {
Draggable,
Header,
WidgetConfig,
PageConfig,
WidgetForm
},
data() {
return {
basicComponents: allWidget.basicComponents,
imgComponents: allWidget.imgComponents,
assistComponents: allWidget.assistComponents,
advancedComponents: allWidget.advancedComponents
}
},
computed: {
disFormList() {
if (this.pageData.list) {
return this.pageData.list.some(v => {
return v.type === 'formList';
});
}
return false
},
...mapState({
pageData: state => state.common.pageData,
configTab: state => state.common.configTab,
})
},
methods: {
handleConfigSelect(value) {
this.$store.commit('setConfigTab', value)
},
handlePreview() {
let newWin = window.open(this.$api.previewUrl());
let timer = setInterval(() => {
newWin.postMessage(this.pageData, this.$api.previewUrl());
}, 200);
window.addEventListener('message', event => {
if (event.origin !== this.$api.previewOrigin()) return;
if (event.data === 'Received') clearInterval(timer)
}, false);
},
handleReset() {
this.$store.commit('setSelectWg', []);
this.$store.commit('setPageData', this.$util.deepClone(pageConfigData.pageConfig));
},
handleSave() {
this.$util.setLStorage('pageData', this.pageData);
this.$alert('保存成功', { showClose: false });
}
},
mounted() {
this.$nextTick(function () {
//防止火狐浏览器拖拽的时候以新标签打开
document.body.ondrop = function (event) {
event.preventDefault();
event.stopPropagation();
}
})
},
created() {
let pageData = this.$util.getLStorage('pageData');
if (pageData) return this.$store.commit('setPageData', pageData);
this.$store.commit('setPageData', this.$util.deepClone(pageConfigData.themes[0].pageData));
}
}
</script>
<style lang="stylus">
@import '../assets/css/index.styl';
@import '../assets/css/widget.styl';
@import '../assets/css/config.styl';
@import '../assets/css/themes.styl';
</style>