RnMultibundler/src/app/screens/main/MainViewScreen.tsx
xuqm 33c05e00ef refactor(app): 优化主视图屏幕和 API 请求逻辑
- 移除了 MainViewScreen 中未使用的类型导入和 Props 类型定义
- 在 useApi 中增加了新的错误处理逻辑,使用 showErrorMessage替代 Toast.show
- 优化了登录退出逻辑,增加了对新状态码的处理
2025-09-01 09:16:12 +08:00

177 行
5.4 KiB
TypeScript

import React, { useState } from 'react';
import {
Button,
Linking,
Platform,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import { Apps, NavigationPushByName } from '@common/NavigationHelper.ts';
import { showMessage } from '@common/ToastHelper.ts';
import Alert from '@common/components/Alert.tsx';
import { version_common } from '@common/common.ts';
import { downloadToFile } from '@common/UpdateHelper.ts';
import UpdateManager from '../../../../specs/NativeUpdateManager.ts';
import Spinner from '@common/components/Spinner.tsx';
import RNFS from 'react-native-fs';
export default function WebViewScreen() {
const [progress, setProgress] = useState('');
const [progressH, setProgressH] = useState('');
const [isLoading, setLoading] = useState(false);
return (
<View style={styles.container}>
<ScrollView>
<>
<Text style={{ fontSize: 20, marginVertical: 15 }}>
</Text>
<Button
title={`进入互联网医院(前台)${isLoading ? progressH : ''}`}
onPress={() => {
setLoading(true);
downloadToFile(
'https://download-api.51trust.com/ywx-android-sdk/buz1.android.zip',
'buz1.android.zip',
(bytesWritten, contentLength) => {
setProgressH(
`进度: ${((bytesWritten / contentLength) * 100).toFixed(
2,
)}%`,
);
},
)
.then(() => {
NavigationPushByName(Apps.Hospital, {});
})
.finally(() => {
setLoading(false);
});
}}
/>
<View style={{ height: 15 }} />
<Button
title={`进入医网签(后台)`}
onPress={() => {
NavigationPushByName(Apps.Ywq, {});
}}
/>
<View style={{ height: 15 }} />
<Button
title={'Toast'}
onPress={() => {
showMessage('APP页面弹出toast');
}}
/>
<View style={{ height: 45 }} />
<Button
title={'应用更新模拟'}
onPress={() => {
Alert.show(
'提示',
<Text style={styles.alertText}>
,
</Text>,
{
action: () => {
if (Platform.OS === 'ios') {
Linking.openURL(
'https://apps.apple.com/cn/app/%E5%8C%BB%E7%BD%91%E4%BF%A1/id1074200788',
);
return;
}
Linking.openURL('https://www.51trust.com/download.html/');
},
},
{
action: () => {},
},
);
}}
/>
<View style={{ height: 45 }} />
<Text>
{version_common}
{isLoading ? `(${progress})` : ''}
</Text>
<View style={{ height: 15 }} />
<Button
title={'基础包前台更新'}
onPress={() => {
Alert.show(
'提示',
<Text style={styles.alertText}>
,
</Text>,
{
action: () => {
setLoading(true);
downloadToFile(
'https://download-api.51trust.com/ywx-android-sdk/common1.android.zip',
'common1.android.zip',
(_bytesWritten, _contentLength, pro) => {
setProgress(`进度: ${pro}%`);
},
)
.then(() => {
UpdateManager.reload();
})
.finally(() => {
setLoading(false);
});
},
},
{
action: () => {},
},
);
}}
/>
<View style={{ height: 15 }} />
<Button
title={'基础包后台更新'}
onPress={() => {
downloadToFile(
'https://download-api.51trust.com/ywx-android-sdk/common2.android.zip',
'common2.android.zip',
(bytesWritten, contentLength) => {
setProgress(
`进度: ${((bytesWritten / contentLength) * 100).toFixed(
2,
)}%`,
);
},
).then(() => {
Alert.show(
'提示',
<Text style={styles.alertText}>
,
</Text>,
{},
);
});
}}
/>
<View style={{ height: 45 }} />
<Text>{`${RNFS.ExternalDirectoryPath}/bundles/`}</Text>
</>
</ScrollView>
{isLoading && <Spinner />}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
alertText: {
textAlign: 'center',
color: '#999999',
fontSize: 12,
},
});