index.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import PageCustom from "@/components/page-custom/index";
  2. import NavBarNormal from "@/components/NavBarNormal";
  3. import { View } from "@tarojs/components";
  4. import Logo from "@/components/logo";
  5. import SummaryBar from "./components/SummaryBar";
  6. import { useAgentStore } from "@/store/agentStore";
  7. import { useEffect } from "react";
  8. import { useComponentStore } from "@/store/componentStore";
  9. import ComponentList from "@/components/component-list";
  10. import { useUserStore } from "@/store/userStore";
  11. import style from './index.module.less'
  12. interface IProps {
  13. agentId: string;
  14. }
  15. export default function Index({ agentId }: IProps) {
  16. const { fetchAgent } = useAgentStore();
  17. const agent = useAgentStore((state)=> state.agent);
  18. const { fetchMyEntList } = useUserStore();
  19. const { setComponentList } = useComponentStore()
  20. const components = useComponentStore((state) => state.components);
  21. useEffect(() => {
  22. if (agentId) {
  23. fetchAgent(agentId)
  24. }
  25. }, [agentId]);
  26. useEffect(()=> {
  27. const components = agent?.components ?? []
  28. // 过滤掉没有 id 的组件防止有错误数据
  29. setComponentList(components.filter(c => !!c.data?.id), agentId);
  30. }, [agent])
  31. useEffect(()=> {
  32. fetchMyEntList()
  33. }, [])
  34. // 自定义背景样式
  35. const bgImageStyle = {
  36. backgroundImage: `url(${agent?.avatarUrl})`,
  37. };
  38. return (
  39. <PageCustom styleBg={bgImageStyle}>
  40. <NavBarNormal leftColumn={Logo}></NavBarNormal>
  41. <View className={style.blurBg}>
  42. {(!!agent) ? <SummaryBar isVisitor={false} agent={agent}></SummaryBar> : <></>}
  43. <View className={`flex flex-col gap-12 w-full p-16`}>
  44. <ComponentList components={components}></ComponentList>
  45. </View>
  46. </View>
  47. </PageCustom>
  48. );
  49. }