From 57532862e0a5d79cfab0dca736fd607587efb659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E7=8E=89=E7=90=B3?= <1584592841@qq.com> Date: Wed, 20 Jul 2022 09:41:23 +0800 Subject: [PATCH 1/4] =?UTF-8?q?token=20=E9=85=8D=E7=BD=AE=E6=88=90?= =?UTF-8?q?=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 8 ++++---- src/components/Accountant/Query.jsx | 5 +++-- src/components/Accountant/WareIn.jsx | 12 ++++++------ src/components/Accountant/WareOut.jsx | 8 ++++---- src/components/Header.jsx | 2 -- src/components/LoginReg/LoginCard.jsx | 14 +++++--------- src/components/System/AuthManage/Auth.jsx | 6 +++--- src/components/System/Customer/Custom.jsx | 8 ++++---- src/components/System/Employee/Employee.jsx | 10 +++++----- src/components/System/Order/Order.jsx | 16 ++++++++-------- src/components/System/Ware/Position.jsx | 10 +++++----- src/components/System/Ware/PositionDetail.jsx | 7 ++++--- src/components/System/Ware/WareManage.jsx | 12 ++++++------ src/components/WareClerk/GoodsIn.jsx | 6 +++--- src/components/WareClerk/GoodsOut.jsx | 4 ++-- src/components/WareClerk/Tasks.jsx | 4 ++-- src/components/WareClerk/WareChange.jsx | 8 ++++---- src/components/WareManager/Stock.jsx | 4 ++-- src/components/WareManager/WareQuery.jsx | 4 ++-- src/utils/adminRequest.js | 12 ++++++++++++ 20 files changed, 84 insertions(+), 76 deletions(-) create mode 100644 src/utils/adminRequest.js diff --git a/src/App.js b/src/App.js index f8c0df7..5d65ef4 100644 --- a/src/App.js +++ b/src/App.js @@ -1,9 +1,9 @@ import { Navigate, Route, Routes } from "react-router-dom"; import { LoginReg, NotFoundPage, Admin } from "./pages"; import { Into, Login } from "./userPages/index"; -import axios from 'axios'; +import axios from "axios"; -axios.defaults.baseURL="http://localhost:80" +// axios.defaults.baseURL = "http://localhost:80"; function App() { return ( @@ -17,8 +17,8 @@ function App() { } /> } /> - }/> - }/> + } /> + } /> diff --git a/src/components/Accountant/Query.jsx b/src/components/Accountant/Query.jsx index f9ca252..cf64bf9 100644 --- a/src/components/Accountant/Query.jsx +++ b/src/components/Accountant/Query.jsx @@ -1,9 +1,10 @@ import React, { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; -import axios from "axios"; import { Modal, Table, message } from "antd"; import { FiSearch } from "react-icons/fi"; +import adminRequest from "../../utils/adminRequest"; + import { wareCategories, statusCategories, @@ -94,7 +95,7 @@ const Query = () => { }; useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/order-manage/queryAll") .then((res) => { if (res.data.code === 10000) { diff --git a/src/components/Accountant/WareIn.jsx b/src/components/Accountant/WareIn.jsx index ccadee9..556ae6d 100644 --- a/src/components/Accountant/WareIn.jsx +++ b/src/components/Accountant/WareIn.jsx @@ -1,10 +1,10 @@ import React, { useState, useEffect } from "react"; import { useLocation, useNavigate } from "react-router-dom"; -import axios from "axios"; import { Button, message } from "antd"; import InputArea from "../InputArea"; import Selector from "../Selector"; +import adminRequest from "../../utils/adminRequest"; const editCSS = "pl-0 my-1 rounded border-2 border-b-blue-200 outline-none focus:ring focus:ring-blue-300 focus:border-white duration-150 ease-in"; @@ -34,7 +34,7 @@ const WareIn = () => { const settleFee = (e) => { e.preventDefault(); - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/update", { @@ -47,7 +47,7 @@ const WareIn = () => { .then((res) => { if (res.data.code === 10000) { message.success("信息录入成功"); - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/settlefee", {}, @@ -71,7 +71,7 @@ const WareIn = () => { const wareInHandler = () => { setLoading(true); - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/status", {}, @@ -108,7 +108,7 @@ const WareIn = () => { //获取类别1 useEffect(() => { - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/categories" ) @@ -129,7 +129,7 @@ const WareIn = () => { useEffect(() => { let resObj = {}; for (let item of goodsCate1) { - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/names", {}, diff --git a/src/components/Accountant/WareOut.jsx b/src/components/Accountant/WareOut.jsx index 99d0097..ed6be2e 100644 --- a/src/components/Accountant/WareOut.jsx +++ b/src/components/Accountant/WareOut.jsx @@ -1,9 +1,9 @@ import React, { useState } from "react"; import { useLocation } from "react-router-dom"; import { message, Button } from "antd"; -import axios from "axios"; import InputArea from "../InputArea"; +import adminRequest from "../../utils/adminRequest"; const editCSS = "pl-0 my-1 rounded border-2 border-b-blue-200 outline-none focus:ring focus:ring-blue-300 focus:border-white duration-150 ease-in"; @@ -22,7 +22,7 @@ const WareOut = () => { const settleFee = (e) => { e.preventDefault(); - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-out/update", { @@ -34,7 +34,7 @@ const WareOut = () => { .then((res) => { if (res.data.code === 10000) { message.success("费用填写成功"); - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-out/settlefee", {}, @@ -58,7 +58,7 @@ const WareOut = () => { const wareOutHandler = () => { setLoading(true); - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-out/status", {}, diff --git a/src/components/Header.jsx b/src/components/Header.jsx index 2e1f265..7161843 100644 --- a/src/components/Header.jsx +++ b/src/components/Header.jsx @@ -2,7 +2,6 @@ import React, { useState } from "react"; import { FiHelpCircle } from "react-icons/fi"; import { MdLogout } from "react-icons/md"; import Avatar from "../img/avatar.png"; -import axios from "axios"; const Header = ({ priority, username }) => { const [date, setDate] = useState(new Date()); @@ -11,7 +10,6 @@ const Header = ({ priority, username }) => { localStorage.removeItem("username"); localStorage.removeItem("priority"); localStorage.removeItem("token"); - axios.defaults.headers.common["token"] = ""; window.location.href = "/"; }; diff --git a/src/components/LoginReg/LoginCard.jsx b/src/components/LoginReg/LoginCard.jsx index 490e407..dee6f67 100644 --- a/src/components/LoginReg/LoginCard.jsx +++ b/src/components/LoginReg/LoginCard.jsx @@ -1,16 +1,14 @@ import React, { useState, useEffect } from "react"; import { AiOutlineUser, AiOutlineCheck } from "react-icons/ai"; -import { Navigate, useNavigate } from "react-router-dom"; +import { useNavigate } from "react-router-dom"; import { motion } from "framer-motion"; -import axios from "axios"; import InputArea from "../InputArea"; import PwArea from "./PwArea"; import RememberPw from "./RememberPw"; import { onLogin } from "../../utils/adminCookie"; import { accounts } from "../../utils/data"; - -axios.defaults.baseURL = "http://127.0.0.1:8088"; +import adminRequest from "../../utils/adminRequest"; const LoginCard = () => { const navigate = useNavigate(); @@ -26,7 +24,7 @@ const LoginCard = () => { const getCode = (e) => { e.stopPropagation(); - axios + adminRequest .get("http://127.0.0.1:8088/passport/generate-code", { withCredentials: true, }) @@ -45,7 +43,7 @@ const LoginCard = () => { navigate("/admin"); onLogin(accounts.filter((item) => item.username === uname.value)); } - axios + adminRequest .post( "http://127.0.0.1:8088/passport/employeelogin", {}, @@ -62,8 +60,6 @@ const LoginCard = () => { console.log(res.data); if (res.data.success) { setLoginFail(false); - axios.defaults.headers.common["token"] = res.data.data.token; - // onLogin({ username: uname.value, priority: res.data.data.priority }); localStorage.setItem("username", uname.value); localStorage.setItem("priority", res.data.data.priority); localStorage.setItem("token", res.data.data.token); @@ -79,7 +75,7 @@ const LoginCard = () => { }; useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/passport/generate-code", { withCredentials: true, }) diff --git a/src/components/System/AuthManage/Auth.jsx b/src/components/System/AuthManage/Auth.jsx index 9e97d0e..bb87952 100644 --- a/src/components/System/AuthManage/Auth.jsx +++ b/src/components/System/AuthManage/Auth.jsx @@ -1,9 +1,9 @@ import React, { useState, useEffect } from "react"; -import axios from "axios"; import { Tabs, Table, Modal, Button, message } from "antd"; import { priority } from "../../../utils/data"; import AlterAuth from "./AlterAuth"; +import adminRequest from "../../../utils/adminRequest"; const { TabPane } = Tabs; @@ -46,7 +46,7 @@ const Auth = () => { const handleSubmit = (e) => { e.preventDefault(); - axios + adminRequest .post( "http://127.0.0.1:8088/admin/system/auth-manage/update", {}, @@ -69,7 +69,7 @@ const Auth = () => { }; useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/auth-manage/findAll") .then((res) => { if (res.data.code === 10000) { diff --git a/src/components/System/Customer/Custom.jsx b/src/components/System/Customer/Custom.jsx index e85977a..54f2c7f 100644 --- a/src/components/System/Customer/Custom.jsx +++ b/src/components/System/Customer/Custom.jsx @@ -1,11 +1,11 @@ import React, { useState, useEffect } from "react"; -import axios from "axios"; import { FiSearch } from "react-icons/fi"; import { Table, Modal, Button, message } from "antd"; import InputArea from "../../InputArea"; import { sex, status } from "../../../utils/data"; import EditCustomer from "./EditCustomer"; +import adminRequest from "../../../utils/adminRequest"; const Custom = () => { const [info, setInfo] = useState(""); @@ -62,7 +62,7 @@ const Custom = () => { }; const deleteHandleOk = () => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/custom-manage/delete", { params: { ic: curData.userIc }, }) @@ -98,7 +98,7 @@ const Custom = () => { const handleEditSubmit = (e) => { e.preventDefault(); const [name, username, password, , , phone] = document.forms[1]; - axios + adminRequest .post("http://127.0.0.1:8088/admin/system/custom-manage/update", { userIc: curData.userIc, userName: name.value, @@ -125,7 +125,7 @@ const Custom = () => { }; useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/custom-manage/queryAll") .then((res) => { if (res.data.code === 10000) { diff --git a/src/components/System/Employee/Employee.jsx b/src/components/System/Employee/Employee.jsx index 8ceec21..0d442dd 100644 --- a/src/components/System/Employee/Employee.jsx +++ b/src/components/System/Employee/Employee.jsx @@ -1,5 +1,4 @@ import React, { useState, useEffect } from "react"; -import axios from "axios"; import { FiSearch } from "react-icons/fi"; import { Table, Modal, Button, message } from "antd"; @@ -7,6 +6,7 @@ import InputArea from "../../InputArea"; import AddEmployee from "./AddEmployee"; import { sex, status, priority } from "../../../utils/data"; import EditEmployee from "./EditEmployee"; +import adminRequest from "../../../utils/adminRequest"; const Employee = () => { const [info, setInfo] = useState(""); @@ -67,7 +67,7 @@ const Employee = () => { }; const deleteHandleOk = () => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/employee-manage/delete", { params: { id: curData.employeeId }, }) @@ -114,7 +114,7 @@ const Employee = () => { const handleEditSubmit = (e) => { e.preventDefault(); const [name, username, password, ,] = document.forms[1]; - axios + adminRequest .post("http://127.0.0.1:8088/admin/system/employee-manage/update", { employeeId: curData.employeeId, employeeName: name.value, @@ -140,7 +140,7 @@ const Employee = () => { const handleAddSubmit = (e) => { e.preventDefault(); const [name, username, password] = document.forms[1]; - axios + adminRequest .post("http://127.0.0.1:8088/admin/system/employee-manage/add", { employeeName: name.value, employeeUsername: username.value, @@ -163,7 +163,7 @@ const Employee = () => { }; useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/employee-manage/findAll", { withCredentials: true, }) diff --git a/src/components/System/Order/Order.jsx b/src/components/System/Order/Order.jsx index 5763189..7a843d8 100644 --- a/src/components/System/Order/Order.jsx +++ b/src/components/System/Order/Order.jsx @@ -1,5 +1,4 @@ import React, { useState, useEffect } from "react"; -import axios from "axios"; import { Modal, Table, Button, message } from "antd"; import { FiSearch } from "react-icons/fi"; @@ -13,6 +12,7 @@ import Selector from "../../Selector"; import InputArea from "../../InputArea"; import EditOrder from "./EditOrder"; import AddOrder from "./AddOrder"; +import adminRequest from "../../../utils/adminRequest"; const Order = () => { const [cate, setCate] = useState(6); @@ -82,7 +82,7 @@ const Order = () => { }; const deleteHandleOk = () => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/order-manage/delete", { params: { id: curData.orderId }, }) @@ -151,7 +151,7 @@ const Order = () => { const handleEditSubmit = (e) => { e.preventDefault(); const [status, amount, price] = document.forms[1]; - axios + adminRequest .post("http://127.0.0.1:8088/admin/system/order-manage/update", { orderId: curData.orderId, orderStatus: status.value, @@ -177,7 +177,7 @@ const Order = () => { e.preventDefault(); if (isFormExchangeType) { const [owner, , buyer, seller, weight, price, amount] = document.forms[1]; - axios + adminRequest .post("http://127.0.0.1:8088/admin/system/order-manage/addOrder", { orderOwner: owner.value, orderBuyer: buyer.value, @@ -204,7 +204,7 @@ const Order = () => { .catch((err) => console.log(err)); } else { const [owner, , weight, price, amount] = document.forms[1]; - axios + adminRequest .post("http://127.0.0.1:8088/admin/system/order-manage/addOrder", { orderOwner: owner.value, orderWeight: weight.value, @@ -276,7 +276,7 @@ const Order = () => { //获取类别1 useEffect(() => { - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/categories" ) @@ -297,7 +297,7 @@ const Order = () => { useEffect(() => { let resObj = {}; for (let item of goodsCate1) { - axios + adminRequest .post( "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/names", {}, @@ -320,7 +320,7 @@ const Order = () => { //更新单据信息 useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/order-manage/queryAll") .then((res) => { setOrderData(res.data.data.orderList); diff --git a/src/components/System/Ware/Position.jsx b/src/components/System/Ware/Position.jsx index 68265f2..9b8ced6 100644 --- a/src/components/System/Ware/Position.jsx +++ b/src/components/System/Ware/Position.jsx @@ -1,13 +1,13 @@ -import React, { useState, useLayoutEffect, useRef } from "react"; +import React, { useState, useRef } from "react"; import { IoMdAdd } from "react-icons/io"; import { BsFillSquareFill } from "react-icons/bs"; import { Modal, Button, message } from "antd"; -import axios from "axios"; import PositionItem from "./PositionItem"; import PositionDetail from "./PositionDetail"; import AddPosition from "./AddPosition"; import emptyPosition from "../../../img/emptyPosition.png"; +import adminRequest from "../../../utils/adminRequest"; //仓位(下半部分 const Position = ({ repo, update }) => { @@ -48,7 +48,7 @@ const Position = ({ repo, update }) => { e.preventDefault(); const [positionNum] = document.forms[0]; console.log(positionNum.value, repo.repositoryId, formAddStatus); - axios + adminRequest .post("http://127.0.0.1:8088/admin/system/ware-manage/addPosition", { positionNum: positionNum.value, positionRepository: repo.repositoryId, @@ -69,7 +69,7 @@ const Position = ({ repo, update }) => { }; // useLayoutEffect(() => { - //axios get /admin/system/ware-manage/queryPosition + //adminRequest get /admin/system/ware-manage/queryPosition //params //id:id //then setPositionData @@ -78,7 +78,7 @@ const Position = ({ repo, update }) => { // firstUpdate.current = false; // return; // } - // axios + // adminRequest // .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") // .then((res) => { // // console.log( diff --git a/src/components/System/Ware/PositionDetail.jsx b/src/components/System/Ware/PositionDetail.jsx index b1a4c8b..a829fbe 100644 --- a/src/components/System/Ware/PositionDetail.jsx +++ b/src/components/System/Ware/PositionDetail.jsx @@ -1,10 +1,11 @@ import React, { useState } from "react"; -import axios from "axios"; import { AiOutlineEdit } from "react-icons/ai"; import { BsFillTrashFill } from "react-icons/bs"; import { GrClose } from "react-icons/gr"; import { Modal, message } from "antd"; +import adminRequest from "../../../utils/adminRequest"; + //仓位详情(下半部分右 const PositionDetail = ({ curPos, handleCloseDetail, update }) => { console.log(curPos); @@ -23,7 +24,7 @@ const PositionDetail = ({ curPos, handleCloseDetail, update }) => { }; const deleteHandleOk = () => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/ware-manage/deletePosition", { params: { id: curPos.positionId }, }) @@ -48,7 +49,7 @@ const PositionDetail = ({ curPos, handleCloseDetail, update }) => { }; const handleSubmit = () => { - axios + adminRequest .post( "http://127.0.0.1:8088/admin/system/ware-manage/updatePosition", {}, diff --git a/src/components/System/Ware/WareManage.jsx b/src/components/System/Ware/WareManage.jsx index c65c36d..3348b3a 100644 --- a/src/components/System/Ware/WareManage.jsx +++ b/src/components/System/Ware/WareManage.jsx @@ -1,10 +1,10 @@ import React, { useState, useEffect } from "react"; -import axios from "axios"; import { Table, Modal, Button, message } from "antd"; import Position from "./Position"; import AddRepo from "./AddRepo"; import EditRepo from "./EditRepo"; +import adminRequest from "../../../utils/adminRequest"; // 仓库管理 const WareManage = () => { @@ -70,7 +70,7 @@ const WareManage = () => { }; const deleteHandleOk = () => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/ware-manage/deleteRepository", { params: { id: curWare.repositoryId }, }) @@ -93,7 +93,7 @@ const WareManage = () => { const handleAddSubmit = (e) => { e.preventDefault(); const [name, position] = document.forms[0]; - axios + adminRequest .post("http://127.0.0.1:8088/admin/system/ware-manage/addRepository", { repositoryName: name.value, repositoryPosition: position.value, @@ -115,7 +115,7 @@ const WareManage = () => { const handleEditSubmit = (e) => { e.preventDefault(); const [name, position] = document.forms[0]; - axios + adminRequest .post( "http://127.0.0.1:8088/admin/system/ware-manage/updateRepository", {}, @@ -142,7 +142,7 @@ const WareManage = () => { }; useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") .then((res) => { if (res.data.code === 10000) { @@ -155,7 +155,7 @@ const WareManage = () => { }, [repoChange]); useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") .then((res) => { if (res.data.code === 10000) { diff --git a/src/components/WareClerk/GoodsIn.jsx b/src/components/WareClerk/GoodsIn.jsx index 97bf89d..e2c1868 100644 --- a/src/components/WareClerk/GoodsIn.jsx +++ b/src/components/WareClerk/GoodsIn.jsx @@ -1,10 +1,10 @@ import React, { useState, useEffect } from "react"; import { useLocation, useNavigate } from "react-router-dom"; import { Table, Modal, Button, message } from "antd"; -import axios from "axios"; import InputArea from "../InputArea"; import Selector from "../Selector"; +import adminRequest from "../../utils/adminRequest"; const editCSS = "pl-0 mt-1 w-20 rounded border-2 border-b-blue-200 outline-none focus:ring focus:ring-blue-300 focus:border-white duration-150 ease-in"; @@ -108,7 +108,7 @@ const GoodsIn = () => { const rightHandleCancel = () => {}; const goodsInSubmit = () => { - axios + adminRequest .post( "http://127.0.0.1:8088/admin/ware-clerk/tasks/goods-in/order", inventoryList @@ -195,7 +195,7 @@ const GoodsIn = () => { //所有仓库 useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") .then((res) => { if (res.data.code === 10000) { diff --git a/src/components/WareClerk/GoodsOut.jsx b/src/components/WareClerk/GoodsOut.jsx index d012db7..7106846 100644 --- a/src/components/WareClerk/GoodsOut.jsx +++ b/src/components/WareClerk/GoodsOut.jsx @@ -2,7 +2,7 @@ import React, { useState } from "react"; import { useLocation } from "react-router-dom"; import { Table, message } from "antd"; -import axios from "axios"; +import adminRequest from "../../utils/adminRequest"; const GoodsOut = () => { const location = useLocation(); @@ -13,7 +13,7 @@ const GoodsOut = () => { ); const goodsOutSubmit = () => { - axios + adminRequest .post( "http://127.0.0.1:8088/admin/ware-clerk/tasks/goods-out/order", {}, diff --git a/src/components/WareClerk/Tasks.jsx b/src/components/WareClerk/Tasks.jsx index 283f65e..afaf194 100644 --- a/src/components/WareClerk/Tasks.jsx +++ b/src/components/WareClerk/Tasks.jsx @@ -2,10 +2,10 @@ import React, { useState, useEffect } from "react"; import { Link } from "react-router-dom"; import { FiSearch } from "react-icons/fi"; import { Table, message } from "antd"; -import axios from "axios"; import Selector from "../Selector"; import { taskCategories } from "../../utils/data"; +import adminRequest from "../../utils/adminRequest"; const Tasks = () => { const [cate, setCate] = useState(6); @@ -24,7 +24,7 @@ const Tasks = () => { }; useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/ware-clerk/tasks/tasks") .then((res) => { if (res.data.code === 10000) { diff --git a/src/components/WareClerk/WareChange.jsx b/src/components/WareClerk/WareChange.jsx index 35f6fe8..4b37bbd 100644 --- a/src/components/WareClerk/WareChange.jsx +++ b/src/components/WareClerk/WareChange.jsx @@ -1,10 +1,10 @@ import React, { useState, useEffect } from "react"; -import axios from "axios"; import { FiSearch } from "react-icons/fi"; import { Modal, Table, Button, message } from "antd"; import InputArea from "../InputArea"; import Selector from "../Selector"; +import adminRequest from "../../utils/adminRequest"; const WareChange = () => { const [curData, setCurData] = useState(null); @@ -35,7 +35,7 @@ const WareChange = () => { const handleOk = () => { // console.log(curData, repoSelected, posSelected); setLoading(true); - axios + adminRequest .post("http://127.0.0.1:8088/ /admin/ware-clerk/ware-change/change", { ...curData, inventoryRepositoryNew: repoSelected, @@ -140,7 +140,7 @@ const WareChange = () => { //所有库存 useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/ware-manager/stock/findAll") .then((res) => { if (res.data.success) { @@ -158,7 +158,7 @@ const WareChange = () => { //所有仓库 useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") .then((res) => { if (res.data.code === 10000) { diff --git a/src/components/WareManager/Stock.jsx b/src/components/WareManager/Stock.jsx index d22c7a9..522b250 100644 --- a/src/components/WareManager/Stock.jsx +++ b/src/components/WareManager/Stock.jsx @@ -1,11 +1,11 @@ import React, { useState, useEffect } from "react"; -import axios from "axios"; import { FiSearch } from "react-icons/fi"; import { Table, DatePicker, Space, ConfigProvider, message } from "antd"; import locale from "antd/lib/locale/zh_CN"; import Selector from "../Selector"; import InputArea from "../InputArea"; +import adminRequest from "../../utils/adminRequest"; const Stock = () => { @@ -21,7 +21,7 @@ const Stock = () => { const [dataSource, setDataSource] = useState([]); useEffect(() => { - axios + adminRequest .get("http://127.0.0.1:8088/admin/ware-manager/stock/findAll") .then((res) => { if (res.data.success) { diff --git a/src/components/WareManager/WareQuery.jsx b/src/components/WareManager/WareQuery.jsx index 6487c06..745f6d9 100644 --- a/src/components/WareManager/WareQuery.jsx +++ b/src/components/WareManager/WareQuery.jsx @@ -2,11 +2,11 @@ import React, { useState, useEffect } from "react"; import { Tabs, Table, DatePicker, Space, ConfigProvider } from "antd"; import { FiSearch } from "react-icons/fi"; import locale from "antd/lib/locale/zh_CN"; -import axios from "axios"; import moment from "moment"; import Selector from "../Selector"; import { taskCategories } from "../../utils/data"; +import adminRequest from "../../utils/adminRequest"; const { TabPane } = Tabs; @@ -95,7 +95,7 @@ const WareQuery = () => { }; useEffect(() => { - axios.get("/admin/ware-manager/query").then((res) => { + adminRequest.get("/admin/ware-manager/query").then((res) => { setInOutWare(res.data.result.list); // setInOutWare(res.data.result.list.filter(item=>item.type===0||item.type===2)) setInOutSearchRes(res.data.result.list); diff --git a/src/utils/adminRequest.js b/src/utils/adminRequest.js new file mode 100644 index 0000000..4d96866 --- /dev/null +++ b/src/utils/adminRequest.js @@ -0,0 +1,12 @@ +import axios from "axios"; +axios.defaults.baseURL = "http://localhost:80"; + +const adminRequest = axios.create(); +adminRequest.interceptors.request.use((config) => { + if (localStorage.getItem("token")) { + config.headers.common["token"] = localStorage.getItem("token"); + } + return config; +}); + +export default adminRequest; -- Gitee From 36040c21a3fd01cf0c02afead0fcc9ae93e32f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E7=8E=89=E7=90=B3?= <1584592841@qq.com> Date: Wed, 20 Jul 2022 10:27:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=80=9F=E5=8A=A9token=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Header.jsx | 6 +- src/components/LoginReg/LoginCard.jsx | 6 +- src/components/System/AuthManage/Auth.jsx | 5 +- src/pages/Admin.jsx | 79 +++++++++++++---------- src/utils/adminRequest.js | 6 +- 5 files changed, 57 insertions(+), 45 deletions(-) diff --git a/src/components/Header.jsx b/src/components/Header.jsx index 7161843..5631437 100644 --- a/src/components/Header.jsx +++ b/src/components/Header.jsx @@ -7,9 +7,9 @@ const Header = ({ priority, username }) => { const [date, setDate] = useState(new Date()); const logout = () => { - localStorage.removeItem("username"); - localStorage.removeItem("priority"); - localStorage.removeItem("token"); + localStorage.removeItem("USER_NAME_KEY"); + localStorage.removeItem("PRIORITY_KEY"); + localStorage.removeItem("TOKEN_KEY"); window.location.href = "/"; }; diff --git a/src/components/LoginReg/LoginCard.jsx b/src/components/LoginReg/LoginCard.jsx index dee6f67..ddce35c 100644 --- a/src/components/LoginReg/LoginCard.jsx +++ b/src/components/LoginReg/LoginCard.jsx @@ -60,9 +60,9 @@ const LoginCard = () => { console.log(res.data); if (res.data.success) { setLoginFail(false); - localStorage.setItem("username", uname.value); - localStorage.setItem("priority", res.data.data.priority); - localStorage.setItem("token", res.data.data.token); + localStorage.setItem("USER_NAME_KEY", uname.value); + localStorage.setItem("PRIORITY_KEY", res.data.data.priority); + localStorage.setItem("TOKEN_KEY", res.data.data.token); navigate("/admin"); } else { setLoginFail(true); diff --git a/src/components/System/AuthManage/Auth.jsx b/src/components/System/AuthManage/Auth.jsx index bb87952..a33b51a 100644 --- a/src/components/System/AuthManage/Auth.jsx +++ b/src/components/System/AuthManage/Auth.jsx @@ -65,7 +65,10 @@ const Auth = () => { setLoading(false); } }) - .catch((err) => console.log(err)); + .catch((err) => { + console.log(err); + setLoading(false); + }); }; useEffect(() => { diff --git a/src/pages/Admin.jsx b/src/pages/Admin.jsx index ddd43e7..a0a5d21 100644 --- a/src/pages/Admin.jsx +++ b/src/pages/Admin.jsx @@ -1,5 +1,5 @@ import React from "react"; -import { Route, Routes } from "react-router-dom"; +import { Route, Routes, Navigate } from "react-router-dom"; import Header from "../components/Header"; import DashBoard from "../components/DashBoard"; import { @@ -35,41 +35,50 @@ const menuList = [ ]; const Admin = () => { - const username = localStorage.getItem("username"); - const localPriority = localStorage.getItem("priority"); - return ( -
- -
-
- - - } /> - } /> - } /> - } /> - } /> - - - } /> - } /> - } /> - - - } /> - } /> - } /> - } /> - - - } /> - } /> - } /> - - + const username = localStorage.getItem("USER_NAME_KEY"); + const localPriority = localStorage.getItem("PRIORITY_KEY"); + const token = localStorage.getItem("TOKEN_KEY"); + + if (token) { + return ( +
+ +
+
+ + + } /> + } /> + } /> + } /> + } /> + + + } /> + } /> + } /> + + + } /> + } /> + } /> + } /> + + + } /> + } /> + } /> + + +
-
- ); + ); + } else { + return ; + } }; export default Admin; diff --git a/src/utils/adminRequest.js b/src/utils/adminRequest.js index 4d96866..a0356e9 100644 --- a/src/utils/adminRequest.js +++ b/src/utils/adminRequest.js @@ -1,10 +1,10 @@ import axios from "axios"; -axios.defaults.baseURL = "http://localhost:80"; +axios.defaults.baseURL = "http://localhost:8088"; const adminRequest = axios.create(); adminRequest.interceptors.request.use((config) => { - if (localStorage.getItem("token")) { - config.headers.common["token"] = localStorage.getItem("token"); + if (localStorage.getItem("TOKEN_KEY")) { + config.headers.common["token"] = localStorage.getItem("TOKEN_KEY"); } return config; }); -- Gitee From 54af986e56885014bdcd8c72e9793f54ea5d639a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E7=8E=89=E7=90=B3?= <1584592841@qq.com> Date: Thu, 21 Jul 2022 00:37:27 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Accountant/WareIn.jsx | 65 +++--- src/components/Accountant/WareOut.jsx | 56 +++--- src/components/System/Ware/PositionDetail.jsx | 20 +- src/components/WareClerk/GoodsOut.jsx | 26 ++- src/components/WareManager/Analysis.jsx | 190 ++++++++++++++++-- src/components/WareManager/Stock.jsx | 9 +- src/components/WareManager/WareQuery.jsx | 162 ++++++++++----- src/utils/data.js | 8 + 8 files changed, 394 insertions(+), 142 deletions(-) diff --git a/src/components/Accountant/WareIn.jsx b/src/components/Accountant/WareIn.jsx index 556ae6d..9c9d0fa 100644 --- a/src/components/Accountant/WareIn.jsx +++ b/src/components/Accountant/WareIn.jsx @@ -14,14 +14,18 @@ const WareIn = () => { const navigate = useNavigate(); const orderInfo = location.state.record; + // console.log(orderInfo) const [productVOList, setProductVOList] = useState( location.state.record.orderdetailsList.map((item) => ({ ...item, + productID: item.productId, productType: "", })) ); + // console.log(productVOList) + const [amount, setAmount] = useState(orderInfo.orderAmount); const [orderWeight, setOrderWeight] = useState(orderInfo.orderWeight); const [fee, setFee] = useState(""); @@ -36,7 +40,7 @@ const WareIn = () => { e.preventDefault(); adminRequest .post( - "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/update", + "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/settlefee", { ...orderInfo, orderAmount: amount, @@ -46,22 +50,10 @@ const WareIn = () => { ) .then((res) => { if (res.data.code === 10000) { - message.success("信息录入成功"); - adminRequest - .post( - "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/settlefee", - {}, - { params: { order_id: orderInfo.orderId } } - ) - .then((res) => { - if (res.data.code === 10000) { - message.success("费用结算成功"); - setFee(res.data.data.fee); - setBlockSubmit(false); - } else { - message.error(res.data.message); - } - }); + message.success("费用结算成功"); + setFee(res.data.data.fee); + console.log(res.data); + setBlockSubmit(false); } else { message.error(res.data.message); } @@ -73,18 +65,33 @@ const WareIn = () => { setLoading(true); adminRequest .post( - "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/status", - {}, - { params: { order_id: orderInfo.orderId } } + "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/update", + { + ...orderInfo, + orderAmount: amount, + orderWeight: orderWeight, + productVOList: productVOList, + } ) .then((res) => { if (res.data.code === 10000) { - message.success("办理成功"); - setLoading(false); - navigate(-1) - } else { - message.error(res.data.message); - setLoading(false); + message.success("信息更新成功"); + adminRequest + .post( + "http://127.0.0.1:8088/admin/accountant/order-query/ware-in/status", + {}, + { params: { order_id: orderInfo.orderId } } + ) + .then((res) => { + if (res.data.code === 10000) { + message.success("办理成功"); + setLoading(false); + navigate(-1); + } else { + message.error(res.data.message); + setLoading(false); + } + }); } }) .catch((err) => { @@ -308,11 +315,7 @@ const WareIn = () => { > {"办理入库"} -
diff --git a/src/components/Accountant/WareOut.jsx b/src/components/Accountant/WareOut.jsx index ed6be2e..4b721cc 100644 --- a/src/components/Accountant/WareOut.jsx +++ b/src/components/Accountant/WareOut.jsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { useLocation } from "react-router-dom"; +import { useLocation, useNavigate } from "react-router-dom"; import { message, Button } from "antd"; import InputArea from "../InputArea"; @@ -12,6 +12,7 @@ const WareOut = () => { const location = useLocation(); const orderInfo = location.state.record; // console.log(orderInfo); + const navigate = useNavigate(); const [loading, setLoading] = useState(false); const [blockSubmit, setBlockSubmit] = useState(true); @@ -24,7 +25,7 @@ const WareOut = () => { e.preventDefault(); adminRequest .post( - "http://127.0.0.1:8088/admin/accountant/order-query/ware-out/update", + "http://127.0.0.1:8088/admin/accountant/order-query/ware-out/settlefee", { ...orderInfo, orderAmount: orderAmount, @@ -33,22 +34,9 @@ const WareOut = () => { ) .then((res) => { if (res.data.code === 10000) { - message.success("费用填写成功"); - adminRequest - .post( - "http://127.0.0.1:8088/admin/accountant/order-query/ware-out/settlefee", - {}, - { params: { order_id: orderInfo.orderId } } - ) - .then((res) => { - if (res.data.code === 10000) { - message.success("费用结算成功"); - setFee(res.data.data.fee); - setBlockSubmit(false); - } else { - message.error(res.data.message); - } - }); + message.success("费用结算成功"); + setFee(res.data.data.fee); + setBlockSubmit(false); } else { message.error(res.data.message); } @@ -60,17 +48,32 @@ const WareOut = () => { setLoading(true); adminRequest .post( - "http://127.0.0.1:8088/admin/accountant/order-query/ware-out/status", - {}, - { params: { order_id: orderInfo.orderId } } + "http://127.0.0.1:8088/admin/accountant/order-query/ware-out/update", + { + ...orderInfo, + orderAmount: orderAmount, + orderWeight: orderWeight, + } ) .then((res) => { if (res.data.code === 10000) { - message.success("办理成功"); - setLoading(false); - } else { - message.error(res.data.message); - setLoading(false); + message.success("信息更新成功"); + adminRequest + .post( + "http://127.0.0.1:8088/admin/accountant/order-query/ware-out/status", + {}, + { params: { order_id: orderInfo.orderId } } + ) + .then((res) => { + if (res.data.code === 10000) { + message.success("办理成功"); + setLoading(false); + navigate(-1); + } else { + message.error(res.data.message); + setLoading(false); + } + }); } }) .catch((err) => { @@ -78,7 +81,6 @@ const WareOut = () => { console.log(err); setLoading(false); }); - }; const resetHandler = () => { diff --git a/src/components/System/Ware/PositionDetail.jsx b/src/components/System/Ware/PositionDetail.jsx index a829fbe..c246867 100644 --- a/src/components/System/Ware/PositionDetail.jsx +++ b/src/components/System/Ware/PositionDetail.jsx @@ -8,7 +8,7 @@ import adminRequest from "../../../utils/adminRequest"; //仓位详情(下半部分右 const PositionDetail = ({ curPos, handleCloseDetail, update }) => { - console.log(curPos); + // console.log(curPos); const [status, setStatus] = useState(curPos.positionStatus); @@ -86,12 +86,20 @@ const PositionDetail = ({ curPos, handleCloseDetail, update }) => { 仓位

{curPos.productVOList && - curPos.productVOList.map((item) => ( + curPos.productVOList.map((item, index) => ( <> -

货物编号:{item.productId}

-

货物名称:{item.productName}

-

货物类型:{item.productType}

-

货物数量:{item.productNum}

+

+ {`货物${index + 1}编号:`} + {item.productID} +

+

+ {`货物${index + 1}名称:`} + {item.productName} +

+

+ {`货物${index + 1}数量:`} + {item.amount} +

))}

diff --git a/src/components/WareClerk/GoodsOut.jsx b/src/components/WareClerk/GoodsOut.jsx index 7106846..3f02aac 100644 --- a/src/components/WareClerk/GoodsOut.jsx +++ b/src/components/WareClerk/GoodsOut.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { useLocation } from "react-router-dom"; import { Table, message } from "antd"; @@ -6,18 +6,22 @@ import adminRequest from "../../utils/adminRequest"; const GoodsOut = () => { const location = useLocation(); - // console.log(location.state.record) + console.log(location.state.record); + const orderId = location.state.record.orderId; const [orderList, setOrderList] = useState( - location.state.record.orderdetailsList + // location.state.record.orderdetailsList + [] ); + console.log(orderId); + const goodsOutSubmit = () => { adminRequest .post( "http://127.0.0.1:8088/admin/ware-clerk/tasks/goods-out/order", {}, - { params: orderId } + { params: { order_id: orderId } } ) .then((res) => { if (res.data.code === 10000) { @@ -33,6 +37,18 @@ const GoodsOut = () => { }); }; + useEffect(() => { + adminRequest + .post( + "http://127.0.0.1:8088/admin/ware-clerk/tasks/getposition", + {}, + { params: { order_id: orderId } } + ) + .then((res) => { + console.log(res.data.data); + }); + }, []); + const goodsColumns = [ { title: "货品编号", @@ -48,7 +64,7 @@ const GoodsOut = () => { // }, { title: "出库件数", - dataIndex: "out", + dataIndex: "amount", }, { title: "仓库号", diff --git a/src/components/WareManager/Analysis.jsx b/src/components/WareManager/Analysis.jsx index df775d4..d50fb34 100644 --- a/src/components/WareManager/Analysis.jsx +++ b/src/components/WareManager/Analysis.jsx @@ -1,12 +1,108 @@ -import React, { useEffect, useRef } from "react"; +import React, { useState, useEffect, useRef } from "react"; +import { Tabs, message } from "antd"; import * as echarts from "echarts"; +import adminRequest from "../../utils/adminRequest"; + +const { TabPane } = Tabs; + const Analysis = () => { const inOutRef = useRef(null); const inOutRefBar = useRef(null); + const monthProRef = useRef(null); + const weekProRef = useRef(null); + + const [initial, setInitial] = useState(true); + const [repoList, setRepoList] = useState([]); + const [repoIdList, setRepoIdList] = useState([]); + const [repoPosNum, setRepoPosNum] = useState([]); + const [repoRateList, setRepoRateList] = useState([]); + + const [monthProfit, setMonthProfit] = useState([]); + const [weekProfit, setWeekProfit] = useState([]); + + const [rateFinished, setRateFinished] = useState(false); + + var temp = [], + chartInstance, + chartInstanceBar, + chartMonth, + chartWeek; + + const getRateList = async () => { + for (let j = 0, len = repoIdList.length; j < len; j++) { + let id = repoIdList[j]; + await adminRequest + .get( + `http://127.0.0.1:8088/admin/ware-manager/analysis/storage/rate/repository/${id}` + ) + .then((res) => { + if (res.status === 200) { + temp.push(((res.data / repoPosNum[j]) * 100).toFixed(2)); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); + } + if (temp !== []) { + setRepoRateList([...temp]); + setRateFinished((pre) => !pre); + } + }; useEffect(() => { - let chartInstance = echarts.init(inOutRef.current); + setRepoIdList([]); + setRepoRateList([]); + adminRequest + .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") + .then((res) => { + if (res.data.success) { + setRepoList(res.data.data.repositoryList); + setRepoIdList( + res.data.data.repositoryList.map((item) => item.repositoryId) + ); + setRepoPosNum( + res.data.data.repositoryList.map( + (item) => item.positionVOList.length + ) + ); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); + + adminRequest + .get("http://127.0.0.1:8088/admin/ware-manager/analysis/profit/month") + .then((res) => { + if (res.data.success) { + console.log(res.data.data["month profit"]); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); + + adminRequest + .get("http://127.0.0.1:8088/admin/ware-manager/analysis/profit/week") + .then((res) => { + if (res.data.success) { + console.log(res.data.data["week profit"]); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); + + if ( + chartInstance != null && + chartInstance != "" && + chartInstance != undefined + ) { + chartInstance.dispose(); //销毁 + } + chartInstance = echarts.init(inOutRef.current); const option = { tooltip: { trigger: "item", @@ -45,7 +141,62 @@ const Analysis = () => { }; chartInstance.setOption(option); - let chartInstanceBar = echarts.init(inOutRefBar.current); + if (chartMonth != null && chartMonth != "" && chartMonth != undefined) { + chartMonth.dispose(); //销毁 + } + chartMonth = echarts.init(monthProRef.current); + const optionMonth = { + toolbox: { + feature: { + saveAsImage: {}, + }, + }, + xAxis: { + type: "category", + data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], + }, + yAxis: { + type: "value", + }, + series: [ + { + data: [ + ["Mon", 820], + ["Tue", 932], + ["Wed", 901], + ["Thu", 934], + ["Fri", 1290], + ["Sat", 1330], + ["Sun", 1320], + ], + type: "line", + label: { + show: true, + position: "bottom", + }, + }, + ], + }; + chartMonth.setOption(optionMonth); + }, []); + + useEffect(() => { + getRateList(); + }, [repoIdList]); + + useEffect(() => { + if (initial) { + setInitial(false); + return; + } + if ( + chartInstanceBar != null && + chartInstanceBar != "" && + chartInstanceBar != undefined + ) { + chartInstanceBar.dispose(); //销毁 + } + chartInstanceBar = echarts.init(inOutRefBar.current); const optionBar = { tooltip: { trigger: "axis", @@ -61,11 +212,8 @@ const Analysis = () => { }, grid: { top: "15%", - left: "15%", - right: "10%", - bottom: "10%", }, xAxis: { @@ -76,7 +224,7 @@ const Analysis = () => { show: false, //不显示坐标轴线 }, type: "category", - data: ["01", "02", "03", "04", "05", "06", "07", "08"], + data: repoIdList, }, yAxis: { type: "value", @@ -91,28 +239,29 @@ const Analysis = () => { color: ["#5459BC"], series: [ { - data: [26, 20, 16, 42, 90, 40, 65, 50], + //比例 + data: repoRateList, type: "bar", barWidth: 20, itemStyle: { emphasis: { - barBorderRadius: 6, + borderRadius: 6, }, normal: { - barBorderRadius: 6, + borderRadius: 6, }, }, }, ], }; chartInstanceBar.setOption(optionBar); - }, []); + }, [rateFinished]); return (

-
- -
-

13:00~14:00

- {/* */} + +
+ + +
+
+ +
+
+
@@ -139,7 +296,6 @@ const Analysis = () => { -

13:00~14:00

{/* */}
diff --git a/src/components/WareManager/Stock.jsx b/src/components/WareManager/Stock.jsx index 522b250..46e92ca 100644 --- a/src/components/WareManager/Stock.jsx +++ b/src/components/WareManager/Stock.jsx @@ -8,11 +8,6 @@ import InputArea from "../InputArea"; import adminRequest from "../../utils/adminRequest"; const Stock = () => { - - const onChange = (date, dateString) => { - setTime(dateString); - }; - const [cate, setCate] = useState(-1); //-1是全部仓库 const [time, setTime] = useState(null); const [info, setInfo] = useState(null); @@ -20,6 +15,10 @@ const Stock = () => { const [searchRes, setSearchRes] = useState([]); const [dataSource, setDataSource] = useState([]); + const onChange = (date, dateString) => { + setTime(dateString); + }; + useEffect(() => { adminRequest .get("http://127.0.0.1:8088/admin/ware-manager/stock/findAll") diff --git a/src/components/WareManager/WareQuery.jsx b/src/components/WareManager/WareQuery.jsx index 745f6d9..fff8bff 100644 --- a/src/components/WareManager/WareQuery.jsx +++ b/src/components/WareManager/WareQuery.jsx @@ -1,18 +1,18 @@ import React, { useState, useEffect } from "react"; -import { Tabs, Table, DatePicker, Space, ConfigProvider } from "antd"; +import { Tabs, Table, DatePicker, Space, ConfigProvider, message } from "antd"; import { FiSearch } from "react-icons/fi"; import locale from "antd/lib/locale/zh_CN"; import moment from "moment"; import Selector from "../Selector"; -import { taskCategories } from "../../utils/data"; +import { flowCategories } from "../../utils/data"; import adminRequest from "../../utils/adminRequest"; const { TabPane } = Tabs; // 流水查询 const WareQuery = () => { - const [cate, setCate] = useState(6); + const [cate, setCate] = useState(3); //全部 const [inTime, setInTime] = useState(null); const [outTime, setOutTime] = useState(null); const [inTime2, setInTime2] = useState(null); @@ -33,136 +33,196 @@ const WareQuery = () => { if (+cate === 3) { setInOutSearchRes(inOutWare); } else { - setInOutSearchRes(inOutWare.filter((item) => item.type == cate)); + setInOutSearchRes(inOutWare.filter((item) => item.recordsType == cate)); } } else { if (+cate === 3) { - if (!inTime) { + if (!inTime && outTime) { setInOutSearchRes( - inOutWare.filter((item) => item.out.split(" ")[0] == outTime) + inOutWare.filter((item) => + item.outputTime + ? item.outputTime.split("T")[0] + : item.outputTime == outTime + ) ); - } else if (!outTime) { + } else if (!outTime && inTime) { setInOutSearchRes( - inOutWare.filter((item) => item.in.split(" ")[0] == inTime) + inOutWare.filter((item) => + item.importTime + ? item.importTime.split("T")[0] + : item.importTime == inTime + ) ); } else { setInOutSearchRes( - inOutWare.filter( - (item) => - item.in.split(" ")[0] == inTime && - item.out.split(" ")[0] == outTime + inOutWare.filter((item) => + item.importTime.split("T")[0] == inTime && item.outputTime + ? item.outputTime.split("T")[0] + : item.outputTime == outTime ) ); } } else { if (!inTime) { setInOutSearchRes( - inOutWare.filter( - (item) => item.type == cate && item.out.split(" ")[0] == outTime + inOutWare.filter((item) => + item.recordsType == cate && item.outputTime + ? item.outputTime.split("T")[0] + : item.outputTime == outTime ) ); } else if (!outTime) { setInOutSearchRes( - inOutWare.filter( - (item) => item.type == cate && item.in.split(" ")[0] == inTime + inOutWare.filter((item) => + item.recordsType == cate && item.importTime + ? item.importTime.split("T")[0] + : item.importTime == inTime ) ); } else { setInOutSearchRes( - inOutWare.filter( - (item) => - item.type == cate && - item.in.split(" ")[0] == inTime && - item.out.split(" ")[0] == outTime + inOutWare.filter((item) => + item.recordsType == cate && item.importTime + ? item.importTime.split("T")[0] + : item.importTime == inTime && item.outputTime + ? item.outputTime.split("T")[0] + : item.outputTime == outTime ) ); } } } - // console.log(cate, inTime, outTime); }; const changeWareSubmitHandler = (e) => { e.preventDefault(); if (!inTime2 && !outTime2) { setChangeWareSearchRes(changeWare); - } else if (!inTime2) { - setChangeWareSearchRes(changeWare.filter((item) => item.out == outTime2)); + } else if (!inTime2 && outTime2) { + setChangeWareSearchRes( + changeWare.filter((item) => + item.outputTime + ? item.outputTime.split("T")[0] + : item.outputTime == outTime2 + ) + ); + } else if (inTime2 && !outTime2) { + setChangeWareSearchRes( + changeWare.filter((item) => + item.importTime + ? item.importTime.split("T")[0] + : item.importTime == inTime2 + ) + ); } else { - setChangeWareSearchRes(changeWare.filter((item) => item.in == inTime2)); + setChangeWareSearchRes( + changeWare.filter( + (item) => + (item.importTime + ? item.importTime.split("T")[0] + : item.importTime == inTime2) && + (item.outputTime + ? item.outputTime.split("T")[0] + : item.outputTime == outTime2) + ) + ); } - // console.log(inTime2, outTime2); }; useEffect(() => { - adminRequest.get("/admin/ware-manager/query").then((res) => { - setInOutWare(res.data.result.list); - // setInOutWare(res.data.result.list.filter(item=>item.type===0||item.type===2)) - setInOutSearchRes(res.data.result.list); - }); + adminRequest + .get("http://127.0.0.1:8088/admin/manager/queryAll") + .then((res) => { + console.log(res); + if (res.data.success) { + // console.log(res.data.data.items); + setInOutWare( + res.data.data.items.filter((item) => item.recordsType !== null) + ); + setInOutSearchRes( + res.data.data.items.filter((item) => item.recordsType !== null) + ); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); + + adminRequest + .get("http://127.0.0.1:8088/admin/ware-manager/query/movement/repository") + .then((res) => { + if (res.data.success) { + // console.log(res.data.data.move); + setChangeWare(res.data.data.move); + setChangeWareSearchRes(res.data.data.move); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); }, []); const columns = [ { title: "类型", - dataIndex: "type", + dataIndex: "recordsType", render: (record) => record === 0 ? : , }, { title: "仓库号", - dataIndex: "repository", + dataIndex: "latRepository", }, { title: "仓位号", - dataIndex: "position", + dataIndex: "latPosition", }, { title: "货品名称", - dataIndex: "name", + dataIndex: "productName", }, { title: "入库时间", - dataIndex: "time", - render: (record) => record.split(" ")[0], + dataIndex: "importTime", + render: (record) => (record ? record.split("T")[0] : record), }, { title: "出库时间", - dataIndex: "time", - render: (record) => record.split(" ")[0], + dataIndex: "outputTime", + render: (record) => (record ? record.split("T")[0] : record), }, ]; const column = [ { title: "货品编号", - dataIndex: "product", + dataIndex: "productId", }, { title: "原仓库号", - dataIndex: "repository", + dataIndex: "preRepository", }, { title: "原仓位号", - dataIndex: "position", + dataIndex: "prePosition", }, { - title: "仓库号", - dataIndex: "repository", + title: "现仓库号", + dataIndex: "latRepository", }, { - title: "仓位号", - dataIndex: "position", + title: "现仓位号", + dataIndex: "latPosition", }, { title: "入库时间", - dataIndex: "time", - render: (record) => record.split(" ")[0], + dataIndex: "importTime", + render: (record) => (record ? record.split("T")[0] : record), }, { title: "出库时间", - dataIndex: "time", - render: (record) => record.split(" ")[0], + dataIndex: "outputTime", + render: (record) => (record ? record.split("T")[0] : record), }, ]; @@ -179,7 +239,7 @@ const WareQuery = () => { setCate(e.target.value)} - categories={taskCategories} + categories={flowCategories} /> diff --git a/src/utils/data.js b/src/utils/data.js index 64e90c5..10d5ab3 100644 --- a/src/utils/data.js +++ b/src/utils/data.js @@ -103,6 +103,14 @@ export const taskCategories = [ { id: 6, name: "全部" }, ]; +//流水查询类型 +export const flowCategories = [ + { id: 0, name: "入库" }, + { id: 1, name: "过户" }, + { id: 2, name: "出库" }, + { id: 3, name: "全部" }, +]; + export const statusCategories = [ { id: 0, name: "未支付" }, { id: 1, name: "已支付" }, -- Gitee From 6c4dbf3bf00002349b77fa83c514952af332126f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E7=8E=89=E7=90=B3?= <1584592841@qq.com> Date: Thu, 21 Jul 2022 03:07:11 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/System/Ware/Position.jsx | 30 +-- src/components/System/Ware/WareManage.jsx | 2 +- src/components/WareClerk/GoodsOut.jsx | 36 ++- src/components/WareManager/Analysis.jsx | 253 ++++++++++++++++------ 4 files changed, 212 insertions(+), 109 deletions(-) diff --git a/src/components/System/Ware/Position.jsx b/src/components/System/Ware/Position.jsx index 9b8ced6..95697c1 100644 --- a/src/components/System/Ware/Position.jsx +++ b/src/components/System/Ware/Position.jsx @@ -67,35 +67,7 @@ const Position = ({ repo, update }) => { }) .catch((err) => console.log(err)); }; - - // useLayoutEffect(() => { - //adminRequest get /admin/system/ware-manage/queryPosition - //params - //id:id - //then setPositionData - - // if(firstUpdate){ - // firstUpdate.current = false; - // return; - // } - // adminRequest - // .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") - // .then((res) => { - // // console.log( - // // res.data.data.repositoryList.filter( - // // (item) => item.repositoryId === positionData.repositoryId - // // )[0].positionVOList - // // ); - // setPositionData( - // (pre) => - // res.data.data.repositoryList.filter( - // (item) => item.repositoryId === pre.repositoryId - // )[0].positionVOList - // ); - // }) - // .catch((err) => console.log(err)); - // }, [isPositionUpdate]); - + return (
diff --git a/src/components/System/Ware/WareManage.jsx b/src/components/System/Ware/WareManage.jsx index 3348b3a..9f6703b 100644 --- a/src/components/System/Ware/WareManage.jsx +++ b/src/components/System/Ware/WareManage.jsx @@ -145,7 +145,7 @@ const WareManage = () => { adminRequest .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") .then((res) => { - if (res.data.code === 10000) { + if (res.data.success) { setWareData(res.data.data.repositoryList); } else { message.error(res.data.message); diff --git a/src/components/WareClerk/GoodsOut.jsx b/src/components/WareClerk/GoodsOut.jsx index 3f02aac..9be9ea3 100644 --- a/src/components/WareClerk/GoodsOut.jsx +++ b/src/components/WareClerk/GoodsOut.jsx @@ -1,12 +1,13 @@ import React, { useState, useEffect } from "react"; -import { useLocation } from "react-router-dom"; +import { useLocation,useNavigate } from "react-router-dom"; import { Table, message } from "antd"; import adminRequest from "../../utils/adminRequest"; const GoodsOut = () => { const location = useLocation(); - console.log(location.state.record); + // console.log(location.state.record); + const navigate = useNavigate(); const orderId = location.state.record.orderId; const [orderList, setOrderList] = useState( @@ -14,8 +15,6 @@ const GoodsOut = () => { [] ); - console.log(orderId); - const goodsOutSubmit = () => { adminRequest .post( @@ -27,6 +26,7 @@ const GoodsOut = () => { if (res.data.code === 10000) { message.success(res.data.message); //跳转 + navigate(-1); } else { message.error(res.data.message); } @@ -45,18 +45,32 @@ const GoodsOut = () => { { params: { order_id: orderId } } ) .then((res) => { - console.log(res.data.data); - }); + if (res.data.success) { + // console.log( + // res.data.data.items.filter( + // (item) => item.inventoryRepository !== null + // ) + // ); + setOrderList( + res.data.data.items.filter( + (item) => item.inventoryRepository !== null + ) + ); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); }, []); const goodsColumns = [ { title: "货品编号", - dataIndex: "productId", + dataIndex: "inventoryProduct", }, { title: "货品名称", - dataIndex: "productName", + dataIndex: "inventoryProductName", }, // { // title: "货品类型", @@ -64,15 +78,15 @@ const GoodsOut = () => { // }, { title: "出库件数", - dataIndex: "amount", + dataIndex: "inventoryNum", }, { title: "仓库号", - dataIndex: "in", + dataIndex: "inventoryRepository", }, { title: "仓位号", - dataIndex: "in", + dataIndex: "inventoryPosition", }, ]; diff --git a/src/components/WareManager/Analysis.jsx b/src/components/WareManager/Analysis.jsx index d50fb34..7c91d91 100644 --- a/src/components/WareManager/Analysis.jsx +++ b/src/components/WareManager/Analysis.jsx @@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from "react"; import { Tabs, message } from "antd"; import * as echarts from "echarts"; +import Selector from "../Selector"; import adminRequest from "../../utils/adminRequest"; const { TabPane } = Tabs; @@ -13,6 +14,7 @@ const Analysis = () => { const weekProRef = useRef(null); const [initial, setInitial] = useState(true); + const [inOutRate, setInOutRate] = useState(0); const [repoList, setRepoList] = useState([]); const [repoIdList, setRepoIdList] = useState([]); const [repoPosNum, setRepoPosNum] = useState([]); @@ -21,6 +23,10 @@ const Analysis = () => { const [monthProfit, setMonthProfit] = useState([]); const [weekProfit, setWeekProfit] = useState([]); + const [selectedRepo, setSelectedRepo] = useState(""); + const [curRepoList, setCurRepoList] = useState([]); + const [curRepoCategories, setCurRepoCategories] = useState([]); + const [rateFinished, setRateFinished] = useState(false); var temp = [], @@ -29,7 +35,9 @@ const Analysis = () => { chartMonth, chartWeek; + //利用率、周月利润 const getRateList = async () => { + //算利用率 for (let j = 0, len = repoIdList.length; j < len; j++) { let id = repoIdList[j]; await adminRequest @@ -45,6 +53,40 @@ const Analysis = () => { }) .catch((err) => console.log(err)); } + + //月利润 + await adminRequest + .get("http://127.0.0.1:8088/admin/ware-manager/analysis/profit/month") + .then((res) => { + if (res.data.success) { + let tempArr = []; + tempArr = res.data.data["month profit"].map((item, index) => { + return ([index] = [item["对应月"], item["利润"]]); + }); + setMonthProfit(tempArr); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); + + //周利润 + await adminRequest + .get("http://127.0.0.1:8088/admin/ware-manager/analysis/profit/week") + .then((res) => { + if (res.data.success) { + // console.log(res.data.data["week profit"]); + let tempArr = []; + tempArr = res.data.data["week profit"].map((item, index) => { + return ([index] = [item["对应周"], item["利润"]]); + }); + setWeekProfit(tempArr); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); + if (temp !== []) { setRepoRateList([...temp]); setRateFinished((pre) => !pre); @@ -52,8 +94,21 @@ const Analysis = () => { }; useEffect(() => { - setRepoIdList([]); - setRepoRateList([]); + //rate + adminRequest + .get("http://127.0.0.1:8088/admin/ware-manager/analysis/rate") + .then((res) => { + if (res.data.success) { + // console.log(res.data.data.rate); + //rate = 出库比入库 + setInOutRate(res.data.data.rate); + } else { + message.error(res.data.message); + } + }) + .catch((err) => console.log(err)); + + //仓库数据 adminRequest .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") .then((res) => { @@ -73,28 +128,36 @@ const Analysis = () => { }) .catch((err) => console.log(err)); + //仓库列表 adminRequest - .get("http://127.0.0.1:8088/admin/ware-manager/analysis/profit/month") + .get("http://127.0.0.1:8088/admin/system/ware-manage/queryAll") .then((res) => { if (res.data.success) { - console.log(res.data.data["month profit"]); + // console.log(res.data.data.repositoryList); + setCurRepoList(res.data.data.repositoryList); + setCurRepoCategories( + res.data.data.repositoryList.map((item) => ({ + id: item.repositoryId, + name: item.repositoryId, + })) + ); } else { message.error(res.data.message); } }) .catch((err) => console.log(err)); + }, []); - adminRequest - .get("http://127.0.0.1:8088/admin/ware-manager/analysis/profit/week") - .then((res) => { - if (res.data.success) { - console.log(res.data.data["week profit"]); - } else { - message.error(res.data.message); - } - }) - .catch((err) => console.log(err)); + useEffect(() => { + getRateList(); + }, [repoIdList]); + //其他两个图表 + useEffect(() => { + if (initial) { + setInitial(false); + return; + } if ( chartInstance != null && chartInstance != "" && @@ -106,6 +169,7 @@ const Analysis = () => { const option = { tooltip: { trigger: "item", + formatter: "{c}%", }, legend: { top: "5%", @@ -133,62 +197,15 @@ const Analysis = () => { show: false, }, data: [ - { value: 65, name: "入库" }, - { value: 35, name: "出库" }, + { value: 100 - (inOutRate * 100).toFixed(2), name: "入库" }, + { value: (inOutRate * 100).toFixed(2), name: "出库" }, ], }, ], }; chartInstance.setOption(option); - if (chartMonth != null && chartMonth != "" && chartMonth != undefined) { - chartMonth.dispose(); //销毁 - } - chartMonth = echarts.init(monthProRef.current); - const optionMonth = { - toolbox: { - feature: { - saveAsImage: {}, - }, - }, - xAxis: { - type: "category", - data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], - }, - yAxis: { - type: "value", - }, - series: [ - { - data: [ - ["Mon", 820], - ["Tue", 932], - ["Wed", 901], - ["Thu", 934], - ["Fri", 1290], - ["Sat", 1330], - ["Sun", 1320], - ], - type: "line", - label: { - show: true, - position: "bottom", - }, - }, - ], - }; - chartMonth.setOption(optionMonth); - }, []); - - useEffect(() => { - getRateList(); - }, [repoIdList]); - - useEffect(() => { - if (initial) { - setInitial(false); - return; - } + //仓库使用率 if ( chartInstanceBar != null && chartInstanceBar != "" && @@ -255,8 +272,77 @@ const Analysis = () => { ], }; chartInstanceBar.setOption(optionBar); + + //月利润 + if (chartMonth != null && chartMonth != "" && chartMonth != undefined) { + chartMonth.dispose(); //销毁 + } + chartMonth = echarts.init(monthProRef.current); + const optionMonth = { + xAxis: { + type: "category", + name: "月份", + }, + yAxis: { + type: "value", + name: "利润(元)", + }, + series: [ + { + data: monthProfit, + type: "line", + encode: { + x: "月份", + y: "利润", + }, + label: { + show: true, + position: "bottom", + }, + }, + ], + }; + chartMonth.setOption(optionMonth); }, [rateFinished]); + //周利润 + const onChangeTab = (key) => { + if (key === "2") { + setTimeout(() => { + if (chartWeek != null && chartWeek != "" && chartWeek != undefined) { + chartWeek.dispose(); //销毁 + } + chartWeek = echarts.init(weekProRef.current); + console.log(weekProfit); + const optionWeek = { + xAxis: { + type: "category", + name: "周数", + }, + yAxis: { + type: "value", + name: "利润(元)", + }, + series: [ + { + data: weekProfit, + type: "line", + encode: { + x: "周数", + y: "利润", + }, + label: { + show: true, + position: "bottom", + }, + }, + ], + }; + chartWeek.setOption(optionWeek); + }, 20); + } + }; + return (
@@ -265,8 +351,8 @@ const Analysis = () => { 出入库次数占比
-

13:00~14:00

-
+ {/*

13:00~14:00

*/} +
@@ -274,7 +360,7 @@ const Analysis = () => { 盈利报表
- +
@@ -296,7 +382,38 @@ const Analysis = () => { - {/* */} +
+ { + setSelectedRepo(+e.target.value); + }} + className={ + "w-20 pt-1 outline-none border-gray-300 border-2 rounded-lg font-medium" + } + categories={curRepoCategories} + /> + 选择仓库 +
+
+ {selectedRepo !== "" && ( + <> + {curRepoList + .filter((item) => item.repositoryId === selectedRepo)[0] + .positionVOList.map((item) => ( +
+ {/* {item.positionNum} */} +
+ ))} + + )} +
-- Gitee