LoginVL.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /**
  2. * LUMI版本Login页面
  3. * @邠心vbe on 2024/05/31
  4. */
  5. import React from 'react';
  6. import { BackHandler, Image, ScrollView, StyleSheet, TextInput, View } from 'react-native';
  7. import { PageList } from '../Router';
  8. import apiUser from '../../api/apiUser';
  9. import Button from '../../components/Button';
  10. import Dialog from '../../components/Dialog';
  11. import { setAccessToken } from '../../api/http';
  12. import TextView from '../../components/TextView';
  13. import { BackButton } from '../../components/Toolbar';
  14. import CheckBoxText from '../../components/CheckBoxText';
  15. import { getStorageJsonSync, setStorageJson } from '../../utils/storage';
  16. export default class LoginVL extends React.Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. email: '',
  21. password: '',
  22. rememberMe: false,
  23. showPassword: false
  24. }
  25. this.isHide = false;
  26. }
  27. componentDidMount() {
  28. BackHandler.addEventListener('hardwareBackPress', this.toExit)
  29. this.props.navigation.addListener('focus', () => {
  30. this.isHide = false;
  31. });
  32. this.props.navigation.addListener('blur', () => {
  33. this.isHide = true;
  34. });
  35. //this.getEmail();
  36. }
  37. componentWillUnmount() {
  38. BackHandler.removeEventListener("hardwareBackPress", this.toExit)
  39. }
  40. toExit = () => {
  41. if (!this.isHide)
  42. return true;
  43. }
  44. async getEmail() {
  45. const data = await getStorageJsonSync('loginData');
  46. if (data && data.email) {
  47. this.setState({
  48. email: data.email
  49. });
  50. }
  51. }
  52. onLogin() {
  53. //console.log(this.state);
  54. if (this.state.email == '') {
  55. toastShort($t('sign.plsInputEmail'));
  56. return;
  57. }
  58. if (this.state.password == '') {
  59. toastShort($t('sign.plsInputPassword'));
  60. return;
  61. }
  62. Dialog.showProgressDialog();
  63. apiUser.login(this.state).then(res => {
  64. console.log('res.data', res);
  65. if (res.data.accessToken) {
  66. setAccessToken(res.data.accessToken);
  67. Dialog.dismissLoading();
  68. if (this.state.rememberMe) {
  69. setStorageJson('loginData', this.state);
  70. } else {
  71. setStorageJson('loginData', {});
  72. }
  73. startPage(PageList.home);
  74. //this.props.navigation.goBack();
  75. } else {
  76. toastShort(res.msg);
  77. Dialog.dismissLoading();
  78. }
  79. }).catch(err => {
  80. toastShort(err);
  81. Dialog.dismissLoading();
  82. });
  83. }
  84. getBackTopPosition() {
  85. return isIOS ? statusHeight : 4;
  86. }
  87. togglePassword() {
  88. this.setState({
  89. showPassword: !this.state.showPassword
  90. })
  91. }
  92. render() {
  93. return (
  94. <View style={ui.flex1}>
  95. {/* <View style={[styles.backBtn, {top: this.getBackTopPosition()}]}>
  96. <BackButton/>
  97. </View> */}
  98. <ScrollView
  99. style={styles.container}
  100. keyboardShouldPersistTaps={isIOS ? 'never' : 'handled'}>
  101. <View style={styles.header}>
  102. <Image
  103. style={styles.headerImg}
  104. resizeMode='contain'
  105. source={require('../../images/app-logo.png')} />
  106. </View>
  107. <View style={styles.loginView}>
  108. <View style={ui.center}>
  109. {/* <Image
  110. style={styles.logoImg}
  111. resizeMode='contain'
  112. source={require('../../images/app-logo.png')} /> */}
  113. <TextView style={styles.loginTitle}>{$t('sign.plsLoginTitle')}</TextView>
  114. </View>
  115. <View style={styles.loginForm}>
  116. <View style={styles.inputView}>
  117. {/* <Zocial name='email' size={28} color='#999999' /> */}
  118. {/* <Image
  119. style={styles.inputIcon}
  120. source={require('../../images/user/sign-email.png')}
  121. /> */}
  122. <TextInput
  123. style={styles.inputText}
  124. placeholder={"example@email.com"}
  125. placeholderTextColor={textPlacehoder}
  126. keyboardType="email-address"
  127. textContentType='emailAddress'
  128. defaultValue={this.state.email}
  129. maxLength={50}
  130. clearButtonMode='while-editing'
  131. autoCapitalize="none"
  132. autoComplete="off"
  133. autoCorrect={false}
  134. onChangeText={(v) => {
  135. this.setState({
  136. email: v
  137. })
  138. }}/>
  139. </View>
  140. <View style={styles.inputView}>
  141. {/* <Fontisto name='locked' size={28} color='#999999' style={{marginLeft: 3, marginRight: 2}} /> */}
  142. {/* <Image
  143. style={styles.inputIcon}
  144. source={require('../../images/user/sign-password.png')}
  145. /> */}
  146. <TextInput
  147. style={styles.inputText}
  148. placeholder={$t('sign.labelPassword')}
  149. placeholderTextColor={textPlacehoder}
  150. textContentType='password'
  151. secureTextEntry={!this.state.showPassword}
  152. maxLength={20}
  153. onChangeText={(v) => {
  154. this.setState({
  155. password: v
  156. })
  157. }}
  158. onSubmitEditing={() => {
  159. //this.onLogin();
  160. }}/>
  161. <MaterialCommunityIcons
  162. name={this.state.showPassword ? 'eye' : 'eye-off' }
  163. size={14}
  164. color={"#ccc"}
  165. onPress={() => this.togglePassword()}/>
  166. </View>
  167. <View style={ui.flexcw}>
  168. <View style={$padding(12, 8)}>
  169. {/* <CheckBoxText
  170. value={this.state.rememberMe}
  171. onValueChange={(newValue) => {
  172. this.setState({ rememberMe: newValue });
  173. }}
  174. text={$t('sign.rememberMe')}
  175. /> */}
  176. </View>
  177. <TextView
  178. style={styles.linksText}
  179. onPress={() => startPage(PageList.forgotPasswordLumi)}>{$t('sign.forgotPassword')}</TextView>
  180. </View>
  181. <Button
  182. style={styles.loginButton}
  183. text={$t('sign.btnSignIn')}
  184. elevation={1.5}
  185. onClick={() => {
  186. this.onLogin()
  187. }}
  188. />
  189. </View>
  190. </View>
  191. <View style={styles.signView}>
  192. <TextView style={{color: textPrimary}}>{$t('sign.tipNewUser')}</TextView>
  193. {/* <Text
  194. style={styles.linksText}
  195. onPress={() => {
  196. startPage(PageList.register);
  197. }}
  198. >Click here to sign up</Text> */}
  199. <TextView
  200. style={styles.linksText}
  201. onPress={() => startPage(PageList.registerLumi)}>{$t('sign.registerPublicUser')}</TextView>
  202. {/* <Text
  203. style={styles.linksText}
  204. onPress={() => startPage(PageList.register, {isFleetUser: true})}>{$t('sign.registerDriverUser')}</Text> */}
  205. </View>
  206. </ScrollView>
  207. </View>
  208. );
  209. }
  210. };
  211. const styles = StyleSheet.create({
  212. container: {
  213. flex: 1,
  214. backgroundColor: colorLight
  215. },
  216. backBtn:{
  217. top: 4,
  218. left: 2,
  219. zIndex: 1,
  220. position: 'absolute'
  221. },
  222. header: {
  223. paddingTop: 22,
  224. paddingBottom: 20,
  225. paddingLeft: 32,
  226. paddingRight: 32,
  227. alignItems: 'center',
  228. backgroundColor: colorPrimary
  229. },
  230. headerImg: {
  231. width: $vw(65),
  232. height: $vw(56.118)
  233. },
  234. loginView: {
  235. padding: 16,
  236. marginTop: -24,
  237. borderTopLeftRadius: 24,
  238. borderTopRightRadius: 24,
  239. backgroundColor: colorLight
  240. },
  241. logoImg: {
  242. width:136.19,
  243. height: 42.85,
  244. marginTop: 18
  245. },
  246. loginForm: {
  247. paddingLeft: 16,
  248. paddingRight: 16,
  249. },
  250. loginTitle: {
  251. fontSize: 28,
  252. fontWeight: 'bold',
  253. color: textPrimary
  254. },
  255. inputIcon: {
  256. width: 24,
  257. height: 24
  258. },
  259. inputView: {
  260. marginTop: 30,
  261. borderRadius: 0,
  262. paddingTop: 6,
  263. paddingLeft: 16,
  264. paddingRight: 16,
  265. paddingBottom: 6,
  266. alignItems: 'center',
  267. flexDirection: 'row',
  268. borderWidth: 1,
  269. borderColor: '#DADADA',
  270. borderRadius: 4
  271. },
  272. inputText: {
  273. flex: 1,
  274. color: textPrimary,
  275. fontSize: 12,
  276. paddingTop: 6,
  277. paddingLeft: 6,
  278. paddingBottom: 6
  279. },
  280. loginButton: {
  281. marginTop: 32,
  282. borderRadius: 4,
  283. backgroundColor: colorPrimary
  284. },
  285. signView: {
  286. paddingTop: 32,
  287. paddingBottom: 16,
  288. alignItems: 'center',
  289. },
  290. checkText: {
  291. color: textPrimary,
  292. fontSize: 14,
  293. paddingLeft: 8
  294. },
  295. linksText: {
  296. ...ui.link,
  297. fontSize: 14,
  298. padding: 4,
  299. marginTop: 5,
  300. //fontWeight: 'bold',
  301. textDecorationLine: 'underline'
  302. }
  303. });