index.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { useEffect, useState } from "react";
  2. import { View,Image } from "@tarojs/components";
  3. import Taro, { useDidShow, useReady } from "@tarojs/taro";
  4. import NavBarNormal from "@/components/NavBarNormal/index";
  5. import LogoImage from '@/images/logo.png'
  6. import PageCustom from "@/components/page-custom/index";
  7. import { UserInfoResponse } from '@/xiaolanbenlib/api/auth'
  8. import { onLogout, useIsLogin } from '@/xiaolanbenlib/hooks/data/useAuth'
  9. import refreshUserId, { clearUserInfo, getOpenIdAsync } from '@/xiaolanbenlib/utils/auth'
  10. import WelcomeTips from '../WelcomeTips/index'
  11. import { useAgentStore } from '@/store/agentStore'
  12. import { useSystemStore } from '@/store/systemStore'
  13. import { TAgent } from "@/types/agent";
  14. import { useUserStore } from "@/store/userStore";
  15. interface IProps {
  16. // setDefault: (agent: TAgent) => void
  17. }
  18. export default function Index({}: IProps) {
  19. const [userInfo, setUserInfo] = useState<UserInfoResponse>()
  20. const isLogin = useIsLogin()
  21. const {fetchAgents} = useAgentStore()
  22. const { fetchSysCoreCnf } = useSystemStore()
  23. const { fetchtMyInfo } = useUserStore()
  24. async function initUserInfo() {
  25. await refreshUserId()
  26. .then( async (value) => {
  27. setUserInfo(value)
  28. getOpenIdAsync().then((openId) => {
  29. console.log('🚀 ~ getOpenIdAsync ~ value:', openId)
  30. })
  31. })
  32. .catch((error) => {
  33. if (error.message === 'unauthorized' || error.code === 401) {
  34. Taro.showToast({
  35. title: '未登录',
  36. icon: 'none',
  37. duration: 2000,
  38. })
  39. }
  40. })
  41. await fetchSysCoreCnf()
  42. await fetchtMyInfo()
  43. // 获取智能体
  44. await fetchAgents()
  45. }
  46. useEffect(() => {
  47. if (isLogin) {
  48. initUserInfo()
  49. }
  50. }, [isLogin])
  51. const renderLogo = ()=> {
  52. return <View><Image className="w-68 h-24" src={LogoImage}></Image></View>
  53. }
  54. return (
  55. <PageCustom>
  56. <NavBarNormal leftColumn={renderLogo}></NavBarNormal>
  57. <View className="relative w-full">
  58. <WelcomeTips></WelcomeTips>
  59. </View>
  60. </PageCustom>
  61. );
  62. }