|
@@ -1,3 +1,4 @@
|
|
|
+import _ from 'lodash'
|
|
|
import {defineStore} from 'pinia'
|
|
|
import copy from '@/store/copy'
|
|
|
import lock from '@/store/lock'
|
|
@@ -8,6 +9,7 @@ import snapshot from '@/store/snapshot'
|
|
|
import Constant from "@/utils/constant";
|
|
|
import EditorUtils from '@/utils/EditorUtils'
|
|
|
import {ruleStore} from "@/store/ruler-things";
|
|
|
+import {tableBands, tableColTemplate} from "@/components/config/globalConfig";
|
|
|
|
|
|
export const globalStore = defineStore('global', {
|
|
|
state: () => {
|
|
@@ -64,6 +66,12 @@ export const globalStore = defineStore('global', {
|
|
|
// 如果没点中组件,并且在画布空白处弹起鼠标,则取消当前组件的选中状态
|
|
|
isClickComponent: false,
|
|
|
curTableSettingId: null,
|
|
|
+ selectedTableCell: {
|
|
|
+ bandRowName: "",
|
|
|
+ rowNo: -1,
|
|
|
+ colNo: -1,
|
|
|
+ element: {}
|
|
|
+ },
|
|
|
editorMenuInfo: {
|
|
|
visible: false,
|
|
|
style: {
|
|
@@ -100,18 +108,18 @@ export const globalStore = defineStore('global', {
|
|
|
this.curComponentIndex = index
|
|
|
this.curTableCell = null
|
|
|
},
|
|
|
-
|
|
|
- setCurTableCell({component}) {
|
|
|
- this.curTableCell = component
|
|
|
+ setSelectedTableCell({bandRowName, rowNo, colNo, element}) {
|
|
|
+ this.selectedTableCell = {bandRowName, rowNo, colNo, element}
|
|
|
+ },
|
|
|
+ getSelectedTableCell() {
|
|
|
+ return this.selectedTableCell;
|
|
|
},
|
|
|
-
|
|
|
setPageSize({pageWidth, pageHeight}) {
|
|
|
this.pageConfig.pageWidth = pageWidth
|
|
|
this.pageConfig.pageHeight = pageHeight
|
|
|
ruleStore().setRect({pageWidth, pageHeight})
|
|
|
ruleStore().setReDrawRuler()
|
|
|
},
|
|
|
-
|
|
|
togglePageDirection(pageDirection) {
|
|
|
const pageConfig = this.pageConfig
|
|
|
pageConfig.pageDirection = pageDirection
|
|
@@ -134,7 +142,6 @@ export const globalStore = defineStore('global', {
|
|
|
updateDataValue({data, key, value}) {
|
|
|
data[key] = value
|
|
|
},
|
|
|
-
|
|
|
setExpression({bandCode, expression, id}) {
|
|
|
const elementBand = this.elementBands.get(bandCode)
|
|
|
if (elementBand) {
|
|
@@ -155,7 +162,6 @@ export const globalStore = defineStore('global', {
|
|
|
}
|
|
|
this.curComponent.expression = expression;
|
|
|
},
|
|
|
-
|
|
|
setPropValue({propValue, id}) {
|
|
|
const componentData = this.componentData
|
|
|
if (this.componentData.length) {
|
|
@@ -197,15 +203,6 @@ export const globalStore = defineStore('global', {
|
|
|
addDataSource(dataSource) {
|
|
|
this.dataSources.push(dataSource);
|
|
|
},
|
|
|
-
|
|
|
- setDataSet(dataset) {
|
|
|
- this.dataset = dataset
|
|
|
- },
|
|
|
-
|
|
|
- setCurTableSettingId(id) {
|
|
|
- this.curTableSettingId = id
|
|
|
- },
|
|
|
-
|
|
|
setShapeStyle({top, left, width, height, rotate}) {
|
|
|
if (top) {
|
|
|
this.curComponent.style.top = Math.round(top)
|
|
@@ -223,11 +220,9 @@ export const globalStore = defineStore('global', {
|
|
|
this.curComponent.style.rotate = Math.round(rotate)
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
setShapeSingleStyle({key, value}) {
|
|
|
this.curComponent.style[key] = value
|
|
|
},
|
|
|
-
|
|
|
setComponentData(componentData = []) {
|
|
|
this.componentData = componentData
|
|
|
},
|
|
@@ -299,27 +294,6 @@ export const globalStore = defineStore('global', {
|
|
|
elementBand.elements.splice(elementIdx, 1)
|
|
|
}
|
|
|
},
|
|
|
- // addComponent({component, index}) {
|
|
|
- // if (index !== undefined) {
|
|
|
- // this.componentData.splice(index, 0, component)
|
|
|
- // } else {
|
|
|
- // this.componentData.push(component)
|
|
|
- // }
|
|
|
- // },
|
|
|
- // deleteComponent(index) {
|
|
|
- // if (index === undefined) {
|
|
|
- // index = this.curComponentIndex
|
|
|
- // }
|
|
|
- //
|
|
|
- // if (index === this.curComponentIndex) {
|
|
|
- // this.curComponentIndex = null
|
|
|
- // this.curComponent = null
|
|
|
- // }
|
|
|
- //
|
|
|
- // if (/\d/.test(index)) {
|
|
|
- // this.componentData.splice(index, 1)
|
|
|
- // }
|
|
|
- // },
|
|
|
addTableCellElement({bandCode, elementId, bandRowName, rowNo, colNo, element}) {
|
|
|
const elementBand = this.elementBands.get(bandCode);
|
|
|
// 数组角标从0开始
|
|
@@ -332,10 +306,8 @@ export const globalStore = defineStore('global', {
|
|
|
}
|
|
|
const col = tableElement.config[bandRowName].rows[rowNo].cols[colNo];
|
|
|
if (col) {
|
|
|
- console.log('col 1 =>>', col)
|
|
|
col.element = element
|
|
|
} else {
|
|
|
- console.log('col 2 =>>', col)
|
|
|
tableElement.config[bandRowName].rows[rowNo].cols[colNo] = {
|
|
|
colspan: 1,
|
|
|
rowspan: 1,
|
|
@@ -347,6 +319,48 @@ export const globalStore = defineStore('global', {
|
|
|
deleteTableCellElement({bandRowName, rowNo, colNo}) {
|
|
|
|
|
|
},
|
|
|
+ addTableCol({bandCode, elementIdx, colNo}) {
|
|
|
+ if (_.isEmpty(bandCode) || _.isNull(elementIdx)) {
|
|
|
+ console.error("bandCode or elementIdx must be not null");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const element = this.elementBands.get(bandCode).elements[elementIdx];
|
|
|
+ if (!element) {
|
|
|
+ console.error("elementBand not found");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (let tableBand of tableBands) {
|
|
|
+ const tableBandCode = tableBand.code;
|
|
|
+ if (!Reflect.has(element.config, tableBandCode)) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ const rows = element.config[tableBandCode].rows
|
|
|
+ for (let row of rows) {
|
|
|
+ row.cols[colNo] = tableColTemplate
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ removeTableCol({bandCode, elementIdx, colNo}) {
|
|
|
+ if (_.isEmpty(bandCode) || _.isNull(elementIdx)) {
|
|
|
+ console.error("bandCode or elementIdx must be not null");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const element = this.elementBands.get(bandCode).elements[elementIdx];
|
|
|
+ if (!element) {
|
|
|
+ console.error("elementBand not found");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (let tableBand of tableBands) {
|
|
|
+ const tableBandCode = tableBand.code;
|
|
|
+ if (!Reflect.has(element.config, tableBandCode)) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ const rows = element.config[tableBandCode].rows
|
|
|
+ for (let row of rows) {
|
|
|
+ Reflect.deleteProperty(row.cols, colNo)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
showEditorMenu({top, left}) {
|
|
|
const editorMenuPos = EditorUtils.getEditorMenuPos(top, left);
|
|
|
this.editorMenuInfo = {
|
|
@@ -372,4 +386,4 @@ export const globalStore = defineStore('global', {
|
|
|
return this.pageConfig
|
|
|
},
|
|
|
}
|
|
|
-})
|
|
|
+})
|