Quellcode durchsuchen

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

zlisen vor 4 Jahren
Ursprung
Commit
7c07676a8c

BIN
public/yz_logo.png Datei anzeigen


+ 13
- 0
src/components/GlobalHeader/index.jsx Datei anzeigen

@@ -0,0 +1,13 @@
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 Datei anzeigen

@@ -2,6 +2,16 @@
2 2
 
3 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 15
 .menu {
6 16
   :global(.anticon) {
7 17
     margin-right: 8px;

+ 3
- 3
src/components/TableList/TableList.jsx Datei anzeigen

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

+ 45
- 32
src/components/TableList/index.jsx Datei anzeigen

@@ -1,5 +1,5 @@
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 3
 import { notification } from 'antd';
4 4
 import request from '@/utils/request'
5 5
 import TableList from './TableList';
@@ -7,56 +7,69 @@ import Pagination from './Pagination';
7 7
 
8 8
 export default React.forwardRef((props, ref) => {
9 9
   const [loading, setLoading] = useState(false)
10
-  const [pageConfig, setPageConfig] = useState({ current: 1, pageSize: 10, total: 0 })
10
+  const mounted = useRef(false)
11 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 35
   const fetchData = useCallback(
39 36
     () => {
40
-      const url = `${api.url}?${paramsStr}`
41 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 45
         setLoading(false)
45 46
         setList(records)
46
-        updatePageConfig({current, total})
47
+        setPageTotal(total)
47 48
       }).catch((err) => {
48 49
         console.error(err)
49 50
         setLoading(false)
50 51
         notification.warn({ message: err.message })
51 52
       })
52 53
     },
53
-    [paramsStr, api],
54
+    [params, pageConfig, api],
54 55
   )
55 56
 
56 57
   // 监控查询参数的修改
57 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 71
     fetchData()
59
-  }, [paramsStr])
72
+  }, [pageConfig])
60 73
 
61 74
   // 透传给父组件部分方法
62 75
   useImperativeHandle(ref, () => ({
@@ -66,7 +79,7 @@ export default React.forwardRef((props, ref) => {
66 79
   return (
67 80
     <>
68 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 Datei anzeigen

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

+ 1
- 2
src/models/login.js Datei anzeigen

@@ -47,8 +47,7 @@ const Model = {
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 53
     *logout(_, { put, call }) {

+ 40
- 14
src/pages/building/List/index.jsx Datei anzeigen

@@ -1,19 +1,38 @@
1 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 4
 import QueryTable from '@/components/QueryTable'
5
+import request from '@/utils/request'
6
+import apis from '@/services/apis'
5 7
 import getSearchFields from './searchFields'
6 8
 import getTableColumns from './tableColumns'
7 9
 
8 10
 export default (props) => {
9 11
   const ref = useRef()
12
+  const [loading, setLoading] = useState(false)
10 13
   const [page, setPage] = useState({current: 1, pageSize: 10})
11 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 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 38
   const searchFields = useMemo(getSearchFields, [])
@@ -25,16 +44,23 @@ export default (props) => {
25 44
     })
26 45
   }, [page])
27 46
 
47
+  const actionRender = () => {
48
+    return <Button type="primary" icon="plus">新增</Button>
49
+  }
50
+
28 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 Datei anzeigen

@@ -170,7 +170,7 @@
170 170
       <div
171 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 174
         <div class="page-loading-warp">
175 175
           <div class="ant-spin ant-spin-lg ant-spin-spinning">
176 176
             <span class="ant-spin-dot ant-spin-dot-spin"
@@ -181,11 +181,11 @@
181 181
         </div>
182 182
         <div style="display: flex;justify-content: center;align-items: center;">
183 183
           <img
184
-            src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
184
+            src="./yz_logo.png"
185 185
             width="32"
186 186
             style="margin-right: 8px;"
187 187
           />
188
-          Ant Design
188
+          南京 云致
189 189
         </div>
190 190
       </div>
191 191
     </div>

+ 21
- 7
src/utils/utils.js Datei anzeigen

@@ -29,13 +29,27 @@ export const getPageQuery = () => parse(window.location.href.split('?')[1]);
29 29
  */
30 30
 
31 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 54
 export const getRouteAuthority = (path, routeData) => {
41 55
   let authorities;