Compare commits
4 Commits
a6647dcefe
...
9b44a03ad0
Author | SHA1 | Date |
---|---|---|
|
9b44a03ad0 | 2 months ago |
|
9a82c26ace | 2 months ago |
|
70f4d52912 | 2 months ago |
|
ad14e6d7ee | 2 months ago |
@ -0,0 +1,35 @@
|
||||
{
|
||||
// 一、格式化相关
|
||||
"editor.formatOnType": false,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnPaste": false,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit"
|
||||
},
|
||||
|
||||
// 二、编辑器显示与行为
|
||||
"editor.tabSize": 2,
|
||||
"editor.snippetSuggestions": "top",
|
||||
"editor.guides.bracketPairs": "active",
|
||||
"editor.suggestSelection": "first",
|
||||
"editor.acceptSuggestionOnCommitCharacter": false,
|
||||
"editor.quickSuggestions": {
|
||||
"other": true,
|
||||
"comments": true,
|
||||
"strings": true
|
||||
},
|
||||
|
||||
// 三、换行和列宽限制
|
||||
"editor.wordWrap": "on",
|
||||
"editor.wordWrapColumn": 180,
|
||||
"editor.rulers": [180],
|
||||
|
||||
// 四、文件与保存
|
||||
"files.autoSave": "off",
|
||||
|
||||
// 五、Git 设置
|
||||
"git.confirmSync": false,
|
||||
|
||||
// 六、工作台与启动项
|
||||
"workbench.startupEditor": "newUntitledFile"
|
||||
}
|
@ -1,16 +1,93 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import melonJson from "./melon.json";
|
||||
import { containers, basicFields } from "@/utils/widgetsConfig";
|
||||
import type { IWidget } from '@/types/widgetsConfigInterface'
|
||||
/**
|
||||
* 初始化和重置文书结构
|
||||
* @param widgetJson
|
||||
*/
|
||||
export const initJson = (widgetJson: any) => {
|
||||
widgetJson['widgetList'] = []
|
||||
// widgetJson['formConfig'] = {}
|
||||
widgetJson['subDomList'] = []
|
||||
widgetJson['activeConfig']['activeId'] = ""
|
||||
widgetJson['activeConfig']['activeDisplayName'] = ""
|
||||
}
|
||||
|
||||
export const addItem = (fatherId = "", widgetJson: any) => {
|
||||
if (fatherId) { } else {
|
||||
widgetJson['widgetList'] = [melonJson]
|
||||
/**
|
||||
* 根据表单元素 格式化对应的属性
|
||||
* @param addItemDataOrigin
|
||||
*/
|
||||
export const formatAddItem = (addItemTypeName: string) => {
|
||||
let addItemData = null;
|
||||
let activeId = ""
|
||||
let activeDisplayName = ""
|
||||
const allWidgetList = [...containers, ...basicFields];
|
||||
const targetItem = allWidgetList.filter(item => {
|
||||
return item['type'] == addItemTypeName
|
||||
})
|
||||
if (targetItem['length']) {
|
||||
addItemData = structuredClone(targetItem[0]);
|
||||
addItemData['key'] = `${Date.now().toString().slice(-6)}${Math.floor(Math.random() * 900) + 100}`;
|
||||
addItemData['id'] = `${addItemData['type']}-${addItemData['key']}`
|
||||
addItemData['subDomList'] = [];
|
||||
addItemData['options']['name'] = addItemData['id']
|
||||
activeId = addItemData['id']
|
||||
activeDisplayName = addItemData['displayName']
|
||||
}
|
||||
return {
|
||||
addItemData,
|
||||
activeId,
|
||||
activeDisplayName
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新的子元素
|
||||
* @param widgetJson 文书结构JSON
|
||||
* @param addItemTypeName 新元素类型
|
||||
* @param fatherId 父容器id
|
||||
*/
|
||||
export const addItem = (widgetJson: any, addItemTypeName: any) => {
|
||||
const { addItemData, activeId, activeDisplayName } = formatAddItem(addItemTypeName)
|
||||
if (widgetJson['activeConfig']['activeId']) { } else {
|
||||
widgetJson['subDomList'].push(addItemData)
|
||||
}
|
||||
widgetJson['activeConfig']['activeId'] = activeId
|
||||
widgetJson['activeDisplayName'] = activeDisplayName
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据id寻找结构
|
||||
* @param subDomList widgetJson['subDomList']
|
||||
* @param returnParent 是否返回父容器节点
|
||||
*/
|
||||
export const handleFindDomById = (subDomList: any, activeKey: string, returnParent = false) => {
|
||||
let found: IWidget | null = null
|
||||
|
||||
function dfs(nodes: IWidget[], parent: IWidget | null): boolean {
|
||||
for (const node of nodes) {
|
||||
if (node['id'] === activeKey) {
|
||||
found = returnParent ? parent?.category === 'container' ? parent : null : node
|
||||
return true
|
||||
}
|
||||
|
||||
// 针对 subDomList 为二维数组或一维数组都做兼容处理
|
||||
const children = node.subDomList
|
||||
if (Array.isArray(children)) {
|
||||
if (Array.isArray(children[0])) {
|
||||
// 二维数组情况
|
||||
for (const row of children as IWidget[][]) {
|
||||
if (dfs(row, node)) return true
|
||||
}
|
||||
} else {
|
||||
// 一维数组情况
|
||||
if (dfs(children as IWidget[], node)) return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
dfs(subDomList, null)
|
||||
return found
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { formatAddItem, handleFindDomById } from "@/utils/index";
|
||||
import type { IWidget, IWidgetJson } from '@/types/widgetsConfigInterface'
|
||||
|
||||
/**
|
||||
* 新增表格 默认会自动生成一个单元格
|
||||
* @param widgetJson
|
||||
* @param addItemTypeName
|
||||
* @param fatherId
|
||||
*/
|
||||
export const addTable = (widgetJson: IWidgetJson, addItemTypeName: any) => {
|
||||
const tableCol = formatAddItem('table-cell');
|
||||
const { addItemData, activeId, activeDisplayName } = formatAddItem(addItemTypeName);
|
||||
if (addItemData && tableCol['addItemData']) {
|
||||
addItemData['subDomList'] = [[tableCol['addItemData']]];
|
||||
}
|
||||
if (widgetJson['activeConfig']['activeId']) {
|
||||
if (widgetJson['activeConfig']['activeId'].startsWith('table-cell')) {
|
||||
// 单元格里面直接加
|
||||
const tableJson = handleFindDomById(widgetJson['subDomList'], widgetJson['activeConfig']['activeId'], false);
|
||||
if (tableJson && addItemData) {
|
||||
(tableJson['subDomList'] as IWidget[]).push(addItemData)
|
||||
}
|
||||
} else if (widgetJson['activeConfig']['activeId'].startsWith('table')) {
|
||||
// 表格后面加
|
||||
if (addItemData) {
|
||||
widgetJson['subDomList'].push(addItemData)
|
||||
}
|
||||
} else {
|
||||
// 寻找上一层单元格加
|
||||
const tableJson = handleFindDomById(widgetJson['subDomList'], widgetJson['activeConfig']['activeId'], true);
|
||||
if (tableJson && addItemData) {
|
||||
(tableJson['subDomList'] as IWidget[]).push(addItemData)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (addItemData) {
|
||||
widgetJson['subDomList'].push(addItemData)
|
||||
}
|
||||
}
|
||||
widgetJson['activeConfig']['activeId'] = tableCol['activeId']
|
||||
widgetJson['activeConfig']['activeDisplayName'] = tableCol['activeDisplayName']
|
||||
// widgetJson['activeConfig']['activeId'] = activeId
|
||||
// widgetJson['activeConfig']['activeDisplayName'] = activeDisplayName
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增表格行 以第一列的个数为准
|
||||
* @param widgetJson
|
||||
* @param addItemTypeName
|
||||
* @param fatherId
|
||||
*/
|
||||
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++) {
|
||||
const { addItemData } = formatAddItem(addItemTypeName);
|
||||
if (addItemData) {
|
||||
newRow.push(addItemData);
|
||||
}
|
||||
}
|
||||
if (isPush) {
|
||||
(tableJson['subDomList'] as IWidget[][]).splice(rowIndex + 1, 0, newRow)
|
||||
} else {
|
||||
(tableJson['subDomList'] as IWidget[][]).splice(rowIndex, 0, newRow)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增表格列 遍历每一行增加
|
||||
* @param widgetJson 树结构
|
||||
* @param colIndex 添加位置列下标
|
||||
* @param isPush 是否为右侧添加
|
||||
* @param returnParent 是否返回父节点
|
||||
* @param addItemTypeName 新增元素名称
|
||||
*/
|
||||
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];
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue