Yansen 2 年前
父节点
当前提交
c56a7f7bcf

+ 11
- 9
src/layouts/AuthLayout/components/Menus.jsx 查看文件

@@ -6,17 +6,19 @@ const menuStyle = { height: '100%' };
6 6
 export default (props) => {
7 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 23
   return (
22 24
     <Menu style={menuStyle} theme={theme} items={items} selectedKeys={selectedKeys} />

+ 12
- 2
src/pages/guaranteeTask/Edit/DishList.jsx 查看文件

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

+ 7
- 3
src/pages/guaranteeTask/Edit/components/Selector.jsx 查看文件

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

+ 0
- 1
src/pages/rotationChart/introduction/edit/index.jsx 查看文件

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

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

@@ -9,13 +9,18 @@ const instance = axios.create({
9 9
 
10 10
 // 添加请求拦截器
11 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 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 21
   return {
17 22
     ...config,
18
-    successTip,
23
+    successTip : tip,
19 24
     headers: {
20 25
       ...headers,
21 26
       Authorization: token,