1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import React, { useMemo, useRef, useCallback, useState, useEffect } from 'react'
- import {Button,message} from 'antd'
- import apis from '@/services/apis'
- import AuthButton from '@/components/AuthButton';
- import QueryTable from '@/components/QueryTable'
- import getTableColumns from './tableColumns'
- import { router } from 'umi';
- import { fetch} from '@/utils/request';
- import request from '@/utils/request'
- import getSearchFields from './searchFields'//searchbox
-
- export default (props) => {
- const ref = useRef()
- const [page, setPage] = useState({current: 1, pageSize: 10})
- const toEdit = useCallback((row) => {
- router.push({
- pathname: '/building/Developers/Edit',
- query: {
- brandId: row?.brandId || undefined,
- },
- });
- }, [])
-
-
-
- //编辑
- // const onEdit =useCallback((row,brandId)=>{
- // request({
- // ...apis.brand.alterBrand,
- // urlData: { id: brandId },
- // data:{ ...row}
- // }).then((data) => {
- // setNewsData(data)
- // }).catch((err) => {
- // message.error(err.msg || err.message)
- // })
- // },[])
-
- //删除
- const onDelete = useCallback((row,brandId) => {
- request({ ...apis.brand.deleBrand, urlData: { id: brandId }, data: { ...row, } }).then((data) => {
- ref.current.reload();//调用ref对象都有current对象
- message.info('操作成功!')
- }).catch((err) => {
- console.log(err)
- message.info(err.msg || err.message)
- })
- }, [])//格式
- const searchFields = useMemo(getSearchFields, [])//搜索框
-
- const tableColumns = useMemo(() => {
- return getTableColumns({
- page,//
- onEdit:(e)=>toEdit(e),
- onDelete,
- // onEdit,
- })
- }, [page])
-
- const actionRender = () => {
- return (
- //name
- <AuthButton name="building.brand.add" noRight={null}>
- <Button type="primary" icon="plus" onClick={toEdit} >
- 新增
- </Button>
- </AuthButton>
- );
- };
-
- return (
- <>
- <QueryTable
- ref={ref}//绑定到table
- rowKey="brandId"
- api={apis.brand.list}
- columns={tableColumns}
- actionRender={actionRender}
- searchFields={searchFields}
- />
- </>
- )
- }
|