From a512ba3db6dd48d3fd95ead36bf28c2b9bd7d546 Mon Sep 17 00:00:00 2001 From: woai3c <411020382@qq.com> Date: Fri, 23 Feb 2024 15:51:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 2 +- src/components/Editor/AceEditor.vue | 84 +++++++++++---------- src/components/Toolbar.vue | 110 ++++++++++++++++++++++++++-- src/styles/dark.scss | 2 +- src/styles/global.scss | 2 +- 5 files changed, 154 insertions(+), 46 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 93e2fbe..409f3bf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": "explicit" }, "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"], "stylelint.validate": [ diff --git a/src/components/Editor/AceEditor.vue b/src/components/Editor/AceEditor.vue index f592934..f9f120c 100644 --- a/src/components/Editor/AceEditor.vue +++ b/src/components/Editor/AceEditor.vue @@ -1,38 +1,38 @@ @@ -67,8 +67,8 @@ export default { mounted() { ace.config.set('basePath', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.14/') this.editor = ace.edit(this.$refs.ace, { - maxLines: 34, - minLines: 34, + maxLines: 40, + minLines: 40, fontSize: 14, theme: 'ace/theme/one_dark', mode: 'ace/mode/json5', @@ -112,7 +112,7 @@ export default { } - diff --git a/src/components/Toolbar.vue b/src/components/Toolbar.vue index 1bb6b57..c75cee2 100644 --- a/src/components/Toolbar.vue +++ b/src/components/Toolbar.vue @@ -1,7 +1,9 @@ @@ -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;