소스 검색

Merge branch 'master' of http://git.ycjcjy.com/jgz/admin

fangmingyue 2 년 전
부모
커밋
ffda5ff66f

config/defaultSettings.ts → config/defaultSettings.js 파일 보기

@@ -1,9 +1,5 @@
1
-import { Settings as LayoutSettings } from '@ant-design/pro-components';
2 1
 
3
-const Settings: LayoutSettings & {
4
-  pwa?: boolean;
5
-  logo?: string;
6
-} = {
2
+const Settings = {
7 3
   navTheme: 'dark',
8 4
   // 拂晓蓝
9 5
   primaryColor: '#1890ff',
@@ -12,10 +8,13 @@ const Settings: LayoutSettings & {
12 8
   fixedHeader: false,
13 9
   fixSiderbar: true,
14 10
   colorWeak: false,
15
-  title: '军供',
11
+  title: '海安军供',
16 12
   pwa: false,
17 13
   logo: '/w2/logo.png',
18 14
   iconfontUrl: '',
15
+  splitMenus: false,
16
+  headerRender: false,
17
+  footerRender: false,
19 18
 };
20 19
 
21 20
 export default Settings;

+ 1
- 2
config/routes.js 파일 보기

@@ -73,8 +73,7 @@
73 73
     path: '/package/list',
74 74
     name: '套餐管理',
75 75
     icon: 'VideoCameraOutlined',
76
-    component: './package/list',
77
-
76
+    component: './package/index',
78 77
   },
79 78
   {
80 79
     component: './404',

+ 31
- 4
package.json 파일 보기

@@ -45,8 +45,8 @@
45 45
   ],
46 46
   "dependencies": {
47 47
     "@ant-design/icons": "^4.7.0",
48
-    "@ant-design/pro-components": "1.1.1",
49
-    "@umijs/route-utils": "^2.0.0",
48
+    "@ant-design/pro-components": "^2.0.0",
49
+    "@umijs/route-utils": "^2.1.3",
50 50
     "antd": "^4.20.0",
51 51
     "classnames": "^2.3.0",
52 52
     "lodash": "^4.17.0",
@@ -65,7 +65,6 @@
65 65
     "@types/classnames": "^2.3.1",
66 66
     "@types/express": "^4.17.0",
67 67
     "@types/history": "^4.7.0",
68
-    "@types/jest": "^26.0.0",
69 68
     "@types/lodash": "^4.14.0",
70 69
     "@types/react": "^17.0.0",
71 70
     "@types/react-dom": "^17.0.0",
@@ -79,7 +78,6 @@
79 78
     "eslint": "^7.32.0",
80 79
     "gh-pages": "^3.2.0",
81 80
     "husky": "^7.0.4",
82
-    "jsdom-global": "^3.0.0",
83 81
     "lint-staged": "^10.0.0",
84 82
     "mockjs": "^1.1.0",
85 83
     "prettier": "^2.5.0",
@@ -90,5 +88,34 @@
90 88
   },
91 89
   "engines": {
92 90
     "node": ">=12.0.0"
91
+  },
92
+  "create-umi": {
93
+    "ignoreScript": [
94
+      "docker*",
95
+      "functions*",
96
+      "site",
97
+      "generateMock"
98
+    ],
99
+    "ignoreDependencies": [
100
+      "netlify*",
101
+      "serverless"
102
+    ],
103
+    "ignore": [
104
+      ".dockerignore",
105
+      ".git",
106
+      ".github",
107
+      ".gitpod.yml",
108
+      "CODE_OF_CONDUCT.md",
109
+      "Dockerfile",
110
+      "Dockerfile.*",
111
+      "lambda",
112
+      "LICENSE",
113
+      "netlify.toml",
114
+      "README.*.md",
115
+      "azure-pipelines.yml",
116
+      "docker",
117
+      "CNAME",
118
+      "create-umi"
119
+    ]
93 120
   }
94 121
 }

+ 30
- 7
src/app.jsx 파일 보기

@@ -1,9 +1,6 @@
1
-import Footer from '@/components/Footer';
2
-import RightContent from '@/components/RightContent';
3
-import { currentUser as queryCurrentUser } from '@/services/api/login';
4 1
 import { requestConfig } from '@/utils/request';
5
-import { SettingDrawer } from '@ant-design/pro-components';
6 2
 import { history } from '@umijs/max';
3
+import { SettingDrawer } from '@ant-design/pro-components';
7 4
 import defaultSettings from '../config/defaultSettings';
