LoginScreen.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* eslint-disable no-unused-vars */
  2. /* eslint-disable camelcase */
  3. import * as WebBrowser from "expo-web-browser";
  4. import * as React from "react";
  5. import {
  6. Image,
  7. StyleSheet,
  8. View,
  9. } from "react-native";
  10. import {
  11. Layout,
  12. Tab,
  13. TabView,
  14. useTheme,
  15. Button,
  16. } from "@ui-kitten/components";
  17. import { useModel } from "flooks";
  18. import { useFocusEffect } from "@react-navigation/native";
  19. import * as RootNavigation from "../navigation/RootNavigation";
  20. import FormInput from "../components/FormInput";
  21. // import { useAndroidBackHandler } from "react-navigation-backhandler";
  22. const styles = StyleSheet.create({
  23. container: {
  24. flex: 1,
  25. alignItems: "center",
  26. justifyContent: "center",
  27. },
  28. center: {
  29. alignSelf: "stretch",
  30. marginHorizontal: 13,
  31. backgroundColor: "#fff",
  32. paddingTop: 20,
  33. paddingBottom: 10,
  34. borderRadius: 7,
  35. },
  36. tabContent: {
  37. backgroundColor: "#fff",
  38. marginTop: 20,
  39. paddingHorizontal: 9,
  40. },
  41. tabMain: {
  42. // paddingVertical: 10,
  43. width: "100%",
  44. paddingTop: 10,
  45. borderTopWidth: 1,
  46. borderColor: "#E5E5E5",
  47. },
  48. logo: {
  49. width: 217,
  50. height: 100,
  51. alignSelf: "center",
  52. },
  53. image: {
  54. width: 256,
  55. height: 100,
  56. position: "absolute",
  57. left: "50%",
  58. top: -65,
  59. marginLeft: -128,
  60. },
  61. tab: {
  62. borderBottomWidth: 1,
  63. borderColor: "#e5e5e5",
  64. marginHorizontal: 10,
  65. },
  66. tabItem: {
  67. paddingTop: 20,
  68. paddingBottom: 10,
  69. textAlign: "center",
  70. color: "#000",
  71. fontSize: 13,
  72. },
  73. tabItemActive: {
  74. paddingTop: 20,
  75. paddingBottom: 11,
  76. textAlign: "center",
  77. fontSize: 13,
  78. color: "#FFC21C",
  79. },
  80. form: {
  81. paddingTop: 10,
  82. },
  83. layoutLeft: {
  84. paddingLeft: 70,
  85. flexDirection: "row",
  86. paddingBottom: 10,
  87. },
  88. btnList: {
  89. flexDirection: "row",
  90. justifyContent: "space-between",
  91. paddingLeft: 60,
  92. marginTop: -10,
  93. marginBottom: 10,
  94. },
  95. btn: {
  96. paddingVertical: 0,
  97. },
  98. formSub: {
  99. alignItems: "flex-start",
  100. },
  101. primary: {
  102. minWidth: 112,
  103. paddingHorizontal: 10,
  104. },
  105. });
  106. const img1 = require("../assets/images/loginImg.png")
  107. const img2 = require("../assets/images/loginLogo.png")
  108. export default function LoginScreen() {
  109. const theme = useTheme();
  110. const { changeBackground } = useModel("barModel", true);
  111. const {
  112. welcom,
  113. login_tab_1,
  114. login_tab_2,
  115. login_form_1,
  116. login_pla_1,
  117. login_form_2,
  118. login_pla_2,
  119. login_form_3,
  120. login_pla_3,
  121. login_btn_sub,
  122. login_btn_forget,
  123. login_btn_rej,
  124. login_btn_code_1,
  125. login_btn_code_2,
  126. } = useModel("wordsModel");
  127. const tabs = [
  128. {
  129. value: 1,
  130. label: login_tab_1,
  131. },
  132. {
  133. value: 2,
  134. label: login_tab_2,
  135. },
  136. ];
  137. const [selectedIndex, setSelectedIndex] = React.useState(0);
  138. const [phone, changePhone] = React.useState("");
  139. const [password, changePassword] = React.useState("");
  140. const [code, changeCode] = React.useState("");
  141. const [sendNum, changeNum] = React.useState(60);
  142. const [isSend, changeSend] = React.useState(false);
  143. const canLogin = React.useMemo(() => {
  144. if (
  145. (selectedIndex === 0 && phone && password) ||
  146. (selectedIndex === 1 && phone && code)
  147. ) {
  148. return true;
  149. // eslint-disable-next-line no-else-return
  150. } else {
  151. return false;
  152. }
  153. }, [phone, password, code, selectedIndex]);
  154. const { loginByPassword, loginByCode } = useModel("userModel", true);
  155. useFocusEffect(
  156. React.useCallback(() => {
  157. changeBackground(theme["color-primary-100"]);
  158. }, [])
  159. );
  160. return (
  161. <View
  162. style={[
  163. styles.container,
  164. { backgroundColor: theme["color-primary-100"] },
  165. ]}
  166. >
  167. <View style={styles.center}>
  168. <Image
  169. source={img1}
  170. style={styles.image}
  171. />
  172. <Image
  173. source={img2}
  174. style={styles.logo}
  175. />
  176. <View style={styles.tabContent}>
  177. <TabView
  178. selectedIndex={selectedIndex}
  179. onSelect={index => setSelectedIndex(index)}
  180. indicatorStyle={{ height: 0 }}
  181. >
  182. <Tab title={login_tab_1}>
  183. <Layout style={styles.tabMain}>
  184. {/* 手机号 */}
  185. <FormInput
  186. label={`${login_form_1 }:`}
  187. value={phone}
  188. type='phone'
  189. placeholder={login_pla_1}
  190. onChange={changePhone}
  191. textAlign='right'
  192. labelStyle={{ width: 50 }}
  193. />
  194. {/* 密码 */}
  195. <FormInput
  196. label={`${login_form_2 }:`}
  197. value={password}
  198. type='password'
  199. placeholder={login_pla_2}
  200. onChange={changePassword}
  201. textAlign='right'
  202. labelStyle={{ width: 50 }}
  203. />
  204. </Layout>
  205. </Tab>
  206. <Tab title={login_tab_2}>
  207. <Layout style={styles.tabMain}>
  208. {/* 手机号 */}
  209. <FormInput
  210. label={`${login_form_1 }:`}
  211. value={phone}
  212. type='phone'
  213. placeholder={login_pla_1}
  214. onChange={changePhone}
  215. textAlign='right'
  216. labelStyle={{ width: 50 }}
  217. />
  218. {/* 验证码 */}
  219. <FormInput
  220. label={`${login_form_3 }:`}
  221. value={code}
  222. type='code'
  223. placeholder={login_pla_3}
  224. onChange={changeCode}
  225. textAlign='right'
  226. btnText={login_btn_code_1}
  227. labelStyle={{ width: 50 }}
  228. />
  229. </Layout>
  230. </Tab>
  231. </TabView>
  232. {/* 注册找回密码 */}
  233. <Layout style={styles.btnList} level='1'>
  234. <Button appearance='ghost' status='basic' size='small'>
  235. {login_btn_forget}
  236. </Button>
  237. <Button
  238. appearance='ghost'
  239. status='basic'
  240. size='tiny'
  241. onPress={() => RootNavigation.navigate("Register")}
  242. >
  243. {login_btn_rej}
  244. </Button>
  245. </Layout>
  246. {/* 登录 */}
  247. <Layout style={styles.layoutLeft} level='1'>
  248. <Button
  249. status='primary'
  250. disabled={!canLogin}
  251. onPress={() => {
  252. if (selectedIndex === 0) {
  253. loginByPassword(phone, password);
  254. } else {
  255. loginByCode(phone, code).then(_ => {});
  256. }
  257. }}
  258. >
  259. {login_btn_sub}
  260. </Button>
  261. </Layout>
  262. </View>
  263. </View>
  264. </View>
  265. );
  266. }