Commit de0e8cd0 authored by 田翔's avatar 田翔

fix: 增删改查完成

parent e8229e69
......@@ -204,7 +204,7 @@ const SearchGroup = forwardRef((props, ref) => {
};
const btnsClick = type => {
props && props.btnsClick(type);
props && props.btnsClick(type, null);
};
return (
......
import React, { useEffect, useMemo, useRef, useState } from 'react'
import styles from './index.less'
import { Table, Tooltip, message, Button, Pagination } from 'antd'
import { Table, Tooltip, message, Button, Pagination, Popconfirm } from 'antd'
import SearchGroup from './components/SearchGroup'
import TablePack from './components/TablePack'
import { GetAccountConfigInfo, GetAccountPageList, getStationListByUserID, GetTableJson, SaveTableDataInfo } from '../../apis/process'
import {
GetAccountConfigInfo,
GetAccountPageList,
getStationListByUserID,
GetTableJson,
GetTableDataInfo,
EditTableDataInfo,
SaveTableDataInfo,
DeleteTableDataInfo,
} from '../../apis/process'
import { isJson, isObject } from '../../utils/index'
import IconPack from '../widgets/IconPack'
import FormRender from '../FormRender'
......@@ -36,6 +45,7 @@ const TableRender = (props) => {
const [config, setConfig] = useState({ webShowFieldGroup: '', addFieldGroup: '', formJson: {} })
const [schemaValues, setSchemaValues] = useState({ formJson: {}, values: [] })
const [submitLoading, setSubmitLoading] = useState(false)
const [operation, setOperation] = useState({ id: null, state: '添加' })
const formRenderRef = useRef()
const fileColumns = useMemo(() => {
......@@ -95,13 +105,30 @@ const TableRender = (props) => {
<div style={{ display: 'flex', justifyContent: 'center' }}>
{
btns.map(v => {
if (v.title === '删除') {
return (
<Popconfirm
title='确定要删除数据吗?'
onConfirm={() => btnsClick(v.title, r.ID)}
okText='确定'
cancelText='取消'
>
<Button
type='link'
title='删除'
style={{ padding: '0 7px' }}
icon={v.icon}
/>
</Popconfirm>
)
}
return (
<Button
type='link'
title={v.title}
icon={v.icon}
style={{ padding: '0 7px' }}
onClick={() => btnsClick(v.title, r)}
onClick={() => btnsClick(v.title, r.ID)}
>
</Button>
)
......@@ -114,18 +141,34 @@ const TableRender = (props) => {
]
}, [fileColumns])
const btnsClick = (type, row) => {
const btnsClick = async (type, id) => {
const { addFieldGroup, editFieldGroup, formJson } = config
const addField = addFieldGroup ? addFieldGroup.split(',').filter(v => v) : []
const editField = editFieldGroup ? editFieldGroup.split(',').filter(v => v) : []
setOperation({ type, id })
if (type === '添加') {
addClick(addField, formJson)
saveClick(addField, formJson, [], type)
}
if (type === '编辑' || type === '详情') {
const { code, data, msg } = await GetTableDataInfo({ accountName, id })
if (code === 0) {
saveClick(editField, formJson, data, type)
} else {
message.error(msg)
}
}
if (type === '删除') {
const { code, data, msg } = await DeleteTableDataInfo({ accountTable: accountName, ids: id })
if (code === 0) {
message.success('删除成功!')
getDataSource()
} else {
message.error(msg)
}
}
// if (['添加', '详情', '编辑'].includes(type)) {
// setDetailShow(true)
// }
}
const addClick = (addField, formJson) => {
const saveClick = (addField, formJson, values, type) => {
let json = JSON.parse(JSON.stringify(formJson))
let parent = json?.properties
if (isObject(parent)) {
......@@ -134,6 +177,9 @@ const TableRender = (props) => {
let child = parent[v]?.properties
if (isObject(child)) {
for (let s in child) {
if (type === '详情') {
child[s].disabled = true
}
if (addField.includes(s)) {
child[s].hidden = false
hidden = false
......@@ -145,7 +191,7 @@ const TableRender = (props) => {
parent[v].hidden = hidden
}
}
setSchemaValues({ formJson: json, values: [] })
setSchemaValues({ formJson: json, values })
setDetailShow(true)
}
......@@ -154,12 +200,25 @@ const TableRender = (props) => {
if (errors.length) {
return message.error('请完善表单内容')
}
const { type, id } = operation
setSubmitLoading(true)
const { code, data } = await SaveTableDataInfo({ accountTable: accountName, id: null, values: formValue })
if (code === 0) {
message.success('保存成功!')
setSubmitLoading(false)
setDetailShow(false)
if (type === '添加') {
const { code, data } = await SaveTableDataInfo({ accountTable: accountName, id: operation.id, values: formValue })
if (code === 0) {
message.success('保存成功!')
setSubmitLoading(false)
setDetailShow(false)
getDataSource()
}
}
if (type === '编辑') {
const { code, data } = await EditTableDataInfo({ accountTable: accountName, id: operation.id, values: formValue })
if (code === 0) {
message.success('修改!')
setSubmitLoading(false)
setDetailShow(false)
getDataSource()
}
}
}
......@@ -238,27 +297,31 @@ const TableRender = (props) => {
</div>
</div>
</div>
<div className={styles.tableDetail} style={{ display: detailShow ? 'block' : 'none' }}>
<div className={styles.formBox}>
<FormRender ref={formRenderRef} schemaValues={schemaValues} />
</div>
<div className={styles.formBtns}>
<Button
onClick={() => setDetailShow(false)}
>
返回
</Button>
<Button
type='primary'
loading={submitLoading}
onClick={submit}
>
提交
</Button>
</div>
</div>
{
detailShow ? (
<div className={styles.tableDetail}>
<div className={styles.formBox}>
<FormRender ref={formRenderRef} schemaValues={schemaValues} />
</div>
<div className={styles.formBtns}>
<Button
onClick={() => setDetailShow(false)}
>
返回
</Button>
<Button
style={{ marginLeft: '10px', display: ['添加', '编辑'].includes(operation.type) ? 'block' : 'none' }}
type='primary'
loading={submitLoading}
onClick={submit}
>
提交
</Button>
</div>
</div>
) : null
}
</div>
)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment