张涛 1 год назад
Родитель
Сommit
60446c3727
5 измененных файлов: 41 добавлений и 54 удалений
  1. 1
    1
      public/config.js
  2. 18
    6
      src/pages/login/LoginForm.jsx
  3. 8
    28
      src/pages/login/index.jsx
  4. 12
    13
      src/utils/request.js
  5. 2
    6
      vite.config.js

+ 1
- 1
public/config.js Просмотреть файл

@@ -1,5 +1,5 @@
1 1
 
2
-var SERVER_BASE = 'http://crm.njyunzhi.com';
2
+var SERVER_BASE = 'http://api.crm.njyunzhi.com';
3 3
 
4 4
 // 获取真实的上传文件地址
5 5
 function getRealPath(path) {

+ 18
- 6
src/pages/login/LoginForm.jsx Просмотреть файл

@@ -7,14 +7,13 @@ export default (props) => {
7 7
   const { onSuccess, mode, appid } = props;
8 8
   const [form] = Form.useForm();
9 9
   const [loading, setLoading] = React.useState(false);
10
+  console.log(process.env.NODE_ENV);
10 11
   const onFinish = (values) => {
11
-
12 12
     setLoading(true);
13 13
     login(values)
14 14
       .then((res) => {
15 15
         setLoading(true);
16
-        // console.log('res.user', res.user)
17
-        onSuccess(res)
16
+        onSuccess(res.user);
18 17
         setLoading(false);
19 18
       })
20 19
       .catch((err) => {
@@ -25,11 +24,24 @@ export default (props) => {
25 24
     setLoading(false);
26 25
   };
27 26
   return (
28
-    <Form form={form} layout="vertical" onFinish={onFinish} style={{ width: '260px', marginTop: '24px', paddingBottom: '24px' }}>
29
-      <Form.Item label="账户" name="account" rules={[{ required: true, message: '请输入账户' }]}>
27
+    <Form
28
+      form={form}
29
+      layout="vertical"
30
+      onFinish={onFinish}
31
+      style={{ width: "260px", marginTop: "24px", paddingBottom: "24px" }}
32
+    >
33
+      <Form.Item
34
+        label="账户"
35
+        name="account"
36
+        rules={[{ required: true, message: "请输入账户" }]}
37
+      >
30 38
         <Input placeholder="请输入账户" style={{ borderRadius: "4px" }} />
31 39
       </Form.Item>
32
-      <Form.Item label="密 码" name="password" rules={[{ required: true, message: '请输入密码' }]}>
40
+      <Form.Item
41
+        label="密 码"
42
+        name="password"
43
+        rules={[{ required: true, message: "请输入密码" }]}
44
+      >
33 45
         <Input.Password
34 46
           placeholder="请输入密码"
35 47
           style={{ borderRadius: "4px" }}

+ 8
- 28
src/pages/login/index.jsx Просмотреть файл

@@ -1,5 +1,5 @@
1 1
 import React, { useEffect } from "react";
2
-import { Button } from "antd";
2
+import { Button, message } from "antd";
3 3
 import { Helmet } from "react-helmet";
4 4
 import { useNavigate, useSearchParams } from "react-router-dom";
5 5
 import { useModel } from "@/store";
@@ -20,31 +20,13 @@ export default (props) => {
20 20
 
21 21
   const onChangeType = () => {
22 22
     setLoginType(loginType == 0 ? 1 : 0);
23
-  }
24
-
25
-
26
-  const onSuccess = ({ ticket }) => {
23
+  };
27 24
 
28
-    // console.log('ticket', ticket);
29
-    if (searchParams.get("redirect")) {
30
-      // console.log('爱', searchParams.get("redirect"));
31
-      const redirect = decodeURIComponent(searchParams.get("redirect"));
32
-      let href = "";
33
-      if (redirect.indexOf("#") === -1) {
34
-        href = redirect + `#/?ticket=${ticket}`;
35
-      } else if (redirect.indexOf("?") > -1) {
36
-        href = redirect + `ticket=${ticket}`;
37
-      } else {
38
-        href = redirect + `?ticket=${ticket}`;
39
-      }
40
-      window.location.href = href;
41
-    } else if (searchParams.get("back")) {
42
-      // console.log('else if', searchParams.get("back"));
43
-      navigate(-1);
44
-      // navigate("/");
45
-    } else {
46
-      console.log('else');
47
-      navigate("/");
25
+  const onSuccess = (row) => {
26
+    try {
27
+      navigate("/custom");
28
+    } catch (e) {
29
+      message.error(e);
48 30
     }
49 31
   };
50 32
 
@@ -68,9 +50,7 @@ export default (props) => {
68 50
                 <h2>
69 51
                   <span>密码登录</span>
70 52
                 </h2>
71
-                <LoginForm
72
-                  onSuccess={onSuccess}
73
-                />
53
+                <LoginForm onSuccess={onSuccess} />
74 54
               </div>
75 55
             </div>
76 56
           </div>

+ 12
- 13
src/utils/request.js Просмотреть файл

@@ -4,9 +4,9 @@ import { message } from "antd";
4 4
 import { getToken, setToken } from "./token";
5 5
 
6 6
 const instance = axios.create({
7
-  baseURL: SERVER_BASE,
7
+  baseURL: process.env.NODE_ENV == "development" ? "" : SERVER_BASE,
8 8
   timeout: 10000,
9
-  withCredentials: true, // 跨域
9
+  // withCredentials: true, // 跨域
10 10
 });
11 11
 
12 12
 // 添加请求拦截器
@@ -21,7 +21,7 @@ instance.interceptors.request.use(
21 21
       params = {},
22 22
     } = config;
23 23
     let token = localStorage.getItem("token") || "";
24
-    const tokenB = (`Bearer ${token}`);
24
+    const tokenB = `Bearer ${token}`;
25 25
     // console.log('----tokenB---->', tokenB);
26 26
 
27 27
     let noTip = silent;
@@ -29,13 +29,12 @@ instance.interceptors.request.use(
29 29
       noTip = method.toLocaleLowerCase() === "get" ? true : false;
30 30
     }
31 31
 
32
-    const ticketOrigin = localStorage.getItem('ticket');
32
+    const ticketOrigin = localStorage.getItem("ticket");
33 33
     if (params.ticket && params.ticket != ticketOrigin) {
34
-      token = '';
35
-      localStorage.setItem('ticket', params.ticket);
34
+      token = "";
35
+      localStorage.setItem("ticket", params.ticket);
36 36
     } else {
37
-      params.ticket = undefined,
38
-        params.appid = undefined;
37
+      (params.ticket = undefined), (params.appid = undefined);
39 38
     }
40 39
 
41 40
     // 在发送请求之前做些什么
@@ -104,7 +103,7 @@ instance.interceptors.response.use(
104 103
 
105 104
 export default instance;
106 105
 
107
-export function queryTable (apiRequest) {
106
+export function queryTable(apiRequest) {
108 107
   return function (params) {
109 108
     const { pageSize } = params;
110 109
     return apiRequest({
@@ -127,7 +126,7 @@ export function queryTable (apiRequest) {
127 126
   };
128 127
 }
129 128
 
130
-export function queryDict (
129
+export function queryDict(
131 130
   apiRequest,
132 131
   { labelKey = "name", valueKey = "id" } = {}
133 132
 ) {
@@ -152,7 +151,7 @@ export function queryDict (
152 151
       });
153 152
   };
154 153
 }
155
-export function restful (url) {
154
+export function restful(url) {
156 155
   const list = (params) => instance.get(url, { params });
157 156
   const get = (id) => instance.get(`${url}/${id}`);
158 157
   const add = (data) => instance.post(url, data);
@@ -162,7 +161,7 @@ export function restful (url) {
162 161
   return [list, get, add, update, del];
163 162
 }
164 163
 
165
-export function useRequest (fn) {
164
+export function useRequest(fn) {
166 165
   const [loading, setLoading] = React.useState(false);
167 166
 
168 167
   const p = (...args) =>
@@ -182,7 +181,7 @@ export function useRequest (fn) {
182 181
   return [loading, p];
183 182
 }
184 183
 
185
-function downloadBlob (response) {
184
+function downloadBlob(response) {
186 185
   let fileName = "未知文件";
187 186
   const contentType = response.headers["content-type"];
188 187
   const contentDisposition = response.headers["content-disposition"];

+ 2
- 6
vite.config.js Просмотреть файл

@@ -11,14 +11,10 @@ export default defineConfig({
11 11
     host: "0.0.0.0",
12 12
     proxy: {
13 13
       '/api': {
14
-        target: 'http://192.168.89.25:8090',
14
+        target: 'http://127.0.0.1:8090',
15 15
         changeOrigin: true,
16
-        rewrite: (path) => path.replace(/^\/api/, '/')
17
-        // onProxyReq: function (request) {
18
-        //   request.setHeader("origin", "http://192.168.89.25:9999")
19
-        // }
20 16
       },
21
-      // '/': 'http://192.168.89.25:9999',
17
+      // '/': 'http://192.168.89.25:8090',
22 18
     },
23 19
   },
24 20
   plugins: [