From a9805c8f1f8601c81bacbfeb0a17f5608a5957bc Mon Sep 17 00:00:00 2001 From: Mercutio Date: Wed, 12 Apr 2023 08:19:33 +0800 Subject: [PATCH] test --- src/App.vue | 4 ++ .../form-designer/toolbar-panel/index.vue | 65 +++++++++++++++++++ src/lang/zh-CN.js | 2 + src/lang/zh-CN_render.js | 1 + 4 files changed, 72 insertions(+) diff --git a/src/App.vue b/src/App.vue index 804b649..0638dc6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,6 +4,7 @@ @@ -56,6 +57,9 @@ export default { insertFormJson() { let jsonObj = require('./assets/testForm.json') this.$refs.vfDesignerRef.setFormJson(jsonObj) + }, + getFieldList() { + console.log(this.$refs.vfDesignerRef.getFieldWidgets()) } } } diff --git a/src/components/form-designer/toolbar-panel/index.vue b/src/components/form-designer/toolbar-panel/index.vue index 355b284..d763423 100644 --- a/src/components/form-designer/toolbar-panel/index.vue +++ b/src/components/form-designer/toolbar-panel/index.vue @@ -62,6 +62,7 @@ + +
+ +
+ +
+ @@ -208,6 +225,7 @@ showExportJsonDialogFlag: false, showExportCodeDialogFlag: false, showFormDataDialogFlag: false, + showFieldListDataDialogFlag: false, showExportSFCDialogFlag: false, showNodeTreeDrawerFlag: false, @@ -221,6 +239,9 @@ formDataJson: '', formDataRawJson: '', + fieldListJson: '', + fieldListRawJson: '', + vueCode: '', htmlCode: '', @@ -578,6 +599,37 @@ }) }, + getFieldListPromiseWrap () { + let callback = function nullFunc() {} + let promise = new window.Promise(function (resolve, reject) { + callback = function(fieldListJson, fieldListRawJson, error) { + !error ? resolve(fieldListJson, fieldListRawJson) : reject(error); + }; + }); + try { + const fieldListData = this.$refs['preForm'].getFieldWidgets() + const fieldListJson = JSON.stringify(fieldListData, null, ' ') + const fieldListRawJson = JSON.stringify(fieldListData) + callback(fieldListJson, fieldListRawJson) + } catch (error) { + callback(this.formDataModel, this.i18nt('render.hint.fieldListGenerateFailed')) + } + + return promise + }, + + getFieldList () { + // console.log('【getFieldWidgets】',this.$refs['preForm'].getFieldWidgets()) + // console.log('【getContainerWidgets】',this.$refs['preForm'].getContainerWidgets()) + this.getFieldListPromiseWrap().then((fieldListJson, fieldListRawJson)=>{ + this.fieldListJson = fieldListJson + this.fieldListRawJson = fieldListRawJson + this.showFieldListDataDialogFlag = true + }).catch(error => { + this.$message.error(error) + }) + }, + copyFormDataJson(e) { copyToClipboard(this.formDataRawJson, e, this.$message, @@ -586,10 +638,23 @@ ) }, + copyFieldListJson(e) { + copyToClipboard(this.fieldListRawJson, e, + this.$message, + this.i18nt('designer.hint.copyJsonSuccess'), + this.i18nt('designer.hint.copyJsonFail') + ) + }, + + saveFormData() { this.saveAsFile(this.htmlCode, `formData${generateId()}.json`) }, + savefieldListData() { + this.saveAsFile(this.htmlCode, `fieldListData${generateId()}.json`) + }, + resetForm() { this.$refs['preForm'].resetForm() }, diff --git a/src/lang/zh-CN.js b/src/lang/zh-CN.js index 50b42db..7db3b05 100644 --- a/src/lang/zh-CN.js +++ b/src/lang/zh-CN.js @@ -92,10 +92,12 @@ export default { saveVueCode: '保存Vue文件', saveHtmlCode: '保存Html文件', getFormData: '获取数据', + getFieldListData: '获取字段列表', resetForm: '重置表单', disableForm: '禁用编辑', enableForm: '恢复编辑', exportFormData: '表单数据', + exportFieldListData: '表单字段列表', copyFormData: '复制JSON', saveFormData: '保存为文件', copyVue2SFC: '复制Vue2代码', diff --git a/src/lang/zh-CN_render.js b/src/lang/zh-CN_render.js index 1dd74c4..63e0106 100644 --- a/src/lang/zh-CN_render.js +++ b/src/lang/zh-CN_render.js @@ -26,6 +26,7 @@ export default { downloadFile: '下载', removeFile: '移除', validationFailed: '表单数据校验失败', + fieldListGenerateFailed: '表单字段列表生成失败', subFormAction: '操作', subFormAddAction: '新增',