You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2020/05/21 03:37:33 UTC

[incubator-apisix-dashboard] 02/02: feat: added initial state

This is an automated email from the ASF dual-hosted git repository.

juzhiyuan pushed a commit to branch feat-layout
in repository https://gitbox.apache.org/repos/asf/incubator-apisix-dashboard.git

commit 311f2d363f855a818a09d11d037c6901596b83ac
Author: juzhiyuan <jj...@gmail.com>
AuthorDate: Thu May 21 11:37:12 2020 +0800

    feat: added initial state
---
 src/app.tsx | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/app.tsx b/src/app.tsx
index 7a5b6af..e94290a 100644
--- a/src/app.tsx
+++ b/src/app.tsx
@@ -1,11 +1,34 @@
 import React from 'react';
 import { notification } from 'antd';
-import { RequestConfig } from 'umi';
+import { RequestConfig, history } from 'umi';
 import { BasicLayoutProps, Settings as LayoutSettings } from '@ant-design/pro-layout';
 
 import { getAdminAPIConfig } from '@/utils/setting';
 import RightContent from '@/components/RightContent';
 import Footer from '@/components/Footer';
+import { queryCurrent } from '@/services/user';
+import defaultSettings from '../config/defaultSettings';
+
+export async function getInitialState(): Promise<{
+  currentUser?: API.CurrentUser;
+  settings?: LayoutSettings;
+}> {
+  // 如果是登录页面,不执行
+  if (history.location.pathname !== '/user/login') {
+    try {
+      const currentUser = await queryCurrent();
+      return {
+        currentUser,
+        settings: defaultSettings,
+      };
+    } catch (error) {
+      history.push('/user/login');
+    }
+  }
+  return {
+    settings: defaultSettings,
+  };
+}
 
 export const layout = ({
   initialState,