1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import { PageLoading } from '@ant-design/pro-layout';
- import { history, useModel } from 'umi';
- import { queryTenantData } from '@/services/sagacare_service/member';
- export const initialStateConfig = {
- loading: <PageLoading />,
- };
- export async function getInitialState(): Promise<{
- projectId: String;
- currentUser?: API.CurrentUser;
- companyConfig?: any;
-
- }> {
- const { location } = history;
- var token = localStorage.getItem('token');
-
-
-
- if (location.pathname.indexOf('login') > -1 && token) {
- history.push('/home');
- }
-
- let currentUser = {
- appId: 'wxda2ef261ac3cca32',
- companyId: '17fe48afcdde4d6797583c6d6270a035',
- loginType: 'app',
- manageUserType: 3,
- name: '赵静',
- openId: 'oDcGY5Qq3Vk-7WKTNsn-lLGNT118',
- phone: '13810794283',
- projectId: 'Pj1101080259',
- userId: 'db445a9cd7be4341a14448928014605c',
- };
- let projectId = 'Pj1101080259';
- if (location.pathname.indexOf('login') == -1 && token) {
- var localUser = localStorage.getItem('user') || '';
- currentUser = JSON.parse(localUser);
- projectId = currentUser?.projectId;
- }
- let companyConfig = {};
- if (currentUser.userId) {
- const res = await queryTenantData(currentUser);
- companyConfig = res.data;
- }
- return {
- projectId,
- currentUser,
- companyConfig,
- };
- }
- export const request = {
- requestInterceptors: [
- (url: any, options: any) => {
- return {
- url,
- options: {
- ...options,
- interceptors: true,
- headers: {
- ...options.headers,
- 'saga-token': localStorage.getItem('token'),
- },
- },
- };
- },
- ],
- responseInterceptors: [
- async (response: any) => {
- return response;
- },
- ],
- errorHandler: (error: any) => {
- const { response } = error;
- if (!response) {
-
- }
- throw error;
- },
- };
|