增加状态显示

This commit is contained in:
2026-03-05 23:20:40 +08:00
parent 6e48882bb0
commit f0eb7fead5
5 changed files with 34 additions and 4 deletions

26
App.tsx
View File

@@ -58,6 +58,7 @@ export default class App extends Component<AppProps, WalletmanAppState> {
showBharatPeBusinessBind: false,
showMobikwikPersonalBind: false,
showFreechargePersonalBind: false,
proxyStatus: 'idle',
};
this.deviceId = DeviceInfo.getUniqueIdSync();
@@ -128,6 +129,7 @@ export default class App extends Component<AppProps, WalletmanAppState> {
const { clientId } = this;
console.log('[Proxy] 初始化后台服务:', clientId, 'userId:', userId);
this.setState({ proxyStatus: 'connecting' });
await proxyBackgroundService.start({
wsUrl: Api.WS_URL,
clientId: this.clientId || '',
@@ -138,12 +140,15 @@ export default class App extends Component<AppProps, WalletmanAppState> {
reconnectMaxAttempts: Infinity,
onConnected: () => {
console.log('[Proxy] 后台服务已连接');
this.setState({ proxyStatus: 'connected' });
},
onDisconnected: () => {
console.log('[Proxy] 后台服务已断开');
this.setState({ proxyStatus: 'disconnected' });
},
onError: (error: string) => {
console.warn('[Proxy] 错误:', error);
console.log('[Proxy] 错误:', error);
this.setState({ proxyStatus: 'error', proxyError: error });
},
});
} catch (error) {
@@ -554,6 +559,25 @@ export default class App extends Component<AppProps, WalletmanAppState> {
render() {
return (
<View style={styles.container}>
{(() => {
const { proxyStatus, proxyError } = this.state;
const cfg: Record<string, { label: string; color: string }> = {
idle: { label: '未连接', color: '#95a5a6' },
connecting: { label: '连接中…', color: '#f39c12' },
connected: { label: '已连接', color: '#2ecc71' },
disconnected: { label: '已断开', color: '#e74c3c' },
error: { label: '连接失败', color: '#e74c3c' },
};
const { label, color } = cfg[proxyStatus];
return (
<View style={{ flexDirection: 'row', alignItems: 'center', paddingVertical: 6, paddingHorizontal: 12 }}>
<View style={{ width: 8, height: 8, borderRadius: 4, backgroundColor: color, marginRight: 6 }} />
<Text style={{ color, fontSize: 13 }}>
Proxy {label}{proxyStatus === 'error' && proxyError ? `${proxyError}` : ''}
</Text>
</View>
);
})()}
{this.renderBindModal()}
<View style={[styles.bindButton, { backgroundColor: "transparent", flexDirection: "row", justifyContent: "space-between", alignItems: "center" }]}>
<TouchableOpacity style={[styles.bindButton, { marginBottom: 0, width: '45%', backgroundColor: "#888888" }]} onPress={() => {