8 5
 
9 6
 const isDev = process.env.NODE_ENV === 'development';
@@ -40,9 +37,19 @@ export async function getInitialState() {
40 37
 
41 38
 // ProLayout 支持的api https://procomponents.ant.design/components/layout
42 39
 export const layout = ({ initialState, setInitialState }) => {
43
-  return {
40
+  const cfg = {
44 41
     // rightContentRender: () => <RightContent />,
45 42
     disableContentMargin: false,
43
+    token: {
44
+      sider: {
45
+        colorMenuBackground: '#001529',
46
+        colorTextMenuTitle: '#fff',
47
+        colorTextMenu: 'hsla(0,0%,100%,.65);',
48
+        colorBgMenuItemHover: '#fff',
49
+        colorBgMenuItemSelected: '#1890ff',
50
+        colorTextMenuSelected: '#fff',
51
+      },
52
+    },
46 53
     // waterMarkProps: {
47 54
     //   content: initialState?.currentUser?.name,
48 55
     // },
@@ -64,7 +71,6 @@ export const layout = ({ initialState, setInitialState }) => {
64 71
     //     ]
65 72
     //   : [],
66 73
     menuHeaderRender: undefined,
67
-
68 74
     // 自定义 403 页面
69 75
     // unAccessible: <div>unAccessible</div>,
70 76
     // 增加一个 loading 的状态
@@ -73,12 +79,29 @@ export const layout = ({ initialState, setInitialState }) => {
73 79
       return (
74 80
         <>
75 81
           {children}
82
+          {/* {!props.location?.pathname?.includes('/login') && (
83
+            <SettingDrawer
84
+              disableUrlParams
85
+              enableDarkTheme
86
+              settings={initialState?.settings}
87
+              onSettingChange={(settings) => {
88
+                setInitialState((preInitialState) => ({
89
+                  ...preInitialState,
90
+                  settings,
91
+                }));
92
+              }}
93
+            />
94
+          )} */}
76 95
         </>
77 96
       );
78 97
     },
79 98
 
80
-    ...initialState?.settings,
99
+    settings: initialState?.settings,
81 100
   };
101
+
102
+  console.log(cfg)
103
+
104
+  return cfg;
82 105
 };
83 106
 
84 107
 export const request = requestConfig;

+ 1
- 21
src/components/Footer/index.jsx 파일 보기

@@ -1,7 +1,7 @@
1 1
 import { DefaultFooter } from '@ant-design/pro-components';
2 2
 
3 3
 const Footer = () => {
4
-  const defaultMessage = '无际科技';
4
+  const defaultMessage = '南京云致';
5 5
 
6 6
   const currentYear = new Date().getFullYear();
7 7
 
@@ -11,26 +11,6 @@ const Footer = () => {
11 11
         background: 'none',
12 12
       }}
13 13
       copyright={`${currentYear} ${defaultMessage}`}
14
-      // links={[
15
-      //   {
16
-      //     key: 'Ant Design Pro',
17
-      //     title: 'Ant Design Pro',
18
-      //     href: 'https://pro.ant.design',
19
-      //     blankTarget: true,
20
-      //   },
21
-      //   {
22
-      //     key: 'github',
23
-      //     title: <GithubOutlined />,
24
-      //     href: 'https://github.com/ant-design/ant-design-pro',
25
-      //     blankTarget: true,
26
-      //   },
27
-      //   {
28
-      //     key: 'Ant Design',
29
-      //     title: 'Ant Design',
30
-      //     href: 'https://ant.design',
31
-      //     blankTarget: true,
32
-      //   },
33
-      // ]}
34 14
     />
35 15
   );
36 16
 };

+ 62
- 0
src/pages/package/BasicForm.jsx 파일 보기

@@ -0,0 +1,62 @@
1
+import React, { useState, useEffect } from 'react';
2
+import { Button, Checkbox, Form, Input } from 'antd';
3
+import { addPackage, updataPackage } from '@/services/api/package';
4
+
5
+export default (props) => {
6
+  const { current, onChange } = props;
7
+
8
+  const [form] = Form.useForm();
9
+  const [loading, setLoading] = useState(false);
10
+
11
+  const onFinish = (values) => {
12
+    setLoading(true);
13
+
14
+    const data = current.id ? { ...current, ...values } : values;
15
+    const func = current.id ? updataPackage : addPackage;
16
+    
17
+    func(data, current.id).then(res => {
18
+      setLoading(false);
19
+      onChange(res);
20
+    }).catch(() => {
21
+      setLoading(false);
22
+    });
23
+  }
24
+
25
+  useEffect(() => {
26
+    form.setFieldsValue({
27
+      name: current.name,
28
+      unit: current.unit,
29
+    });
30
+  }, [form, current])
31
+
32
+  return (
33
+    <Form
34
+      form={form}
35
+      labelCol={{ span: 6 }}
36
+      wrapperCol={{ span: 16 }}
37
+      onFinish={onFinish}
38
+      autoComplete="off"
39
+    >
40
+      <Form.Item
41
+        label="套餐名称"
42
+        name="name"
43
+        rules={[{ required: true, message: '请输入套餐名称' }]}
44
+      >
45
+        <Input placeholder='请输入套餐名称' />
46
+      </Form.Item>
47
+
48
+      <Form.Item
49
+        label="套餐单位"
50
+        name="unit"
51
+      >
52
+        <Input placeholder='请输入套餐单位' />
53
+      </Form.Item>
54
+
55
+      <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
56
+        <Button type="primary" htmlType="submit" loading={loading}>
57
+          提交
58
+        </Button>
59
+      </Form.Item>
60
+    </Form>
61
+  )
62
+}

+ 81
- 0
src/pages/package/DishList.jsx 파일 보기

@@ -0,0 +1,81 @@
1
+import React, { useState } from 'react';
2
+import { List, Popconfirm, Select } from 'antd';
3
+
4
+const { Option } = Select;
5
+
6
+const Header = props => {
7
+  const { onChange } = props;
8
+  const [data, setData] = useState([]);
9
+  const [value, setValue] = useState();
10
+
11
+  const handleSearch = (newValue) => {
12
+    if (newValue) {
13
+      // fetch(newValue, setData);
14
+    } else {
15
+      setData([]);
16
+    }
17
+  };
18
+
19
+  const handleChange = (newValue) => {
20
+    setValue(newValue);
21
+    if (newValue) {
22
+      onChange(data.filter(x => x.id === newValue)[0]);
23
+    }
24
+  };
25
+
26
+  const options = data.map(d => <Option key={d.id} value={d.id}>{d.name}</Option>);
27
+
28
+  return (
29
+    <Select
30
+      style={{ width: '100%' }}
31
+      showSearch
32
+      value={value}
33
+      placeholder='请选择菜肴'
34
+      defaultActiveFirstOption={false}
35
+      showArrow={false}
36
+      filterOption={false}
37
+      onSearch={handleSearch}
38
+      onChange={handleChange}
39
+      notFoundContent={null}
40
+    >
41
+      {options}
42
+    </Select>
43
+  );
44
+}
45
+
46
+
47
+export default (props) => {
48
+  const [list, setList] = useState([]);
49
+
50
+  const onAdd = item => {
51
+    const origin = list.filter(x => x.id !== item.id)[0];
52
+    if (!origin) {
53
+      setList([...list, item]);
54
+    }
55
+  }
56
+
57
+  return (
58
+    <List
59
+      header={<Header onChange={onAdd} />}
60
+      bordered
61
+      dataSource={list}
62
+      renderItem={item => (
63
+        <List.Item
64
+          className={classNames({ active: current.id === item.id })}
65
+          onClick={() => setCurrent(item)}
66
+          actions={[
67
+            <Popconfirm
68
+              key="delete"
69
+              title="确认删除套餐?"
70
+              onConfirm={() => onDelete(item)}
71
+              >
72
+              <a href="#">删除</a>
73
+            </Popconfirm>
74
+          ]}
75
+        >
76
+          {item.name}
77
+        </List.Item>
78
+      )}
79
+    />
80
+  );
81
+}

+ 129
- 0
src/pages/package/List.jsx 파일 보기

@@ -0,0 +1,129 @@
1
+import React, { useState, useEffect, useRef } from 'react';
2
+import { Row, Col, Button, List, Popconfirm, Input } from 'antd';
3
+import classNames from 'classnames';
4
+import { getPackageList, deletePackage } from '@/services/api/package';
5
+
6
+export default (props) => {
7
+  const { current, setCurrent } = props;
8
+  const [loading, setLoading] = useState(false);
9
+  const [hasMore, setHasMore] = useState(true);
10
+  const [filter, setFilter] = useState({ pageNum: 1, pageSize: 10, total: 0 });
11
+  const [list, setList] = useState([]);
12
+  const listRef = useRef();
13
+  listRef.current = list;
14
+
15
+  const onLoadMore = () => {
16
+    setFilter({
17
+      ...filter,
18
+      pageNum: filter.pageNum + 1,
19
+    })
20
+  }
21
+
22
+  const loadMore = loading || !hasMore ? null : (
23
+    <div
24
+      style={{
25
+        textAlign: 'center',
26
+        marginTop: 12,
27
+        height: 32,
28
+        lineHeight: '32px',
29
+      }}
30
+    >
31
+      <Button onClick={onLoadMore}>加载更多</Button>
32
+    </div>
33
+  );
34
+
35
+  const onSearch = (val) => {
36
+    setFilter({
37
+      ...filter,
38
+      name: val,
39
+      pageNum: 1,
40
+    })
41
+  }
42
+
43
+  const onDelete = (item) => {
44
+    setLoading(true);
45
+    deletePackage(item.id).then(res => {
46
+      setLoading(false);
47
+
48
+      const newList = listRef.current.filter(x => x.id !== item.id);
49
+      setList(newList);
50
+      if (item.id === current.id) {
51
+        setCurrent(newList[0] || {});
52
+      }
53
+    }).catch(() => {
54
+      setLoading(false);
55
+    });
56
+  };
57
+
58
+  useEffect(() => {
59
+    setLoading(true);
60
+    getPackageList(filter).then(res => {
61
+      setLoading(false);
62
+
63
+      const { records = [], current, total, pages } = res
64
+
65
+      if (current === 1) {
66
+        setList(records)
67
+        setCurrent((records || [])[0] || {})
68
+      } else {
69
+        setList(listRef.current.concat(records))
70
+      }
71
+
72
+      setHasMore(current < pages)
73
+    }).catch(() => {
74
+      setLoading(false);
75
+    });
76
+  }, [filter]);
77
+
78
+  useEffect(() => {
79
+    if (!current || !current.id) return;
80
+
81
+    let found = false;
82
+    let newList = listRef.current.map(x => {
83
+      if (x.id === current.id) {
84
+        found = true;
85
+        return current;
86
+      }
87
+
88
+      return x;
89
+    })
90
+
91
+    if (!found) {
92
+      newList = newList.concat(current);
93
+    }
94
+
95
+    setList(newList);
96
+  }, [current])
97
+
98
+  return (
99
+    <List
100
+      bordered
101
+      header={
102
+        <Input.Group compact>
103
+          <Input.Search allowClear placeholder="请输入筛选名称" onSearch={onSearch} style={{ width: 'calc(100% - 60px)' }} />
104
+          <Button type='link' onClick={() => setCurrent({})} >新增</Button>
105
+        </Input.Group>
106
+      }
107
+      dataSource={list}
108
+      loading={loading}
109
+      loadMore={loadMore}
110
+      renderItem={item => (
111
+        <List.Item
112
+          className={classNames({ active: current.id === item.id })}
113
+          onClick={() => setCurrent(item)}
114
+          actions={[
115
+            <Popconfirm
116
+              key="delete"
117
+              title="确认删除套餐?"
118
+              onConfirm={() => onDelete(item)}
119
+              >
120
+              <a href="#">删除</a>
121
+            </Popconfirm>
122
+          ]}
123
+        >
124
+          {item.name}
125
+        </List.Item>
126
+      )}
127
+    />
128
+  )
129
+}

+ 0
- 0
src/pages/package/a.js 파일 보기


+ 30
- 0
src/pages/package/index.jsx 파일 보기

@@ -0,0 +1,30 @@
1
+import React, { useState } from 'react';
2
+import { PageContainer } from '@ant-design/pro-components';
3
+import { Row, Col, Card } from 'antd';
4
+import List from './List';
5
+import BasicForm from './BasicForm';
6
+import DishList from './DishList';
7
+
8
+import './style.less';
9
+
10
+export default (props) => {
11
+  const [current, setCurrent] = useState({});
12
+
13
+  return (
14
+    <PageContainer>
15
+      <Card>
16
+        <Row gutter={100}>
17
+          <Col span={8}>
18
+            <List current={current} setCurrent={setCurrent}/>
19
+          </Col>
20
+          <Col span={8}>
21
+            <BasicForm current={current} onChange={it => setCurrent(it)} />
22
+            <div style={{ marginTop: '100px' }}>
23
+              <DishList />
24
+            </div>
25
+          </Col>
26
+        </Row>
27
+      </Card>
28
+    </PageContainer>
29
+  )
30
+}

+ 0
- 115
src/pages/package/list/index.jsx 파일 보기

@@ -1,115 +0,0 @@
1
-import { getPackageList, addPackage, updataPackage } from '@/services/api/package';
2
-import { queryTable } from '@/utils/request';
3
-import { PageContainer, ProTable } from '@ant-design/pro-components';
4
-import { history } from '@umijs/max';
5
-import { Button, message, Popconfirm, EditForm } from 'antd';
6
-import { useRef, useState } from 'react';
7
-
8
-const PackageList = (props) => {
9
-  console.log(props, '===');
10
-  const [showDetail, setShowDetail] = useState(false);
11
-  const [activeKey, setActiveKey] = useState('');
12
-  const actionRef = useRef();
13
-
14
-  const updata = (row) => {
15
-    if (row.id) {
16
-      updataPackage(row.id, { state: row.state === '1' ? '2' : '1' }).then((res) => {
17
-        message.success('修改成功');
18
-        actionRef.current.reload();
19
-      });
20
-    }
21
-  };
22
-
23
-  const handleDelete = (id) => {
24
-    if (id) {
25
-      deleteBanner(id).then((res) => {
26
-        message.success('删除成功');
27
-        actionRef.current.reload();
28
-      });
29
-    }
30
-  };
31
-
32
-  const columns = [
33
-    {
34
-      title: '套餐名称',
35
-      dataIndex: 'name',
36
-    },
37
-
38
-    {
39
-      title: '套餐单位',
40
-      dataIndex: 'unit',
41
-    },
42
-    {
43
-      title: '包含菜肴(份)',
44
-      dataIndex: 'itemId.amount',
45
-    },
46
-    {
47
-      title: '包含食材(种)',
48
-      dataIndex: 'itemId.amount',
49
-    },
50
-    {
51
-      title: '操作',
52
-      valueType: 'option',
53
-      width: 200,
54
-      render: (_, record) => [
55
-        <Button
56
-          key={1}
57
-          style={{ padding: 0 }}
58
-          type="link"
59
-          onClick={() => {
60
-            updata(record);
61
-          }}
62
-        >
63
-          {record.state === '1' ? '下架' : '上架'}
64
-        </Button>,
65
-        <Button
66
-          key={2}
67
-          style={{ padding: 0 }}
68
-          type="link"
69
-          onClick={() => {
70
-            console.log(record, ']]');
71
-            history.push(`/rotationChart/add?id=${record.id}`);
72
-          }}
73
-        >
74
-          编辑
75
-        </Button>,
76
-
77
-        <Popconfirm
78
-          key={3}
79
-          title="您是否确认删除 ?"
80
-          onConfirm={() => handleDelete(record.id)}
81
-          okText="确定"
82
-          cancelText="取消"
83
-        >
84
-          {/* manualPush */}
85
-          <Button style={{ padding: 0 }} type="link">
86
-            删除
87
-          </Button>
88
-        </Popconfirm>,
89
-      ],
90
-    },
91
-  ];
92
-
93
-  return (
94
-    <PageContainer>
95
-      <ProTable
96
-        search={false}
97
-        actionRef={actionRef}
98
-        rowKey="id"
99
-        toolBarRender={() => [
100
-          <Button
101
-            key="2"
102
-            type="primary"
103
-            onClick={() => { setCurrent({}); setVisible(true); }}
104
-          >
105
-            新增
106
-          </Button>,
107
-        ]}
108
-        // request={queryTable(getDishList)}
109
-        columns={columns}
110
-      />
111
-    </PageContainer>
112
-  );
113
-};
114
-
115
-export default PackageList;

+ 6
- 0
src/pages/package/style.less 파일 보기

@@ -0,0 +1,6 @@
1
+
2
+.ant-list-item {
3
+  &.active {
4
+    background-color: #e6f7ff;
5
+  }
6
+}

+ 8
- 1
src/services/api/package.js 파일 보기

@@ -21,4 +21,11 @@ export const addPackage = (data) => request('/package', { method: 'post', data }
21 21
  * @param {*} data
22 22
  * @returns
23 23
  */
24
-export const updataPackage = (id, data) => request(`/package/${id}`, { method: 'put', data });
24
+export const updataPackage = (data, id) => request(`/package/${id}`, { method: 'put', data });
25
+
26
+/**
27
+ * 删除
28
+ *  @param {*} id
29
+ * @returns
30
+ */
31
+export const deletePackage = id => request(`/package/${id}`, { method: 'delete' });