|
70 | 70 | :ui-schema="uiSchema" |
71 | 71 | :error-schema="errorSchema" |
72 | 72 | :custom-formats="customFormats" |
| 73 | + :form-footer="formFooter" |
73 | 74 | @on-change="handleDataChange" |
74 | 75 | @on-cancel="handleCancel" |
75 | 76 | @on-submit="handleSubmit" |
|
107 | 108 | }; |
108 | 109 | }, |
109 | 110 | computed: { |
| 111 | + formFooter() { |
| 112 | + return { |
| 113 | + show: true, |
| 114 | + okBtn: '保存', |
| 115 | + cancelBtn: this.isTestPage ? '生成预览链接' : '取消' |
| 116 | + }; |
| 117 | + }, |
110 | 118 | curType() { |
111 | 119 | return this.$route.query.type; |
112 | 120 | }, |
113 | | -
|
| 121 | + isTestPage() { |
| 122 | + return this.curType === 'Test'; |
| 123 | + }, |
114 | 124 | curSchemaCode: { |
115 | 125 | get() { |
116 | 126 | return this.genCodeStrComputedGetter('schema'); |
|
177 | 187 | } |
178 | 188 | }, |
179 | 189 | 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)); |
182 | 204 | }, |
183 | 205 | handleDataChange() { |
184 | 206 | console.log('Data change'); |
185 | 207 | }, |
186 | | - handleCancel() { |
187 | | - console.log('Cancel'); |
| 208 | + handleSubmit() { |
| 209 | + console.log('Submit'); |
188 | 210 | }, |
189 | 211 | clipboard(value) { |
190 | 212 | if (document.execCommand) { |
|
202 | 224 | this.$message.info(value); |
203 | 225 | return false; |
204 | 226 | }, |
205 | | - handleSubmit() { |
206 | | - console.log('Submit'); |
207 | | - if (this.$route.query.type === 'Test') { |
| 227 | + handleCancel() { |
| 228 | + if (this.isTestPage) { |
208 | 229 | const genRoute = this.$router.resolve({ |
209 | 230 | query: { |
210 | 231 | 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), |
215 | 236 | } |
216 | 237 | }); |
217 | 238 | const url = `${window.location.origin}${window.location.pathname}${genRoute.href}`; |
|
0 commit comments