LoginScreen.js 8.6 KB

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