| | |
| | | // 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); |
| | |
| | | link: authLink, |
| | | cache: new InMemoryCache(), |
| | | connectToDevTools: true, |
| | | defaultOptions: defaultOptions, |
| | | // defaultOptions: defaultOptions, |
| | | }); |
| | | // const apolloClient = new ApolloClient({ |
| | | // uri: 'https://countries.trevorblades.com/', |