kulley 7 gadi atpakaļ
vecāks
revīzija
ecb5dbb64d
5 mainītis faili ar 40 papildinājumiem un 1 dzēšanām
  1. 0 0
      graphqlALL.txt
  2. 2 0
      package.json
  3. 10 0
      src/App.js
  4. 1 1
      src/config.js
  5. 27 0
      src/cookie.js

+ 0 - 0
src/graphqlALL.txt → graphqlALL.txt


+ 2 - 0
package.json

@@ -2,6 +2,8 @@
   "name": "order",
   "version": "0.1.0",
   "private": true,
+  "homepage": ".",
+  "main": "src/index.js",
   "dependencies": {
     "@babel/core": "7.1.6",
     "@svgr/webpack": "2.4.1",

+ 10 - 0
src/App.js

@@ -5,6 +5,7 @@ import './App.css';
 import My from './page/home/My';
 import Display from './page/display/Display';
 import Manage from "./page/manage/Manage";
+import {getCookie} from "./cookie";
 
 class App extends Component {
     constructor(props) {
@@ -16,6 +17,15 @@ class App extends Component {
         };
     }
 
+    componentWillMount(){
+        // setCookie("openid","o2fcFv8x3wy5WtcP116S5GzzkgDQ");
+        let openid =  getCookie("openid");
+        console.log('openid',openid);
+        if (!openid) {
+            window.location.href = "/subscribe";
+        }
+    }
+
     render() {
         let {userID} = this.state;
         return (

+ 1 - 1
src/config.js

@@ -1,3 +1,3 @@
-const graphqlFC = 'https://orderfcdb.szu.im/graphql';
+const graphqlFC = window.location.origin+'/graphql';
 
 export {graphqlFC}

+ 27 - 0
src/cookie.js

@@ -0,0 +1,27 @@
+export function setCookie(name,value,exdays) {
+    // expires表示过期时间。如果不设置,默认会话结束即关闭浏览器的时候就消失。
+    // 第一步,设置过期时间
+    let date = new Date();
+    date.setDate(date.getDate()+(exdays*24*60*60*1000));
+    document.cookie = name + "=" + value + ";expires=" + date;
+    // alert(document.cookie);
+}
+
+export function getCookie(key) {
+    // 第一步:将字符串转化为数组形式,分割字符串时;后需加空格
+    let arrStr = document.cookie.split('; ');
+    // 第二步:将数组arrStr中的元素再次切割,转换成数组
+    let arrStrLength = arrStr.length;
+
+    for (let i=0;i<arrStrLength;i++){
+        let arr = arrStr[i].split('=');
+        if(arr[0] === key){
+            return arr[1];
+        }
+    }
+    return '';
+}
+
+export function removeCookie(key) {
+    setCookie(key,"任意值",-1);
+}