Yansen 2 years ago
parent
commit
d87bf73d05

+ 1
- 1
config/config.js View File

@@ -44,7 +44,7 @@ export default defineConfig({
44 44
     // 如果不想要 configProvide 动态设置主题需要把这个设置为 default
45 45
     // 只有设置为 variable, 才能使用 configProvide 动态设置主色调
46 46
     // https://ant.design/docs/react/customize-theme-variable-cn
47
-    'root-entry-name': 'variable',
47
+    'root-entry-name': 'default' // 'variable',
48 48
   },
49 49
   ignoreMomentLocale: true,
50 50
   proxy: proxy[REACT_APP_ENV || 'dev'],

config/defaultSettings.ts → config/defaultSettings.js View File

@@ -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 View File

@@ -66,8 +66,7 @@
66 66
     path: '/package/list',
67 67
     name: '套餐管理',
68 68
     icon: 'VideoCameraOutlined',
69
-    component: './package/list',
70
-
69
+    component: './package/index',
71 70
   },
72 71
   {
73 72
     component: './404',

+ 1
- 21
src/components/Footer/index.jsx View File

@@ -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 View File

@@ -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 View File

@@ -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 View File

@@ -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 View File


+ 28
- 0
src/pages/package/index.jsx View File

@@ -0,0 +1,28 @@
1
+import React, { useState } from 'react';
2
+import { PageContainer } from '@ant-design/pro-components';
3
+import { Row, Col } 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
+      <Row gutter={100}>
16
+        <Col span={8}>
17
+          <List current={current} setCurrent={setCurrent}/>
18
+        </Col>
19
+        <Col span={8}>
20
+          <BasicForm current={current} onChange={it => setCurrent(it)} />
21
+          <div style={{ marginTop: '100px' }}>
22
+            <DishList />
23
+          </div>
24
+        </Col>
25
+      </Row>
26
+    </PageContainer>
27
+  )
28
+}

+ 0
- 115
src/pages/package/list/index.jsx View File

@@ -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 View File

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

+ 8
- 1
src/services/api/package.js View File

@@ -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' });