Skip to content

Commit cd25455

Browse files
committed
chore(vue editor): 更新vue editor
1 parent 22be3f1 commit cd25455

File tree

5 files changed

+59
-33
lines changed

5 files changed

+59
-33
lines changed

packages/demo/src/_common/components/component-with-dialog/index.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,26 @@ export default ({
101101
this.$el.parentElement.removeChild(this.$el);
102102
}
103103
},
104-
template: `
105-
<el-dialog
106-
v-bind="curDialogProps"
107-
v-on="curDialogListeners"
108-
:visible.sync="visible">
109-
<VueComponent v-bind="componentProps"
110-
v-on="componentListeners"
111-
></VueComponent>
112-
</el-dialog>
113-
`,
104+
render(h) {
105+
const self = this;
106+
return h('el-dialog', {
107+
on: {
108+
...this.curDialogListeners,
109+
'update:visible': function (val) {
110+
self.visible = val;
111+
}
112+
},
113+
props: {
114+
visible: this.visible,
115+
...this.curDialogProps,
116+
},
117+
}, [
118+
h(VueComponent, {
119+
on: this.componentListeners,
120+
props: this.componentProps,
121+
})
122+
]);
123+
},
114124
});
115125

116126
const componentDialog = (new DialogComponentConstructor({

packages/demo/src/vue-editor/views/editor/Editor.vue

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
<template>
22
<div v-loading="loading" :class="$style.box">
3-
<EditorHeader
4-
v-model="scale"
5-
@onUpdateScale="fixComponentFormPosition"
6-
@onPreview="handlePreview"
7-
@onSave="handleSave"
8-
@onPublish="handlePublish"
9-
></EditorHeader>
3+
<transition name="el-zoom-in-top">
4+
<EditorHeader
5+
v-if="!isPreview"
6+
v-model="scale"
7+
@onUpdateScale="fixComponentFormPosition"
8+
@onPreview="handlePreview"
9+
@onSave="handleSave"
10+
@onPublish="handlePublish"
11+
></EditorHeader>
12+
<el-button
13+
v-else
14+
type="primary"
15+
style="position: fixed;right: 20px;top: 20px;z-index: 5;"
16+
@click="isPreview = false;"
17+
>
18+
结束预览
19+
</el-button>
20+
</transition>
1021
<div :class="[$style.container, showToolBar ? $style.hasTools : '']">
1122
<span :class="$style.leftCaret" @click="showToolBar = !showToolBar">
1223
<i class="el-icon-caret-right"></i>
@@ -41,6 +52,7 @@
4152
>
4253
<ViewComponentWrap
4354
:editor-item="item"
55+
:is-preview="isPreview"
4456
@onOperate="handleItemOperate"
4557
>
4658
<!-- 传入form使用传入的form组件 -->
@@ -55,7 +67,7 @@
5567
>
5668
</component>
5769

58-
<!-- 不传入使用 schema生成form -->
70+
<!-- schema生成form -->
5971
<VueElementForm
6072
v-else
6173
slot="componentForm"
@@ -78,7 +90,6 @@
7890
</ViewComponentWrap>
7991
</div>
8092
</draggable>
81-
8293
<div v-if="trueComponentList.length === 0" :class="$style.tipBox">
8394
<img src="./assets/img/empty-tip.png" alt="empty-img">
8495
<p>左边选择模块拖入该区域</p>
@@ -137,12 +148,12 @@
137148
// fallbackTolerance: 0
138149
},
139150
loading: false,
151+
isPreview: false,
140152
scale: 65,
141153
editComponentList: [],
142154
editHeaderComponentList: [], // 兼容header slot ,插件内部实现导致必须分割多分数据
143155
editFooterComponentList: [], // 兼容footer slot ,插件内部实现导致必须分割多分数据
144156
showToolBar: true,
145-
// defaultDragWidth: 1920,
146157
};
147158
},
148159
@@ -200,6 +211,7 @@
200211
for (let i = 0; i < this.trueComponentList.length; i += 1) {
201212
const item = this.trueComponentList[i];
202213
if (!schemaValidate.isValid(item.componentPack.propsSchema, item.componentValue)) {
214+
debugger;
203215
// 验证失败
204216
// item.isEdit = true; // 打开编辑窗口
205217
@@ -231,12 +243,8 @@
231243
}
232244
});
233245
},
234-
handleSave() {
235-
this.handlePreview();
236-
},
237-
handlePreview() {
238-
// schema validate
239-
if (!this.validateDataList()) return;
246+
handleSave(validData) {
247+
if (!this.validateDataList(validData)) return;
240248
241249
componentWithDialog({
242250
VueComponent: JsonPerttyPrint,
@@ -248,8 +256,12 @@
248256
}
249257
});
250258
},
259+
handlePreview() {
260+
this.isPreview = true;
261+
this.dragOptions.disabled = true;
262+
},
251263
handlePublish() {
252-
this.handlePreview();
264+
this.handleSave(true);
253265
},
254266
// 计算各个组件状态栏按钮状态
255267
computedComponentToolBarStatus() {

packages/demo/src/vue-editor/views/editor/components/ViewComponentWrap.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
export default {
7676
name: 'ViewComponentWrap',
7777
props: {
78+
isPreview: {
79+
type: Boolean,
80+
default: false
81+
},
7882
editorItem: {
7983
type: Object,
8084
default: () => ({})
@@ -86,9 +90,10 @@
8690
methods: {
8791
// 点击只能打开,并且打开状态下只能执行一次
8892
handelClickView(e) {
89-
// 阻止浏览器默认时间
90-
e.preventDefault();
91-
93+
if (!this.isPreview) {
94+
// 阻止浏览器默认事件
95+
e.preventDefault();
96+
}
9297
if (!this.editorItem.isEdit) this.showEditForm();
9398
},
9499

packages/demo/src/vue-editor/views/editor/viewComponents/FlashSaleGoodsList/schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
}
4545
},
4646
"required": [
47-
"startTime",
48-
"goodsTitle"
47+
"startTime"
4948
],
5049
"additionalProperties": false
5150
}

packages/demo/src/vue-editor/views/editor/viewComponents/Text/propsSchema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "http://json-schema.org/draft-06/schema#",
2+
"$schema": "http://json-schema.org/draft-07/schema#",
33
"id": "Text",
44
"title": "单文本输入组件",
55
"description":"单文本输入组件,用于在页面配置一条文字信息" ,

0 commit comments

Comments
 (0)