|
@@ -1,65 +1,57 @@
|
|
|
import { View, Text, } from "@tarojs/components";
|
|
|
-import Taro, { useDidShow } from "@tarojs/taro";
|
|
|
+import Taro, { useDidShow, useReachBottom } from "@tarojs/taro";
|
|
|
import NavBarNormal from "@/components/NavBarNormal/index";
|
|
|
import PageCustom from "@/components/page-custom/index";
|
|
|
import IconArrowDownRounded from '@/components/icon/IconArrowDownRounded';
|
|
|
import DataCard from './components/DataCard'
|
|
|
import VisitorList from "./components/VisitorList";
|
|
|
-import PickerSingleColumn from "@/components/Picker/PickerSingleColumn";
|
|
|
+import AgentList from "./components/AgentList";
|
|
|
import { useEffect, useState } from "react";
|
|
|
import { useAgentStore } from "@/store/agentStore";
|
|
|
import { getVisitorSummary, type TVisitorSummary } from '@/service/visitor'
|
|
|
import { isSuccess } from "@/utils";
|
|
|
+import { TAgent } from "@/types/agent";
|
|
|
+import eventBus, {BUS_EVENTS} from '@/utils/EventBus'
|
|
|
|
|
|
export default () => {
|
|
|
|
|
|
const {agents, fetchAgents} = useAgentStore()
|
|
|
|
|
|
-
|
|
|
+ const [show, setShow] = useState(false);
|
|
|
// 是否显示选择器
|
|
|
- const [showPicker, setShowPicker] = useState(false)
|
|
|
+ const [currentAgent, setCurrentAgent] = useState<TAgent|null>(null)
|
|
|
const [summary, setSummary] = useState<TVisitorSummary>()
|
|
|
|
|
|
- // 当前选中的值
|
|
|
- const [selected, setSelected] = useState<string>();
|
|
|
- const currentAgent = agents.find( _agent => _agent.name === selected)
|
|
|
|
|
|
- const onPicked = (value: string) => {
|
|
|
- setSelected(value)
|
|
|
+ const fetchSummary = async () => {
|
|
|
+ const response = await getVisitorSummary(currentAgent?.agentId)
|
|
|
+ if(isSuccess(response.status)){
|
|
|
+ setSummary(response.data)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- useDidShow(()=> {
|
|
|
+ const fetchInitData = async () => {
|
|
|
+ await fetchAgents();
|
|
|
+ fetchSummary()
|
|
|
|
|
|
- fetchInitData()
|
|
|
- })
|
|
|
-
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- setSelected('全部智能体')
|
|
|
- }, [])
|
|
|
useEffect(() => {
|
|
|
-
|
|
|
- }, [])
|
|
|
-
|
|
|
+ fetchSummary()
|
|
|
+ }, [currentAgent])
|
|
|
|
|
|
- const fetchInitData = async () => {
|
|
|
- await fetchAgents();
|
|
|
- const currentAgent = agents.find( _agent => _agent.name === selected)
|
|
|
- const response = await getVisitorSummary(currentAgent?.agentId)
|
|
|
- if(isSuccess(response.status)){
|
|
|
- setSummary(response.data)
|
|
|
- }
|
|
|
- }
|
|
|
+ useDidShow(()=> {
|
|
|
+ fetchInitData()
|
|
|
+ })
|
|
|
|
|
|
|
|
|
|
|
|
- if(!agents || !selected) {
|
|
|
+ if(!agents) {
|
|
|
return <View>...</View>
|
|
|
}
|
|
|
-
|
|
|
- const options = ['全部智能体', ...agents.map(_agent => _agent.name)]
|
|
|
-
|
|
|
+ useReachBottom(() => {
|
|
|
+ eventBus.trigger(BUS_EVENTS.REACH_BOTTOM)
|
|
|
+ })
|
|
|
const unprocessedDislikeCnt = summary?.unprocessedDislikeCnt ?? 0
|
|
|
|
|
|
return (
|
|
@@ -67,16 +59,20 @@ export default () => {
|
|
|
<NavBarNormal scrollFadeIn leftColumn={()=> <Text className="font-medium text-dark leading-22 text-16">数据分析</Text>}>
|
|
|
</NavBarNormal>
|
|
|
<View className="w-full pt-8 px-16 pb-40">
|
|
|
- {(!!options.length && !!selected) &&
|
|
|
- <PickerSingleColumn options={options} selected={selected} onPicked={onPicked} showPicker={showPicker} setShowPicker={setShowPicker}>
|
|
|
- <View className="flex items-center gap-2 bg-white rounded-12 p-12 mb-16" onClick={() => setShowPicker(true)}>
|
|
|
- <View className="flex-1 text-14 leading-22 text-gray-45">{selected}</View>
|
|
|
+ <View className="flex items-center gap-8 mb-16">
|
|
|
+ <View className="bg-white rounded-12 py-12 px-16" onClick={()=> setCurrentAgent(null)}>
|
|
|
+ <View className={`${currentAgent ? 'text-gray-45' : 'text-black' }`}>全部</View>
|
|
|
+ </View>
|
|
|
+ <View className="flex flex-1 items-center gap-2 bg-white rounded-12 p-12" onClick={()=> setShow(true)}>
|
|
|
+ <View className="flex-1 text-14 leading-22">
|
|
|
+ {currentAgent ? <View className="text-black">{currentAgent?.name}</View> : <View className="text-gray-45">请选择智能体</View> }
|
|
|
+ </View>
|
|
|
+
|
|
|
<View className="flex-center">
|
|
|
<IconArrowDownRounded/>
|
|
|
</View>
|
|
|
</View>
|
|
|
- </PickerSingleColumn>
|
|
|
- }
|
|
|
+ </View>
|
|
|
|
|
|
<View className="grid grid-cols-2 gap-8 bg-white rounded-12 p-12 mb-12">
|
|
|
<DataCard text="今日访问次数" unitText="次" value={summary?.todayPv ?? 0} />
|
|
@@ -97,7 +93,9 @@ export default () => {
|
|
|
</View>
|
|
|
|
|
|
<VisitorList agentId={currentAgent?.agentId}></VisitorList>
|
|
|
-
|
|
|
+
|
|
|
+ <AgentList show={show} setShow={setShow} currentAgent={currentAgent} setCurrentAgent={setCurrentAgent}></AgentList>
|
|
|
+
|
|
|
</View>
|
|
|
|
|
|
</PageCustom>
|