Skip to content

Commit

Permalink
qrcode dev
Browse files Browse the repository at this point in the history
  • Loading branch information
febobo authored and febobo committed Jun 8, 2016
1 parent d7c1f31 commit a1ab578
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 26 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"react-native-vector-icons": "^2.0.2",
"react-redux": "^4.4.5",
"redux": "^3.5.2",
"redux-logger": "^2.6.1",
"redux-thunk": "^2.1.0"
}
}
1 change: 1 addition & 0 deletions src/actions/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export const INDEX_LIST = 'INDEX_LIST';//首页数据
export const TAB_CHANGE = 'TAB_CHANGE';//TAB切换
export const ARTICLE_DETAIL = 'ARTICLE_DETAIL';//文章详情
export const DOWN_LOAD = 'DOWN_LOAD';//下拉图标控制
export const CHECK_TOKEN = 'CHECK_TOKEN'
6 changes: 0 additions & 6 deletions src/actions/EssenceActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import * as types from './actionTypes';
export function essenceList(data , getState){
console.log(getState().Essence && getState().Essence.data)
let oldList = (getState().Essence && getState().Essence.data && getState().Essence.data.concat(data)) || data;
// 下拉分页,往已有的数据塞新数据
// if(oldList){
// data.map( (v,k) =>{
// oldList.push(v);
// })
// }
return {
type : types.INDEX_LIST,
data : oldList
Expand Down
22 changes: 22 additions & 0 deletions src/actions/UserActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {createAction} from 'redux-actions';
import * as types from './actionTypes';
import config from '../config'

export const checkToken = createAction(types.CHECK_TOKEN , async(token) =>{
const params = {
method : 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body : JSON.stringify({
accesstoken : token
})
}
const userLoginInfo = await fetch(`${config.domain}/accesstoken`, params);
const loginUser = await userLoginInfo.json();
const user = await fetch(`${config.domain}/user/${loginUser.loginname}`);
const userInfo = await user.json()
// console.log(await user.json())
return userInfo;
})
4 changes: 3 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as DetailActions from './DetailActions'
import * as EssenceActions from './EssenceActions'
import * as UserActions from './UserActions'
import * as TabActions from './TabActions'

export default {
...DetailActions,
...EssenceActions,
...TabActions
...TabActions,
...UserActions
}
6 changes: 4 additions & 2 deletions src/page/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import TabShow from '../components/TabShow';
import Camera from 'react-native-camera';
import Icon from 'react-native-vector-icons/Ionicons';
import { randomBg } from '../utils';
import QrCode from './QrCode';

import connectComponent from '../utils/connectComponent';
import * as QrCodeComponent from './QrCode';
console.log(QrCodeComponent)
const QrCode = connectComponent(QrCodeComponent);
export default class Login extends Component {
constructor (props){
super(props);
Expand Down
36 changes: 20 additions & 16 deletions src/page/QrCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,15 @@ import BarcodeScanner from 'react-native-barcodescanner';
import Icon from 'react-native-vector-icons/Ionicons';
import { randomBg } from '../utils';

export default class QrCode extends Component {

class QrCode extends Component {
constructor (props){
super(props);
this.state = {
torchMode: 'off',
cameraType: 'back',
};
}

login (){
const { navigator } = this.props;
}

renderHeader (){
return (
<View style={[styles.userHeaderd]}>
<View style={styles.userInfo}>
</View>
</View>
)
this.succesed = false;
}

barcodeReceived(e) {
Expand All @@ -50,12 +39,20 @@ export default class QrCode extends Component {
}

_onBarCodeRead (data){
console.log(data)
if (this.succesed) return;
this.succesed = true;
const { navigator , actions } = this.props;
actions.checkToken(data.data , ()=>{

})
alert('登陆成功');
navigator.pop();
Vibration.vibrate()
return;
alert(1)
}

render (){
console.log(this)
const pointContent = (()=>{
return (
<Icon
Expand Down Expand Up @@ -172,3 +169,10 @@ const styles = StyleSheet.create({
bottom : 25,
},
})

export const LayoutComponent = QrCode;
export function mapStateToProps(state){
return {
User : state && state.User
}
}
18 changes: 18 additions & 0 deletions src/reducers/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as types from '../actions/actionTypes';

const tabInitState = {
count : 1
}
export default function User (state=tabInitState , action={}){
switch (action.type) {
case types.CHECK_TOKEN:
return Object.assign(
{} , state , {
user : 1
}
)
break;
default:
return state;
}
}
4 changes: 3 additions & 1 deletion src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import Essence from './Essence'
import Tab from './Tab'
import Detail from './Detail'
import Comment from './Comment'
import User from './User'
export {
Essence,
Tab,
Detail,
Comment
Comment,
User
}
1 change: 1 addition & 0 deletions src/utils/connectComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const options = {


export default function connectComponent({ mapStateToProps, mapDispatchToProps, mergeProps, LayoutComponent }) {
// console.log(mapStateToProps,22)
return connect(
mapStateToProps || function (state) {
return {};
Expand Down

0 comments on commit a1ab578

Please sign in to comment.