|
|
|
@ -51,8 +51,8 @@ export const addTable = (widgetJson: IWidgetJson, addItemTypeName: any) => {
|
|
|
|
|
* @param addItemTypeName
|
|
|
|
|
* @param fatherId
|
|
|
|
|
*/
|
|
|
|
|
export const addTableRow = (widgetJson: IWidgetJson, addItemTypeName = 'table-cell') => {
|
|
|
|
|
const tableJson = handleFindDomById(widgetJson['subDomList'], widgetJson['activeConfig']['activeId'], false);
|
|
|
|
|
export const addTableRow = (widgetJson: IWidgetJson, rowIndex: number, isPush: boolean, returnParent: boolean, addItemTypeName = 'table-cell') => {
|
|
|
|
|
const tableJson = handleFindDomById(widgetJson['subDomList'], widgetJson['activeConfig']['activeId'], returnParent);
|
|
|
|
|
if (tableJson) {
|
|
|
|
|
const newRow: IWidget[] = []
|
|
|
|
|
for (let index = 0; index < tableJson['subDomList'][0]['length']; index++) {
|
|
|
|
@ -61,24 +61,119 @@ export const addTableRow = (widgetJson: IWidgetJson, addItemTypeName = 'table-ce
|
|
|
|
|
newRow.push(addItemData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
(tableJson['subDomList'] as IWidget[][]).push(newRow)
|
|
|
|
|
if (isPush) {
|
|
|
|
|
(tableJson['subDomList'] as IWidget[][]).splice(rowIndex + 1, 0, newRow)
|
|
|
|
|
} else {
|
|
|
|
|
(tableJson['subDomList'] as IWidget[][]).splice(rowIndex, 0, newRow)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增表格列 遍历每一行增加
|
|
|
|
|
* @param widgetJson
|
|
|
|
|
* @param addItemTypeName
|
|
|
|
|
* @param fatherId
|
|
|
|
|
* @param widgetJson 树结构
|
|
|
|
|
* @param colIndex 添加位置列下标
|
|
|
|
|
* @param isPush 是否为右侧添加
|
|
|
|
|
* @param returnParent 是否返回父节点
|
|
|
|
|
* @param addItemTypeName 新增元素名称
|
|
|
|
|
*/
|
|
|
|
|
export const addTableCol = (widgetJson: IWidgetJson, addItemTypeName = 'table-cell') => {
|
|
|
|
|
const tableJson = handleFindDomById(widgetJson['subDomList'], widgetJson['activeConfig']['activeId'], false);
|
|
|
|
|
export const addTableCol = (widgetJson: IWidgetJson, colIndex: number, isPush: boolean, returnParent: boolean, addItemTypeName = 'table-cell') => {
|
|
|
|
|
const tableJson = handleFindDomById(widgetJson['subDomList'], widgetJson['activeConfig']['activeId'], returnParent);
|
|
|
|
|
if (tableJson && tableJson['subDomList']) {
|
|
|
|
|
for (let index = 0; index < tableJson['subDomList']['length']; index++) {
|
|
|
|
|
const { addItemData } = formatAddItem(addItemTypeName);
|
|
|
|
|
if (addItemData) {
|
|
|
|
|
const row: IWidget[] = tableJson['subDomList'][index];
|
|
|
|
|
row.push(addItemData);
|
|
|
|
|
if (isPush) {
|
|
|
|
|
row.splice(colIndex + 1, 0, addItemData);
|
|
|
|
|
} else {
|
|
|
|
|
row.splice(colIndex, 0, addItemData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 合并右侧单元格
|
|
|
|
|
* @param widgetJson
|
|
|
|
|
* @param rowIndex
|
|
|
|
|
* @param colIndex
|
|
|
|
|
*/
|
|
|
|
|
export const mergeRightCol = (widgetJson: IWidgetJson, rowIndex: number, colIndex: number) => {
|
|
|
|
|
const tableJson = handleFindDomById(widgetJson['subDomList'], widgetJson['activeConfig']['activeId'], true);
|
|
|
|
|
if (tableJson && tableJson['subDomList']) {
|
|
|
|
|
let isStartmerge = false;
|
|
|
|
|
let mergeIndexArr: number[] = [];
|
|
|
|
|
let targetItem = { colspan: 0 };
|
|
|
|
|
const rowData = tableJson['subDomList'][rowIndex];
|
|
|
|
|
for (let index = 0; index < rowData['length']; index++) {
|
|
|
|
|
if (isStartmerge) {
|
|
|
|
|
if (mergeIndexArr.includes(index)) {
|
|
|
|
|
const nextItem = rowData[index]['options'] as any;
|
|
|
|
|
if (nextItem['merged']) {
|
|
|
|
|
targetItem['colspan'] = targetItem['colspan'] + nextItem['colspan']
|
|
|
|
|
}
|
|
|
|
|
nextItem['colspan'] = 1;
|
|
|
|
|
nextItem['merged'] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (colIndex == index) {
|
|
|
|
|
isStartmerge = true;
|
|
|
|
|
targetItem = rowData[index]['options'];
|
|
|
|
|
rowData[index]['options']['colspan']++;
|
|
|
|
|
mergeIndexArr = Array.from({ length: rowData[index]['options']['colspan'] }, (_, i) => index + i);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 合并整行单元格
|
|
|
|
|
* @param widgetJson
|
|
|
|
|
* @param rowIndex
|
|
|
|
|
*/
|
|
|
|
|
export const mergeRow = (widgetJson: IWidgetJson, rowIndex: number) => {
|
|
|
|
|
const tableJson = handleFindDomById(widgetJson['subDomList'], widgetJson['activeConfig']['activeId'], true);
|
|
|
|
|
if (tableJson && tableJson['subDomList']) {
|
|
|
|
|
const rowData = tableJson['subDomList'][rowIndex];
|
|
|
|
|
for (let index = 0; index < rowData['length']; index++) {
|
|
|
|
|
if (index == 0) {
|
|
|
|
|
rowData[index]['options']['colspan'] = rowData['length'];
|
|
|
|
|
} else {
|
|
|
|
|
const nextItem = rowData[index]['options'] as any;
|
|
|
|
|
nextItem['colspan'] = 1;
|
|
|
|
|
nextItem['merged'] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 取消合并右侧单元格
|
|
|
|
|
* @param widgetJson
|
|
|
|
|
* @param rowIndex
|
|
|
|
|
* @param colIndex
|
|
|
|
|
*/
|
|
|
|
|
export const cancelMergeCol = (widgetJson: IWidgetJson, rowIndex: number, colIndex: number) => {
|
|
|
|
|
const tableJson = handleFindDomById(widgetJson['subDomList'], widgetJson['activeConfig']['activeId'], true);
|
|
|
|
|
if (tableJson && tableJson['subDomList']) {
|
|
|
|
|
let isStartmerge = false;
|
|
|
|
|
let mergeIndexArr: number[] = [];
|
|
|
|
|
const rowData = tableJson['subDomList'][rowIndex];
|
|
|
|
|
for (let index = 0; index < rowData['length']; index++) {
|
|
|
|
|
if (isStartmerge) {
|
|
|
|
|
if (mergeIndexArr.includes(index)) {
|
|
|
|
|
(rowData[index]['options'] as any)['merged'] = false;
|
|
|
|
|
(rowData[index]['options'] as any)['colspan'] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (colIndex == index) {
|
|
|
|
|
isStartmerge = true;
|
|
|
|
|
mergeIndexArr = Array.from({ length: rowData[index]['options']['colspan'] }, (_, i) => index + i);
|
|
|
|
|
(rowData[index]['options'] as any)['colspan'] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|