Commit 4a50ff55 by Denglingling

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

(cherry picked from commit b1e53680)
parent 2335cdd0
...@@ -18,7 +18,7 @@ import FillUnitPricePage from './containers/equipConsu/module/FillUnitPricePage' ...@@ -18,7 +18,7 @@ import FillUnitPricePage from './containers/equipConsu/module/FillUnitPricePage'
import QuickOrderPage from './containers/quickOrder/QuickOrderPage'; import QuickOrderPage from './containers/quickOrder/QuickOrderPage';
import TransOrderPage from './containers/transOrder/TransOrderPage'; import TransOrderPage from './containers/transOrder/TransOrderPage';
import TransSearchPage from './containers/transOrder/module/TransSearchPage'; 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 LineOrderPage from './containers/historicalOrder/module/LineOrderPage';
import SubSuccPage from './containers/common/SubSuccPage'; import SubSuccPage from './containers/common/SubSuccPage';
...@@ -35,7 +35,7 @@ const Router = createAppContainer(createStackNavigator({ ...@@ -35,7 +35,7 @@ const Router = createAppContainer(createStackNavigator({
QuickOrderPage: {screen: QuickOrderPage}, QuickOrderPage: {screen: QuickOrderPage},
TransOrderPage: {screen: TransOrderPage}, TransOrderPage: {screen: TransOrderPage},
TransSearchPage: {screen: TransSearchPage}, TransSearchPage: {screen: TransSearchPage},
// HistoricalOrderPage: {screen: HistoricalOrderPage}, HistoricalOrderPage: {screen: HistoricalOrderPage},
LineOrderPage: {screen: LineOrderPage}, LineOrderPage: {screen: LineOrderPage},
SubSuccPage: {screen: SubSuccPage} SubSuccPage: {screen: SubSuccPage}
}, { }, {
......
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
AUTO_LOGIN_FAILURE, AUTO_LOGIN_FAILURE,
SET_DOMAIN_CONFIGURATE SET_DOMAIN_CONFIGURATE
} from '../base/ActionTypes'; } from '../base/ActionTypes';
import { PostRequest,GetRequest } from '../network/RequestUtils'; import { PostRequest } from '../network/RequestUtils';
import { show } from '../utils/Utils'; import { show } from '../utils/Utils';
export function requestLogin(params) { export function requestLogin(params) {
...@@ -15,16 +15,17 @@ export function requestLogin(params) { ...@@ -15,16 +15,17 @@ export function requestLogin(params) {
dispatch(logining()); dispatch(logining());
let {global_domain_config} = getState().login let {global_domain_config} = getState().login
PostRequest(global_domain_config, '/access_token/password/search?app_code=MOBILE', params).then((res) => { 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.error_code === 0){
// if(res.functions && res.functions.length) { if(res.functions && res.functions.length) {
// show('登录成功');
// dispatch(loginSuccess(res, params.data.user_name, params.data.user_password));
// } else {
// show(`当前用户没有菜单权限,\n请联系管理员配置!`)
// dispatch(loginFailure())
// }
show('登录成功'); show('登录成功');
dispatch(loginSuccess(res, params.data.user_name, params.data.user_password)); 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 { }else {
let error_msg = res.error_msg || res.message let error_msg = res.error_msg || res.message
if(res.error_code == -3) { if(res.error_code == -3) {
...@@ -87,13 +88,13 @@ export function autoLogin(params) { ...@@ -87,13 +88,13 @@ export function autoLogin(params) {
PostRequest(global_domain_config, '/access_token/password/search?app_code=MOBILE', params).then((res) => { PostRequest(global_domain_config, '/access_token/password/search?app_code=MOBILE', params).then((res) => {
if(res.error_code === 0){ if(res.error_code === 0){
// console.warn('auto------',res); // console.warn('auto------',res);
// if(res.functions && res.functions.length) { if(res.functions && res.functions.length) {
// dispatch(autoLoginSuccess(res)); dispatch(autoLoginSuccess(res));
// } else { } else {
// show(`当前用户没有菜单权限,\n请联系管理员配置!`) show(`当前用户没有菜单权限,\n请联系管理员配置!`)
// dispatch(autoLoginFailure()) dispatch(autoLoginFailure())
// } }
dispatch(autoLoginSuccess(res)) // dispatch(autoLoginSuccess(res))
}else { }else {
console.warn(res.error_msg); console.warn(res.error_msg);
show(res.error_msg); show(res.error_msg);
......
...@@ -8,7 +8,6 @@ import { ...@@ -8,7 +8,6 @@ import {
TouchableOpacity, TouchableOpacity,
Clipboard Clipboard
} from 'react-native'; } from 'react-native';
import { connect } from 'react-redux';
import HeadBackItem from './HeadBackItem'; import HeadBackItem from './HeadBackItem';
import { import {
promary_color, promary_color,
......
...@@ -21,9 +21,10 @@ import { ...@@ -21,9 +21,10 @@ import {
import { exitLoginStatus } from '../../action/LoginAction'; import { exitLoginStatus } from '../../action/LoginAction';
import HeadBackItem from '../common/HeadBackItem'; import HeadBackItem from '../common/HeadBackItem';
import StatusBarView from '../common/StatusBarView'; 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 TabBottomItem from './module/TabBottomItem';
import HistoricalOrderPage from '../historicalOrder/HistoricalOrderPage'; import HistoricalOrderPage from '../historicalOrder/HistoricalOrderPage';
import { referenceArrSort } from '../../utils/Utils';
class HomePage extends Component { class HomePage extends Component {
...@@ -31,11 +32,11 @@ class HomePage extends Component { ...@@ -31,11 +32,11 @@ class HomePage extends Component {
super(props) super(props)
this.state = { this.state = {
showList: [ showList: [
{ // {
icon: require('../../images/quick_order.png'), // icon: require('../../images/quick_order.png'),
title: '借货订单', // 原快速下单、手术报台 // title: '借货订单', // 原快速下单、手术报台
page: 'QuickOrderPage', // page: 'QuickOrderPage',
}, // },
// { // {
// icon: require('../../images/self_order.png'), // icon: require('../../images/self_order.png'),
// title: '自助下单', // title: '自助下单',
...@@ -46,63 +47,115 @@ class HomePage extends Component { ...@@ -46,63 +47,115 @@ class HomePage extends Component {
// title: '转单申请', // 原转单 // title: '转单申请', // 原转单
// page: 'TransOrderPage', // page: 'TransOrderPage',
// }, // },
{
icon: require('../../images/equip_consu.png'),
title: '消耗确认', // 原器械消耗
page: 'EquipConsuPage',
},
// { // {
// icon: require('../../images/equip_consu.png'), // icon: require('../../images/equip_consu.png'),
// title: '历史订单', // title: '消耗确认', // 原器械消耗
// page: 'HistoricalOrderPage', // page: 'EquipConsuPage',
// }, // },
{ // {
// icon: require('../../images/return_login.png'),
// title: '返回登录页',
// page: 'LoginPage',
// }
],
backLoginInfo: {
icon: require('../../images/return_login.png'), icon: require('../../images/return_login.png'),
title: '返回登录页', title: '返回登录页',
page: 'LoginPage', 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'),
} }
],
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
} }
componentDidMount() {
this.getMenuRuleInfo()
} }
// componentWillReceiveProps(nextProps) { // 获取菜单权限
// console.warn('home---------!!!!',nextProps) getMenuRuleInfo() {
// if(this.props.loginState != nextProps.loginState) { let { functions } = this.props.userInfo
// switch(nextProps.loginState) { let { modDefauIcon, modSeleIcon,
// case LOGIN_NO: hisDefauIcon, hisSeleIcon,
// console.warn('home-------LOGIN_NO---',nextProps.loginState) borrowInfo, consumpInfo,
// break backLoginInfo } = this.state
// default: functions = referenceArrSort(functions, 'child_list', 'function_order')
// break; // 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) {
// 切换 Tab 标签 item.child_list.forEach(chItem => {
switchTabView(obj) { if(chItem.function_code == 'MOBILE_BORROW_ORDER') {
console.log('切换===',obj) borrowInfo.title = chItem.function_name
// if(obj.i == 1) { tempModuleList.push(borrowInfo)
// // 跳转到历史订单页面 } else if(chItem.function_code == 'MOBILE_CONSUMP_CONFIRMA') {
// this.props.navigation.navigate('HistoricalOrderPage', {title: '历史订单'}) consumpInfo.title = chItem.function_name
tempModuleList.push(consumpInfo)
}
})
}
tempModuleList.push(backLoginInfo)
} 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
})
// this.setState({
// initialPage: 0
// })
// }
} }
// 跳转页面 // 跳转页面
jumpToSubpage(index) { jumpToSubpage(index) {
// console.warn('跳转')
// console.warn(index)
let {page, title} = this.state.showList[index] let {page, title} = this.state.showList[index]
if('LoginPage' === page) { if('LoginPage' === page) {
// console.warn('返回!')
// console.warn(this.props)
this.props.exitLoginStatus() this.props.exitLoginStatus()
} }
this.props.navigation.navigate(page, {title}) this.props.navigation.navigate(page, {title})
...@@ -110,7 +163,7 @@ class HomePage extends Component { ...@@ -110,7 +163,7 @@ class HomePage extends Component {
render() { render() {
let {navigation} = this.props let {navigation} = this.props
let { tabNames, tabIconNames, tabSelIconNames, initialPage } = this.state let { tabNames, tabIconNames, tabSelIconNames, initialPage, tabCodes } = this.state
return ( return (
<View style={styles.home_container}> <View style={styles.home_container}>
<StatusBarView <StatusBarView
...@@ -128,16 +181,15 @@ class HomePage extends Component { ...@@ -128,16 +181,15 @@ class HomePage extends Component {
tabBarPosition='bottom' tabBarPosition='bottom'
locked={true} locked={true}
renderTabBar={() => renderTabBar={() =>
// <DefaultTabBar />
<TabBottomItem <TabBottomItem
tabNames={tabNames} tabNames={tabNames}
tabIconNames={tabIconNames} tabIconNames={tabIconNames}
tabSelIconNames={tabSelIconNames} tabSelIconNames={tabSelIconNames}
/> />
} }
// onChangeTab={(obj) => this.switchTabView(obj)}
> >
<View style={styles.home_cont} tabLabel={tabNames[0]}> {
tabCodes.includes('MOBILE_BUSINESS_MODULE') ? <View style={styles.home_cont} tabLabel={tabNames[0]}>
{ {
this.state.showList.map((item, index) => this.state.showList.map((item, index) =>
<TouchableOpacity <TouchableOpacity
...@@ -155,35 +207,14 @@ class HomePage extends Component { ...@@ -155,35 +207,14 @@ class HomePage extends Component {
</TouchableOpacity> </TouchableOpacity>
) )
} }
</View> </View> : null
{/* <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) => tabCodes.includes('MOBILE_HISTORICAL_ORDER') ? <View style={{flex: 1}} tabLabel={tabNames[1]}>
<TouchableOpacity <HistoricalOrderPage navigation={navigation} />
activeOpacity={.8} </View> : null
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> */} </ScrollableTabView>
</SafeAreaView> </SafeAreaView>
</View> </View>
); );
...@@ -193,29 +224,20 @@ class HomePage extends Component { ...@@ -193,29 +224,20 @@ class HomePage extends Component {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
home_container: { home_container: {
flex: 1, flex: 1,
// width: Width(),
// height: Height(),
// flexDirection: 'row',
// flexWrap: 'wrap',
backgroundColor: home_background_color backgroundColor: home_background_color
}, },
home_cont: { home_cont: {
// flex: 1,
flexDirection: 'row', flexDirection: 'row',
flexWrap: 'wrap', flexWrap: 'wrap',
marginTop: '8%', marginTop: '8%',
marginLeft: '10%', marginLeft: '10%',
justifyContent: 'flex-start', justifyContent: 'flex-start'
// backgroundColor: home_background_color
}, },
home_list: { home_list: {
// width: '40%',
width: pxSize(150), width: pxSize(150),
height: pxSize(150), height: pxSize(150),
backgroundColor: foundation_color, backgroundColor: foundation_color,
marginBottom: '6%', marginBottom: '6%',
// paddingTop: '8%',
// paddingBottom: '6%',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
borderRadius: 4 borderRadius: 4
...@@ -229,7 +251,6 @@ const styles = StyleSheet.create({ ...@@ -229,7 +251,6 @@ const styles = StyleSheet.create({
alignItems: 'center' alignItems: 'center'
}, },
img_box: { img_box: {
// width: '28%',
width: pxSize(46), width: pxSize(46),
marginBottom: 6 marginBottom: 6
}, },
...@@ -249,7 +270,8 @@ const styles = StyleSheet.create({ ...@@ -249,7 +270,8 @@ const styles = StyleSheet.create({
}) })
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
loginState:state.login.loginState loginState:state.login.loginState,
userInfo: state.login.userInfo
}) })
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({
......
...@@ -48,8 +48,6 @@ class LoginPage extends Component{ ...@@ -48,8 +48,6 @@ class LoginPage extends Component{
} }
componentDidMount() { componentDidMount() {
// this.subAutoLogin()
SplashScreen.hide() //关闭启动屏幕 SplashScreen.hide() //关闭启动屏幕
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
this.getLocalUserName() this.getLocalUserName()
...@@ -86,14 +84,19 @@ class LoginPage extends Component{ ...@@ -86,14 +84,19 @@ class LoginPage extends Component{
} }
// 获取当前用户名 ??? // 获取当前用户名
getLocalUserName() { getLocalUserName() {
let {username} = this.props let { username, password } = this.props
if(username) { if(username) {
this.setState({ this.setState({
username username
}) })
} }
if(password) {
this.setState({
password
})
}
} }
// 判断是否打开域名弹窗 // 判断是否打开域名弹窗
...@@ -135,18 +138,15 @@ class LoginPage extends Component{ ...@@ -135,18 +138,15 @@ class LoginPage extends Component{
// this.enterHomePage() // this.enterHomePage()
let {username, password, isSubLoding} = this.state let {username, password, isSubLoding} = this.state
// let {global_domain_config} = this.props // let {global_domain_config} = this.props
// if(global_domain_config.includes("obs.uat.guke.tech")) { // if(global_domain_config.includes("obs.uat.guke.tech")) {
// show('请修改正确域名') // show('请修改正确域名')
// return // return
// } // }
if (!isSubLoding) { if (!isSubLoding) {
if (isEmpty(username)) { if(!this.judgeRequireIsEmpty()) {
show('请输入用户名')
return
}
if(isEmpty(password)) {
show('请输入密码')
return return
} }
let params = { let params = {
...@@ -162,25 +162,36 @@ class LoginPage extends Component{ ...@@ -162,25 +162,36 @@ class LoginPage extends Component{
// 自动登录 // 自动登录
subAutoLogin() { subAutoLogin() {
let {username, password, autoLogin} = this.props // let { autoLogin } = this.props
this.setState({ // let { username, password } = this.state
username, // if(!this.judgeRequireIsEmpty()) {
password // 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)) { if (isEmpty(username)) {
return show('请输入用户名')
flag = false
return flag
} }
if(isEmpty(password)) { if(isEmpty(password)) {
return show('请输入密码')
} flag = false
let params = { return flag
data:{
grant_type: "PASSWORD",
user_name: username,
user_password: password
}
} }
autoLogin(params) return flag
} }
// 用户名改变 // 用户名改变
......
...@@ -159,6 +159,60 @@ export function cloneObject(obj) { ...@@ -159,6 +159,60 @@ export function cloneObject(obj) {
return JSON.parse(JSON.stringify(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