|
@@ -1,5 +1,5 @@
|
|
import {AutoColumn, AutoText, isNullOrTrue, Message} from "auto-antd";
|
|
import {AutoColumn, AutoText, isNullOrTrue, Message} from "auto-antd";
|
|
-import {Button, Drawer, Switch, Table, TableProps} from "antd";
|
|
|
|
|
|
+import {Button, Drawer, Modal, Switch, Table, TableProps} from "antd";
|
|
import React, {useEffect, useMemo, useRef, useState} from "react";
|
|
import React, {useEffect, useMemo, useRef, useState} from "react";
|
|
import {ColumnsType} from "antd/lib/table";
|
|
import {ColumnsType} from "antd/lib/table";
|
|
import {CurdForm, ICurdForm, IProps as IFormProps} from "./Form.tsx";
|
|
import {CurdForm, ICurdForm, IProps as IFormProps} from "./Form.tsx";
|
|
@@ -7,6 +7,7 @@ import {LDAP} from "../../api/ldap.ts";
|
|
import {DeleteOutlined, EditOutlined, LoadingOutlined, PlusOutlined, SyncOutlined} from "@ant-design/icons";
|
|
import {DeleteOutlined, EditOutlined, LoadingOutlined, PlusOutlined, SyncOutlined} from "@ant-design/icons";
|
|
import './index.less'
|
|
import './index.less'
|
|
import {ICurdConfig, ICurdData} from "./types.ts";
|
|
import {ICurdConfig, ICurdData} from "./types.ts";
|
|
|
|
+import {Cell} from "./cell";
|
|
|
|
|
|
|
|
|
|
export type CurdColumn = AutoColumn & {
|
|
export type CurdColumn = AutoColumn & {
|
|
@@ -16,6 +17,7 @@ export type CurdColumn = AutoColumn & {
|
|
addable?: boolean // 添加时可编辑
|
|
addable?: boolean // 添加时可编辑
|
|
onlyAdd?: boolean // 仅新增时展示
|
|
onlyAdd?: boolean // 仅新增时展示
|
|
editHide?: boolean // 编辑时隐藏
|
|
editHide?: boolean // 编辑时隐藏
|
|
|
|
+ ellipsis?: boolean // 完整显示
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -83,21 +85,30 @@ export function CurdPage<T extends ICurdData>(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const handleDelete = async (edit: T) => {
|
|
const handleDelete = async (edit: T) => {
|
|
- setLoading(true)
|
|
|
|
- try {
|
|
|
|
- await props.onDelete?.(edit)
|
|
|
|
- setQuery((q: any)=>({...q}))
|
|
|
|
- }catch(err) {
|
|
|
|
- if(err instanceof Error){
|
|
|
|
- Message.warning(err.message)
|
|
|
|
- }else if (typeof err === "string") {
|
|
|
|
- Message.warning(err)
|
|
|
|
- }else {
|
|
|
|
- Message.warning('删除失败,错误信息为:'+ err)
|
|
|
|
|
|
+ Modal.confirm({
|
|
|
|
+ type: 'warning',
|
|
|
|
+ title: '您确定要删除该数据吗?',
|
|
|
|
+ content: '删除操作不可撤销,请谨慎操作',
|
|
|
|
+ onOk: async () => {
|
|
|
|
+ setLoading(true)
|
|
|
|
+ try {
|
|
|
|
+ await props.onDelete?.(edit)
|
|
|
|
+ setQuery((q: any)=>({...q}))
|
|
|
|
+ }catch(err: any) {
|
|
|
|
+ if(err instanceof Error){
|
|
|
|
+ Message.warning(err.message)
|
|
|
|
+ }else if (typeof err === "string") {
|
|
|
|
+ Message.warning(err)
|
|
|
|
+ }else if (err?.msg) {
|
|
|
|
+ Message.warning('删除失败,错误信息为:'+ err.msg)
|
|
|
|
+ }else {
|
|
|
|
+ Message.warning('删除失败,错误信息为:'+ JSON.stringify(err,null,2))
|
|
|
|
+ }
|
|
|
|
+ }finally {
|
|
|
|
+ setLoading(false)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }finally {
|
|
|
|
- setLoading(false)
|
|
|
|
- }
|
|
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -109,6 +120,13 @@ export function CurdPage<T extends ICurdData>(
|
|
dataIndex: column.key,
|
|
dataIndex: column.key,
|
|
title: column.title,
|
|
title: column.title,
|
|
width: column.width,
|
|
width: column.width,
|
|
|
|
+ onCell: (record: Partial<T>) => {
|
|
|
|
+ return {
|
|
|
|
+ record,
|
|
|
|
+ config: column,
|
|
|
|
+ dataIndex: column.key,
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if (col.type == 'switch' && !col.render){
|
|
if (col.type == 'switch' && !col.render){
|
|
col.render = (value: boolean) => <Switch checked={value} disabled/>
|
|
col.render = (value: boolean) => <Switch checked={value} disabled/>
|
|
@@ -193,6 +211,11 @@ export function CurdPage<T extends ICurdData>(
|
|
current: query.current,
|
|
current: query.current,
|
|
onChange: onPageChange,
|
|
onChange: onPageChange,
|
|
}}
|
|
}}
|
|
|
|
+ components={{
|
|
|
|
+ body: {
|
|
|
|
+ cell: Cell,
|
|
|
|
+ }
|
|
|
|
+ }}
|
|
expandable={expandable}
|
|
expandable={expandable}
|
|
bordered={config?.bordered}
|
|
bordered={config?.bordered}
|
|
rowKey={config?.rowKey ?? 'id'}
|
|
rowKey={config?.rowKey ?? 'id'}
|