Skip to content

Commit 9db94d5

Browse files
committed
chore(vue editor): vue表单编辑器支持链接回填数据
1 parent 0c9d5be commit 9db94d5

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

packages/demo/src/index/views/Demo/index.vue

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
:ui-schema="uiSchema"
7171
:error-schema="errorSchema"
7272
:custom-formats="customFormats"
73+
:form-footer="formFooter"
7374
@on-change="handleDataChange"
7475
@on-cancel="handleCancel"
7576
@on-submit="handleSubmit"
@@ -107,10 +108,19 @@
107108
};
108109
},
109110
computed: {
111+
formFooter() {
112+
return {
113+
show: true,
114+
okBtn: '保存',
115+
cancelBtn: this.isTestPage ? '生成预览链接' : '取消'
116+
};
117+
},
110118
curType() {
111119
return this.$route.query.type;
112120
},
113-
121+
isTestPage() {
122+
return this.curType === 'Test';
123+
},
114124
curSchemaCode: {
115125
get() {
116126
return this.genCodeStrComputedGetter('schema');
@@ -177,14 +187,26 @@
177187
}
178188
},
179189
initData() {
180-
const curPack = schemaTypes[this.curType];
181-
Object.assign(this, this.getDefaultSchemaMap(), curPack);
190+
// eslint-disable-next-line no-unused-vars
191+
const { type, ...queryParams } = this.$route.query;
192+
193+
let queryParamsObj = {};
194+
try {
195+
queryParamsObj = Object.entries(queryParams).reduce((preVal, [key, value]) => {
196+
preVal[key] = JSON.parse(decodeURIComponent(String(value)));
197+
return preVal;
198+
}, {});
199+
} catch (e) {
200+
// nothing ...
201+
}
202+
203+
Object.assign(this, this.getDefaultSchemaMap(), Object.assign(schemaTypes[this.curType], queryParamsObj));
182204
},
183205
handleDataChange() {
184206
console.log('Data change');
185207
},
186-
handleCancel() {
187-
console.log('Cancel');
208+
handleSubmit() {
209+
console.log('Submit');
188210
},
189211
clipboard(value) {
190212
if (document.execCommand) {
@@ -202,16 +224,15 @@
202224
this.$message.info(value);
203225
return false;
204226
},
205-
handleSubmit() {
206-
console.log('Submit');
207-
if (this.$route.query.type === 'Test') {
227+
handleCancel() {
228+
if (this.isTestPage) {
208229
const genRoute = this.$router.resolve({
209230
query: {
210231
type: 'Test',
211-
schema: this.curSchemaCode,
212-
formData: this.curFormDataCode,
213-
uiSchema: this.curUiSchemaCode,
214-
errSchema: this.curErrorSchemaCode,
232+
schema: encodeURIComponent(this.curSchemaCode),
233+
formData: encodeURIComponent(this.curFormDataCode),
234+
uiSchema: encodeURIComponent(this.curUiSchemaCode),
235+
errorSchema: encodeURIComponent(this.curErrorSchemaCode),
215236
}
216237
});
217238
const url = `${window.location.origin}${window.location.pathname}${genRoute.href}`;

0 commit comments

Comments
 (0)