import Inputs from "@/components/input/Inputs"; import { View, Text, Image } from "@tarojs/components"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import check from '@/assets/svg/check.svg' import Texts from "@/components/basic/Texts"; import Box from "@/components/layout/Box"; import { ComponentStatus, TextType } from "@/utils/types"; import Buttons from "@/components/basic/Buttons"; import './Auth.scss' import { clientId, login } from "@/services/user"; import { useDispatch, useSelector } from "react-redux"; import Taro from "@tarojs/taro"; import { ColorType } from "@/context/themes/color"; import { loginSuccess } from "@/store/user"; let useNavigation; if (process.env.TARO_ENV == 'rn') { useNavigation = require("@react-navigation/native").useNavigation } export default function Login(props: { register: () => void }) { const { t } = useTranslation() const dispatch = useDispatch(); const [name, setName] = useState(''); const [password, setPassword] = useState(''); const user = useSelector((state: any) => state.user); let navigation; if (useNavigation) { navigation = useNavigation() } useEffect(() => { if (user.isLogin) { if (process.env.TARO_ENV=='rn'){ navigation.pop(2) return } if (user.scenario_select_count > 0) { Taro.navigateBack({ delta: 2 }) } else { Taro.navigateBack({ delta: 1 }) Taro.redirectTo({ url: '/pages/clock/ChooseScenario' }) } } }, [user.isLogin]) const handleNameChange = (value: string) => { setName(value); }; const handlePasswordChange = (value: string) => { setPassword(value); } const isLoginButtonDisabled = name === '' || password === ''; function loginComponent() { return { }} placeholder={t('feature.auth.login.input_account_placeholder')}> { }} placeholder={t('feature.auth.login.input_password_placeholder')}> } function LoginF() { if (isLoginButtonDisabled) { return; } login(name, password).then(res => { dispatch(loginSuccess(res)) clientId() // navigation.goBack(3) }).catch(e => { // alert(e.data.error_message) // alert(''+JSON.stringify(e)) Taro.showToast({ icon:'none', title:e.error_message }) console.log('error',e) }) // dispatch(login(name, password) as any); } return { loginComponent() } {t('page.auth.agreement')} {t('feature.auth.login.footer_desc')} props.register()}>{t('feature.auth.login.footer_sign_up')} return {/* */} {/* {t('page.auth.agreement')} */} {t('feature.auth.login.footer_desc')} props.register()}>{t('feature.auth.login.footer_sign_up')} }