From 21c9c72db79cd1cc450d7dfb668cbab43befa991 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期五, 13 六月 2025 14:27:52 +0800
Subject: [PATCH] 添加登陆后二次获取机构信息

---
 src/utils/graphql.js |   63 ++++++++++++++++++++-----------
 1 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/src/utils/graphql.js b/src/utils/graphql.js
index e1d8377..ce053c7 100644
--- a/src/utils/graphql.js
+++ b/src/utils/graphql.js
@@ -3,37 +3,56 @@
 // const apolloClient = new ApolloClient({
 //   uri: 'http://127.0.0.1:7001/graphql'
 // })
-
+import {
+  MessageBox
+} from 'element-ui'
 // export default apolloClient;
 // 瀹氫箟涓嶅悓璇锋眰鍦板潃
-const EFORMURI = "http://192.168.3.88:18080/dream_test/graphql";
-const IOTURI = "https://www.9village.cn/dream_test" + "/graphql";
+const EFORMURI = "/dream/graphql";
+const IOTURI = "/dream/graphql";
 // import ApolloClient from 'apollo-boost' //寮曞叆apollo-boost鎻掍欢
-import { ApolloClient } from "apollo-client";
-import { createHttpLink } from "apollo-link-http";
-import { InMemoryCache } from "apollo-cache-inmemory";
-import { ApolloLink } from "apollo-link";
+import {
+  ApolloClient
+} from "apollo-client";
+import {
+  createHttpLink
+} from "apollo-link-http";
+import {
+  InMemoryCache
+} from "apollo-cache-inmemory";
+import {
+  ApolloLink
+} from "apollo-link";
 
 const httpLink = createHttpLink({
   uri: EFORMURI, //閰嶇疆api璋冪敤杩炴帴
 });
 
 const middlewareLink = new ApolloLink((operation, forward) => {
-  operation.setContext({
-    headers: {
-      Authorization: JSON.parse(localStorage.getItem("user")).jwtToken,
-      // Authorization:'eyJhbGciOiJIUzI1NiJ9.eyJleHBUaW1lIjoiMjAyNC8wNy8zMSAxODoxMSIsInVzZXJJZCI6NDQsImp0aSI6ImVlMDM3NmFjLWQ5OTAtNDRkZS05YTVmLTUxYjhjMjc0YWNiOSIsImlhdCI6MTcyMjQxMzUwMSwic3ViIjoieWNsIiwiZXhwIjoxNzIyNDIwNzAxfQ.bSd0qag44dwXeJQpvryYJXEtrQ03-8MmHQWhgILGXO4',
-      staffId: JSON.parse(localStorage.getItem("user")).staffs[0].id,
-      playerId:
-        JSON.parse(localStorage.getItem("user")).players.length > 0
-          ? JSON.parse(localStorage.getItem("user")).players[0].id
-          : 0,
-    },
-  }); //request鎷︽埅鍣�
+  const user = JSON.parse(localStorage.getItem("user"))
+  if (user) {
+    operation.setContext({
+      headers: {
+        Authorization: user.jwtToken,
+        // Authorization:'eyJhbGciOiJIUzI1NiJ9.eyJleHBUaW1lIjoiMjAyNC8wNy8zMSAxODoxMSIsInVzZXJJZCI6NDQsImp0aSI6ImVlMDM3NmFjLWQ5OTAtNDRkZS05YTVmLTUxYjhjMjc0YWNiOSIsImlhdCI6MTcyMjQxMzUwMSwic3ViIjoieWNsIiwiZXhwIjoxNzIyNDIwNzAxfQ.bSd0qag44dwXeJQpvryYJXEtrQ03-8MmHQWhgILGXO4',
+        staffId: JSON.parse(localStorage.getItem("selectStaff")).id,
+        playerId: user.players.length > 0 ?
+          user.players[0].id : 0,
+      },
+    }); //request鎷︽埅鍣�
 
-  return forward(operation).map((response) => {
-    return response;
-  }); //response鎷︽埅鍣紝浣嗘槸姝ゅ骞朵笉鑳藉閿欒鍝嶅簲杩涜鎷︽埅
+    return forward(operation).map((response) => {
+      return response;
+    }); //response鎷︽埅鍣紝浣嗘槸姝ゅ骞朵笉鑳藉閿欒鍝嶅簲杩涜鎷︽埅
+  } else {
+    MessageBox.confirm('鐧诲綍鐘舵�佸凡杩囨湡锛屾偍鍙互缁х画鐣欏湪璇ラ〉闈紝鎴栬�呴噸鏂扮櫥褰�', '绯荤粺鎻愮ず', {
+      confirmButtonText: '閲嶆柊鐧诲綍',
+      cancelButtonText: '鍙栨秷',
+      type: 'warning'
+    }).then(() => {
+      location.href = '/#/login';
+    })
+  }
 });
 
 const authLink = middlewareLink.concat(httpLink);
@@ -53,7 +72,7 @@
   link: authLink,
   cache: new InMemoryCache(),
   connectToDevTools: true,
-  defaultOptions: defaultOptions,
+  // defaultOptions: defaultOptions,
 });
 // const apolloClient = new ApolloClient({
 //   uri: 'https://countries.trevorblades.com/',

--
Gitblit v1.8.0