ChooseAuth.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { View ,Text} from "@tarojs/components";
  2. import Buttons from '@/components/basic/Buttons'
  3. import Texts from '@/components/basic/Texts'
  4. import './ChooseAuth.scss'
  5. import { ButtonType, ComponentStatus, TextType } from "../../utils/types";
  6. import Taro, { useReady } from "@tarojs/taro";
  7. import { useDispatch, useSelector } from "react-redux";
  8. import { useEffect, useState } from "react";
  9. import { wxLogin } from "@/services/user";
  10. import { ColorType } from "@/context/themes/color";
  11. import { ChooseScenarioBtn } from "@/features/common/SpecBtns";
  12. export default function Page() {
  13. const dispatch = useDispatch();
  14. var code = '';
  15. const user = useSelector((state: any) => state.user);
  16. useEffect(() => {
  17. if (user.isLogin) {
  18. if (user.scenario_select_count > 0) {
  19. Taro.navigateBack({
  20. delta: 1
  21. })
  22. }
  23. else {
  24. Taro.redirectTo({
  25. url: '/pages/clock/ChooseScenario'
  26. })
  27. }
  28. }
  29. }, [user.isLogin])
  30. useReady(() => {
  31. if (process.env.TARO_ENV === 'weapp'){
  32. Taro.login().then(res => {
  33. code = res.code;
  34. })
  35. }
  36. })
  37. async function login() {
  38. dispatch(wxLogin(code) as any);
  39. // try {
  40. // const { encryptedData, iv } = await Taro.getUserProfile({
  41. // desc: '获取用户信息',
  42. // });
  43. // dispatch(wxLogin(code, encryptedData, iv) as any);
  44. // // 在这里处理用户信息
  45. // } catch (error) {
  46. // console.log('获取用户信息失败:', error);
  47. // }
  48. }
  49. function createAccount() {
  50. Taro.navigateTo({
  51. url: '/pages/account/Auth'
  52. })
  53. }
  54. return <View className="container choose_container">
  55. <Texts text='fast16cc' type={TextType.big} />
  56. <Text className="slogon">健康生物钟</Text>
  57. <ChooseScenarioBtn title='微信登录' onClick={login} background={ColorType.fast} />
  58. {/* <View style={{ height: 100 }} /> */}
  59. {/* <Buttons title='微信登录' onClick={login} btnStyle={{ width: 289, marginBottom: 30,backgroundColor:ColorType.fast }} /> */}
  60. {/* <Buttons title='Create account' type={ButtonType.outline} onClick={createAccount} btnStyle={{ width: 289, marginBottom: 30 }} /> */}
  61. </View>;
  62. }