Commit b1e53680 by Denglingling

1、完善自动登录;2、完善pc端配置菜单权限,APP显示动态菜单;

parent dfd91c2c
......@@ -18,7 +18,7 @@ import FillUnitPricePage from './containers/equipConsu/module/FillUnitPricePage'
import QuickOrderPage from './containers/quickOrder/QuickOrderPage';
import TransOrderPage from './containers/transOrder/TransOrderPage';
import TransSearchPage from './containers/transOrder/module/TransSearchPage';
// import HistoricalOrderPage from './containers/historicalOrder/HistoricalOrderPage';
import HistoricalOrderPage from './containers/historicalOrder/HistoricalOrderPage';
import LineOrderPage from './containers/historicalOrder/module/LineOrderPage';
import SubSuccPage from './containers/common/SubSuccPage';
......@@ -35,7 +35,7 @@ const Router = createAppContainer(createStackNavigator({
QuickOrderPage: {screen: QuickOrderPage},
TransOrderPage: {screen: TransOrderPage},
TransSearchPage: {screen: TransSearchPage},
// HistoricalOrderPage: {screen: HistoricalOrderPage},
HistoricalOrderPage: {screen: HistoricalOrderPage},
LineOrderPage: {screen: LineOrderPage},
SubSuccPage: {screen: SubSuccPage}
}, {
......
......@@ -7,7 +7,7 @@ import {
AUTO_LOGIN_FAILURE,
SET_DOMAIN_CONFIGURATE
} from '../base/ActionTypes';
import { PostRequest,GetRequest } from '../network/RequestUtils';
import { PostRequest } from '../network/RequestUtils';
import { show } from '../utils/Utils';
export function requestLogin(params) {
......@@ -15,16 +15,17 @@ export function requestLogin(params) {
dispatch(logining());
let {global_domain_config} = getState().login
PostRequest(global_domain_config, '/access_token/password/search?app_code=MOBILE', params).then((res) => {
// console.log('res-------', res)
if(res.error_code === 0){
// if(res.functions && res.functions.length) {
// show('登录成功');
// dispatch(loginSuccess(res, params.data.user_name, params.data.user_password));
// } else {
// show(`当前用户没有菜单权限,\n请联系管理员配置!`)
// dispatch(loginFailure())
// }
show('登录成功');
dispatch(loginSuccess(res, params.data.user_name, params.data.user_password));
if(res.functions && res.functions.length) {
show('登录成功');
dispatch(loginSuccess(res, params.data.user_name, params.data.user_password));
} else {
show(`当前用户没有菜单权限,\n请联系管理员配置!`)
dispatch(loginFailure())
}
// show('登录成功');
// dispatch(loginSuccess(res, params.data.user_name, params.data.user_password));
}else {
let error_msg = res.error_msg || res.message
if(res.error_code == -3) {
......@@ -87,13 +88,13 @@ export function autoLogin(params) {
PostRequest(global_domain_config, '/access_token/password/search?app_code=MOBILE', params).then((res) => {
if(res.error_code === 0){
// console.warn('auto------',res);
// if(res.functions && res.functions.length) {
// dispatch(autoLoginSuccess(res));
// } else {
// show(`当前用户没有菜单权限,\n请联系管理员配置!`)
// dispatch(autoLoginFailure())
// }
dispatch(autoLoginSuccess(res))
if(res.functions && res.functions.length) {
dispatch(autoLoginSuccess(res));
} else {
show(`当前用户没有菜单权限,\n请联系管理员配置!`)
dispatch(autoLoginFailure())
}
// dispatch(autoLoginSuccess(res))
}else {
console.warn(res.error_msg);
show(res.error_msg);
......
......@@ -8,7 +8,6 @@ import {
TouchableOpacity,
Clipboard
} from 'react-native';
import { connect } from 'react-redux';
import HeadBackItem from './HeadBackItem';
import {
promary_color,
......
......@@ -21,9 +21,10 @@ import {
import { exitLoginStatus } from '../../action/LoginAction';
import HeadBackItem from '../common/HeadBackItem';
import StatusBarView from '../common/StatusBarView';
import ScrollableTabView , { DefaultTabBar } from 'react-native-scrollable-tab-view';
import ScrollableTabView from 'react-native-scrollable-tab-view';
import TabBottomItem from './module/TabBottomItem';
import HistoricalOrderPage from '../historicalOrder/HistoricalOrderPage';
import { referenceArrSort } from '../../utils/Utils';
class HomePage extends Component {
......@@ -31,11 +32,11 @@ class HomePage extends Component {
super(props)
this.state = {
showList: [
{
icon: require('../../images/quick_order.png'),
title: '借货订单', // 原快速下单、手术报台
page: 'QuickOrderPage',
},
// {
// icon: require('../../images/quick_order.png'),
// title: '借货订单', // 原快速下单、手术报台
// page: 'QuickOrderPage',
// },
// {
// icon: require('../../images/self_order.png'),
// title: '自助下单',
......@@ -46,63 +47,115 @@ class HomePage extends Component {
// title: '转单申请', // 原转单
// page: 'TransOrderPage',
// },
{
icon: require('../../images/equip_consu.png'),
title: '消耗确认', // 原器械消耗
page: 'EquipConsuPage',
},
// {
// icon: require('../../images/equip_consu.png'),
// title: '历史订单',
// page: 'HistoricalOrderPage',
// title: '消耗确认', // 原器械消耗
// page: 'EquipConsuPage',
// },
{
icon: require('../../images/return_login.png'),
title: '返回登录页',
page: 'LoginPage',
}
// {
// icon: require('../../images/return_login.png'),
// title: '返回登录页',
// page: 'LoginPage',
// }
],
tabNames: ['业务模块', '历史订单'],
tabIconNames: [require('../../images/tab_mod_def.png'), require('../../images/tab_his_def.png')],
tabSelIconNames:[require('../../images/tab_mod_sel.png'), require('../../images/tab_his_sel.png')],
initialPage: 0
backLoginInfo: {
icon: require('../../images/return_login.png'),
title: '返回登录页',
page: 'LoginPage',
},
borrowInfo: {
icon: require('../../images/quick_order.png'),
title: '借货订单',
page: 'QuickOrderPage'
},
consumpInfo: {
icon: require('../../images/equip_consu.png'),
title: '消耗确认',
page: 'EquipConsuPage'
},
selfOrderInfo: {
icon: require('../../images/self_order.png'),
title: '自助下单',
page: 'SelfOrderPage'
},
transInfo: {
icon: require('../../images/trans_order.png'),
title: '转单申请',
page: 'TransOrderPage'
},
// tabNames: ['业务模块', '历史订单'],
// tabIconNames: [require('../../images/tab_mod_def.png'), require('../../images/tab_his_def.png')],
// tabSelIconNames:[require('../../images/tab_mod_sel.png'), require('../../images/tab_his_sel.png')],
tabNames: [], // Tab标题
tabIconNames: [], // Tab默认图标
tabSelIconNames:[], // Tab选择后图标
tabCodes: [], // Tab标题对应代码
initialPage: 0,
modDefauIcon: require('../../images/tab_mod_def.png'),
modSeleIcon: require('../../images/tab_mod_sel.png'),
hisDefauIcon: require('../../images/tab_his_def.png'),
hisSeleIcon: require('../../images/tab_his_sel.png'),
}
}
// componentWillReceiveProps(nextProps) {
// console.warn('home---------!!!!',nextProps)
// if(this.props.loginState != nextProps.loginState) {
// switch(nextProps.loginState) {
// case LOGIN_NO:
// console.warn('home-------LOGIN_NO---',nextProps.loginState)
// break
// default:
// break;
// }
// }
// }
componentDidMount() {
this.getMenuRuleInfo()
}
// 切换 Tab 标签
switchTabView(obj) {
console.log('切换===',obj)
// if(obj.i == 1) {
// // 跳转到历史订单页面
// this.props.navigation.navigate('HistoricalOrderPage', {title: '历史订单'})
// 获取菜单权限
getMenuRuleInfo() {
let { functions } = this.props.userInfo
let { modDefauIcon, modSeleIcon,
hisDefauIcon, hisSeleIcon,
borrowInfo, consumpInfo,
backLoginInfo } = this.state
functions = referenceArrSort(functions, 'child_list', 'function_order')
// console.log('referenceArrSort---->', functions)
let tempTabNames = []
let tempTabCodes = []
let tempTabIconNames = []
let tempTabSelIconNames = []
let tempModuleList = []
functions.forEach(item => {
tempTabNames.push(item.function_name)
tempTabCodes.push(item.function_code)
if(item.function_code == 'MOBILE_BUSINESS_MODULE') {
tempTabIconNames.push(modDefauIcon)
tempTabSelIconNames.push(modSeleIcon)
if(item.child_list && item.child_list.length) {
item.child_list.forEach(chItem => {
if(chItem.function_code == 'MOBILE_BORROW_ORDER') {
borrowInfo.title = chItem.function_name
tempModuleList.push(borrowInfo)
} else if(chItem.function_code == 'MOBILE_CONSUMP_CONFIRMA') {
consumpInfo.title = chItem.function_name
tempModuleList.push(consumpInfo)
}
})
}
tempModuleList.push(backLoginInfo)
// this.setState({
// initialPage: 0
// })
// }
} else if(item.function_code == 'MOBILE_HISTORICAL_ORDER') {
tempTabIconNames.push(hisDefauIcon)
tempTabSelIconNames.push(hisSeleIcon)
}
})
this.setState({
tabNames: tempTabNames,
tabCodes: tempTabCodes,
tabIconNames: tempTabIconNames,
tabSelIconNames: tempTabSelIconNames,
showList: tempModuleList
})
}
// 跳转页面
jumpToSubpage(index) {
// console.warn('跳转')
// console.warn(index)
let {page, title} = this.state.showList[index]
if('LoginPage' === page) {
// console.warn('返回!')
// console.warn(this.props)
this.props.exitLoginStatus()
}
this.props.navigation.navigate(page, {title})
......@@ -110,7 +163,7 @@ class HomePage extends Component {
render() {
let {navigation} = this.props
let { tabNames, tabIconNames, tabSelIconNames, initialPage } = this.state
let { tabNames, tabIconNames, tabSelIconNames, initialPage, tabCodes } = this.state
return (
<View style={styles.home_container}>
<StatusBarView
......@@ -128,62 +181,40 @@ class HomePage extends Component {
tabBarPosition='bottom'
locked={true}
renderTabBar={() =>
// <DefaultTabBar />
<TabBottomItem
tabNames={tabNames}
tabIconNames={tabIconNames}
tabSelIconNames={tabSelIconNames}
/>
}
// onChangeTab={(obj) => this.switchTabView(obj)}
>
<View style={styles.home_cont} tabLabel={tabNames[0]}>
{
this.state.showList.map((item, index) =>
<TouchableOpacity
activeOpacity={.8}
style={[styles.home_list, (index%2 !== 0) && styles.home_list_even]}
onPress={() => this.jumpToSubpage(index)}
key={index}
>
<View style={styles.list_item}>
<View style={styles.img_box}>
<Image source={item.icon} style={styles.list_img}/>
</View>
<Text style={styles.list_tit}>{item.title}</Text>
</View>
</TouchableOpacity>
)
}
</View>
{/* <Text tabLabel={tabNames[0]}>------Tab1-----</Text> */}
<View style={{flex: 1}} tabLabel={tabNames[1]}>
<HistoricalOrderPage navigation={navigation} />
</View>
</ScrollableTabView>
{/* <View style={styles.home_cont}>
{
this.state.showList.map((item, index) =>
<TouchableOpacity
activeOpacity={.8}
style={[styles.home_list, (index%2 !== 0) && styles.home_list_even]}
onPress={() => this.jumpToSubpage(index)}
key={index}
>
<View style={styles.list_item}>
<View style={styles.img_box}>
<Image source={item.icon} style={styles.list_img}/>
tabCodes.includes('MOBILE_BUSINESS_MODULE') ? <View style={styles.home_cont} tabLabel={tabNames[0]}>
{
this.state.showList.map((item, index) =>
<TouchableOpacity
activeOpacity={.8}
style={[styles.home_list, (index%2 !== 0) && styles.home_list_even]}
onPress={() => this.jumpToSubpage(index)}
key={index}
>
<View style={styles.list_item}>
<View style={styles.img_box}>
<Image source={item.icon} style={styles.list_img}/>
</View>
<Text style={styles.list_tit}>{item.title}</Text>
</View>
<Text style={styles.list_tit}>{item.title}</Text>
</View>
</TouchableOpacity>
)
</TouchableOpacity>
)
}
</View> : null
}
</View> */}
{
tabCodes.includes('MOBILE_HISTORICAL_ORDER') ? <View style={{flex: 1}} tabLabel={tabNames[1]}>
<HistoricalOrderPage navigation={navigation} />
</View> : null
}
</ScrollableTabView>
</SafeAreaView>
</View>
);
......@@ -193,29 +224,20 @@ class HomePage extends Component {
const styles = StyleSheet.create({
home_container: {
flex: 1,
// width: Width(),
// height: Height(),
// flexDirection: 'row',
// flexWrap: 'wrap',
backgroundColor: home_background_color
},
home_cont: {
// flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
marginTop: '8%',
marginLeft: '10%',
justifyContent: 'flex-start',
// backgroundColor: home_background_color
justifyContent: 'flex-start'
},
home_list: {
// width: '40%',
width: pxSize(150),
height: pxSize(150),
backgroundColor: foundation_color,
marginBottom: '6%',
// paddingTop: '8%',
// paddingBottom: '6%',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 4
......@@ -229,7 +251,6 @@ const styles = StyleSheet.create({
alignItems: 'center'
},
img_box: {
// width: '28%',
width: pxSize(46),
marginBottom: 6
},
......@@ -249,7 +270,8 @@ const styles = StyleSheet.create({
})
const mapStateToProps = (state) => ({
loginState:state.login.loginState
loginState:state.login.loginState,
userInfo: state.login.userInfo
})
const mapDispatchToProps = (dispatch) => ({
......
......@@ -48,8 +48,6 @@ class LoginPage extends Component{
}
componentDidMount() {
// this.subAutoLogin()
SplashScreen.hide() //关闭启动屏幕
this.timer = setTimeout(() => {
this.getLocalUserName()
......@@ -86,14 +84,19 @@ class LoginPage extends Component{
}
// 获取当前用户名 ???
// 获取当前用户名
getLocalUserName() {
let {username} = this.props
let { username, password } = this.props
if(username) {
this.setState({
username
})
}
if(password) {
this.setState({
password
})
}
}
// 判断是否打开域名弹窗
......@@ -135,18 +138,15 @@ class LoginPage extends Component{
// this.enterHomePage()
let {username, password, isSubLoding} = this.state
// let {global_domain_config} = this.props
// if(global_domain_config.includes("obs.uat.guke.tech")) {
// show('请修改正确域名')
// return
// }
if (!isSubLoding) {
if (isEmpty(username)) {
show('请输入用户名')
return
}
if(isEmpty(password)) {
show('请输入密码')
if(!this.judgeRequireIsEmpty()) {
return
}
let params = {
......@@ -162,25 +162,36 @@ class LoginPage extends Component{
// 自动登录
subAutoLogin() {
let {username, password, autoLogin} = this.props
this.setState({
username,
password
})
// let { autoLogin } = this.props
// let { username, password } = this.state
// if(!this.judgeRequireIsEmpty()) {
// return
// }
// let params = {
// data:{
// grant_type: "PASSWORD",
// user_name: username,
// user_password: password
// }
// }
// autoLogin(params)
}
// 判断用户名、密码是否填写
judgeRequireIsEmpty() {
let flag = true
let {username, password} = this.state
if (isEmpty(username)) {
return
show('请输入用户名')
flag = false
return flag
}
if(isEmpty(password)) {
return
}
let params = {
data:{
grant_type: "PASSWORD",
user_name: username,
user_password: password
}
show('请输入密码')
flag = false
return flag
}
autoLogin(params)
return flag
}
// 用户名改变
......
......@@ -159,6 +159,60 @@ export function cloneObject(obj) {
return JSON.parse(JSON.stringify(obj))
}
/**
* 引用数组升序排序
* @param {Array} arr 原数组
* @param {String} typeName 排序字段名
*/
export function ascArray(arr, typeName) {
if(!arr.length) {
return
}
arr.sort((obj1, obj2) => {
return obj1[typeName] - obj2[typeName]
})
return arr
}
/**
* 引用数组降序排序
* @param {Array} arr 原数组
* @param {String} typeName 排序字段名
*/
export function descArray(arr, typeName) {
if(!arr.length) {
return
}
arr.sort((obj1, obj2) => {
return obj2[typeName] - obj1[typeName]
})
return arr
}
/**
* 引用数组每一个对象,指定字段名及子项指定字段,的排序字段,都进行排序
* 如:arr= [{id:2, name: 'xiaomi', child: [{ id:8, name: 'caiyan', child: [] }, { id:6, name: 'change', child: [] }, { id:1, name: 'wangsan', child: [] }]
* @param {Array} arr 原数组 如:arr
* @param {String} speciField 指定字段 如:'child'
* @param {String} typeName 排序字段名 如:'id'
* @param {String} sortType 排序方式 默认 'asc', 降序'desc'
*/
export function referenceArrSort(arr, speciField, typeName, sortType) {
if(!arr.length) {
return
}
if(sortType == 'desc') {
descArray(arr, typeName)
} else {
ascArray(arr, typeName)
}
arr = arr.map(item => {
if(item[speciField] && item[speciField].length) {
referenceArrSort(item[speciField], speciField, typeName, sortType )
}
return item
})
return arr
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment