Browse Source

添加用户先查询用户

Csy817 6 years ago
parent
commit
1586d19500
4 changed files with 40 additions and 22 deletions
  1. 2 2
      public/index.html
  2. 28 19
      src/App.js
  3. 1 1
      src/pages/my/all/index.js
  4. 9 0
      src/utils/gql.js

+ 2 - 2
public/index.html

@@ -2,7 +2,7 @@
 <html lang="en">
 <html lang="en">
   <head>
   <head>
     <meta charset="utf-8" />
     <meta charset="utf-8" />
-    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
+    <!--<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />-->
     <meta
     <meta
       name="viewport"
       name="viewport"
       content="width=device-width, initial-scale=1, shrink-to-fit=no"
       content="width=device-width, initial-scale=1, shrink-to-fit=no"
@@ -13,7 +13,7 @@
       manifest.json provides metadata used when your web app is installed on a
       manifest.json provides metadata used when your web app is installed on a
       user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
       user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
     -->
     -->
-    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
+    <!--<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />-->
     <!--
     <!--
       Notice the use of %PUBLIC_URL% in the tags above.
       Notice the use of %PUBLIC_URL% in the tags above.
       It will be replaced with the URL of the `public` folder during the build.
       It will be replaced with the URL of the `public` folder during the build.

+ 28 - 19
src/App.js

@@ -10,7 +10,7 @@ import Cart from './pages/cart'
 import My from './pages/my'
 import My from './pages/my'
 import {graphqlFC} from "./configs/url"
 import {graphqlFC} from "./configs/url"
 import {getCookie, setCookie} from "./utils/cookie"
 import {getCookie, setCookie} from "./utils/cookie"
-import {create_user} from "./utils/gql"
+import {find_user_by_openid, create_user} from "./utils/gql"
 import {idGen} from "./utils/func"
 import {idGen} from "./utils/func"
 import './app.css'
 import './app.css'
 
 
@@ -84,8 +84,8 @@ class App extends Component {
     }
     }
 
 
     oauthLogin = () => {
     oauthLogin = () => {
-        setCookie("openid","obR_j5GbxDfGlOolvSeTdZUwfpKA")
         let openid =  getCookie("openid")
         let openid =  getCookie("openid")
+        // setCookie("openid","obR_j5GbxDfGlOolvSeTdZUwfpKA")
         let user_id =  getCookie("user_id")
         let user_id =  getCookie("user_id")
         console.log('oauthLogin openid',openid)
         console.log('oauthLogin openid',openid)
 
 
@@ -93,27 +93,36 @@ class App extends Component {
             window.location.href = "/subscribe"
             window.location.href = "/subscribe"
 
 
         }else if(!user_id){
         }else if(!user_id){
-            let createdAt = moment().format('YYYY-MM-DD HH:mm:ss')
-            let id = idGen('user')
-            const userContent = {
-                email: "",
-                updatedAt: "",
-                password: "",
-                telephone: "",
-                username: "",
-                createdAt,
-                openid,
-                id,
-                userData_id: ""
-
-            }
-            request(graphqlFC, create_user ,userContent)
+            request(graphqlFC, find_user_by_openid ,{openid})
                 .then(data => {
                 .then(data => {
                     console.log('create user data',data)
                     console.log('create user data',data)
-                    setCookie('user_id',id)
+                    if(data){
+                        let createdAt = moment().format('YYYY-MM-DD HH:mm:ss')
+                        let id = idGen('user')
+                        const userContent = {
+                            email: "",
+                            updatedAt: "",
+                            password: "",
+                            telephone: "",
+                            username: "",
+                            createdAt,
+                            openid,
+                            id,
+                            userData_id: ""
+
+                        }
+                        request(graphqlFC, create_user ,userContent)
+                            .then(data => {
+                                console.log('create user data',data)
+                                setCookie('user_id',id)
+                            })
+                            .catch(err => {
+                                console.log(err, `graphql-request create user error`)
+                            })
+                    }
                 })
                 })
                 .catch(err => {
                 .catch(err => {
-                    console.log(err, `graphql-request create user error`)
+                    console.log(err, `graphql-request find user error`)
                 })
                 })
         }
         }
     }
     }

+ 1 - 1
src/pages/my/all/index.js

@@ -91,7 +91,7 @@ class All extends Component {
             <div className='my-wrap all'>
             <div className='my-wrap all'>
                 <div className='avatar-area'>
                 <div className='avatar-area'>
                     <div className='avatar'/>
                     <div className='avatar'/>
-                    <div className='nickname'>110</div>
+                    <div className='nickname'>昵称</div>
                 </div>
                 </div>
                 <div className='my-card order-card'>
                 <div className='my-card order-card'>
                     <div className='card-title'>
                     <div className='card-title'>

+ 9 - 0
src/utils/gql.js

@@ -16,6 +16,14 @@ const create_user = `
     }
     }
 `
 `
 
 
+const find_user_by_openid = `
+    query userbyprops($openid: String) {
+        userbyprops: user_by_props(openid: $openid) {
+            id
+        }
+    }
+`
+
 const category_by_props = `
 const category_by_props = `
     query categorybyprops($sort_by: category_sort_by, $limit: Int, $status: String) {
     query categorybyprops($sort_by: category_sort_by, $limit: Int, $status: String) {
         categorybyprops: category_by_props(sort_by: $sort_by limit: $limit status: $status) {
         categorybyprops: category_by_props(sort_by: $sort_by limit: $limit status: $status) {
@@ -774,6 +782,7 @@ const update_product = `
 
 
 export {
 export {
     create_user,
     create_user,
+    find_user_by_openid,
     category_by_props,
     category_by_props,
     update_category,
     update_category,
     delete_category,
     delete_category,