feat: 基础迁移完成了

This commit is contained in:
许永平
2025-07-03 18:09:07 +08:00
parent 47ff85bafa
commit 2564e3cfac
13 changed files with 989 additions and 20 deletions

View File

@@ -1,23 +1,87 @@
import React from 'react';
import logo from './logo.svg';
import React, { useState, useEffect } from 'react';
import './App.css';
import { fetchDeviceList } from '@/api/devices';
import { fetchWechatAccountList } from '@/api/wechat-accounts';
import { fetchScenes } from '@/api/scenarios';
import TestComponent from '@/components/TestComponent';
import type { Device } from '@/types/device';
import type { WechatFriend } from '@/types/wechat';
function App() {
const [devices, setDevices] = useState<any[]>([]);
const [wechatAccounts, setWechatAccounts] = useState<any[]>([]);
const [scenes, setScenes] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const testAPIs = async () => {
setLoading(true);
try {
// 测试设备API
const deviceResponse = await fetchDeviceList(1, 5);
console.log('设备API响应:', deviceResponse);
setDevices(deviceResponse.data?.list || []);
// 测试微信账号API
const wechatResponse = await fetchWechatAccountList({ page: 1, limit: 5 });
console.log('微信账号API响应:', wechatResponse);
setWechatAccounts(wechatResponse.data?.list || []);
// 测试场景API
const sceneResponse = await fetchScenes({ page: 1, limit: 5 });
console.log('场景API响应:', sceneResponse);
setScenes(sceneResponse.data || []);
} catch (error) {
console.error('API测试失败:', error);
} finally {
setLoading(false);
}
};
useEffect(() => {
// 页面加载时自动测试API
testAPIs();
}, []);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
<h1>nkebao2 - </h1>
<p>Cunkebao迁移过来的基础文件是否正常工作</p>
<TestComponent
title="路径别名测试"
className="mb-4 bg-blue-50"
/>
<button onClick={testAPIs} disabled={loading}>
{loading ? '测试中...' : '重新测试API'}
</button>
<div style={{ marginTop: '20px', textAlign: 'left', maxWidth: '800px' }}>
<h3>:</h3>
<div style={{ marginBottom: '20px' }}>
<h4>API ( {devices.length} ):</h4>
<pre style={{ fontSize: '12px', background: '#f5f5f5', padding: '10px', borderRadius: '4px' }}>
{JSON.stringify(devices.slice(0, 2), null, 2)}
</pre>
</div>
<div style={{ marginBottom: '20px' }}>
<h4>API ( {wechatAccounts.length} ):</h4>
<pre style={{ fontSize: '12px', background: '#f5f5f5', padding: '10px', borderRadius: '4px' }}>
{JSON.stringify(wechatAccounts.slice(0, 2), null, 2)}
</pre>
</div>
<div style={{ marginBottom: '20px' }}>
<h4>API ( {scenes.length} ):</h4>
<pre style={{ fontSize: '12px', background: '#f5f5f5', padding: '10px', borderRadius: '4px' }}>
{JSON.stringify(scenes.slice(0, 2), null, 2)}
</pre>
</div>
</div>
</header>
</div>
);