Forráskód Böngészése

同步的dispatch使用store校验

shaogen1995 2 éve
szülő
commit
f66a1733e5

+ 3 - 5
houtai/src/App.tsx

@@ -7,8 +7,8 @@ import AuthRoute from "./components/AuthRoute";
 import SpinLoding from "./components/SpinLoding";
 import AsyncSpinLoding from "./components/AsyncSpinLoding";
 import { Image } from "antd";
-import { useDispatch, useSelector } from "react-redux";
-import { RootState } from "./store";
+import { useSelector } from "react-redux";
+import store, { RootState } from "./store";
 import UpAsyncLoding from "./components/UpAsyncLoding";
 import VideoLookDom from "./components/VideoLookDom";
 import MessageCom from "./components/Message";
@@ -16,8 +16,6 @@ const Layout = React.lazy(() => import("./pages/Layout"));
 const Login = React.lazy(() => import("./pages/Login"));
 
 export default function App() {
-  const dispatch = useDispatch();
-
   // 从仓库中获取查看图片的信息
   const lookBigImg = useSelector(
     (state: RootState) => state.loginStore.lookBigImg
@@ -46,7 +44,7 @@ export default function App() {
           src: lookBigImg.url,
           onVisibleChange: (value) => {
             // 清除仓库信息
-            dispatch({
+            store.dispatch({
               type: "login/lookBigImg",
               payload: { url: "", show: false },
             });

+ 3 - 5
houtai/src/components/ImageLazy/index.tsx

@@ -5,7 +5,7 @@ import { baseURL } from "@/utils/http";
 import imgLoding from "@/assets/img/loading.gif";
 import imgErr from "@/assets/img/IMGerror.png";
 import { EyeOutlined } from "@ant-design/icons";
-import { useDispatch } from "react-redux";
+import store from "@/store";
 
 type Props = {
   width?: number | string;
@@ -22,8 +22,6 @@ function ImageLazy({
   noLook,
   offline = false,
 }: Props) {
-  const dispatch = useDispatch();
-
   // 图片占位符
   const [placeholderUrl, setPlaceholderUrl] = useState(
     src ? imgLoding : imgErr
@@ -60,11 +58,11 @@ function ImageLazy({
 
   // 点击预览图片
   const lookBigImg = useCallback(() => {
-    dispatch({
+    store.dispatch({
       type: "login/lookBigImg",
       payload: { url: offline ? src : baseURL + src, show: true },
     });
-  }, [dispatch, offline, src]);
+  }, [offline, src]);
 
   return (
     <div className={styles.ImageLazy} style={{ width: width, height: height }}>

+ 4 - 6
houtai/src/components/UpAsyncLoding/index.tsx

@@ -1,11 +1,9 @@
-import { RootState } from "@/store";
+import store, { RootState } from "@/store";
 import { Button } from "antd";
 import React, { useCallback } from "react";
-import { useDispatch, useSelector } from "react-redux";
+import { useSelector } from "react-redux";
 import styles from "./index.module.scss";
 function UpAsyncLoding() {
-  const dispatch = useDispatch();
-
   // 从仓库中获取取消上传的函数
   const closeUpFile = useSelector(
     (state: RootState) => state.loginStore.closeUpFile
@@ -15,12 +13,12 @@ function UpAsyncLoding() {
     closeUpFile.fu();
 
     setTimeout(() => {
-      dispatch({
+      store.dispatch({
         type: "login/closeUpFile",
         payload: { fu: () => {}, state: false },
       });
     }, 200);
-  }, [closeUpFile, dispatch]);
+  }, [closeUpFile]);
 
   return (
     <div id="UpAsyncLoding" className={styles.UpAsyncLoding}>

+ 4 - 4
houtai/src/components/VideoLook/index.tsx

@@ -1,8 +1,8 @@
 import React from "react";
 import { PlayCircleOutlined } from "@ant-design/icons";
 import styles from "./index.module.scss";
-import { useDispatch } from "react-redux";
 import { baseURL } from "@/utils/http";
+import store from "@/store";
 
 type Props = {
   width?: number;
@@ -11,13 +11,13 @@ type Props = {
 };
 
 function VideoLook({ src, width = 100, height = 100 }: Props) {
-  const dispatch = useDispatch();
-
   return (
     <div className={styles.VideoLook} style={{ width, height }}>
       <div
         className="videoLookBox"
-        onClick={() => dispatch({ type: "login/lookVideo", payload: src })}
+        onClick={() =>
+          store.dispatch({ type: "login/lookVideo", payload: src })
+        }
       >
         <div className="videoCover">
           <video src={baseURL + src}></video>

+ 3 - 4
houtai/src/components/VideoLookDom/index.tsx

@@ -1,12 +1,11 @@
 import React from "react";
 import { CloseCircleOutlined } from "@ant-design/icons";
 import styles from "./index.module.scss";
-import { useDispatch, useSelector } from "react-redux";
-import { RootState } from "@/store";
+import { useSelector } from "react-redux";
+import store, { RootState } from "@/store";
 import { baseURL } from "@/utils/http";
 function VideoLookDom() {
   const videoSrc = useSelector((state: RootState) => state.loginStore.videoSrc);
-  const dispatch = useDispatch();
   return (
     <div
       className={styles.VideoLookDom}
@@ -20,7 +19,7 @@ function VideoLookDom() {
 
       <div
         className="close"
-        onClick={() => dispatch({ type: "login/lookVideo", payload: "" })}
+        onClick={() => store.dispatch({ type: "login/lookVideo", payload: "" })}
       >
         <CloseCircleOutlined />
       </div>

+ 4 - 6
houtai/src/pages/B2Goods/GoodsAdd/index.tsx

@@ -1,4 +1,4 @@
-import { RootState } from "@/store";
+import store, { RootState } from "@/store";
 import {
   Button,
   Checkbox,
@@ -16,7 +16,7 @@ import React, {
   useRef,
   useState,
 } from "react";
-import { useDispatch, useSelector } from "react-redux";
+import { useSelector } from "react-redux";
 import TextArea from "antd/es/input/TextArea";
 import styles from "./index.module.scss";
 import { MessageFu } from "@/utils/message";
@@ -50,8 +50,6 @@ const UpAsyncLodingDom: any = document.querySelector("#UpAsyncLoding");
 const progressDom: any = document.querySelector("#progress");
 
 function GoodsAdd({ id, closeMoalFu, addListFu, editListFu }: Props) {
-  const dispatch = useDispatch();
-
   // 后面添加的的知识驿站
   const [valueZS1, setValueZS1] = useState("");
   const [valueZS2, setValueZS2] = useState<any>([]);
@@ -756,9 +754,9 @@ function GoodsAdd({ id, closeMoalFu, addListFu, editListFu }: Props) {
                   className="clearCover"
                   hidden={!fileList.video.filePath}
                   onClick={() =>
-                    dispatch({
+                    store.dispatch({
                       type: "login/lookVideo",
-                      payload: fileList.video.filePath,
+                      payload: fileList.video.filePath!,
                     })
                   }
                 >

+ 4 - 4
houtai/src/pages/B6Smart/SmartHotTable/index.tsx

@@ -8,7 +8,7 @@ import React, {
 } from "react";
 import styles from "./index.module.scss";
 import { useDispatch, useSelector } from "react-redux";
-import { RootState } from "@/store";
+import store, { RootState } from "@/store";
 import classNames from "classnames";
 import {
   smartGetListAPI,
@@ -46,7 +46,7 @@ function SmartHotTable() {
           { id: Date.now(), type: "edit", name: "" },
           ...results,
         ];
-        dispatch({ type: "smart/getHotList", payload: newList });
+       store.dispatch({ type: "smart/getHotList", payload: newList });
       } else {
         const newList = [...results];
         newList.forEach((v) => {
@@ -55,10 +55,10 @@ function SmartHotTable() {
             v.type = "edit";
           }
         });
-        dispatch({ type: "smart/getHotList", payload: newList });
+        store.dispatch({ type: "smart/getHotList", payload: newList });
       }
     },
-    [dispatch, results]
+    [results]
   );
 
   // 点击删除

+ 2 - 2
houtai/src/pages/B6Smart/index.tsx

@@ -22,7 +22,7 @@ import styles from "./index.module.scss";
 import { DndProvider, useDrag, useDrop } from "react-dnd";
 import { HTML5Backend } from "react-dnd-html5-backend";
 import { useDispatch, useSelector } from "react-redux";
-import { RootState } from "@/store";
+import store, { RootState } from "@/store";
 import SmartAutoAdd from "./SmartAutoAdd";
 import { SmartTableType } from "@/types";
 import SmartHotTable from "./SmartHotTable";
@@ -236,7 +236,7 @@ function Smart() {
 
   const addTableFu = useCallback(() => {
     // 先把仓库表格的数据清空,在发请求重新拿数据,让表格滚动到顶部
-    dispatch({ type: "smart/getAutoList", payload: [] });
+    store.dispatch({ type: "smart/getAutoList", payload: [] });
     dispatch(smartGetListAPI("play"));
   }, [dispatch]);
 

+ 32 - 35
houtai/src/pages/Login/index.tsx

@@ -8,16 +8,14 @@ import encodeStr from "@/utils/pass";
 import { userLoginAPI } from "@/store/action/login";
 import { setTokenInfo } from "@/utils/storage";
 import history from "@/utils/history";
-import { useDispatch } from "react-redux";
 import { MessageFu } from "@/utils/message";
+import store from "@/store";
 
 export default function Login() {
-  const dispatch = useDispatch();
-
   // 进登录页面把权限的信息初始化,防止登录成功之后进到首页,数据渲染问题
   useEffect(() => {
-    dispatch({ type: "login/setAuthPageArr", payload: [] });
-  }, [dispatch]);
+    store.dispatch({ type: "login/setAuthPageArr", payload: [] });
+  }, []);
 
   // 账号密码
   const [userName, setUserName] = useState("");
@@ -48,38 +46,37 @@ export default function Login() {
   return (
     <div className={styles.Login}>
       <div className="main">
-
-          <div className="logo"></div>
-          {/* 账号密码输入框 */}
-          <div className="inputBox">
-            <div className="inputBoxRow">
-              <Input
-                onKeyUp={(e) => keyUpEntFu(e)}
-                value={userName}
-                onChange={(e) => setUserName(e.target.value.trim())}
-                prefix={<UserOutlined />}
-                placeholder="请输入用户名"
-                maxLength={15}
-              />
-            </div>
-            <div className="inputBoxRow">
-              <Input.Password
-                onKeyUp={(e) => keyUpEntFu(e)}
-                value={passWord}
-                onChange={(e) => setPassWord(e.target.value.trim())}
-                prefix={<LockOutlined />}
-                placeholder="请输入用户密码"
-                maxLength={15}
-              />
-            </div>
+        <div className="logo"></div>
+        {/* 账号密码输入框 */}
+        <div className="inputBox">
+          <div className="inputBoxRow">
+            <Input
+              onKeyUp={(e) => keyUpEntFu(e)}
+              value={userName}
+              onChange={(e) => setUserName(e.target.value.trim())}
+              prefix={<UserOutlined />}
+              placeholder="请输入用户名"
+              maxLength={15}
+            />
           </div>
-
-          {/* 登录按钮 */}
-          <div className="loginBtn">
-            <Button type="primary" size="large" onClick={loginClickFu}>
-              登 录
-            </Button>
+          <div className="inputBoxRow">
+            <Input.Password
+              onKeyUp={(e) => keyUpEntFu(e)}
+              value={passWord}
+              onChange={(e) => setPassWord(e.target.value.trim())}
+              prefix={<LockOutlined />}
+              placeholder="请输入用户密码"
+              maxLength={15}
+            />
           </div>
+        </div>
+
+        {/* 登录按钮 */}
+        <div className="loginBtn">
+          <Button type="primary" size="large" onClick={loginClickFu}>
+            登 录
+          </Button>
+        </div>
       </div>
     </div>
   );

+ 1 - 0
houtai/src/utils/domShow.ts

@@ -0,0 +1 @@
+export const a = () => {};