Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion HelloWorld/.ruby-version

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion HelloWorld/android/app/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13)
# Define the library name here.
project(rndiffapp_appmodules)
project(helloworld_appmodules)
# This file includes all the necessary to let you build your application with the New Architecture.
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <CoreComponentsRegistry.h>
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/components/rncore/ComponentDescriptors.h>
#include <rncli.h>

namespace facebook {
Expand Down
11 changes: 0 additions & 11 deletions HelloWorld/ios/.xcode.env

This file was deleted.

47 changes: 0 additions & 47 deletions HelloWorld/ios/HelloWorld/LaunchScreen copy.storyboard

This file was deleted.

2 changes: 0 additions & 2 deletions HelloWorld/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ
platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false

production = ENV["PRODUCTION"] == "1"

target 'HelloWorld' do
config = use_native_modules!

Expand Down
5 changes: 3 additions & 2 deletions HelloWorld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
"@uiw/formatter": "~1.3.3",
"@uiw/react-native": "^3.0.4",
"react": "18.1.0",
"react-native": "0.70.5",
"react-native": "0.70.6",
"react-native-device-info": "~10.0.2",
"react-native-gesture-handler": "~2.5.0",
"react-native-reanimated": "~2.9.1",
"react-native-safe-area-context": "~4.3.1",
"react-native-screens": "~3.15.0",
"react-native-svg": "12.1.1",
"react-redux": "7.2.6",
"redux": "4.1.2"
"redux": "4.1.2",
"react-query":"~3.39.2"
},
"devDependencies": {
"@babel/core": "~7.18.9",
Expand Down
50 changes: 27 additions & 23 deletions HelloWorld/src/App.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
import 'react-native-gesture-handler';
import React from 'react';
import {StatusBar} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {Provider} from 'react-redux';
import {store} from './models';
import { StatusBar } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { Provider } from 'react-redux';
import { store } from './models';
import AuthLoadingScreen from './pages/AuthLoading';
import {stackPageData} from './routes';
import { stackPageData } from './routes';
import { QueryClient, QueryClientProvider } from 'react-query'

const Stack = createStackNavigator();
const queryClient = new QueryClient()

export default () => {
return (
<Provider store={store}>
<StatusBar barStyle="light-content" />
<AuthLoadingScreen>
{token => (
<NavigationContainer>
<Stack.Navigator initialRouteName={token ? 'Home' : 'SignIn'}>
{stackPageData.map((props, index) => {
return (
<Stack.Screen
key={index}
{...props}
<QueryClientProvider client={queryClient}>
<StatusBar barStyle="light-content" />
<AuthLoadingScreen>
{token => (
<NavigationContainer>
<Stack.Navigator initialRouteName={token ? 'Home' : 'SignIn'}>
{stackPageData.map((props, index) => {
return (
<Stack.Screen
key={index}
{...props}
// name="Home"
// options={{
// header: () => null
// }}
// component={Home}
/>
);
})}
</Stack.Navigator>
</NavigationContainer>
)}
</AuthLoadingScreen>
/>
);
})}
</Stack.Navigator>
</NavigationContainer>
)}
</AuthLoadingScreen>
</QueryClientProvider>
</Provider>
);
};
67 changes: 67 additions & 0 deletions HelloWorld/src/hooks/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Alert } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { userLogin, userAuth } from '../services/users';
import { useQuery, useMutation } from 'react-query'
import Global from '../global';

// 登录
export const login = ({ config = {}, update, formData, remember }) => {
const mutation = useMutation({
mutationFn: userLogin,
onSuccess: async (data) => {
if (data?.token && data?.data) {
await AsyncStorage.setItem('token', data.token);
if (remember) {
await AsyncStorage.setItem('cachLoginName', formData.loginName);
await AsyncStorage.setItem('cachPassword', formData.password);
}
await AsyncStorage.setItem('userData', JSON.stringify(data.data));
update({ token: data.token, userData: data.data });
if (Global.navigation) {
Global.navigation.replace('Home');
}
} else if (data && data.message) {
Alert.alert(`Login failed - ${data.error}`, data.message);
}
},
...config
})
return mutation
}

// 验证token
export const authToken = ({ token, update }) => {
const mutation = useMutation({
mutationFn: userAuth,
onMutate: async () => {
let host = await AsyncStorage.getItem('apihost');
if (!host && conf.hosts[0]) {
await AsyncStorage.setItem('apihost', JSON.stringify(conf.hosts[0]));
await update({ apihost: conf.hosts[0] });
}
if (!token) {
await AsyncStorage.removeItem('userData');
await AsyncStorage.removeItem('token');
}
},
onSuccess: async (data) => {
if (data?.token) {
await update({ authState: true, token: data.token });
} else {
await update({ authState: true, token: null });
}
}
})
return mutation
}

// 退出
export const logout = ({ update }) => {
AsyncStorage.removeItem('token');
AsyncStorage.removeItem('userData');
update({ token: null, userData: null });
if (Global.navigation) {
Global.navigation.navigate?.('SignIn');
}
}

27 changes: 4 additions & 23 deletions HelloWorld/src/models/global.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import {userAuth} from '../services/users';
import { userAuth } from '../services/users';
import conf from '../config';

export default {
Expand All @@ -10,29 +10,10 @@ export default {
authState: false,
token: null,
apihost: null,
userData: null,
},
reducers: {
update: (state, payload) => ({...state, ...payload}),
update: (state, payload) => ({ ...state, ...payload }),
},
effects: dispatch => ({
async authToken(_, {global}) {
let host = await AsyncStorage.getItem('apihost');
if (!host && conf.hosts[0]) {
await AsyncStorage.setItem('apihost', JSON.stringify(conf.hosts[0]));
await this.update({apihost: conf.hosts[0]});
}

if (!global.token) {
await AsyncStorage.removeItem('userData');
await AsyncStorage.removeItem('token');
}

const data = await userAuth();
if (data && data.token) {
await this.update({authState: true, token: data.token});
} else {
await this.update({authState: true, token: null});
}
},
}),
effects: dispatch => ({}),
};
2 changes: 0 additions & 2 deletions HelloWorld/src/models/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {init} from '@rematch/core';
import createLoadingPlugin from '@rematch/loading';
import * as global from './global';
import * as users from './users';

const loadingPlugin = createLoadingPlugin({});

export const store = init({
models: {
global: global.default,
users: users.default,
},
plugins: [
loadingPlugin,
Expand Down
52 changes: 0 additions & 52 deletions HelloWorld/src/models/users.js

This file was deleted.

Loading