瀏覽代碼

新增登陆的页面

JXDS18FUJT 2 年之前
父節點
當前提交
8ef769d849
共有 5 個文件被更改,包括 152 次插入85 次删除
  1. 43 0
      package-lock.json
  2. 2 1
      package.json
  3. 13 80
      src/utils/api.js
  4. 73 0
      src/utils/request.js
  5. 21 4
      src/views/login/login.js

+ 43 - 0
package-lock.json

@@ -381,6 +381,28 @@
       "resolved": "https://registry.npmmirror.com/aws4/-/aws4-1.12.0.tgz",
       "integrity": "sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg=="
     },
+    "axios": {
+      "version": "1.3.2",
+      "resolved": "https://registry.npmmirror.com/axios/-/axios-1.3.2.tgz",
+      "integrity": "sha512-1M3O703bYqYuPhbHeya5bnhpYVsDDRyQSabNja04mZtboLNSuZ4YrltestrLXfHgmzua4TpUqRiVKbiQuo2epw==",
+      "requires": {
+        "follow-redirects": "^1.15.0",
+        "form-data": "^4.0.0",
+        "proxy-from-env": "^1.1.0"
+      },
+      "dependencies": {
+        "form-data": {
+          "version": "4.0.0",
+          "resolved": "https://registry.npmmirror.com/form-data/-/form-data-4.0.0.tgz",
+          "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
+          "requires": {
+            "asynckit": "^0.4.0",
+            "combined-stream": "^1.0.8",
+            "mime-types": "^2.1.12"
+          }
+        }
+      }
+    },
     "axobject-query": {
       "version": "0.1.0",
       "resolved": "https://registry.npmmirror.com/axobject-query/-/axobject-query-0.1.0.tgz",
@@ -1293,6 +1315,15 @@
       "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
       "optional": true
     },
+    "bindings": {
+      "version": "1.5.0",
+      "resolved": "https://registry.npmmirror.com/bindings/-/bindings-1.5.0.tgz",
+      "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
+      "optional": true,
+      "requires": {
+        "file-uri-to-path": "1.0.0"
+      }
+    },
     "bluebird": {
       "version": "3.7.2",
       "resolved": "https://registry.npmmirror.com/bluebird/-/bluebird-3.7.2.tgz",
@@ -3731,6 +3762,12 @@
         "schema-utils": "^0.3.0"
       }
     },
+    "file-uri-to-path": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmmirror.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
+      "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
+      "optional": true
+    },
     "filename-regex": {
       "version": "2.0.1",
       "resolved": "https://registry.npmmirror.com/filename-regex/-/filename-regex-2.0.1.tgz",
@@ -8792,6 +8829,11 @@
         "ipaddr.js": "1.9.1"
       }
     },
+    "proxy-from-env": {
+      "version": "1.1.0",
+      "resolved": "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
+      "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
+    },
     "prr": {
       "version": "1.0.1",
       "resolved": "https://registry.npmmirror.com/prr/-/prr-1.0.1.tgz",
@@ -11208,6 +11250,7 @@
           "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==",
           "optional": true,
           "requires": {
+            "bindings": "^1.5.0",
             "nan": "^2.12.1"
           }
         },

+ 2 - 1
package.json

