From 9d059f329e8d9fd629bdbf209e66ae7220155320 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期日, 22 十二月 2024 14:55:38 +0800
Subject: [PATCH] 订单打印

---
 src/utils/graphql.js |   59 +++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/src/utils/graphql.js b/src/utils/graphql.js
index 8019fde..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 = "/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("selectStaff")).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