LoginVL.js 8.5 KB

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