Yansen 2 years ago
parent
commit
c56a7f7bcf

+ 11
- 9
src/layouts/AuthLayout/components/Menus.jsx View File

6
 export default (props) => {
6
 export default (props) => {
7
   const { theme, items, location } = props;
7
   const { theme, items, location } = props;
8
 
8
 
9
-  const selectedKeys = React.useMemo(() => {
10
-    const parts = location.pathname.split('/').filter(Boolean);
11
-    const keys = parts.reduce((acc, it) => {
12
-      const parent = acc.pop();
13
-      const path = !parent ? `/${it}` : `${parent}/${it}`
9
+  // const selectedKeys = React.useMemo(() => {
10
+  //   const parts = location.pathname.split('/').filter(Boolean);
11
+  //   const keys = parts.reduce((acc, it) => {
12
+  //     const parent = acc.pop();
13
+  //     const path = !parent ? `/${it}` : `${parent}/${it}`
14
 
14
 
15
-      return acc.concat([parent, path].filter(Boolean));
16
-    }, []);
15
+  //     return acc.concat([parent, path].filter(Boolean));
16
+  //   }, []);
17
 
17
 
18
-    return keys;
19
-  }, [location.pathname]);
18
+  //   return keys;
19
+  // }, [location.pathname]);
20
+
21
+  const selectedKeys = [location.pathname];
20
 
22
 
21
   return (
23
   return (
22
     <Menu style={menuStyle} theme={theme} items={items} selectedKeys={selectedKeys} />
24
     <Menu style={menuStyle} theme={theme} items={items} selectedKeys={selectedKeys} />

+ 12
- 2
src/pages/guaranteeTask/Edit/DishList.jsx View File

1
-import React, { useState, useEffect, useRef } from 'react';
1
+import React, { useState, useEffect, useRef, useMemo } from 'react';
2
 import { Row, Col, Card, Button, notification } from 'antd';
2
 import { Row, Col, Card, Button, notification } from 'antd';
3
 import EditableTag from '@/components/EditableTag';
3
 import EditableTag from '@/components/EditableTag';
4
 import { getDishList } from '@/services/dish';
4
 import { getDishList } from '@/services/dish';
17
   const [list, setList] = useState([]);
17
   const [list, setList] = useState([]);
18
   const [loading, setLoading] = useState(false);
18
   const [loading, setLoading] = useState(false);
19
   const packageRef = useRef();
19
   const packageRef = useRef();
20
+  const dishRef = useRef();
21
+
22
+  const calorie = useMemo(() => {
23
+    return list.reduce((acc, it) => {
24
+      const dish = dishRef.current.filterItem(it.dishId) || {};
25
+      return acc + dish.calorie || 0;
26
+    }, 0);
27
+  }, [list]);
20
 
28
 
21
   const handlePackageSubmit = ({item, amount}) => {
29
   const handlePackageSubmit = ({item, amount}) => {
22
     packageRef.current = item;
30
     packageRef.current = item;
50
     const found = list.filter(x => x.dishId === item.id)[0]
58
     const found = list.filter(x => x.dishId === item.id)[0]
51
     if (found) {
59
     if (found) {
52
       found.dishAmount = amount;
60
       found.dishAmount = amount;
61
+      found.calorie = item.calorie || 0;
53
     } else {
62
     } else {
54
       list.push({
63
       list.push({
55
         guaranteeId: dataSource.id,
64
         guaranteeId: dataSource.id,
125
         <div style={{ marginTop: '48px' }}>
134
         <div style={{ marginTop: '48px' }}>
126
           <h3>选择菜肴</h3>
135
           <h3>选择菜肴</h3>
127
           <Selector
136
           <Selector
137
+            ref={dishRef}
128
             placeholder="请选择菜肴"
138
             placeholder="请选择菜肴"
129
             disabled={!dataSource}
139
             disabled={!dataSource}
130
             fetch={getDishList}
140
             fetch={getDishList}
134
       </Col>
144
       </Col>
135
       <Col span={16}>
145
       <Col span={16}>
136
         <Card
146
         <Card
137
-          title="已选菜肴"
147
+          title={`已选菜肴 共计${calorie}卡`}
138
           loading={loading}
148
           loading={loading}
139
           extra={<Button disabled={!dataSource} type='primary' loading={loading} onClick={onSubmit}>保存</Button>}
149
           extra={<Button disabled={!dataSource} type='primary' loading={loading} onClick={onSubmit}>保存</Button>}
140
         >
150
         >

+ 7
- 3
src/pages/guaranteeTask/Edit/components/Selector.jsx View File

1
-import React, { useState, useEffect } from 'react';
1
+import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
2
 import { Button, Input, InputNumber, Select, notification } from 'antd';
2
 import { Button, Input, InputNumber, Select, notification } from 'antd';
3
 
3
 
4
 const { Group } = Input;
4
 const { Group } = Input;
5
 const { Option } = Select;
5
 const { Option } = Select;
6
 
6
 
7
-export default (props) => {
7
+export default forwardRef((props, ref) => {
8
   const { fetch, placeholder, disabled, onSubmit } = props;
8
   const { fetch, placeholder, disabled, onSubmit } = props;
9
 
9
 
10
   const [data, setData] = useState([]);
10
   const [data, setData] = useState([]);
13
 
13
 
14
   const options = data.map(d => <Option key={d.id}>{d.name}</Option>);
14
   const options = data.map(d => <Option key={d.id}>{d.name}</Option>);
15
 
15
 
16
+  useImperativeHandle(ref, () => ({
17
+    filterItem: id => data.filter(x => x.id === id)[0],
18
+  }));
19
+
16
   const handleSearch = (name) => {
20
   const handleSearch = (name) => {
17
     fetch({ pageNum: 1, pageSize: 20, name }).then(res => {
21
     fetch({ pageNum: 1, pageSize: 20, name }).then(res => {
18
       setData(res.records || []);
22
       setData(res.records || []);
74
       <Button type="primary" disabled={disabled} onClick={handleSubmit}>确定</Button>
78
       <Button type="primary" disabled={disabled} onClick={handleSubmit}>确定</Button>
75
     </Group>
79
     </Group>
76
   )
80
   )
77
-}
81
+})

+ 0
- 1
src/pages/rotationChart/introduction/edit/index.jsx View File

39
   }, [isEdit]);
39
   }, [isEdit]);
40
 
40
 
41
   const onFinish = async (values) => {
41
   const onFinish = async (values) => {
42
-    console.log('---------values--------', values)
43
     //添加,修改
42
     //添加,修改
44
     addRegulation({ ...values, id: data?.id, type: "station" }).then((res) => {
43
     addRegulation({ ...values, id: data?.id, type: "station" }).then((res) => {
45
       // message.success('成功');
44
       // message.success('成功');

+ 7
- 2
src/utils/request.js View File

9
 
9
 
10
 // 添加请求拦截器
10
 // 添加请求拦截器
11
 instance.interceptors.request.use(function (config) {
11
 instance.interceptors.request.use(function (config) {
12
-  const { headers = {}, responseType = 'json', download = false, successTip = true } = config;
12
+  const { headers = {}, method = 'get', responseType = 'json', download = false, successTip } = config;
13
   const token = localStorage.getItem('token') || '';
13
   const token = localStorage.getItem('token') || '';
14
 
14
 
15
+  let tip = successTip;
16
+  if (tip === undefined) {
17
+    tip = method === 'get' ? false : true;
18
+  }
19
+
15
   // 在发送请求之前做些什么
20
   // 在发送请求之前做些什么
16
   return {
21
   return {
17
     ...config,
22
     ...config,
18
-    successTip,
23
+    successTip : tip,
19
     headers: {
24
     headers: {
20
       ...headers,
25
       ...headers,
21
       Authorization: token,
26
       Authorization: token,