|
| 1 | +/* react redux */ |
| 2 | +// eslint-disable-next-line no-use-before-define |
| 3 | +import React, { Fragment } from 'react' |
| 4 | +import bus from '@/utils/eventBus' |
| 5 | +import axiosReq from '@/utils/axiosReq.js' |
| 6 | +import { connect } from 'react-redux' |
| 7 | +// import { useSelector, useDispatch } from 'react-redux' |
| 8 | +import { Button, message, Popconfirm, Space, Table, Tag } from 'antd' |
| 9 | +function ErrorLog(props) { |
| 10 | + // const [uState, setState] = React.useState({ count: 111 }) |
| 11 | + //redux相关 |
| 12 | + // const countNum = useSelector((state) => state.count.countNum) |
| 13 | + // const dispatch = useDispatch() |
| 14 | + // function testChangeState() { |
| 15 | + // setState({ |
| 16 | + // ...uState, |
| 17 | + // count: uState.count + 1000 |
| 18 | + // }) |
| 19 | + // } |
| 20 | + |
| 21 | + const errlogTest = () => { |
| 22 | + throw new Error('error test') |
| 23 | + } |
| 24 | + |
| 25 | + /*删除*/ |
| 26 | + let deleteByIdReq = (id) => { |
| 27 | + return axiosReq({ |
| 28 | + url: '/ty-user/errorCollection/deleteById', |
| 29 | + data: { id: id }, |
| 30 | + isParams: true, |
| 31 | + method: 'delete', |
| 32 | + bfLoading: true |
| 33 | + }) |
| 34 | + } |
| 35 | + const tableDelClick = (row) => { |
| 36 | + deleteByIdReq(row.id).then(() => { |
| 37 | + selectPageReq() |
| 38 | + message.success(`【${row.pageUrl}】删除成功`).then() |
| 39 | + }) |
| 40 | + } |
| 41 | + const columns = [ |
| 42 | + { |
| 43 | + title: '错误日志', |
| 44 | + dataIndex: 'errorLog', |
| 45 | + key: 'errorLog' |
| 46 | + }, |
| 47 | + { |
| 48 | + title: '页面路径', |
| 49 | + dataIndex: 'pageUrl', |
| 50 | + key: 'pageUrl' |
| 51 | + }, |
| 52 | + { |
| 53 | + title: '创建时间', |
| 54 | + dataIndex: 'createTime', |
| 55 | + key: 'createTime' |
| 56 | + }, |
| 57 | + { |
| 58 | + title: 'Action', |
| 59 | + key: 'action', |
| 60 | + render: (text, record) => ( |
| 61 | + <Space size="middle" key={record}> |
| 62 | + <Button type="primary" size="small" onClick={() => tableDelClick(record)}> |
| 63 | + 删除 |
| 64 | + </Button> |
| 65 | + </Space> |
| 66 | + ) |
| 67 | + } |
| 68 | + ] |
| 69 | + const [tableData, setTableData] = React.useState([]) |
| 70 | + |
| 71 | + React.useEffect(() => { |
| 72 | + //类似于ComponentDidMount |
| 73 | + selectPageReq() |
| 74 | + //监听页面报错然后触发更新 |
| 75 | + bus.on('reloadErrorPage', () => { |
| 76 | + selectPageReq() |
| 77 | + }) |
| 78 | + return (state) => { |
| 79 | + //类似于ComponentUnMount |
| 80 | + console.log('useEffectreturn') |
| 81 | + } |
| 82 | + }, []) |
| 83 | + let selectPageReq = () => { |
| 84 | + let reqConfig = { |
| 85 | + url: '/ty-user/errorCollection/selectPage', |
| 86 | + method: 'get', |
| 87 | + isParams: true, |
| 88 | + isAlertErrorMsg: false |
| 89 | + } |
| 90 | + axiosReq(reqConfig).then((resData) => { |
| 91 | + setTableData(resData.data?.records) |
| 92 | + }) |
| 93 | + } |
| 94 | + const [rowIdArr, setRowIdArr] = React.useState([]) |
| 95 | + const tableOnChange = (pagination, filters, sorter, extra) => { |
| 96 | + console.log(pagination, filters, sorter, extra) |
| 97 | + } |
| 98 | + const onSelectChange = (selectedRowKeys) => { |
| 99 | + setRowIdArr(selectedRowKeys) |
| 100 | + } |
| 101 | + const rowSelection = { |
| 102 | + type: 'checkbox', |
| 103 | + onChange: onSelectChange |
| 104 | + } |
| 105 | + const multiDelBtnClick = () => { |
| 106 | + if (rowIdArr.length === 0) { |
| 107 | + message.warning('表格选项不能为空', 'warning').then() |
| 108 | + return |
| 109 | + } |
| 110 | + Popconfirm({ title: '确认' }) |
| 111 | + axiosReq({ |
| 112 | + url: `/ty-user/errorCollection/deleteBatchIds`, |
| 113 | + data: rowIdArr, |
| 114 | + method: 'DELETE', |
| 115 | + bfLoading: true |
| 116 | + }).then(() => { |
| 117 | + selectPageReq() |
| 118 | + message.success('删除成功').then() |
| 119 | + }) |
| 120 | + } |
| 121 | + return ( |
| 122 | + <Fragment> |
| 123 | + <div className="mb-1"> |
| 124 | + <Button type="primary" onClick={errlogTest}> |
| 125 | + error test |
| 126 | + </Button> |
| 127 | + <Button className="ml-1" type="primary" onClick={multiDelBtnClick}> |
| 128 | + 删除 |
| 129 | + </Button> |
| 130 | + </div> |
| 131 | + <Table |
| 132 | + rowSelection={rowSelection} |
| 133 | + bordered |
| 134 | + columns={columns} |
| 135 | + dataSource={tableData} |
| 136 | + rowKey="id" |
| 137 | + onChange={(pagination, filters, sorter, extra) => { |
| 138 | + tableOnChange(pagination, filters, sorter, extra) |
| 139 | + }} |
| 140 | + /> |
| 141 | + </Fragment> |
| 142 | + ) |
| 143 | +} |
| 144 | + |
| 145 | +//配置使用redux |
| 146 | +export default connect((state) => ({ |
| 147 | + countNum: state.count.countNum |
| 148 | +}))(ErrorLog) |
0 commit comments