From bfaf8ea7d8ead0164852054d6dcd1d4241fd4132 Mon Sep 17 00:00:00 2001 From: ival <610568032@qq.com> Date: Thu, 8 Apr 2021 18:40:12 +0800 Subject: [PATCH] =?UTF-8?q?iscs=E5=89=8D=E7=AB=AF=E7=BB=98=E5=88=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0indexDb=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/iscs_new/factory/index.js | 1 - src/utils/indexedDb.js | 1 + src/views/iscs_new/iscsDraw/index.vue | 22 +++--- src/views/iscs_new/iscsDraw/iscsCanvas.vue | 28 +++++-- src/views/iscs_new/utils/indexedDb.js | 85 ++++++++++++++-------- 5 files changed, 91 insertions(+), 46 deletions(-) diff --git a/src/iscs_new/factory/index.js b/src/iscs_new/factory/index.js index 07bed7656..e866d4ed3 100644 --- a/src/iscs_new/factory/index.js +++ b/src/iscs_new/factory/index.js @@ -105,7 +105,6 @@ class ShapeFactory extends Eventful { list.forEach(el => { this.mapTemplate[el.type] = templateParser.parse(el); }) - console.log(this.mapTemplate); } parse(source={}, take=None) { diff --git a/src/utils/indexedDb.js b/src/utils/indexedDb.js index 2a882c8a3..3cffc3021 100644 --- a/src/utils/indexedDb.js +++ b/src/utils/indexedDb.js @@ -18,6 +18,7 @@ export function openIndexedDB() { Vue.prototype.$db = event.target.result; Vue.prototype.$db.createObjectStore('mapData', { keyPath: 'id' }); Vue.prototype.$db.createObjectStore('runPlan', { keyPath: 'templateId' }); + Vue.prototype.$db.createObjectStore('composeList', { keyPath: 'id' }); }; } // 新增数据 diff --git a/src/views/iscs_new/iscsDraw/index.vue b/src/views/iscs_new/iscsDraw/index.vue index 450dcb3c3..3f1fa5035 100644 --- a/src/views/iscs_new/iscsDraw/index.vue +++ b/src/views/iscs_new/iscsDraw/index.vue @@ -36,7 +36,7 @@ import BuilderFactory from '@/iscs_new/core/form/builderFactory'; import DataForm from '../components/dataForm'; import orders from '@/iscs_new/utils/orders'; import * as utils from '@/iscs_new/utils/utils'; -import IndexedDb from '../utils/indexedDb.js'; +import idb from '../utils/indexedDb.js'; import shapeType from '@/iscs_new/constant/shapeType.js'; export default { @@ -70,14 +70,9 @@ export default { } }, mounted() { - this.db = new IndexedDb(['composeList']); - console.log(this.db, 11111111111); this.composeName = this.$route.query.composeName; this.elementList = new BuilderFactory().getFormList(); this.enabledTab = this.elementList[0].code; - }, - beforeDestroy() { - }, methods: { onIscsChange(mode, system, part) { @@ -90,14 +85,19 @@ export default { const type = this.$route.query.type||"<模型类型>"; const source = this.$iscs.getSource(); if (id && source) { - const shapeList = source.elementList.map(el => { + const elementList = source.elementList.map(el => { return this.$iscs.getShapeByCode(el.code); }); - const rect = shapeList.reduce( + const shapeList = elementList.map(el => el.model); + const rect = elementList.reduce( (temp,el) => el&&temp? temp.union(el.getBoundingRect().clone()): el.getBoundingRect(), null); - const position = [(rect.x + rect.width)/2, (rect.y + rect.height)/2]; + const position = rect? [(rect.x + rect.width)/2, (rect.y + rect.height)/2]: [0,0]; const model = { id, name, type, shapeList, position }; - console.log(model) + idb.remove('composeList', model.id); + idb.add('composeList', model); + idb.list('composeList').then(list => { + console.log(list) + }) } }, onSelectTab() { @@ -116,7 +116,7 @@ export default { } }, onSubmit(){ - this.$refs['dataform'+this.enabledTab][0].$refs['form'].validate((valid) => { + this.$refs['dataform'+this.enabledTab][0].$refs['form'].validate((valid) => { if (valid) { const formModel = this.$refs['dataform' + this.enabledTab][0].formModel; const newModel = JSON.parse(JSON.stringify(formModel)); diff --git a/src/views/iscs_new/iscsDraw/iscsCanvas.vue b/src/views/iscs_new/iscsDraw/iscsCanvas.vue index b8c3a600d..077d92cd4 100644 --- a/src/views/iscs_new/iscsDraw/iscsCanvas.vue +++ b/src/views/iscs_new/iscsDraw/iscsCanvas.vue @@ -7,6 +7,7 @@