Açıklama Yok

LoginViewController.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /**
  2. * Created by zack on 2018/6/19.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. TouchableOpacity,
  9. Platform,
  10. Image,TextInput
  11. } from 'react-native'
  12. import React, {Component} from 'react'
  13. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../utils/DimensionsTools'
  14. import HttpTools from '../../network/HttpTools'
  15. import {signUpByEmail, signUpByPhone, userSmsCode, userEmailCode, login} from '../../network/API'
  16. import ToastMsg from '../../utils/ToastMsg'
  17. import {GlobalUserStorageTool, UserStorageKey} from '../../utils/GlobalUserStorageTool'
  18. import ActionSheet from 'react-native-actionsheet'
  19. import BaseNavigationBarStyle from '../base/BaseNavigationBarStyle'
  20. export default class LoginViewController extends Component {
  21. constructor(props) {
  22. super(props)
  23. this.state = {
  24. account: props.account,
  25. password: '',
  26. isRememberAccount: true
  27. }
  28. }
  29. clickBackButton() {
  30. this.props.navigator.pop()
  31. }
  32. login() {
  33. if (this.state.account === null || !this.state.account.length) {
  34. ToastMsg.show('请输入您的账号')
  35. return;
  36. }
  37. if (!this.state.password.length) {
  38. ToastMsg.show("请输入您的密码");
  39. return
  40. }
  41. if (this.state.password.length < 6) {
  42. ToastMsg.show("密码长度不能少于6位");
  43. return
  44. }
  45. let param = JSON.stringify({
  46. forget_me: false,
  47. password: this.state.password,
  48. username: this.state.account
  49. })
  50. HttpTools.post(login, param, (response) => {
  51. console.log(response)
  52. if (response && response.token) { //登录成功
  53. GlobalUserStorageTool.save(UserStorageKey.UserInfo, response)
  54. GlobalUserStorageTool.save(UserStorageKey.AccountAndPassword, {account: this.state.account, password: this.state.password})
  55. global.token = response.token
  56. this.props.navigator.popToRoot()
  57. }else {
  58. ToastMsg.show(response.msg)
  59. }
  60. }, (error) => {
  61. ToastMsg.show('登录失败')
  62. })
  63. }
  64. loginByVerificationCode() {
  65. this.props.navigator.pop()
  66. }
  67. resetPassword() {
  68. this.props.navigator.push({
  69. screen: 'ForgotPasswordViewController',
  70. title: '',
  71. backButtonTitle: '',
  72. passProps: {
  73. didSelectedItem: (phoneCode)=> {
  74. this.setState({phoneCode: phoneCode})
  75. }
  76. },
  77. navigatorStyle: {
  78. navBarHidden: true
  79. }
  80. })
  81. }
  82. render() {
  83. return(
  84. <View style={styles.View}>
  85. <View style={styles.NavigationBarBgView}>
  86. <View style={styles.NavigationBar}>
  87. <TouchableOpacity onPress={() => {
  88. this.clickBackButton()
  89. }} style={styles.BackImageView}>
  90. <Image source={require("../../resources/images/TabBar/Learn/btn_back.png")}/>
  91. </TouchableOpacity>
  92. <Image source={require('../../resources/images/LoginSignUp/logo.png')} style={styles.LogoImageView}/>
  93. </View>
  94. </View>
  95. <View style={styles.AccountTextInputBgView}>
  96. <TextInput onChangeText={(text) => {
  97. this.setState({account: text})
  98. }} keyboardType={'email-address'} placeholder={'请输入邮箱或手机号'} placeholderTextColor={'#b8bcbf'} style={styles.AccountTextInput}/>
  99. <View style={styles.LineView}/>
  100. </View>
  101. <View style={styles.PasswordTextInputBgView}>
  102. <View style={styles.PasswordContainerView}>
  103. <TextInput onChangeText={(text) => {
  104. this.setState({password: text})
  105. }} secureTextEntry={true} placeholder={'请输入密码'} placeholderTextColor={'#b8bcbf'} style={styles.PasswordTextInput}/>
  106. <TouchableOpacity onPress={() => {
  107. this.resetPassword()
  108. }}>
  109. <Text style={styles.ForgotPasswordButtonText}>{'忘记密码'}</Text>
  110. </TouchableOpacity>
  111. </View>
  112. <View style={styles.LineView}/>
  113. </View>
  114. <View style={styles.CheckBoxAndSignUpBgView}>
  115. <Text style={{color: '#e66a6a', fontSize: 12}}>{'密码错误'}</Text>
  116. </View>
  117. <TouchableOpacity onPress={() => {
  118. this.login()
  119. }} style = {styles.SignUpButton}>
  120. <Text style={styles.SignUpButtonText}>{'登录'}</Text>
  121. </TouchableOpacity>
  122. <View style={styles.BottomLoginAndSignUpBgView}>
  123. <TouchableOpacity onPress={() => {
  124. this.loginByVerificationCode()
  125. }}>
  126. <Text style={styles.AccountLoginText}>{'验证码登录'}</Text>
  127. </TouchableOpacity>
  128. <TouchableOpacity onPress={() => {
  129. this.props.navigator.push({
  130. screen: 'SignUpViewController',
  131. title: '',
  132. backButtonTitle: '',
  133. passProps: {
  134. },
  135. navigatorStyle: {
  136. navBarHidden: true
  137. }
  138. })
  139. }}>
  140. <Text style={styles.SignUpText}>{'免费注册'}</Text>
  141. </TouchableOpacity>
  142. </View>
  143. <View style={styles.BottomSignUpView}>
  144. <View style={styles.VBgView}>
  145. <View style={[styles.VLineView, {marginLeft: 15,}]}/>
  146. <Text style={styles.VText}>{'使用其他方式登录'}</Text>
  147. <View style={styles.VLineView}/>
  148. <View />
  149. </View>
  150. <View style={styles.IconBgView}>
  151. <TouchableOpacity style={styles.IconView}>
  152. <Image source={require('../../resources/images/LoginSignUp/wechat.png')}/>
  153. </TouchableOpacity>
  154. <TouchableOpacity style={styles.IconView}>
  155. <Image source={require('../../resources/images/LoginSignUp/QQ.png')}/>
  156. </TouchableOpacity>
  157. <TouchableOpacity style={styles.IconView}>
  158. <Image source={require('../../resources/images/LoginSignUp/weibo.png')}/>
  159. </TouchableOpacity>
  160. <TouchableOpacity style={styles.IconView}>
  161. <Image source={require('../../resources/images/LoginSignUp/Facebook.png')}/>
  162. </TouchableOpacity>
  163. <TouchableOpacity style={styles.IconView}>
  164. <Image source={require('../../resources/images/LoginSignUp/twitter.png')}/>
  165. </TouchableOpacity>
  166. <TouchableOpacity style={styles.IconView}>
  167. <Image source={require('../../resources/images/LoginSignUp/Google.png')}/>
  168. </TouchableOpacity>
  169. </View>
  170. </View>
  171. </View>
  172. )
  173. }
  174. }
  175. const styles = StyleSheet.create({
  176. View: {
  177. width: ScreenDimensions.width,
  178. height: ScreenDimensions.height,
  179. backgroundColor: 'white'
  180. },
  181. NavigationBarBgView: {
  182. position: 'absolute',
  183. left: 0,
  184. top: 0,
  185. height: NavigationBarHeight.height,
  186. width: ScreenDimensions.width,
  187. backgroundColor: "#ffffff",
  188. shadowColor: "#eeeeee",
  189. shadowOffset: {
  190. width: 0,
  191. height: -1
  192. },
  193. shadowRadius: 0,
  194. shadowOpacity: 1,
  195. flexDirection: 'row',
  196. alignItems: 'center',
  197. justifyContent: 'space-between',
  198. elevation: 5, //only for android
  199. },
  200. NavigationBar: {
  201. position: 'absolute',
  202. left: 0,
  203. top: 0,
  204. height: NavigationBarHeight.height,
  205. width: ScreenDimensions.width,
  206. backgroundColor: "#ffffff",
  207. shadowColor: "#eeeeee",
  208. shadowOffset: {
  209. width: 0,
  210. height: -1
  211. },
  212. shadowRadius: 0,
  213. shadowOpacity: 1,
  214. flexDirection: 'row',
  215. alignItems: 'center',
  216. justifyContent: 'center',
  217. elevation: 5, //only for android
  218. },
  219. LogoImageView: {
  220. width: 80,
  221. height: 25,
  222. },
  223. BackImageView: {
  224. position: 'absolute',
  225. left: 15,
  226. top: (NavigationBarHeight.height - 15)/2.0
  227. },
  228. AccountTextInputBgView: {
  229. width: ScreenDimensions.width - 30,
  230. height: 50,
  231. marginLeft: 15,
  232. marginTop: NavigationBarHeight.height + 20
  233. },
  234. LineView: {
  235. width: ScreenDimensions.width - 30,
  236. backgroundColor: '#efeff4',
  237. height: 0.5,
  238. },
  239. AccountTextInput: {
  240. width: ScreenDimensions.width - 30,
  241. textAlign: 'left',
  242. fontSize: 14,
  243. color: '#4A4A4A',
  244. height:49,
  245. },
  246. VerifyTextInputBgView: {
  247. width: ScreenDimensions.width - 30,
  248. height: 50,
  249. marginLeft: 15,
  250. marginTop: 28
  251. },
  252. VerifyTextInputContainerView: {
  253. width: ScreenDimensions.width - 30,
  254. height: 49,
  255. flexDirection: 'row',
  256. alignItems: 'center',
  257. justifyContent: 'space-between'
  258. },
  259. VerifyTextInput: {
  260. width: ScreenDimensions.width - 30 - 100,
  261. textAlign: 'left',
  262. fontSize: 14,
  263. color: '#4A4A4A',
  264. height:49,
  265. },
  266. VerifyButtonBgView: {
  267. width: 100,
  268. flexDirection: 'row',
  269. alignItems: 'center',
  270. justifyContent: 'space-between',
  271. },
  272. VerifyButtonText: {
  273. fontSize: 14,
  274. color: '#5a9cd9',
  275. },
  276. VerifyLineView: {
  277. width: 1,
  278. height: 21,
  279. backgroundColor: 'rgba(80, 80, 80, 0.36)'
  280. },
  281. PasswordTextInputBgView: {
  282. width: ScreenDimensions.width - 30,
  283. height: 50,
  284. marginLeft: 15,
  285. marginTop: 28,
  286. },
  287. PasswordContainerView: {
  288. width: ScreenDimensions.width - 30,
  289. flexDirection: 'row',
  290. justifyContent: 'center',
  291. alignItems: 'center'
  292. },
  293. PasswordTextInput: {
  294. width: ScreenDimensions.width - 30 - 60,
  295. textAlign: 'left',
  296. fontSize: 14,
  297. color: '#4A4A4A',
  298. height:49,
  299. },
  300. ForgotPasswordButton: {
  301. },
  302. ForgotPasswordButtonText: {
  303. fontSize: 14,
  304. color: '#666666'
  305. },
  306. CheckBoxAndSignUpBgView: {
  307. marginTop: 25,
  308. width: ScreenDimensions.width - 30,
  309. marginLeft: 15,
  310. flexDirection: 'row',
  311. justifyContent: 'space-between',
  312. alignItems: 'center',
  313. },
  314. CheckBoxBgView: {
  315. flexDirection: 'row',
  316. alignItems: 'center',
  317. justifyContent: 'center',
  318. },
  319. CheckBoxImageView: {
  320. width: 13,
  321. height: 13,
  322. marginRight: 3,
  323. },
  324. CheckBoxText: {
  325. fontSize: 14,
  326. color: '#979696'
  327. },
  328. FreeSignUpButtonText: {
  329. fontSize: 14,
  330. color: '#5a9cd9'
  331. },
  332. SignUpButton: {
  333. width:ScreenDimensions.width - 30,
  334. height: 50,
  335. backgroundColor: '#e66a6a',
  336. justifyContent: 'center',
  337. alignItems: 'center',
  338. borderRadius: 5,
  339. marginTop: 20,
  340. marginLeft: 15,
  341. },
  342. SignUpButtonText: {
  343. fontSize: 16,
  344. color: '#ffffff'
  345. },
  346. LoginButtonBgView: {
  347. width: ScreenDimensions.width,
  348. marginTop: 18
  349. },
  350. LoginButton: {
  351. marginLeft: 15,
  352. },
  353. LoginText1: {
  354. fontSize: 14,
  355. color: '#909090'
  356. },
  357. LoginText2: {
  358. fontSize: 14,
  359. color: '#5a9cd9'
  360. },
  361. BottomSignUpView: {
  362. position: 'absolute',
  363. left: 0,
  364. bottom: 0,
  365. width: ScreenDimensions.width,
  366. height: 100,
  367. },
  368. VBgView: {
  369. flexDirection: 'row',
  370. alignItems: 'center',
  371. justifyContent: 'space-between',
  372. width: ScreenDimensions.width
  373. },
  374. VLineView: {
  375. width: (ScreenDimensions.width - 120 - 15*4)/2.0,
  376. height: 0.5,
  377. backgroundColor: '#e1e3e6'
  378. },
  379. VText: {
  380. fontSize: 14,
  381. color: '#8c8c8c',
  382. width: 120,
  383. textAlign: 'center'
  384. },
  385. IconBgView: {
  386. width: ScreenDimensions.width,
  387. height: 25,
  388. flexDirection: 'row',
  389. alignItems: 'center',
  390. justifyContent: 'space-around',
  391. marginTop: 32
  392. },
  393. IconView: {
  394. width: 25,
  395. height: 25,
  396. },
  397. BottomLoginAndSignUpBgView: {
  398. width: ScreenDimensions.width - 30,
  399. marginLeft: 15,
  400. marginTop: 23,
  401. flexDirection: 'row',
  402. justifyContent: 'space-between'
  403. },
  404. AccountLoginText: {
  405. fontSize: 13,
  406. color: '#979696',
  407. },
  408. SignUpText: {
  409. fontSize: 13,
  410. color: '#7dafe0',
  411. },
  412. })