@@ -4,6 +4,7 @@
   "private": true,
   "dependencies": {
     "autoprefixer": "7.1.6",
+    "axios": "^1.3.2",
     "babel-core": "6.26.0",
     "babel-eslint": "7.2.3",
     "babel-jest": "20.0.3",
@@ -50,7 +51,7 @@
   },
   "homepage": ".",
   "scripts": {
-    "dev": "cross-env port=443 host=nbjk-h5.zzxcx.net https=true node scripts/start.js",
+    "dev": "node scripts/start.js",
     "build": "node scripts/build.js",
     "build:dev": "node scripts/build.dev.js",
     "test": "node scripts/test.js --env=jsdom"

+ 13 - 80
src/utils/api.js

@@ -1,87 +1,20 @@
 /**
  * api by wuwc on 2017-12-25.
  */
-import 'whatwg-fetch';
-import Promise from 'promise-polyfill';
+import request  from "./request";
+const api = {
+    loginGzhcode:(data)=>{
+        return  request({
+            url:"login/gzhcode",
+            headers: {
+                isToken: "0",
+            },
+            method: 'post',
+            data
+        })
 
-export default class Api {
 
-    /* 环境以及api前缀 */
-    apiPrefix = "";
-
-    /* headers */
-    headers = {
-        'Content-Type': 'application/json',
-        'Token': 'wuwangcheng',
-        'CompanyId': '123456789'
-    };
-
-    /* api */
-    urls = {
-        getSongs: '/getSongs',
-        getSongSheets: '/getSongSheets',
-        getPlayInfo: '/getPlayInfo'
-    };
-
-    constructor() {
-        //设置base地址
-        this.apiPrefix = process.env.NODE_ENV !== 'production' ? '/api' : 'http://www.i728.top/pages/11/api';
-
-        //拼接url
-        for (let key in this.urls) {
-            this.urls[key] = process.env.NODE_ENV !== 'production' ? this.apiPrefix + this.urls[key] : this.apiPrefix + this.urls[key] + '.json';
-        }
-
-    }
-
-    /* 参数合并 */
-    args(parameter) {
-        const DEFAULT = {
-            "a": "1",
-            "b": "2",
-            "c": "3"
-        };
-        return JSON.stringify({...DEFAULT, ...parameter});
-    }
-
-
-    /* 统一处理 */
-    _g(promise) {
-        return promise.then((res) => {
-            switch (res.state) {
-                case "200":
-                    return res;
-                case "500":
-                    console.log("500处理");
-                    break;
-                case "1000":
-                    console.log("1000处理");
-                    break;
-                default:
-                    console.log(res.msg);
-                    break;
-            }
-        });
-    }
-
-    /* 错误处理函数 */
-    handleError(error) {
-        console.error('An error occurred', error);
-        return Promise.reject(error.message || error);
     }
 
-    /* 请求函数 */
-    ajax(url, type = "GET", args = {}) {
-        const body = this.args(args);
-        const params = {method: type, headers: this.headers};
-        if (type !== "GET") params.body = body;
-        return fetch(url, params).then((res) => this._g(res.json())).catch(this.handleError);
-    }
-
-
-    /* 所有接口 */
-    getSongs = () => this.ajax(this.urls.getSongs);
-    getSongSheets = () => this.ajax(this.urls.getSongSheets);
-    getPlayInfo = (songId) => this.ajax(this.urls.getPlayInfo, "POST", {"songId": songId});
-
-}
+}
+export default api

+ 73 - 0
src/utils/request.js

@@ -0,0 +1,73 @@
+import axios from "axios";
+const request = axios.create({
+	baseURL: process.env.NODE_ENV  === "production" ? "https://nbjk.zzxcx.net/nbjk-admin" : "https://nbjk1.zzxcx.net/nbjk-admin",
+	//"/prod-api" : "/dev-api"
+});
+request.interceptors.request.use(config => {
+	const token = window.localStorage.getItem("token") || ""
+	if (config.headers.isToken === "0") {
+		config.headers["Authorization"] = ""
+	}
+
+	else {
+		config.headers["Authorization"] = token?"Bearer " + token:"";
+                                                                              
+	}
+	// 让每个请求携带自定义token 请根据实际情况自行修改
+	// config.headers["Authorization"]="Bearer " +token;
+
+	return config;
+
+})
+request.interceptors.response.use((res) => {
+	// if (res && res.data) {
+
+	// 	switch (res.data.code) {
+	// 		case 200:
+	// 			break;
+	// 		case 401:
+	// 			// Toast("登录失败,需要再次登录")
+	// 			window.setTimeout(() => {
+
+	// 				switch (import.meta.env.MODE) {
+	// 					case "development":
+	// 						location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3043c2c1decb01ed&redirect_uri=https://sdjk-h5.zzxcx.net/&response_type=code&scope=snsapi_userinfo&state=LOGIN#wechat_redirect`)
+	// 						break;
+	// 					case "test":
+	// 						location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3043c2c1decb01ed&redirect_uri=https://sdjk-h51.zzxcx.net/&response_type=code&scope=snsapi_userinfo&state=LOGIN#wechat_redirect`)
+	// 						break;
+	// 					case "production":
+	// 						location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3043c2c1decb01ed&redirect_uri=https://sdjk-h5.zzxcx.net/&response_type=code&scope=snsapi_userinfo&state=LOGIN#wechat_redirect`);
+	// 						break;
+	// 				}
+	// 			}, 2000)
+				
+	// 			break;
+	// 		case 502:
+	// 			console.log('进入502')
+	// 			if (res.data.msg == "微信授权无效,请重新授权") {
+	// 				location.replace("https://coach.zzxcx.net/")
+	// 				return
+	// 			}
+			
+	// 			Toast.fail(res.data.msg)
+				
+
+	// 			break;
+	// 		default:
+	// 			Toast.fail(res.data.msg)
+				
+	// 			break;
+	// 	}
+	// }
+
+	// console.log(res)
+
+	return res;
+},(error=>{
+	
+}));
+
+export default request;
+
+

+ 21 - 4
src/views/login/login.js

@@ -1,7 +1,7 @@
 import React, { Component } from 'react';
 import { connect } from "react-redux";
 import './login.css'
-
+import api from './../../utils/api'
 const mapStateToProps = (state) => ({
   
 });
@@ -18,9 +18,23 @@ class LoginViews extends Component {
     constructor() {
         super();
         this.state = {
+            code:""
 
         };
     }
+    bindCode(e){
+
+        this.setState({code:e.target.value})
+
+    }
+    login(e){
+        api.loginGzhcode({
+            authorizationCode:this.state.code
+        }).then(res=>{
+            console.log(res)
+        })
+
+    }
 
 
 
@@ -55,6 +69,10 @@ class LoginViews extends Component {
     *
     * */
     componentDidMount() {
+        console.log(new URLSearchParams(window.location.search))
+        this.setState({
+            code:new URLSearchParams(window.location.search).get('code')||""
+        })
      
     }
 
@@ -64,9 +82,8 @@ class LoginViews extends Component {
     render() {
         return (
             <div className="container">
-                <a href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx457ba48e0801c0b6&redirect_uri=https://gzh.zzxcx.net/login&response_type=code&scope=snsapi_base&state=STATE' className='login'>
-                    开始登陆
-                </a>
+                <input value={this.state.code} onInput={this.bindCode.bind(this)} />
+                <button onClick={this.login.bind(this)}>请求登陆接口</button>
             </div>
 
         )