|
|
@@ -5,176 +5,175 @@ import { RequestConfig, history } from 'umi';
|
|
|
import type { RequestOptionsInit } from 'umi-request';
|
|
|
import { UserDataType, getQiankunMicroApps } from '@/service/login';
|
|
|
|
|
|
-import { BasicLayoutProps } from '@ant-design/pro-layout';
|
|
|
import { logoutHandle } from './global';
|
|
|
import { KcimCenterSysId, Platforms } from './constant';
|
|
|
import { SpacicalPageParamsType } from './typings';
|
|
|
import { createFromIconfontCN } from '@ant-design/icons';
|
|
|
import { changeFavicon, getHospType, handleLogin } from './pages/login';
|
|
|
import { getSysParamsByCode } from './service';
|
|
|
-import '../public/zhongtaiC';
|
|
|
|
|
|
-window.isParentApp = true;
|
|
|
+// 全局变量声明
|
|
|
+declare global {
|
|
|
+ interface Window {
|
|
|
+ isParentApp?: boolean;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
const loginPath = '/login';
|
|
|
|
|
|
-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 : '';
|
|
|
+// 获取医院标识
|
|
|
+const getHospSign = (): string => {
|
|
|
+ if (history?.location.query) {
|
|
|
+ const queryHospSign = history.location.query.hospSign as string;
|
|
|
+ if (queryHospSign) return queryHospSign;
|
|
|
}
|
|
|
-}
|
|
|
+ return localStorage.getItem('hospSign') || '';
|
|
|
+};
|
|
|
+
|
|
|
+const hospSign = getHospSign();
|
|
|
|
|
|
const IconFont = createFromIconfontCN({
|
|
|
- scriptUrl: '',
|
|
|
-});
|
|
|
+ scriptUrl: '/zhongtaiC.js',
|
|
|
+});
|
|
|
|
|
|
/** 获取用户信息比较慢的时候会展示一个 loading */
|
|
|
export const initialStateConfig = {
|
|
|
loading: <PageLoading />,
|
|
|
};
|
|
|
|
|
|
-type InitialStateType = {
|
|
|
+interface InitialStateType {
|
|
|
navData: any[];
|
|
|
- menuData: any[]; //中台菜单
|
|
|
- customerType: string; //客户类型
|
|
|
- userData?: UserDataType; //登录返回用户信息
|
|
|
- userInfo: any; //当前用户详细信息
|
|
|
- systemLists?: TopBar.Tab[]; //当前医院可选子系统列表
|
|
|
- openedSysLists?: TopBar.Tab[]; //当前已打开的系统列表
|
|
|
- currentSelectedSys?: TopBar.Tab; //当前选中的tab
|
|
|
+ menuData: any[]; // 中台菜单
|
|
|
+ customerType: string; // 客户类型
|
|
|
+ userData?: UserDataType; // 登录返回用户信息
|
|
|
+ userInfo: any; // 当前用户详细信息
|
|
|
+ systemLists?: TopBar.Tab[]; // 当前医院可选子系统列表
|
|
|
+ openedSysLists?: TopBar.Tab[]; // 当前已打开的系统列表
|
|
|
+ currentSelectedSys?: TopBar.Tab; // 当前选中的tab
|
|
|
logout?: () => Promise<boolean>;
|
|
|
childAppIsShowMenu?: boolean;
|
|
|
pageTitle: string;
|
|
|
spacicalPageParamsType?: SpacicalPageParamsType[];
|
|
|
getHospSubSystemListFunc?: () => Promise<any[]>;
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
interface MyRequestOptions extends RequestOptionsInit {
|
|
|
prefix?: string; // 自定义前缀
|
|
|
}
|
|
|
|
|
|
-export async function getInitialState(): Promise<InitialStateType> {
|
|
|
- const fetchUserInfo = async () => {
|
|
|
- try {
|
|
|
- const queryParams = new URLSearchParams(location.search);
|
|
|
- const importUserData = queryParams.get('userData');
|
|
|
- const env = queryParams.get('env');
|
|
|
-
|
|
|
- if (importUserData) {
|
|
|
- localStorage.setItem('userData', importUserData);
|
|
|
- return JSON.parse(importUserData);
|
|
|
- }
|
|
|
+/**
|
|
|
+ * 获取用户信息
|
|
|
+ */
|
|
|
+const fetchUserInfo = async (): Promise<UserDataType | undefined> => {
|
|
|
+ try {
|
|
|
+ const queryParams = new URLSearchParams(location.search);
|
|
|
+ const importUserData = queryParams.get('userData');
|
|
|
+ const env = queryParams.get('env');
|
|
|
|
|
|
- const userData = localStorage.getItem('userData');
|
|
|
+ if (importUserData) {
|
|
|
+ localStorage.setItem('userData', importUserData);
|
|
|
+ return JSON.parse(importUserData);
|
|
|
+ }
|
|
|
|
|
|
- if (userData) {
|
|
|
- if (env === 'demo') {
|
|
|
- history.replace('/index');
|
|
|
- }
|
|
|
- return JSON.parse(userData);
|
|
|
- }
|
|
|
- // 如果没有 userData 且 env 参数为 demo,则发起一个请求
|
|
|
+ const userData = localStorage.getItem('userData');
|
|
|
+ if (userData) {
|
|
|
if (env === 'demo') {
|
|
|
- // 获取 hospSign 参数
|
|
|
-
|
|
|
- const hospSign = queryParams.get('hospSign');
|
|
|
- // 发起请求的代码,根据实际需求调整
|
|
|
- const resp = await handleLogin('demo', '123456', hospSign as string);
|
|
|
- if (resp) {
|
|
|
- history.replace('/index');
|
|
|
- return resp;
|
|
|
- }
|
|
|
+ history.replace('/index');
|
|
|
}
|
|
|
+ return JSON.parse(userData);
|
|
|
+ }
|
|
|
|
|
|
- throw Error;
|
|
|
- } catch (error) {
|
|
|
- const currentUrlParams = new URLSearchParams(window.location.search);
|
|
|
- const hospSign = 'yourDefaultHospSign'; // 定义默认的 hospSign,如果需要的话
|
|
|
-
|
|
|
- // 如果 hospSign 已存在,保留其值,否则添加新的 hospSign 参数
|
|
|
- if (!currentUrlParams.has('hospSign')) {
|
|
|
- currentUrlParams.append('hospSign', hospSign);
|
|
|
+ if (env === 'demo') {
|
|
|
+ const hospSign = queryParams.get('hospSign');
|
|
|
+ const resp = await handleLogin('demo', '123456', hospSign || '');
|
|
|
+ if (resp) {
|
|
|
+ history.replace('/index');
|
|
|
+ return resp;
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new Error('No user data found');
|
|
|
+ } catch (error) {
|
|
|
+ const currentUrlParams = new URLSearchParams(window.location.search);
|
|
|
+ const defaultHospSign = 'yourDefaultHospSign';
|
|
|
|
|
|
- history.push(`${loginPath}?${currentUrlParams.toString()}`);
|
|
|
+ if (!currentUrlParams.has('hospSign')) {
|
|
|
+ currentUrlParams.append('hospSign', defaultHospSign);
|
|
|
}
|
|
|
+
|
|
|
+ history.push(`${loginPath}?${currentUrlParams.toString()}`);
|
|
|
return undefined;
|
|
|
- };
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
- //获取当前账号所有子应用列表
|
|
|
- const getHospSubSystemListFunc = async () => {
|
|
|
- // const data = await getHospSubSystemList();
|
|
|
- // if (data) {
|
|
|
- // const _data = data.map((t) => ({
|
|
|
- // ...t,
|
|
|
- // icon: getAppIcon(t.name),
|
|
|
- // path: t.path,
|
|
|
- // }));
|
|
|
-
|
|
|
- // return _data;
|
|
|
- // }
|
|
|
- return [];
|
|
|
- };
|
|
|
+/**
|
|
|
+ * 获取医院子系统列表
|
|
|
+ */
|
|
|
+const getHospSubSystemListFunc = async (): Promise<any[]> => {
|
|
|
+ // TODO: 实现获取子系统列表的逻辑
|
|
|
+ return [];
|
|
|
+};
|
|
|
|
|
|
+export async function getInitialState(): Promise<InitialStateType> {
|
|
|
const logout = logoutHandle;
|
|
|
const userData = await fetchUserInfo();
|
|
|
|
|
|
- let customerType = undefined;
|
|
|
-
|
|
|
+ let customerType: string | undefined;
|
|
|
if (userData?.token) {
|
|
|
customerType = await getHospType();
|
|
|
}
|
|
|
|
|
|
let systemLists: userRelationInfo.OwnAppsItem[] = [];
|
|
|
- // let navData:any[] = [];
|
|
|
if (userData) {
|
|
|
systemLists = await getHospSubSystemListFunc();
|
|
|
- // navData = await getUserPlatformNav();
|
|
|
}
|
|
|
|
|
|
const localInitData = localStorage.getItem('initialState');
|
|
|
const currentSelectedTab = localStorage.getItem('currentSelectedTab');
|
|
|
- const { loginPic } = JSON.parse(localStorage.getItem('currentSelectedSubHop') as string);
|
|
|
- const userInfo = JSON.parse(localStorage.getItem('userInfo') as string);
|
|
|
-
|
|
|
- if (loginPic.length > 0) {
|
|
|
- const arr = loginPic.split('|');
|
|
|
- if (arr.length == 2) {
|
|
|
- changeFavicon(arr[1]);
|
|
|
+ const currentSelectedSubHop = localStorage.getItem('currentSelectedSubHop');
|
|
|
+ const userInfo = localStorage.getItem('userInfo');
|
|
|
+
|
|
|
+ if (currentSelectedSubHop) {
|
|
|
+ const { loginPic } = JSON.parse(currentSelectedSubHop);
|
|
|
+ if (loginPic) {
|
|
|
+ const [_, favicon] = loginPic.split('|');
|
|
|
+ if (favicon) {
|
|
|
+ changeFavicon(favicon);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
- currentSelectedSys: currentSelectedTab != null ? JSON.parse(currentSelectedTab) : undefined,
|
|
|
+ currentSelectedSys: currentSelectedTab ? JSON.parse(currentSelectedTab) : undefined,
|
|
|
openedSysLists: [],
|
|
|
- ...JSON.parse(localInitData ? localInitData : '{}'), //覆盖,恢复tab状态
|
|
|
+ ...(localInitData ? JSON.parse(localInitData) : {}),
|
|
|
userData,
|
|
|
logout,
|
|
|
pageTitle: '欢迎进入医管平台',
|
|
|
favicon: '',
|
|
|
customerType,
|
|
|
- userInfo,
|
|
|
+ userInfo: userInfo ? JSON.parse(userInfo) : null,
|
|
|
spacicalPageParamsType: [],
|
|
|
getHospSubSystemListFunc,
|
|
|
- systemLists: systemLists,
|
|
|
+ systemLists,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 请求拦截器
|
|
|
+ */
|
|
|
const requestInterceptorsHandle = (url: string, options: MyRequestOptions) => {
|
|
|
const prefix = options.prefix || '/gateway';
|
|
|
const userData = localStorage.getItem('userData');
|
|
|
- let authHeader = { token: '' };
|
|
|
+ const authHeader = { token: '' };
|
|
|
|
|
|
if (userData) {
|
|
|
const { token } = JSON.parse(userData);
|
|
|
- if (url.indexOf('/centerSys/route/list') == -1) {
|
|
|
+ if (!url.includes('/centerSys/route/list')) {
|
|
|
authHeader.token = token;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
const finalUrl = url.startsWith(prefix) ? url : `${prefix}${url}`;
|
|
|
|
|
|
return {
|
|
|
@@ -183,25 +182,19 @@ const requestInterceptorsHandle = (url: string, options: MyRequestOptions) => {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * 响应拦截器
|
|
|
+ */
|
|
|
const responseInterceptorsHandle = async (response: Response, options: RequestOptionsInit) => {
|
|
|
const { url, method } = options;
|
|
|
- const _response: {
|
|
|
- errorMessage: any;
|
|
|
- message: any;
|
|
|
- data?: any;
|
|
|
- status: number;
|
|
|
- errorCode?: number;
|
|
|
- success?: boolean;
|
|
|
- msg?: string;
|
|
|
- } = await response.clone().json();
|
|
|
-
|
|
|
- if (_response.errorCode == 401) {
|
|
|
+ const _response = await response.clone().json();
|
|
|
+
|
|
|
+ if (_response.errorCode === 401) {
|
|
|
Modal.confirm({
|
|
|
title: '抱歉,你的登录已过期,请重新登录!',
|
|
|
okText: '确定',
|
|
|
cancelText: '取消',
|
|
|
maskClosable: false,
|
|
|
- // cancelButtonProps:
|
|
|
onOk: () => {
|
|
|
logoutHandle();
|
|
|
return Promise.resolve(true);
|
|
|
@@ -210,41 +203,37 @@ const responseInterceptorsHandle = async (response: Response, options: RequestOp
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (_response.status == 200) {
|
|
|
- if (url != '/centerSys/menu/checkKeygen' && method == 'POST') {
|
|
|
+ if (_response.status === 200) {
|
|
|
+ if (url !== '/centerSys/menu/checkKeygen' && method === 'POST') {
|
|
|
message.success({
|
|
|
- content: `操作成功!`,
|
|
|
+ content: '操作成功!',
|
|
|
duration: 1,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if (_response.data != null || _response.data != undefined) {
|
|
|
- return _response.data;
|
|
|
- } else {
|
|
|
- return true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if ((_response.msg && _response.msg.indexOf('Token') != -1) || (_response.msg && _response.msg.indexOf('token') != -1)) {
|
|
|
- Modal.confirm({
|
|
|
- title: '抱歉,你的登录已过期,请重新登录!',
|
|
|
- okText: '确定',
|
|
|
- cancelText: '取消',
|
|
|
- maskClosable: false,
|
|
|
- // cancelButtonProps:
|
|
|
- onOk: () => {
|
|
|
- logoutHandle();
|
|
|
- return Promise.resolve(true);
|
|
|
- },
|
|
|
- });
|
|
|
- return;
|
|
|
- } else {
|
|
|
- notification.error({
|
|
|
- message: '错误:',
|
|
|
- description: `${_response.msg ? _response.msg : _response.message ? _response.message : _response.errorMessage}`,
|
|
|
- });
|
|
|
- }
|
|
|
- return false;
|
|
|
+ return _response.data ?? true;
|
|
|
}
|
|
|
+
|
|
|
+ const errorMessage = _response.msg || _response.message || _response.errorMessage;
|
|
|
+ if (errorMessage?.toLowerCase().includes('token')) {
|
|
|
+ Modal.confirm({
|
|
|
+ title: '抱歉,你的登录已过期,请重新登录!',
|
|
|
+ okText: '确定',
|
|
|
+ cancelText: '取消',
|
|
|
+ maskClosable: false,
|
|
|
+ onOk: () => {
|
|
|
+ logoutHandle();
|
|
|
+ return Promise.resolve(true);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ notification.error({
|
|
|
+ message: '错误:',
|
|
|
+ description: errorMessage,
|
|
|
+ });
|
|
|
+ return false;
|
|
|
};
|
|
|
|
|
|
interface ErrorInfoStructure {
|
|
|
@@ -356,10 +345,10 @@ export const qiankun = async () => {
|
|
|
// name: 'microApp', // 唯一 id
|
|
|
// entry: '//localhost:8808', // 开发
|
|
|
// },
|
|
|
- {
|
|
|
- name: 'nursingWorkersManaSystem', // 唯一 id
|
|
|
- entry: '//116.169.61.56:29528', //测试
|
|
|
- },
|
|
|
+ // {
|
|
|
+ // name: 'nursingWorkersManaSystem', // 唯一 id
|
|
|
+ // entry: '//116.169.61.56:29528', //测试
|
|
|
+ // },
|
|
|
// {
|
|
|
// name: 'reviewMana', // 唯一 id
|
|
|
// entry: '//120.27.235.181:5000/pfmview/',
|
|
|
@@ -368,20 +357,20 @@ export const qiankun = async () => {
|
|
|
// },
|
|
|
{
|
|
|
name: 'budgetManaSystem', // 唯一 id
|
|
|
- entry: '//localhost:8002',
|
|
|
- //entry: '//120.27.235.181:5000/perform/', //开发
|
|
|
+ //entry: '//localhost:8002',
|
|
|
+ entry: '//120.27.235.181:5000/perform/', //开发
|
|
|
//entry: '//47.96.149.190:5000/perform/', //演示
|
|
|
//entry: '//198.198.203.161:5000/perform/', //淮南
|
|
|
},
|
|
|
- // {
|
|
|
- // name: 'pfmBackMana', // 唯一 id
|
|
|
- // entry: '//localhost:8001'
|
|
|
- // //entry: '//120.27.235.181:5000/pfmManager/', // 开发
|
|
|
- // },
|
|
|
+ {
|
|
|
+ name: 'pfmBackMana', // 唯一 id
|
|
|
+ //entry: '//localhost:8001'
|
|
|
+ entry: '//120.27.235.181:5000/pfmManager/', // 开发
|
|
|
+ },
|
|
|
{
|
|
|
name: 'CostAccountingSys', // 唯一 id
|
|
|
- //entry: '//localhost:8001',
|
|
|
- entry: '//120.27.235.181:5000/costAccount/', // 开发
|
|
|
+ entry: '//localhost:8001',
|
|
|
+ //entry: '//120.27.235.181:5000/costAccount/', // 开发
|
|
|
},
|
|
|
{
|
|
|
name: 'MediResourceManaSys', // 唯一 id
|
|
|
@@ -474,7 +463,18 @@ export function patchRoutes({ routes }: { routes: any }) {
|
|
|
treeLoop(routes[0]);
|
|
|
}
|
|
|
|
|
|
+// 定义布局组件的类型
|
|
|
+interface BasicLayoutProps {
|
|
|
+ headerRender?: boolean;
|
|
|
+ rightContentRender?: () => React.ReactNode;
|
|
|
+ footerRender?: () => React.ReactNode;
|
|
|
+ onPageChange?: () => void;
|
|
|
+ menuHeaderRender?: React.ReactNode;
|
|
|
+}
|
|
|
+
|
|
|
+// 布局组件配置
|
|
|
export const layout = ({ initialState }: { initialState?: InitialStateType }): BasicLayoutProps => {
|
|
|
+ // 解构初始状态数据,设置默认值
|
|
|
const { navData = [], menuData = [], customerType = '' } = initialState || {};
|
|
|
|
|
|
return {
|