Skip to content

Commit 9c3267e

Browse files
committed
登录权限验证
1 parent d90e9b9 commit 9c3267e

File tree

6 files changed

+367
-115
lines changed

6 files changed

+367
-115
lines changed

App.js

Lines changed: 205 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,74 @@
88

99
import React, {Component} from 'react';
1010
import {Platform, StyleSheet, Text, View, Image, StatusBar } from 'react-native';
11-
import { createStackNavigator, createBottomTabNavigator, createAppContainer, TabBarBottom } from 'react-navigation'
11+
import { createStackNavigator, NavigationActions, createBottomTabNavigator, createAppContainer, TabBarBottom } from 'react-navigation'
1212
import { getSession } from './src/utils'
1313
import Home from './src/views/Home'
1414
import Detail from './src/views/Detail'
1515
import Info from './src/views/Info'
1616
import Me from './src/views/Me'
1717
import { Provider } from 'react-redux'
18+
import { createStore } from 'redux'
19+
import Index from './src/store'
1820
// AsyncStorage.setItem('userinfo', 'I like to save it.')
1921
// const storeUserinfo = AsyncStorage.getItem('userinfo')
2022
// let islogin
2123
// console.log(this);
2224
getSession('loginname')
25+
const store = createStore(Index)
26+
store.subscribe(() => {
27+
//监听state变化
28+
// console.log(store.getState());
29+
// console.log(Tab);
30+
Tab(store)
31+
// AppContainer = createAppContainer(AppNavigator(store));
32+
});
2333
// let a = getSession('loginname')
2434
// console.log(a._55, a);
35+
// console.log(store.getState());
2536

