浏览代码

Merge branch 'master' of http://git.ycjcjy.com/marketing/pc-admin into master

zlisen 4 年前
父节点
当前提交
7c07676a8c

二进制
public/yz_logo.png 查看文件


+ 13
- 0
src/components/GlobalHeader/index.jsx 查看文件

1
+import React from 'react'
2
+import RightContent from './RightContent'
3
+import styles from './index.less';
4
+
5
+export default (props) => {
6
+  
7
+  return (
8
+    <div className={styles['g-header']}>
9
+      <h1>{props.title}</h1>
10
+      <RightContent />
11
+    </div>
12
+  )
13
+}

+ 10
- 0
src/components/GlobalHeader/index.less 查看文件

2
 
2
 
3
 @pro-header-hover-bg: rgba(0, 0, 0, 0.025);
3
 @pro-header-hover-bg: rgba(0, 0, 0, 0.025);
4
 
4
 
5
+.g-header {
6
+  flex: 100 100 0%;
7
+  display: flex;
8
+
9
+  h1 {
10
+    margin: 0;
11
+    padding: 0;
12
+  }
13
+}
14
+
5
 .menu {
15
 .menu {
6
   :global(.anticon) {
16
   :global(.anticon) {
7
     margin-right: 8px;
17
     margin-right: 8px;

+ 3
- 3
src/components/TableList/TableList.jsx 查看文件

4
 
4
 
5
 const Actions = (props) => {
5
 const Actions = (props) => {
6
   const style = {
6
   const style = {
7
-    marginBottom: '1em'
7
+    padding: '1em',
8
   }
8
   }
9
 
9
 
10
   return (
10
   return (
15
 }
15
 }
16
 
16
 
17
 export default (props) => {
17
 export default (props) => {
18
-  const { actions, ...leftProps } = props
18
+  const { actionRender, ...leftProps } = props
19
 
19
 
20
   const tableProps = {
20
   const tableProps = {
21
     ...leftProps,
21
     ...leftProps,
24
   
24
   
25
   return (
25
   return (
26
     <div className={Styles['box-wrapper']}>
26
     <div className={Styles['box-wrapper']}>
27
-      {actions && <Actions>{actions}</Actions>}
27
+      {typeof actionRender === 'function' && <Actions>{actionRender()}</Actions>}
28
       <Table {...tableProps} />
28
       <Table {...tableProps} />
29
     </div>
29
     </div>
30
   )
30
   )

+ 45
- 32
src/components/TableList/index.jsx 查看文件

1
-import React, { useCallback, useState, useEffect, useImperativeHandle } from 'react';
2
-import { stringify } from 'querystring';
1
+import React, { useCallback, useRef, useState, useEffect, useImperativeHandle } from 'react';
2
+// import { stringify } from 'querystring';
3
 import { notification } from 'antd';
3
 import { notification } from 'antd';
4
 import request from '@/utils/request'
4
 import request from '@/utils/request'
5
 import TableList from './TableList';
5
 import TableList from './TableList';
7
 
7
 
8
 export default React.forwardRef((props, ref) => {
8
 export default React.forwardRef((props, ref) => {
9
   const [loading, setLoading] = useState(false)
9
   const [loading, setLoading] = useState(false)
10
-  const [pageConfig, setPageConfig] = useState({ current: 1, pageSize: 10, total: 0 })
10
+  const mounted = useRef(false)
11
   const [list, setList] = useState()
11
   const [list, setList] = useState()
12
-  const { api, params = {}, onPageChange, ...tableProps } = props
13
-  const paramsStr = stringify({
14
-    ...params,
15
-    pageNum: pageConfig.current,
16
-    pageSize: pageConfig.pageSize,
17
-  })
18
-
19
-  const updatePageConfig = useCallback((config) => {
20
-    const newPage = {
21
-      ...pageConfig,
22
-      ...config,
23
-    }
24
-
25
-    setPageConfig(newPage)
12
+  const [pageTotal, setPageTotal] = useState(0)
13
+  const [pageConfig, setPageConfig] = useState({ current: 1, pageSize: 10 })
26
 
14
 
27
-    if (onPageChange) {
28
-      onPageChange(newPage)
29
-    }
30
-  }, [pageConfig])
15
+  const { api, params = {}, onPageChange, ...tableProps } = props
31
 
16
 
32
-  const handlePageChange = (current, pageSize) => {
33
-    const config = pageSize ? { current, pageSize } : { current }
34
-    updatePageConfig(config)
35
-  }
17
+  // 更新分页
18
+  const updatePage = useCallback(
19
+    (current, pageSize) => {
20
+      const config = pageSize ? { current, pageSize } : { current }
21
+      const newPage = {
22
+        ...pageConfig,
23
+        ...config,
24
+      }
25
+  
26
+      setPageConfig(newPage)
27
+      if (onPageChange) {
28
+        onPageChange(newPage)
29
+      }
30
+    },
31
+    [pageConfig],
32
+  )
36
 
33
 
37
   // 获取远程数据
34
   // 获取远程数据
38
   const fetchData = useCallback(
35
   const fetchData = useCallback(
39
     () => {
36
     () => {
40
-      const url = `${api.url}?${paramsStr}`
41
       setLoading(true)
37
       setLoading(true)
42
-      request({...api, url}).then((res) => {
43
-        const {current, total, records = []} = res
38
+      const queryParams = {
39
+        ...params,
40
+        pageNum: pageConfig.current,
41
+        pageSize: pageConfig.pageSize,
42
+      }
43
+      request({...api, params: queryParams }).then((res) => {
44
+        const {total, records = []} = res
44
         setLoading(false)
45
         setLoading(false)
45
         setList(records)
46
         setList(records)
46
-        updatePageConfig({current, total})
47
+        setPageTotal(total)
47
       }).catch((err) => {
48
       }).catch((err) => {
48
         console.error(err)
49
         console.error(err)
49
         setLoading(false)
50
         setLoading(false)
50
         notification.warn({ message: err.message })
51
         notification.warn({ message: err.message })
51
       })
52
       })
52
     },
53
     },
53
-    [paramsStr, api],
54
+    [params, pageConfig, api],
54
   )
55
   )
55
 
56
 
56
   // 监控查询参数的修改
57
   // 监控查询参数的修改
57
   useEffect(() => {
58
   useEffect(() => {
59
+    // 通过更新分页来触发查询
60
+    updatePage(1)
61
+  }, [params])
62
+  
63
+  // 监控分页的修改
64
+  useEffect(() => {
65
+    // 首次加载不查询
66
+    if (!mounted.current) {
67
+      mounted.current = true
68
+      return
69
+    }
70
+
58
     fetchData()
71
     fetchData()
59
-  }, [paramsStr])
72
+  }, [pageConfig])
60
 
73
 
61
   // 透传给父组件部分方法
74
   // 透传给父组件部分方法
62
   useImperativeHandle(ref, () => ({
75
   useImperativeHandle(ref, () => ({
66
   return (
79
   return (
67
     <>
80
     <>
68
       <TableList loading={loading} dataSource={list} {...tableProps} />
81
       <TableList loading={loading} dataSource={list} {...tableProps} />
69
-      <Pagination {...pageConfig} onChange={handlePageChange} />
82
+      <Pagination {...pageConfig} total={pageTotal} onChange={updatePage} />
70
     </>
83
     </>
71
   )
84
   )
72
 });
85
 });

+ 4
- 3
src/layouts/BasicLayout.jsx 查看文件

10
 import { Icon, Result, Button } from 'antd';
10
 import { Icon, Result, Button } from 'antd';
11
 import { formatMessage } from 'umi-plugin-react/locale';
11
 import { formatMessage } from 'umi-plugin-react/locale';
12
 import Authorized from '@/utils/Authorized';
12
 import Authorized from '@/utils/Authorized';
13
-import RightContent from '@/components/GlobalHeader/RightContent';
13
+import GlobalHeader from '@/components/GlobalHeader';
14
 import { isAntDesignPro, getAuthorityFromRouter } from '@/utils/utils';
14
 import { isAntDesignPro, getAuthorityFromRouter } from '@/utils/utils';
15
 import logo from '../assets/logo.svg';
15
 import logo from '../assets/logo.svg';
16
 const noMatch = (
16
 const noMatch = (
63
     dispatch,
63
     dispatch,
64
     children,
64
     children,
65
     settings,
65
     settings,
66
+    history,
66
     location = {
67
     location = {
67
       pathname: '/',
68
       pathname: '/',
68
     },
69
     },
76
       });
77
       });
77
     }
78
     }
78
   }; // get children authority
79
   }; // get children authority
80
+  const routeItem = getAuthorityFromRouter(props.route.routes, location.pathname || '/')
79
 
81
 
80
   const authorized = useMemo(() => {
82
   const authorized = useMemo(() => {
81
-    const routeItem = getAuthorityFromRouter(props.route.routes, location.pathname || '/')
82
     if (!routeItem || !routeItem.menuCode) {
83
     if (!routeItem || !routeItem.menuCode) {
83
       return {
84
       return {
84
         authority: undefined,
85
         authority: undefined,
130
       footerRender={footerRender}
131
       footerRender={footerRender}
131
       menuDataRender={menuDataRender(menus)}
132
       menuDataRender={menuDataRender(menus)}
132
       formatMessage={formatMessage}
133
       formatMessage={formatMessage}
133
-      rightContentRender={() => <RightContent />}
134
+      rightContentRender={() => <GlobalHeader title={routeItem.name} history={history} location={location} />}
134
       {...props}
135
       {...props}
135
       {...settings}
136
       {...settings}
136
     >
137
     >

+ 1
- 2
src/models/login.js 查看文件

47
         }
47
         }
48
       }
48
       }
49
 
49
 
50
-      // yield put(routerRedux.replace(redirect || '/'));
51
-      yield put(routerRedux.replace('/'));
50
+      yield put(routerRedux.replace(redirect || '/'));
52
     },
51
     },
53
 
52
 
54
     *logout(_, { put, call }) {
53
     *logout(_, { put, call }) {

+ 40
- 14
src/pages/building/List/index.jsx 查看文件

1
 import React, { useMemo, useRef, useCallback, useState } from 'react'
1
 import React, { useMemo, useRef, useCallback, useState } from 'react'
2
-import { PageHeaderWrapper } from '@ant-design/pro-layout'
3
-import apis from '@/services/apis'
2
+// import { PageHeaderWrapper } from '@ant-design/pro-layout'
3
+import { Button, notification, Spin } from 'antd'
4
 import QueryTable from '@/components/QueryTable'
4
 import QueryTable from '@/components/QueryTable'
5
+import request from '@/utils/request'
6
+import apis from '@/services/apis'
5
 import getSearchFields from './searchFields'
7
 import getSearchFields from './searchFields'
6
 import getTableColumns from './tableColumns'
8
 import getTableColumns from './tableColumns'
7
 
9
 
8
 export default (props) => {
10
 export default (props) => {
9
   const ref = useRef()
11
   const ref = useRef()
12
+  const [loading, setLoading] = useState(false)
10
   const [page, setPage] = useState({current: 1, pageSize: 10})
13
   const [page, setPage] = useState({current: 1, pageSize: 10})
11
   const onPublish = useCallback((row) => {
14
   const onPublish = useCallback((row) => {
12
-    //
15
+    const buidingStatus = row.status === 1 ? 2 : 1
16
+    request({ ...apis.building.updateStatus, data: { id: row.buildingId, status: buidingStatus } }).then(() => {
17
+      notification.success({ message: '操作成功' })
18
+      setLoading(false)
19
+      ref.current.reload()
20
+    }).catch(err => {
21
+      console.error(err)
22
+      setLoading(false)
23
+    })
13
   }, [])
24
   }, [])
14
 
25
 
15
   const onDelete = useCallback((row) => {
26
   const onDelete = useCallback((row) => {
16
-
27
+    setLoading(true)
28
+    request({ ...apis.building.deleteBuilding, urlData: { id: row.buildingId } }).then(() => {
29
+      notification.success({ message: '操作成功' })
30
+      setLoading(false)
31
+      ref.current.reload()
32
+    }).catch((err) => {
33
+      console.error(err)
34
+      setLoading(false)
35
+    })
17
   }, [])
36
   }, [])
18
 
37
 
19
   const searchFields = useMemo(getSearchFields, [])
38
   const searchFields = useMemo(getSearchFields, [])
25
     })
44
     })
26
   }, [page])
45
   }, [page])
27
 
46
 
47
+  const actionRender = () => {
48
+    return <Button type="primary" icon="plus">新增</Button>
49
+  }
50
+
28
   return (
51
   return (
29
-    <PageHeaderWrapper>
30
-      <QueryTable
31
-        ref={ref}
32
-        rowKey="buildingId"
33
-        api={apis.building.getList}
34
-        searchFields={searchFields}
35
-        columns={tableColumns}
36
-        onPageChange={(pg) => setPage(pg)}
37
-      />
38
-    </PageHeaderWrapper>
52
+    // <PageHeaderWrapper>
53
+      <Spin spinning={loading}>
54
+        <QueryTable
55
+          ref={ref}
56
+          rowKey="buildingId"
57
+          api={apis.building.getList}
58
+          searchFields={searchFields}
59
+          columns={tableColumns}
60
+          actionRender={actionRender}
61
+          onPageChange={(pg) => setPage(pg)}
62
+        />
63
+      </Spin>
64
+    // </PageHeaderWrapper>
39
   )
65
   )
40
 }
66
 }

+ 3
- 3
src/pages/document.ejs 查看文件

170
       <div
170
       <div
171
         style="display: flex;justify-content: center;align-items: center;flex-direction: column;min-height: 420px;height: 100%;"
171
         style="display: flex;justify-content: center;align-items: center;flex-direction: column;min-height: 420px;height: 100%;"
172
       >
172
       >
173
-        <img src="/pro_icon.svg" alt="logo" width="256" />
173
+        <!-- <img src="/pro_icon.svg" alt="logo" width="256" /> -->
174
         <div class="page-loading-warp">
174
         <div class="page-loading-warp">
175
           <div class="ant-spin ant-spin-lg ant-spin-spinning">
175
           <div class="ant-spin ant-spin-lg ant-spin-spinning">
176
             <span class="ant-spin-dot ant-spin-dot-spin"
176
             <span class="ant-spin-dot ant-spin-dot-spin"
181
         </div>
181
         </div>
182
         <div style="display: flex;justify-content: center;align-items: center;">
182
         <div style="display: flex;justify-content: center;align-items: center;">
183
           <img
183
           <img
184
-            src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
184
+            src="./yz_logo.png"
185
             width="32"
185
             width="32"
186
             style="margin-right: 8px;"
186
             style="margin-right: 8px;"
187
           />
187
           />
188
-          Ant Design
188
+          南京 云致
189
         </div>
189
         </div>
190
       </div>
190
       </div>
191
     </div>
191
     </div>

+ 21
- 7
src/utils/utils.js 查看文件

29
  */
29
  */
30
 
30
 
31
 export const getAuthorityFromRouter = (router = [], pathname) => {
31
 export const getAuthorityFromRouter = (router = [], pathname) => {
32
-  const authority = router.find(
33
-    ({ routes, path = '/' }) =>
34
-      (path && pathRegexp(path).exec(pathname)) ||
35
-      (routes && getAuthorityFromRouter(routes, pathname)),
36
-  );
37
-  if (authority) return authority;
38
-  return undefined;
32
+  // const authority = router.find(
33
+  //   ({ routes, path = '/' }) =>
34
+  //     (path && pathRegexp(path).exec(pathname)) ||
35
+  //     (routes && getAuthorityFromRouter(routes, pathname)),
36
+  // );
37
+
38
+  // if (authority) return authority;
39
+  // return undefined;
40
+
41
+  for (let r of router) {
42
+    if (pathRegexp(r.path || '/').exec(pathname)) {
43
+      return r
44
+    }
45
+
46
+    if (r.routes && r.routes.length) {
47
+      const f = getAuthorityFromRouter(r.routes, pathname)
48
+      if (f) {
49
+        return f
50
+      }
51
+    }
52
+  }
39
 };
53
 };
40
 export const getRouteAuthority = (path, routeData) => {
54
 export const getRouteAuthority = (path, routeData) => {
41
   let authorities;
55
   let authorities;