Skip to content

Commit

Permalink
增加table树型结构
Browse files Browse the repository at this point in the history
  • Loading branch information
qq958691165 committed Nov 20, 2024
1 parent 16ef5c1 commit 168624e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quansitech/antd-admin",
"version": "1.1.6",
"version": "1.1.7",
"type": "module",
"files": [
"dist"
Expand Down
18 changes: 16 additions & 2 deletions src/components/Table/Action/StartEditable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,30 @@ export default function (props: TableActionProps & {
}) {
const tableContext = useContext(TableContext)

const expandable = tableContext.getTableProps()?.expandable

function allChildren(data: any[], callback: (item: any) => void) {
data.map(item => {
callback(item)
if (item[expandable?.childrenColumnName || 'children']) {
allChildren(item.children, callback)
}
})
}

const onStartClick = () => {
const rowKey = tableContext.getTableProps().rowKey
tableContext.getTableProps().dataSource.map(item => {


allChildren(tableContext.getTableProps().dataSource, item => {
tableContext.actionRef?.startEditable(item[rowKey], item)
})
}

const onCancelClick = () => {
const rowKey = tableContext.getTableProps().rowKey
tableContext.getTableProps().dataSource.map(item => {

allChildren(tableContext.getTableProps().dataSource, item => {
tableContext.actionRef?.cancelEditable(item[rowKey])
})
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,16 @@ export function handleCondition(condition: Condition, data: any) {
return data[condition.field] && !condition.value.includes(data[condition.field]);
}
return false
}

export function deepSet(obj: any, path: string, value: any) {
const paths = path.split('.');
paths.reduce((acc, key, index) => {
if (index === paths.length - 1) {
acc[key] = value;
} else {
acc[key] = acc[key] || {};
}
return acc[key];
}, obj);
}
4 changes: 3 additions & 1 deletion src/lib/schemaHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ProColumnType, ProSchema} from "@ant-design/pro-components";
import {UploadFile} from "antd";
import http from "./http";
import {handleCondition} from "./helpers";
import {deepSet, handleCondition} from "./helpers";

type Handler = (schema: any) => ProSchema | ProColumnType

Expand Down Expand Up @@ -39,6 +39,8 @@ export const commonHandler: Handler = schema => {
if (schema.valueEnum) {
schema.valueEnum = new Map(schema.valueEnum)
}
// 有些表单项宽度并不能撑满,这里强制设置宽度
deepSet(schema, 'fieldProps.style.width', '100%')
return schema
}

Expand Down

0 comments on commit 168624e

Please sign in to comment.