加入服务器的配置设置,可以设置服务器的url+port

This commit is contained in:
2026-03-14 14:10:29 +08:00
parent 0709c07bec
commit 83ce361404
5 changed files with 94 additions and 8 deletions

66
App.tsx
View File

@@ -35,7 +35,7 @@ import {
PaytmBusinessOTPBind,
} from './components/WalletBindComponents';
import Api from './services/api';
import Api, { loadServerDomain, saveServerDomain, getServerDomain } from './services/api';
import { AppProps, WalletmanAppState } from './types';
import { styles } from './styles';
import WebView from "react-native-webview";
@@ -62,6 +62,9 @@ export default class App extends Component<AppProps, WalletmanAppState> {
showMobikwikPersonalBind: false,
showFreechargePersonalBind: false,
proxyStatus: 'idle',
showServerSettings: false,
settingsHost: '',
settingsPort: '',
};
this.deviceId = DeviceInfo.getUniqueIdSync();
@@ -69,6 +72,7 @@ export default class App extends Component<AppProps, WalletmanAppState> {
}
async componentDidMount() {
await loadServerDomain();
await this.setupPermissions();
this.onProxyMessageSub = onProxyMessage((msg) => {
@@ -141,7 +145,7 @@ export default class App extends Component<AppProps, WalletmanAppState> {
wsUrl: Api.WS_URL,
clientId: this.clientId || '',
userId: userId,
// debug: true,
debug: true,
heartbeatInterval: 10000,
reconnectInterval: 5000,
reconnectMaxAttempts: Infinity,
@@ -630,6 +634,60 @@ export default class App extends Component<AppProps, WalletmanAppState> {
return null;
}
openServerSettings = () => {
const domain = getServerDomain();
const colonIdx = domain.lastIndexOf(':');
const host = colonIdx > 0 ? domain.substring(0, colonIdx) : domain;
const port = colonIdx > 0 ? domain.substring(colonIdx + 1) : '';
this.setState({ showServerSettings: true, settingsHost: host, settingsPort: port });
};
saveDomain = async () => {
const { settingsHost, settingsPort } = this.state;
const domain = settingsPort ? `${settingsHost}:${settingsPort}` : settingsHost;
await saveServerDomain(domain);
this.setState({ showServerSettings: false });
Alert.alert('已保存', '重启 App 后生效');
};
renderServerSettingsModal() {
const { showServerSettings, settingsHost, settingsPort } = this.state;
return (
<Modal visible={showServerSettings} transparent animationType="fade">
<View style={{ flex: 1, backgroundColor: 'rgba(0,0,0,0.5)', justifyContent: 'center', alignItems: 'center' }}>
<View style={{ backgroundColor: '#fff', borderRadius: 10, padding: 20, width: '85%' }}>
<Text style={{ fontSize: 16, fontWeight: 'bold', marginBottom: 16 }}></Text>
<Text style={{ fontSize: 13, color: '#666', marginBottom: 4 }}>Host</Text>
<TextInput
style={{ borderWidth: 1, borderColor: '#ddd', borderRadius: 6, paddingHorizontal: 10, paddingVertical: 8, marginBottom: 12, fontSize: 14 }}
value={settingsHost}
onChangeText={t => this.setState({ settingsHost: t })}
placeholder="192.168.1.198"
autoCapitalize="none"
keyboardType="default"
/>
<Text style={{ fontSize: 13, color: '#666', marginBottom: 4 }}>Port</Text>
<TextInput
style={{ borderWidth: 1, borderColor: '#ddd', borderRadius: 6, paddingHorizontal: 10, paddingVertical: 8, marginBottom: 20, fontSize: 14 }}
value={settingsPort}
onChangeText={t => this.setState({ settingsPort: t })}
placeholder="16000"
keyboardType="number-pad"
/>
<View style={{ flexDirection: 'row', justifyContent: 'flex-end' }}>
<TouchableOpacity onPress={() => this.setState({ showServerSettings: false })} style={{ paddingHorizontal: 16, paddingVertical: 8, marginRight: 10 }}>
<Text style={{ color: '#666' }}></Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.saveDomain} style={{ backgroundColor: '#3498db', paddingHorizontal: 16, paddingVertical: 8, borderRadius: 6 }}>
<Text style={{ color: '#fff', fontWeight: 'bold' }}></Text>
</TouchableOpacity>
</View>
</View>
</View>
</Modal>
);
}
render() {
return (
<View style={styles.container}>
@@ -653,6 +711,10 @@ export default class App extends Component<AppProps, WalletmanAppState> {
);
})()}
{this.renderBindModal()}
{this.renderServerSettingsModal()}
<TouchableOpacity onPress={this.openServerSettings} style={{ alignSelf: 'flex-end', paddingHorizontal: 12, paddingVertical: 4 }}>
<Text style={{ fontSize: 12, color: '#3498db' }}> </Text>
</TouchableOpacity>
<View style={[styles.bindButton, { backgroundColor: "transparent", flexDirection: "row", justifyContent: "space-between", alignItems: "center" }]}>
<TouchableOpacity style={[styles.bindButton, { marginBottom: 0, width: '45%', backgroundColor: "#888888" }]} onPress={() => {
this.setState({ showPaytmPersonalBind: true, paytmPersonalBindType: 'otpMode' });