-
JSON
+
JSON
+
导入
+
导出
撤消
重做
@@ -78,10 +108,12 @@ export default {
isScreenshot: false,
scale: 100,
switchValue: false,
+ isShowDialog: false,
+ jsonData: '',
+ isExport: false,
}
},
computed: mapState(['componentData', 'canvasStyleData', 'areaData', 'curComponent', 'curComponentIndex', 'isDarkMode']),
-
created() {
eventBus.$on('preview', this.preview)
eventBus.$on('save', this.save)
@@ -110,12 +142,12 @@ export default {
}, 1000)
},
- handleAceEditorChange() {
+ onAceEditorChange() {
this.isShowAceEditor = !this.isShowAceEditor
},
closeEditor() {
- this.handleAceEditorChange()
+ this.onAceEditorChange()
},
lock() {
@@ -217,6 +249,65 @@ export default {
this.isShowPreview = false
this.$store.commit('setEditMode', 'edit')
},
+
+ onImportJSON() {
+ this.jsonData = ''
+ this.isExport = false
+ this.isShowDialog = true
+ },
+
+ processJSON() {
+ try {
+ const data = JSON.parse(this.jsonData)
+ if (!Array.isArray(data)) {
+ this.$message.error('数据格式错误,组件数据必须是一个数组')
+ return
+ }
+
+ if (this.isExport) {
+ this.downloadFileUtil(this.jsonData, 'application/json', 'data.json')
+ } else {
+ this.$store.commit('setComponentData', data)
+ }
+
+ this.isShowDialog = false
+ } catch (error) {
+ this.$message.error('数据格式错误,请传入合法的 JSON 格式数据')
+ }
+ },
+
+ onExportJSON() {
+ this.isShowDialog = true
+ this.isExport = true
+ this.jsonData = JSON.stringify(this.componentData, null, 4)
+ },
+
+ downloadFileUtil(data, type, fileName = '') {
+ const url = window.URL.createObjectURL(new Blob([data], { type }))
+ const link = document.createElement('a')
+
+ link.style.display = 'none'
+ link.href = url
+ link.setAttribute('download', fileName)
+ document.body.appendChild(link)
+ link.click()
+
+ document.body.removeChild(link)
+ window.URL.revokeObjectURL(url)
+ },
+
+ beforeUpload(e) {
+ // 通过json文件导入
+ const reader = new FileReader()
+ reader.readAsText(e)
+ const self = this
+ reader.onload = function () {
+ self.jsonData = this.result
+ console.log(this.result)
+ }
+
+ return false
+ },
},
}
@@ -310,4 +401,13 @@ export default {
}
}
}
+
+.dialog-footer {
+ display: flex;
+ justify-content: flex-end;
+
+ & > * {
+ margin-left: 10px;
+ }
+}
diff --git a/src/styles/dark.scss b/src/styles/dark.scss
index c1944bf..e949c88 100644
--- a/src/styles/dark.scss
+++ b/src/styles/dark.scss
@@ -10,7 +10,7 @@
--placeholder-bg-color: #242424;
--actived-text-color: #fff;
--actived-bg-color: #409eff;
- --ace-bg-color: #000000d9;
+ --ace-bg-color: #000;
--disable-text-color: #c0c4cc;
--disable-border-color: #4b4a4ad9;
--dropdown-border-color: #000000d9;
diff --git a/src/styles/global.scss b/src/styles/global.scss
index 6b43a56..35fa45d 100644
--- a/src/styles/global.scss
+++ b/src/styles/global.scss
@@ -11,7 +11,7 @@
--placeholder-bg-color: #fff;
--actived-text-color: #409eff;
--actived-bg-color: #ecf5ff;
- --ace-bg-color: #ddd;
+ --ace-bg-color: #e4e7ed;
--disable-text-color: #c0c4cc;
--disable-border-color: #ebeef5;
--dropdown-border-color: #e4e7ed;