Skip to content

Commit bb3f63e

Browse files
author
weimeng
committed
1. 增加redux
2. 增加各种表单组件 3. 支持https ‘
1 parent 101aac3 commit bb3f63e

20 files changed

Lines changed: 1024 additions & 54 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text

app/basic/FormScrollView.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/***********************************************
2+
*
3+
* MIT License
4+
*
5+
* Copyright (c) 2016 珠峰课堂,Ramroll
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
import React, {Component} from 'react'
27+
28+
import {View, ScrollView, TouchableWithoutFeedback, Keyboard} from 'react-native'
29+
export class FormScrollView extends Component {
30+
_press(){
31+
Keyboard.dismiss()
32+
}
33+
34+
componentWillUnmount(){
35+
36+
Keyboard.dismiss()
37+
}
38+
render(){
39+
return (
40+
<ScrollView keyboardShouldPersistTaps={true}>
41+
<TouchableWithoutFeedback onPress={this._press}>
42+
<View>
43+
{this.props.children}
44+
</View>
45+
</TouchableWithoutFeedback>
46+
</ScrollView>
47+
)
48+
49+
}
50+
}

app/domain/api/apis.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/***********************************************
2+
*
3+
* MIT License
4+
*
5+
* Copyright (c) 2016 珠峰课堂,Ramroll
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
27+
import {http_get, http_post, http_put, url_mapper} from "domain/api/http"
28+
29+
import {get_local_token} from "domain/store/storage"
30+
31+
/**
32+
* 请求获取token,并缓存在本地
33+
*/
34+
export const get_token = async () => {
35+
const local_token = await get_local_token()
36+
if(local_token) {
37+
console.log("local-token found:" + local_token)
38+
return
39+
}
40+
const result = await http_get("/token")
41+
console.log(result)
42+
43+
}
44+
45+
/**
46+
* 获取验证码图片
47+
*/
48+
export const get_image = async () => {
49+
50+
51+
const url = url_mapper("/imgcode")
52+
const token = await get_local_token()
53+
54+
const options = {
55+
headers : {
56+
token
57+
}
58+
}
59+
60+
const result = await fetch(url, options)
61+
if(result.status > 400) {
62+
console.error('404')
63+
return
64+
}
65+
// const img = URL.createObjectURL(blob);
66+
// return img
67+
68+
69+
}

app/domain/api/http.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/***********************************************
2+
*
3+
* MIT License
4+
*
5+
* Copyright (c) 2016 珠峰课堂,Ramroll
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
import {AsyncStorage} from "react-native"
27+
import {SERVICE_BASE} from "domain/def"
28+
import qs from 'qs'
29+
import {get_local_token, set_local_token} from "domain/store/storage"
30+
31+
32+
33+
/***
34+
* 生成HTTP请求函数
35+
* @param method
36+
*/
37+
const http_factory = (method) => {
38+
return async (url, params) => {
39+
url = url_mapper(url)
40+
41+
// 获取TOKEN
42+
let token = await get_local_token()
43+
44+
45+
// 生成Fetch的请求选项
46+
const requestOptions = {
47+
method,
48+
headers : {
49+
Accept: 'application/json',
50+
token
51+
},
52+
}
53+
54+
if(method == "GET") {
55+
const queryString = qs.stringify(params)
56+
url = `${url}${queryString && "?"+queryString}`
57+
} else {
58+
requestOptions.headers = {...requestOptions.headers, 'Content-Type': 'application/json'}
59+
requestOptions.body = JSON.stringify(params)
60+
}
61+
62+
63+
/**
64+
* 发送http请求
65+
* @returns {*}
66+
*/
67+
async function send_request(){
68+
return fetch(url)
69+
}
70+
71+
try{
72+
const http_result = await send_request()
73+
const json = await http_result.json()
74+
set_local_token(json.token)
75+
return json
76+
77+
}
78+
catch (e) {
79+
console.error(e + ":" + url)
80+
}
81+
82+
}
83+
}
84+
85+
86+
/**
87+
* URL 计算请求函数
88+
* @param url
89+
*/
90+
export const url_mapper = (url) => {
91+
return SERVICE_BASE.replace(/\/$/, '') + "/" + url.replace(/^\//, '')
92+
93+
}
94+
95+
96+
export const http_get = http_factory("GET")
97+
export const http_post = http_factory("POST")
98+
export const http_put = http_factory("PUT")
99+
export const http_delete = http_factory("DELETE")
100+

app/domain/component/ZImgCode.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/***********************************************
2+
*
3+
* MIT License
4+
*
5+
* Copyright (c) 2016 珠峰课堂,Ramroll
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
import React, {Component} from 'react'
27+
28+
29+
import {TextInput, StyleSheet, View, Text, TouchableOpacity, Image} from 'react-native'
30+
31+
import {flexCenter} from 'basic'
32+
import {COLOR_TEXT_LIGHT, COLOR_LIGHT_BLUE, COLOR_PRIMARY} from "domain/def"
33+
34+
import {url_mapper} from "domain/api/http"
35+
import {get_local_token} from "domain/store/storage"
36+
import {get_image} from "domain/api/apis"
37+
38+
export class ZImgCode extends Component{
39+
40+
constructor(){
41+
super()
42+
43+
this.state = {
44+
img : null
45+
}
46+
47+
}
48+
49+
50+
async _load(){
51+
52+
const token = await get_local_token()
53+
const img = await get_image()
54+
this.setState({
55+
img
56+
})
57+
58+
}
59+
60+
componentDidMount(){
61+
62+
this._load()
63+
64+
}
65+
66+
_change(value){
67+
this.props.onChange(value)
68+
}
69+
70+
render(){
71+
const {error, ...others} = this.props
72+
const {img} = this.state
73+
74+
75+
return <View style={styles.container}>
76+
<TextInput style={styles.input} keyboardType="phone-pad" onChangeText={this._change.bind(this)} {...others} placeholder="图片验证码" />
77+
78+
{img &&
79+
<View style={{...styles.btn, ...styles.btnDisabled}}>
80+
<Image style={{width : 100, height :42}} source={{uri : img }}/>
81+
</View>
82+
}
83+
</View>
84+
}
85+
}
86+
87+
const styles = {
88+
container : {
89+
90+
marginTop : 20,
91+
marginRight : 20,
92+
flexDirection : "row" ,
93+
marginLeft : 20,
94+
alignItems : "center"
95+
96+
},
97+
input : {
98+
borderWidth : 1,
99+
borderRadius : 5,
100+
borderColor : "#eee",
101+
paddingLeft : 20,
102+
paddingRight : 20,
103+
height : 42,
104+
color : COLOR_TEXT_LIGHT,
105+
flex : 1,
106+
107+
} ,
108+
btn : {
109+
borderRadius : 5,
110+
borderColor : COLOR_PRIMARY,
111+
borderWidth : 1,
112+
height : 42,
113+
paddingLeft : 20,
114+
paddingRight : 20,
115+
marginLeft : 10,
116+
backgroundColor : COLOR_LIGHT_BLUE,
117+
...flexCenter
118+
119+
120+
},
121+
btnDisabled : {
122+
backgroundColor : "#f2f3f4",
123+
borderColor : "#eee"
124+
},
125+
btnText: {
126+
color : COLOR_PRIMARY
127+
}
128+
129+
}

0 commit comments

Comments
 (0)