From fc63abc5b1b2c681fa2e3add6876fd63aae52712 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=A5=A5=E6=96=AF?= <9068149@qq.com>
Date: Mon, 1 Nov 2021 17:34:55 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=AF=BC=E5=87=BA/?=
=?UTF-8?q?=E5=AF=BC=E5=87=BAJSON=E5=8A=9F=E8=83=BD=EF=BC=88=E8=80=81?=
=?UTF-8?q?=E7=89=88=E6=9C=AC=E9=9C=80=E8=A6=81npm=20install=EF=BC=8C?=
=?UTF-8?q?=E5=AE=89=E8=A3=85=E4=B8=80=E4=B8=8B=E4=BE=9D=E8=B5=96=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package-lock.json | 5 +++
package.json | 3 +-
src/layout/home/index.vue | 79 ++++++++++++++++++---------------------
3 files changed, 43 insertions(+), 44 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index b61caed..925ac5f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6977,6 +6977,11 @@
"schema-utils": "^2.5.0"
}
},
+ "file-saver": {
+ "version": "2.0.5",
+ "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
+ "integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
+ },
"filesize": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/filesize/-/filesize-3.6.1.tgz",
diff --git a/package.json b/package.json
index 06aeede..f5bb59e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "as-editor",
- "version": "0.1.0",
+ "version": "0.1.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
@@ -13,6 +13,7 @@
"clipboard": "^2.0.6",
"core-js": "^3.19.0",
"element-ui": "^2.15.6",
+ "file-saver": "^2.0.5",
"html2canvas": "1.0.0-alpha.9",
"nprogress": "^0.2.0",
"qrcode": "^1.4.4",
diff --git a/src/layout/home/index.vue b/src/layout/home/index.vue
index b301b3f..2d0ca22 100644
--- a/src/layout/home/index.vue
+++ b/src/layout/home/index.vue
@@ -14,23 +14,16 @@
返回店铺列表
-
重置
+ 查看JSON
+ 导入JSON
+ 导出JSON
+
- 查看JSON
@@ -176,7 +169,8 @@ import componentProperties from '@/utils/componentProperties' // 组件数据
import sliderassembly from 'components/sliderassembly' // 左侧组件大全
import phoneBottom from 'components/phoneBottom' // 手机底部
-import html2canvas from 'html2canvas'
+import html2canvas from 'html2canvas' // 生成图片
+import FileSaver from 'file-saver' // 导入or导出JSON
/* 手机组件 */
import {
@@ -319,37 +313,6 @@ export default {
},
methods: {
- dropDownButton(res) {
- // 设为系统模板
- if (res === '1') {
- this.systemTemplate()
- }
- console.log(res)
- },
-
- /**
- * 设为系统模板
- *
- */
- systemTemplate() {
- this.Preservation(() => {
- const loadingss = this.$loading({
- lock: true,
- text: '添加为系统模板...',
- spinner: 'el-icon-loading',
- background: 'rgba(0, 0, 0, 0.7)',
- })
- this.$httpApi.shelves({ shopTemplateId: this.id }).then((res) => {
- /* 取消加载 */
- loadingss.close()
- console.log(res)
-
- this.$router.push({ path: 'establishShop' })
- this.id = null
- })
- })
- },
-
/**
* 上架
*
@@ -772,6 +735,36 @@ export default {
})
.catch(() => {})
},
+
+ // 导出json
+ exportJSON() {
+ // 将json转换成字符串
+ const data = JSON.stringify({
+ id: this.id,
+ name: this.pageSetup.name,
+ templateJson: JSON.stringify(this.pageSetup),
+ component: JSON.stringify(this.pageComponents),
+ })
+ const blob = new Blob([data], { type: '' })
+ FileSaver.saveAs(blob, `${this.pageSetup.name}.json`)
+ },
+ // 导入json
+ importJSON() {
+ const file = document.getElementById('file').files[0]
+ const reader = new FileReader()
+ reader.readAsText(file)
+ let _this = this
+ reader.onload = function () {
+ // this.result为读取到的json字符串,需转成json对象
+ let ImportJSON = JSON.parse(this.result)
+ // 检测是否导入成功
+ console.log(ImportJSON,'-----------------导入成功')
+ // 导入JSON数据
+ _this.id = ImportJSON.id
+ _this.pageSetup = JSON.parse(ImportJSON.templateJson)
+ _this.pageComponents = JSON.parse(ImportJSON.component)
+ }
+ },
},
watch: {