import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { DetailsTab, useQueryViewStore } from '../store'; import { useShallow } from 'zustand/shallow'; import { useStudioStore, filterRouteInfo, getPayload } from '@/pages/studio/store'; import { QueryView } from '..'; import { useCallback, useMemo, useState } from 'react'; import { pickRouterViewData, RouterViewData, RouterViewItem } from '@kevisual/api/proxy'; import { RouteInfo, fromJSONSchema } from '@kevisual/router/browser'; import { pick } from 'es-toolkit'; import { toast } from 'sonner'; import { Play } from 'lucide-react'; // 视图信息表格组件 export const ViewInfoTable = ({ currentView }: { currentView?: RouterViewData }) => { if (!currentView || !currentView.views || currentView.views.length === 0) { return (
当前视图没有子视图信息
); } return (
{/* 当前选中的视图 ID */} {currentView.viewId && (
{currentView.viewId}
)} {/* Link */} {currentView.link && (
{currentView.link}
)} {/* Summary */} {currentView.summary && (
{currentView.summary}
)} {/* Tags */} {currentView.tags && currentView.tags.length > 0 && (
{currentView.tags.map((tag: string, index: number) => ( {tag} ))}
)} {/* Title */} {currentView.title && (
{currentView.title}
)} {/* Description */} {currentView.description && (
{currentView.description}
)} {/* 子视图列表表格 */}
{currentView.views.map((view: any, index: number) => { const isSelected = view.id === currentView.viewId; return ( ); })}
ID 标题 查询
{view.id || '-'} {isSelected && ( 当前 )}
{view.title || '-'} {view.query || '-'}
); }; export const DetailsInfoPanel = ({ detailsData }: { detailsData: RouterViewItem | null }) => { const queryViewStore = useQueryViewStore(useShallow((state) => ({ editing: state.editing, setEditing: state.setEditing, setDetailsData: state.setDetailsData, setDetailsActiveTab: state.setDetailsActiveTab }))); const studioStore = useStudioStore(useShallow((state) => ({ queryProxy: state.queryProxy, }))); if (!detailsData) { return (
无法获取详情信息
); } const [action, setAction] = useState(detailsData.action ? JSON.stringify(detailsData.action, null, 2) : ''); const otherFilds = useMemo(() => { const { type } = detailsData; if (type === 'api') { {/* 其他字段 */ } return <>{ detailsData.api && (
                {JSON.stringify(detailsData.api, null, 2)}
              
) } } if (type === 'context') { return <>{ detailsData.context && (
                {JSON.stringify(detailsData.context, null, 2)}
              
) } } if (type === 'page') { return <>{ detailsData.page && (
                {JSON.stringify(detailsData.page, null, 2)}
              
) } } return null; }, [detailsData]); const onRun = useCallback(async () => { let _action = detailsData?.action; const isEditing = queryViewStore.editing; if (isEditing) { try { _action = JSON.parse(action as string); } catch (error) { toast.error('操作信息必须是合法的 JSON 格式'); return; } } if (!_action) { toast.error('没有操作信息可供执行'); return; } if (!studioStore.queryProxy) { toast.error('没有可用的查询代理,无法执行操作'); return; } const payload = getPayload(_action as any); const res = await studioStore.queryProxy.run({ ..._action, // @ts-ignore payload, }) console.log('执行结果', res); if (res?.code === 200) { queryViewStore.setDetailsData({ ...detailsData, action: _action, response: res, }); toast.success('操作执行成功', { action: { label: '查看数据', onClick: () => queryViewStore.setDetailsActiveTab('response'), }, closeButton: true, duration: 2000, position: 'top-center', }); } else { toast.error(`操作执行失败: ${res?.message || '未知错误'}`); } }, [queryViewStore.editing, studioStore.queryProxy, action]); const runCom = ( ) const editCom = (<> {queryViewStore.editing && } ) return (
{/* Type */} {detailsData.type && (
{detailsData.type}
)} {/* Title */} {detailsData.title && (
{detailsData.title}
)} {/* Description */} {detailsData.description && (
{detailsData.description}
)} {/* Action */} {!queryViewStore.editing && detailsData.action && (
操作 {runCom} {editCom}
 queryViewStore.setEditing(true)}>
              {JSON.stringify(detailsData.action, null, 2)}
            
)} {queryViewStore.editing && (
操作 {runCom} {editCom}