|
@@ -1,45 +1,58 @@
|
|
/*
|
|
/*
|
|
* @Author: your name
|
|
* @Author: your name
|
|
* @Date: 2021-11-09 13:57:41
|
|
* @Date: 2021-11-09 13:57:41
|
|
- * @LastEditTime: 2021-12-22 09:43:26
|
|
|
|
|
|
+ * @LastEditTime: 2022-02-09 14:09:24
|
|
* @LastEditors: Please set LastEditors
|
|
* @LastEditors: Please set LastEditors
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
* @FilePath: /KC-MiddlePlatform/src/app.ts
|
|
* @FilePath: /KC-MiddlePlatform/src/app.ts
|
|
*/
|
|
*/
|
|
|
|
|
|
-import React from 'react';
|
|
|
|
-import {
|
|
|
|
- PageLoading,
|
|
|
|
-} from '@ant-design/pro-layout';
|
|
|
|
-import { notification, message } from 'antd';
|
|
|
|
|
|
+import React, { useState, useRef } from 'react';
|
|
|
|
+import { PageLoading } from '@ant-design/pro-layout';
|
|
|
|
+import { notification, Modal } from 'antd';
|
|
import { RequestConfig, history } from 'umi';
|
|
import { RequestConfig, history } from 'umi';
|
|
-// import { createLogger } from 'redux-logger';
|
|
|
|
import type { RequestOptionsInit } from 'umi-request';
|
|
import type { RequestOptionsInit } from 'umi-request';
|
|
-
|
|
|
|
import { getHospSubSystemList } from '@/service/login';
|
|
import { getHospSubSystemList } from '@/service/login';
|
|
|
|
|
|
|
|
+import {
|
|
|
|
+ BasicLayoutProps,
|
|
|
|
+ Settings as LayoutSettings,
|
|
|
|
+} from '@ant-design/pro-layout';
|
|
|
|
+
|
|
const loginPath = '/login';
|
|
const loginPath = '/login';
|
|
|
|
|
|
let hospSign: string = ''; //医院标识
|
|
let hospSign: string = ''; //医院标识
|
|
|
|
|
|
|
|
+if (history && history.location.query) {
|
|
|
|
+ hospSign = history.location.query.hospSign as string;
|
|
|
|
+ if (!hospSign) {
|
|
|
|
+ const localHospSign = localStorage.getItem('hospSign');
|
|
|
|
+ hospSign = localHospSign ? localHospSign : '';
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
/** 获取用户信息比较慢的时候会展示一个 loading */
|
|
/** 获取用户信息比较慢的时候会展示一个 loading */
|
|
export const initialStateConfig = {
|
|
export const initialStateConfig = {
|
|
loading: <PageLoading />,
|
|
loading: <PageLoading />,
|
|
};
|
|
};
|
|
|
|
|
|
type InitialStateType = {
|
|
type InitialStateType = {
|
|
- userData?: any;
|
|
|
|
- systemLists?: SystemListItem[]; //当前医院可选子系统列表
|
|
|
|
- openedSysLists?: SystemListItem[]; //当前已打开的系统列表
|
|
|
|
- currentSelectedSys?: SystemListItem; //当前选中的tab
|
|
|
|
|
|
+ userData?: {
|
|
|
|
+ name: string;
|
|
|
|
+ token: string;
|
|
|
|
+ userId: number;
|
|
|
|
+ };
|
|
|
|
+ systemLists?: userRelationInfo.OwnAppsItem[]; //当前医院可选子系统列表
|
|
|
|
+ openedSysLists?: userRelationInfo.OwnAppsItem[]; //当前已打开的系统列表
|
|
|
|
+ currentSelectedSys?: userRelationInfo.OwnAppsItem; //当前选中的tab
|
|
logout?: () => Promise<boolean>;
|
|
logout?: () => Promise<boolean>;
|
|
|
|
+ getHospSubSystemListFunc?: () => Promise<any[]>;
|
|
};
|
|
};
|
|
|
|
|
|
export async function getInitialState(): Promise<InitialStateType> {
|
|
export async function getInitialState(): Promise<InitialStateType> {
|
|
const fetchUserInfo = async () => {
|
|
const fetchUserInfo = async () => {
|
|
try {
|
|
try {
|
|
- const userData = localStorage.getItem('KC-MiddlePlatformUserData');
|
|
|
|
- // console.log({ userData });
|
|
|
|
|
|
+ const userData = localStorage.getItem('userData');
|
|
if (userData) {
|
|
if (userData) {
|
|
return JSON.parse(userData);
|
|
return JSON.parse(userData);
|
|
}
|
|
}
|
|
@@ -50,47 +63,66 @@ export async function getInitialState(): Promise<InitialStateType> {
|
|
return undefined;
|
|
return undefined;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ //获取当前账号所有子应用列表
|
|
|
|
+ const getHospSubSystemListFunc = async () => {
|
|
|
|
+ const data = await getHospSubSystemList();
|
|
|
|
+ if (data) {
|
|
|
|
+ const _data = data.map((t) => ({
|
|
|
|
+ ...t,
|
|
|
|
+ icon:
|
|
|
|
+ t.name == '业务中台'
|
|
|
|
+ ? 'https://i.postimg.cc/J4fsWx1V/2x.png'
|
|
|
|
+ : 'https://i.postimg.cc/yNrSZ4pN/2x.png',
|
|
|
|
+ url: t.name == '业务中台' ? '/platform/setting/userManage' : '/app1',
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+ return _data;
|
|
|
|
+ }
|
|
|
|
+ return [];
|
|
|
|
+ };
|
|
|
|
+
|
|
const logout = () => {
|
|
const logout = () => {
|
|
- localStorage.removeItem('KC-MiddlePlatformUserData');
|
|
|
|
|
|
+ localStorage.removeItem('userData');
|
|
history.replace(`${loginPath}?hospSign=${hospSign}`);
|
|
history.replace(`${loginPath}?hospSign=${hospSign}`);
|
|
return Promise.resolve(true);
|
|
return Promise.resolve(true);
|
|
};
|
|
};
|
|
|
|
|
|
- //获取当前账号所有子应用列表
|
|
|
|
- const systemLists = await getHospSubSystemList();
|
|
|
|
-
|
|
|
|
const userData = await fetchUserInfo();
|
|
const userData = await fetchUserInfo();
|
|
|
|
|
|
|
|
+ let systemLists: userRelationInfo.OwnAppsItem[] = [];
|
|
|
|
+
|
|
|
|
+ if (userData) {
|
|
|
|
+ systemLists = await getHospSubSystemListFunc();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const localInitData = localStorage.getItem('initialState');
|
|
|
|
+
|
|
return {
|
|
return {
|
|
- userData,
|
|
|
|
- openedSysLists: [],
|
|
|
|
currentSelectedSys: undefined,
|
|
currentSelectedSys: undefined,
|
|
|
|
+ openedSysLists: [],
|
|
|
|
+ ...JSON.parse(localInitData ? localInitData : '{}'), //覆盖,恢复tab状态
|
|
|
|
+ userData,
|
|
logout,
|
|
logout,
|
|
- systemLists,
|
|
|
|
|
|
+ getHospSubSystemListFunc,
|
|
|
|
+ systemLists: systemLists,
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// export const dva = {
|
|
|
|
-// config: {
|
|
|
|
-// onAction: createLogger(),
|
|
|
|
-// onError(e: Error) {
|
|
|
|
-// message.error(e.message, 3);
|
|
|
|
-// },
|
|
|
|
-// },
|
|
|
|
-// };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
const requestInterceptorsHandle = (
|
|
const requestInterceptorsHandle = (
|
|
url: string,
|
|
url: string,
|
|
options: RequestOptionsInit,
|
|
options: RequestOptionsInit,
|
|
) => {
|
|
) => {
|
|
|
|
+ const userData = localStorage.getItem('userData');
|
|
|
|
+ let authHeader = { token: '' };
|
|
|
|
+
|
|
|
|
+ if (userData) {
|
|
|
|
+ const { token } = JSON.parse(userData);
|
|
|
|
+ authHeader.token = token;
|
|
|
|
+ }
|
|
|
|
+
|
|
return {
|
|
return {
|
|
url: `${url}`,
|
|
url: `${url}`,
|
|
- options: { ...options, interceptors: true },
|
|
|
|
|
|
+ options: { ...options, interceptors: true, headers: authHeader },
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
|
|
@@ -98,13 +130,28 @@ const responseInterceptorsHandle = async (
|
|
response: Response,
|
|
response: Response,
|
|
options: RequestOptionsInit,
|
|
options: RequestOptionsInit,
|
|
) => {
|
|
) => {
|
|
- const _response: { data: any; status: number; success: boolean } =
|
|
|
|
- await response.clone().json();
|
|
|
|
- // // console.log({_response});
|
|
|
|
- if (_response.success) {
|
|
|
|
- return _response.data;
|
|
|
|
|
|
+ const _response: {
|
|
|
|
+ data?: any;
|
|
|
|
+ status: number;
|
|
|
|
+ success?: boolean;
|
|
|
|
+ msg?: string;
|
|
|
|
+ } = await response.clone().json();
|
|
|
|
+
|
|
|
|
+ if (_response.status == 200) {
|
|
|
|
+ if (_response.data) {
|
|
|
|
+ return _response.data;
|
|
|
|
+ }
|
|
|
|
+ notification.success({
|
|
|
|
+ message: `${_response.msg}`,
|
|
|
|
+ });
|
|
|
|
+ return {
|
|
|
|
+ status: _response.status,
|
|
|
|
+ success: true,
|
|
|
|
+ };
|
|
} else {
|
|
} else {
|
|
- return _response;
|
|
|
|
|
|
+ return {
|
|
|
|
+ ..._response,
|
|
|
|
+ };
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -112,11 +159,11 @@ interface ErrorInfoStructure {
|
|
success: boolean; // if request is success
|
|
success: boolean; // if request is success
|
|
data?: any; // response data
|
|
data?: any; // response data
|
|
status?: number;
|
|
status?: number;
|
|
- errorCode: string; // code for errorType
|
|
|
|
- errorMessage: string; // message display to user
|
|
|
|
- showType?: number; // error display type: 0 silent; 1 message.warn; 2 message.error; 4 notification; 9 page
|
|
|
|
- traceId?: string; // Convenient for back-end Troubleshooting: unique request ID
|
|
|
|
- host?: string; // Convenient for backend Troubleshooting: host of current access server
|
|
|
|
|
|
+ errorCode: string;
|
|
|
|
+ errorMessage: string;
|
|
|
|
+ showType?: number;
|
|
|
|
+ traceId?: string;
|
|
|
|
+ host?: string;
|
|
}
|
|
}
|
|
|
|
|
|
interface ResponseErr extends Error {
|
|
interface ResponseErr extends Error {
|
|
@@ -129,16 +176,22 @@ const errorHandlerFunc = (error: ResponseErr) => {
|
|
|
|
|
|
try {
|
|
try {
|
|
const { info } = error;
|
|
const { info } = error;
|
|
- const errortext = '';
|
|
|
|
- const { status, errorMessage } = info;
|
|
|
|
- notification.error({
|
|
|
|
- message: ` ${status}: ${errorMessage}`,
|
|
|
|
- description: errortext,
|
|
|
|
- });
|
|
|
|
|
|
+ const { errorCode, errorMessage } = info;
|
|
|
|
+
|
|
|
|
+ if (errorMessage.length > 20) {
|
|
|
|
+ notification.error({
|
|
|
|
+ message: ` ${errorCode}:出现错误!`,
|
|
|
|
+ description: errorMessage,
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ notification.error({
|
|
|
|
+ message: ` ${errorCode}:${errorMessage}`,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
} catch (err) {
|
|
} catch (err) {
|
|
console.log({ errorHandlerFunc: err });
|
|
console.log({ errorHandlerFunc: err });
|
|
notification.error({
|
|
notification.error({
|
|
- message: '登录遇到未知错误,查看控制台!',
|
|
|
|
|
|
+ message: '遇到未知错误,查看控制台!',
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
};
|
|
@@ -147,18 +200,16 @@ export const request: RequestConfig = {
|
|
timeout: 10000,
|
|
timeout: 10000,
|
|
errorConfig: {
|
|
errorConfig: {
|
|
adaptor: (resData) => {
|
|
adaptor: (resData) => {
|
|
- if (resData) {
|
|
|
|
|
|
+ if (!resData.success && resData.status != 200) {
|
|
|
|
+ // console.log({resData});
|
|
return {
|
|
return {
|
|
...resData,
|
|
...resData,
|
|
- success: resData.success,
|
|
|
|
- errorMessage: resData.errorMessage,
|
|
|
|
|
|
+ // success:false,
|
|
};
|
|
};
|
|
} else {
|
|
} else {
|
|
return {
|
|
return {
|
|
- success: false,
|
|
|
|
- errorCode: 0,
|
|
|
|
- status: 0,
|
|
|
|
- errorMessage: '出现未知错误!',
|
|
|
|
|
|
+ success: true,
|
|
|
|
+ status: 200,
|
|
};
|
|
};
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -179,3 +230,59 @@ export const request: RequestConfig = {
|
|
requestInterceptors: [requestInterceptorsHandle],
|
|
requestInterceptors: [requestInterceptorsHandle],
|
|
responseInterceptors: [responseInterceptorsHandle],
|
|
responseInterceptors: [responseInterceptorsHandle],
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+// 从接口中获取子应用配置,export 出的 qiankun 变量是一个 promise
|
|
|
|
+export const qiankun = fetch('/config').then(() => ({
|
|
|
|
+ // 注册子应用信息
|
|
|
|
+ apps: [
|
|
|
|
+ {
|
|
|
|
+ name: 'app1', // 唯一 id
|
|
|
|
+ entry: '//localhost:8804', // html entry
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ // 完整生命周期钩子请看 https://qiankun.umijs.org/zh/api/#registermicroapps-apps-lifecycles
|
|
|
|
+ lifeCycles: {
|
|
|
|
+ afterMount: (props: any) => {
|
|
|
|
+ console.log(props);
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ // 支持更多的其他配置,详细看这里 https://qiankun.umijs.org/zh/api/#start-opts
|
|
|
|
+}));
|
|
|
|
+
|
|
|
|
+//向子应用透传
|
|
|
|
+export function useQiankunStateForSlave() {
|
|
|
|
+ const [masterState, setMasterState] = useState({});
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ masterState,
|
|
|
|
+ setMasterState,
|
|
|
|
+ };
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export const layout = ({
|
|
|
|
+ initialState: {
|
|
|
|
+ systemLists = [],
|
|
|
|
+ openedSysLists = [],
|
|
|
|
+ userData,
|
|
|
|
+ currentSelectedSys,
|
|
|
|
+ },
|
|
|
|
+}: {
|
|
|
|
+ initialState: InitialStateType;
|
|
|
|
+}): BasicLayoutProps => {
|
|
|
|
+ return {
|
|
|
|
+ // headerRender: () => (
|
|
|
|
+ // <TopHoc systemLists={systemLists} openedSysLists={openedSysLists} currentSelectedSys={currentSelectedSys} />
|
|
|
|
+ // ),
|
|
|
|
+ headerRender: false,
|
|
|
|
+ rightContentRender: () => <>right</>,
|
|
|
|
+ footerRender: () => null,
|
|
|
|
+ onPageChange: () => {
|
|
|
|
+ //如果没有登录,重定向到 login
|
|
|
|
+ if (!userData && location.pathname !== '/login') {
|
|
|
|
+ history.push('/login');
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ menuHeaderRender: undefined,
|
|
|
|
+ // ...initialState?.settings,
|
|
|
|
+ };
|
|
|
|
+};
|