|
@@ -20,6 +20,7 @@ import { getEnvUrl } from '@common/env/envUtils.ts';
|
|
import { md5_hex } from '@common/utils/md5';
|
|
import { md5_hex } from '@common/utils/md5';
|
|
import { CLIENT_ID, MD5_KEY } from '@common/constants';
|
|
import { CLIENT_ID, MD5_KEY } from '@common/constants';
|
|
import { showErrorMessage } from '@common/ToastHelper.ts';
|
|
import { showErrorMessage } from '@common/ToastHelper.ts';
|
|
|
|
+import DeviceInfo from 'react-native-device-info';
|
|
|
|
|
|
const SUCCESS_STATUS = /^0$/; // 请求成功的状态码
|
|
const SUCCESS_STATUS = /^0$/; // 请求成功的状态码
|
|
|
|
|
|
@@ -69,20 +70,14 @@ const useApi = <
|
|
// 【这里添加额外的 headers】
|
|
// 【这里添加额外的 headers】
|
|
const commonHeaders = useMemo(() => {
|
|
const commonHeaders = useMemo(() => {
|
|
try {
|
|
try {
|
|
- const deviceInfo = JSON.parse(info.deviceInfo ?? '{}') as Record<
|
|
|
|
- string,
|
|
|
|
- string
|
|
|
|
- >;
|
|
|
|
-
|
|
|
|
return {
|
|
return {
|
|
clientId: CLIENT_ID, // 厂商唯一标识,这个值是为医网信app分配的
|
|
clientId: CLIENT_ID, // 厂商唯一标识,这个值是为医网信app分配的
|
|
deviceType: Platform.select({ android: '0', ios: '1' }),
|
|
deviceType: Platform.select({ android: '0', ios: '1' }),
|
|
- version: deviceInfo.versionName,
|
|
|
|
- deviceId: deviceInfo.deviceId,
|
|
|
|
- phoneModel: deviceInfo.phoneModel,
|
|
|
|
- phoneBrand: deviceInfo.phoneBrand,
|
|
|
|
- phoneVersion: deviceInfo.phoneVersion,
|
|
|
|
-
|
|
|
|
|
|
+ version: DeviceInfo.getVersion(),
|
|
|
|
+ deviceId: DeviceInfo.getDeviceId(),
|
|
|
|
+ phoneModel: DeviceInfo.getModel(),
|
|
|
|
+ phoneBrand: DeviceInfo.getBrand(),
|
|
|
|
+ phoneVersion: DeviceInfo.getSystemVersion(),
|
|
userId: userInfo?.userId ?? '',
|
|
userId: userInfo?.userId ?? '',
|
|
sessionId: token ?? '',
|
|
sessionId: token ?? '',
|
|
currentClientId: '',
|
|
currentClientId: '',
|
|
@@ -91,7 +86,7 @@ const useApi = <
|
|
} catch {
|
|
} catch {
|
|
return {};
|
|
return {};
|
|
}
|
|
}
|
|
- }, [info.deviceInfo, token, userInfo?.userId]);
|
|
|
|
|
|
+ }, [token, userInfo?.userId]);
|
|
|
|
|
|
// 【这里定义 Response 的 schema】
|
|
// 【这里定义 Response 的 schema】
|
|
const responseSchema = useMemo(() => {
|
|
const responseSchema = useMemo(() => {
|
|
@@ -180,7 +175,10 @@ const useApi = <
|
|
),
|
|
),
|
|
);
|
|
);
|
|
// 退出登录逻辑
|
|
// 退出登录逻辑
|
|
- if (e.response.data?.status === '017x025'||e.response.data?.status === '017x013') {
|
|
|
|
|
|
+ if (
|
|
|
|
+ e.response.data?.status === '017x025' ||
|
|
|
|
+ e.response.data?.status === '017x013'
|
|
|
|
+ ) {
|
|
showErrorMessage(
|
|
showErrorMessage(
|
|
e.response.data?.message ??
|
|
e.response.data?.message ??
|
|
'该账号已在其他设备登录,请重新登录!',
|
|
'该账号已在其他设备登录,请重新登录!',
|