Commit de0e8cd0 authored by 田翔's avatar 田翔

fix: 增删改查完成

parent e8229e69
...@@ -204,7 +204,7 @@ const SearchGroup = forwardRef((props, ref) => { ...@@ -204,7 +204,7 @@ const SearchGroup = forwardRef((props, ref) => {
}; };
const btnsClick = type => { const btnsClick = type => {
props && props.btnsClick(type); props && props.btnsClick(type, null);
}; };
return ( return (
......
import React, { useEffect, useMemo, useRef, useState } from 'react' import React, { useEffect, useMemo, useRef, useState } from 'react'
import styles from './index.less' 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 SearchGroup from './components/SearchGroup'
import TablePack from './components/TablePack' 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 { isJson, isObject } from '../../utils/index'
import IconPack from '../widgets/IconPack' import IconPack from '../widgets/IconPack'
import FormRender from '../FormRender' import FormRender from '../FormRender'
...@@ -36,6 +45,7 @@ const TableRender = (props) => { ...@@ -36,6 +45,7 @@ const TableRender = (props) => {
const [config, setConfig] = useState({ webShowFieldGroup: '', addFieldGroup: '', formJson: {} }) const [config, setConfig] = useState({ webShowFieldGroup: '', addFieldGroup: '', formJson: {} })
const [schemaValues, setSchemaValues] = useState({ formJson: {}, values: [] }) const [schemaValues, setSchemaValues] = useState({ formJson: {}, values: [] })
const [submitLoading, setSubmitLoading] = useState(false) const [submitLoading, setSubmitLoading] = useState(false)
const [operation, setOperation] = useState({ id: null, state: '添加' })
const formRenderRef = useRef() const formRenderRef = useRef()
const fileColumns = useMemo(() => { const fileColumns = useMemo(() => {
...@@ -95,13 +105,30 @@ const TableRender = (props) => { ...@@ -95,13 +105,30 @@ const TableRender = (props) => {
<div style={{ display: 'flex', justifyContent: 'center' }}> <div style={{ display: 'flex', justifyContent: 'center' }}>
{ {
btns.map(v => { 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 ( return (
<Button <Button
type='link' type='link'
title={v.title} title={v.title}
icon={v.icon} icon={v.icon}
style={{ padding: '0 7px' }} style={{ padding: '0 7px' }}
onClick={() => btnsClick(v.title, r)} onClick={() => btnsClick(v.title, r.ID)}
> >
</Button> </Button>
) )
...@@ -114,18 +141,34 @@ const TableRender = (props) => { ...@@ -114,18 +141,34 @@ const TableRender = (props) => {
] ]
}, [fileColumns]) }, [fileColumns])
const btnsClick = (type, row) => { const btnsClick = async (type, id) => {
const { addFieldGroup, editFieldGroup, formJson } = config const { addFieldGroup, editFieldGroup, formJson } = config
const addField = addFieldGroup ? addFieldGroup.split(',').filter(v => v) : [] const addField = addFieldGroup ? addFieldGroup.split(',').filter(v => v) : []
const editField = editFieldGroup ? editFieldGroup.split(',').filter(v => v) : []
setOperation({ type, id })
if (type === '添加') { 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 json = JSON.parse(JSON.stringify(formJson))
let parent = json?.properties let parent = json?.properties
if (isObject(parent)) { if (isObject(parent)) {
...@@ -134,6 +177,9 @@ const TableRender = (props) => { ...@@ -134,6 +177,9 @@ const TableRender = (props) => {
let child = parent[v]?.properties let child = parent[v]?.properties
if (isObject(child)) { if (isObject(child)) {
for (let s in child) { for (let s in child) {
if (type === '详情') {
child[s].disabled = true
}
if (addField.includes(s)) { if (addField.includes(s)) {
child[s].hidden = false child[s].hidden = false
hidden = false hidden = false
...@@ -145,7 +191,7 @@ const TableRender = (props) => { ...@@ -145,7 +191,7 @@ const TableRender = (props) => {
parent[v].hidden = hidden parent[v].hidden = hidden
} }
} }
setSchemaValues({ formJson: json, values: [] }) setSchemaValues({ formJson: json, values })
setDetailShow(true) setDetailShow(true)
} }
...@@ -154,12 +200,25 @@ const TableRender = (props) => { ...@@ -154,12 +200,25 @@ const TableRender = (props) => {
if (errors.length) { if (errors.length) {
return message.error('请完善表单内容') return message.error('请完善表单内容')
} }
const { type, id } = operation
setSubmitLoading(true) setSubmitLoading(true)
const { code, data } = await SaveTableDataInfo({ accountTable: accountName, id: null, values: formValue }) if (type === '添加') {
if (code === 0) { const { code, data } = await SaveTableDataInfo({ accountTable: accountName, id: operation.id, values: formValue })
message.success('保存成功!') if (code === 0) {
setSubmitLoading(false) message.success('保存成功!')
setDetailShow(false) 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) => { ...@@ -238,27 +297,31 @@ const TableRender = (props) => {
</div> </div>
</div> </div>
</div> </div>
<div className={styles.tableDetail} style={{ display: detailShow ? 'block' : 'none' }}> {
<div className={styles.formBox}> detailShow ? (
<FormRender ref={formRenderRef} schemaValues={schemaValues} /> <div className={styles.tableDetail}>
</div> <div className={styles.formBox}>
<div className={styles.formBtns}> <FormRender ref={formRenderRef} schemaValues={schemaValues} />
<Button </div>
onClick={() => setDetailShow(false)} <div className={styles.formBtns}>
> <Button
返回 onClick={() => setDetailShow(false)}
</Button> >
<Button 返回
type='primary' </Button>
loading={submitLoading} <Button
onClick={submit} style={{ marginLeft: '10px', display: ['添加', '编辑'].includes(operation.type) ? 'block' : 'none' }}
> type='primary'
提交 loading={submitLoading}
</Button> onClick={submit}
</div> >
</div> 提交
</Button>
</div>
</div>
) : null
}
</div> </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