2637
// console.log(AsyncStorage.getItem('userinfo'));
27-
2838
class App extends Component {
39+
constructor () {
40+
super()
41+
this.state = {
42+
nav: '',
43+
login: store.getState().login
44+
}
45+
}
2946
render () {
47+
console.log(this.state.login);
48+
49+
// console.log(store.getState());
50+
// const AppContainer = createAppContainer(AppNavigator(store));
3051
return (
3152
<Provider store={store}>
3253
<AppContainer
54+
ref={navigatorRef => {
55+
this.state.nav = navigatorRef
56+
}}
3357
onNavigationStateChange={
34-
(prevState, currentState) => {
58+
(prevState, currentState, action) => {
3559
StatusBar.setBarStyle('dark-content')
60+
console.log(action);
61+
// this.state.nav.dispatch(SwitchActions.jumpTo({ routeName: action.routeName }))
62+
// setTopLevelNavigator(this.state.nav);
63+
// navigate('Home')
64+
// console.log(prevState, currentState);
65+
// console.log(this.state.nav);
66+
67+
// let state = store.getState().login
68+
// if (state !== '') {
69+
// // this.state.nav
70+
// console.log(this.state.nav);
71+
// this.state.nav._navigation.navigate('Mine')
72+
73+
// // this.state.nav._navigation.dispatch(
74+
// // // this.state.nav._navigation.push('Mine')
75+
// // )
76+
NavigationActions.navigate({ routeName: 'Detail' })
77+
// }
78+
// this.state.nav._navigation.navigate('')
3679
// const currentScene = getCurrentRouteName(currentState)
3780
// const previousScene = getCurrentRouteName(prevState)
3881
// if (previousScene !== currentScene) {
@@ -49,104 +92,168 @@ class App extends Component {
4992
)
5093
}
5194
}
52-
53-
const Tab = createBottomTabNavigator(
54-
{
55-
Home: {
56-
screen: createStackNavigator({ Home }),
57-
navigationOptions: ({ navigation }) => ({
58-
tabBarLabel: '首页',
59-
// title: '111',
60-
// headerTitle: null,
61-
// headerBackTitle: null,
62-
tabBarIcon: ({ focused, tintColor }) => (
63-
// normalImage='https://www.easyicon.net/api/resizeApi.php?id=1225464&size=16'
64-
// normalImage={require('./src/assets/tabbar_merchant.png')}
65-
// selectedImage={require('./src/assets/tabbar_merchant.png')}
66-
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/home.png')}></Image>
67-
)
68-
}),
69-
},
70-
Publish: {
71-
screen: createStackNavigator({ publish: Home }),
72-
navigationOptions: ({ navigation }) => ({
73-
tabBarLabel: '发布',
74-
tabBarIcon: ({ focused, tintColor }) => (
75-
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/publish.png')}></Image>
76-
77-
)
78-
}),
95+
function Tab(params) {
96+
// console.log(params);
97+
this.params = params
98+
return createBottomTabNavigator(
99+
{
100+
Home: {
101+
screen: createStackNavigator({ Home }),
102+
navigationOptions: ({ navigation }) => ({
103+
tabBarLabel: '首页',
104+
// title: '111',
105+
// headerTitle: null,
106+
// headerBackTitle: null,
107+
tabBarIcon: ({ focused, tintColor }) => (
108+
// normalImage='https://www.easyicon.net/api/resizeApi.php?id=1225464&size=16'
109+
// normalImage={require('./src/assets/tabbar_merchant.png')}
110+
// selectedImage={require('./src/assets/tabbar_merchant.png')}
111+
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/home.png')}></Image>
112+
)
113+
}),
114+
},
115+
Publish: {
116+
screen: createStackNavigator({ publish: Home }),
117+
navigationOptions: ({ navigation }) => ({
118+
tabBarLabel: '发布',
119+
tabBarOnPress: ({defaultHandler, navigation}) => {
120+
// console.log(defaultHandler);
121+
jundeLogin(defaultHandler, navigation)
122+
123+
},
124+
tabBarIcon: ({ focused, tintColor }) => (
125+
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/publish.png')}></Image>
126+
127+
)
128+
}),
129+
},
130+
131+
Message: {
132+
screen: createStackNavigator({ message: Home }),
133+
navigationOptions: ({ navigation }) => ({
134+
tabBarLabel: '消息',
135+
tabBarOnPress: ({defaultHandler, navigation}) => {
136+
// console.log(defaultHandler);
137+
jundeLogin(defaultHandler, navigation)
138+
139+
},
140+
tabBarIcon: ({ focused, tintColor }) => (
141+
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/message.png') }></Image>
142+
143+
)
144+
}),
145+
},
146+
Mine: {
147+
screen: createStackNavigator({ Mine: Me }),
148+
navigationOptions: ({ navigation }) => ({
149+
tabBarLabel: '我的',
150+
tabBarIcon: ({ focused, tintColor }) => (
151+
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/me.png') }></Image>
152+
153+
)
154+
}),
155+
},
156+
Info: {
157+
screen: createStackNavigator({ Info: Info }),
158+
// paths: 'people/:name',
159+
navigationOptions: ({ navigation }) => ({
160+
tabBarLabel: '关于',
161+
tabBarOnPress: ({defaultHandler, navigation}) => {
162+
// console.log(defaultHandler);
163+
jundeLogin(defaultHandler, navigation)
164+
165+
},
166+
tabBarIcon: ({ focused, tintColor }) => (
167+
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/info.png') }></Image>
168+
169+
)
170+
}),
171+
},
79172
},
173+
{
174+
tabBarComponent: TabBarBottom,
175+
tabBarPosition: 'bottom',
176+
lazy: true,
177+
animationEnabled: false,
178+
swipeEnabled: false,
179+
onTransitionStart: (start) => {
180+
console.log(strat);
181+
182+
},
183+
tabBarOptions: {
184+
activeTintColor: 'red',
185+
inactiveTintColor: 'green',
186+
style: { backgroundColor: '#ffffff' },
187+
},
188+
})
189+
}
80190

81-
Message: {
82-
screen: createStackNavigator({ message: Home }),
83-
navigationOptions: ({ navigation }) => ({
84-
tabBarLabel: '消息',
85-
tabBarIcon: ({ focused, tintColor }) => (
86-
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/message.png') }></Image>
87-
88-
)
89-
}),
90-
},
91-
Mine: {
92-
screen: createStackNavigator({ Mine: Me }),
93-
navigationOptions: ({ navigation }) => ({
94-
tabBarLabel: '我的',
95-
tabBarIcon: ({ focused, tintColor }) => (
96-
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/me.png') }></Image>
97-
98-
)
99-
}),
100-
},
101-
Info: {
102-
screen: createStackNavigator({ Info: Info }),
103-
paths: 'people/:name',
104-
navigationOptions: ({ navigation }) => ({
105-
tabBarLabel: '关于',
106-
tabBarIcon: ({ focused, tintColor }) => (
107-
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/info.png') }></Image>
108-
109-
)
110-
}),
111-
},
112-
},
113-
{
114-
tabBarComponent: TabBarBottom,
115-
tabBarPosition: 'bottom',
116-
lazy: true,
117-
animationEnabled: false,
118-
swipeEnabled: false,
119-
tabBarOptions: {
120-
activeTintColor: 'red',
121-
inactiveTintColor: 'green',
122-
style: { backgroundColor: '#ffffff' },
123-
},
191+
function jundeLogin (defaultHandler, navigation) {
192+
let login = this.params.getState().login
193+
if (!login || login === '') {
194+
navigation.navigate('Mine')
195+
} else {
196+
defaultHandler()
197+
}
198+
}
199+
// Tabs.navigationOptions = {
200+
// header: null,
201+
// };
202+
function AppNavigator(store) {
203+
let Tabs = Tab(store)
204+
Tabs.navigationOptions = {
205+
header: null,
206+
};
207+
let login
208+
if (store) {
209+
login = store.getState().login
210+
124211
}
125-
)
126-
127-
Tab.navigationOptions = {
128-
header: null,
129-
};
130-
131-
const AppNavigator = createStackNavigator(
132-
{
133-
Tab: {
134-
screen: Tab
135-
},
136-
Detail: {
137-
screen: Detail
138-
}
139-
// Web: { screen: WebScene },
140-
// GroupPurchase: { screen: GroupPurchaseScene },
141-
},
142-
{
143-
defaultNavigationOptions: {
144-
headerBackTitle: null,
145-
headerTintColor: '#333333',
146-
showIcon: true,
212+
// console.log(store.getState().login);
213+
return createStackNavigator(
214+
{
215+
Tab: {
216+
screen: Tabs
217+
},
218+
Detail: {
219+
screen: Detail
220+
},
221+
// onTransitionStart: (start) => {
222+
// console.log(strat);
223+
224+
// },
225+
// Web: { screen: WebScene },
226+
// GroupPurchase: { screen: GroupPurchaseScene },
147227
},
148-
}
149-
)
228+
{
229+
defaultNavigationOptions: {
230+
headerBackTitle: null,
231+
headerTintColor: '#333333',
232+
showIcon: true,
233+
},
234+
}
235+
)
236+
}
237+
// const AppNavigator = createStackNavigator(
238+
// {
239+
// Tab: {
240+
// screen: Tab
241+
// },
242+
// Detail: {
243+
// screen: Detail
244+
// }
245+
// // Web: { screen: WebScene },
246+
// // GroupPurchase: { screen: GroupPurchaseScene },
247+
// },
248+
// {
249+
// defaultNavigationOptions: {
250+
// headerBackTitle: null,
251+
// headerTintColor: '#333333',
252+
// showIcon: true,
253+
// },
254+
// }
255+
// )
150256

151-
const AppContainer = createAppContainer(AppNavigator);
257+
let AppContainer = createAppContainer(AppNavigator())
258+
// const AppContainer = createAppContainer(AppNavigator());
152259
export default App

src/components/Message/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { Component } from 'react'
2+
// import { getALl } from '../../config/api'
3+
// import axios from 'axios'
4+
import {Platform, StyleSheet, Text, View, Dimensions, findNodeHandle } from 'react-native';
5+
export default class Message extends Component {
6+
constructor () {
7+
super()
8+
this.state = {
9+
// dataList: [],
10+
isactive: 0
11+
}
12+
}
13+
render () {
14+
// const actives = this.state.isactive === index ? styles.active : ''
15+
return (
16+
<View>
17+
<Text>111</Text>
18+
</View>
19+
)
20+
}
21+
}

0 commit comments

Comments
 (0)