私域操盘手 - 调整微信号详情页部分页面数据,使用跳转时传递的列表数据而不是接口数据
This commit is contained in:
@@ -134,6 +134,28 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
|||||||
const friendsLoadingRef = useRef<HTMLDivElement | null>(null)
|
const friendsLoadingRef = useRef<HTMLDivElement | null>(null)
|
||||||
const friendsContainerRef = useRef<HTMLDivElement | null>(null)
|
const friendsContainerRef = useRef<HTMLDivElement | null>(null)
|
||||||
|
|
||||||
|
const [initialData, setInitialData] = useState<{
|
||||||
|
avatar: string;
|
||||||
|
nickname: string;
|
||||||
|
status: "normal" | "abnormal";
|
||||||
|
wechatId: string;
|
||||||
|
deviceName: string;
|
||||||
|
} | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// 从 URL 参数中获取初始数据
|
||||||
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
|
const dataParam = searchParams.get('data');
|
||||||
|
if (dataParam) {
|
||||||
|
try {
|
||||||
|
const decodedData = JSON.parse(decodeURIComponent(dataParam));
|
||||||
|
setInitialData(decodedData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('解析初始数据失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
// 计算好友列表容器高度
|
// 计算好友列表容器高度
|
||||||
const getFriendsContainerHeight = () => {
|
const getFriendsContainerHeight = () => {
|
||||||
// 最少显示一条记录的高度,最多显示十条记录的高度
|
// 最少显示一条记录的高度,最多显示十条记录的高度
|
||||||
@@ -411,6 +433,14 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
|||||||
if (response && response.code === 200) {
|
if (response && response.code === 200) {
|
||||||
// 转换数据格式
|
// 转换数据格式
|
||||||
const transformedAccount = transformWechatAccountDetail(response)
|
const transformedAccount = transformWechatAccountDetail(response)
|
||||||
|
// 使用初始数据覆盖API返回的部分字段
|
||||||
|
if (initialData) {
|
||||||
|
transformedAccount.avatar = initialData.avatar;
|
||||||
|
transformedAccount.nickname = initialData.nickname;
|
||||||
|
transformedAccount.status = initialData.status;
|
||||||
|
transformedAccount.wechatId = initialData.wechatId;
|
||||||
|
transformedAccount.deviceName = initialData.deviceName;
|
||||||
|
}
|
||||||
setAccount(transformedAccount)
|
setAccount(transformedAccount)
|
||||||
|
|
||||||
// 如果有好友总数,更新friendsTotal状态
|
// 如果有好友总数,更新friendsTotal状态
|
||||||
@@ -425,6 +455,14 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
|||||||
})
|
})
|
||||||
// 获取失败时使用模拟数据
|
// 获取失败时使用模拟数据
|
||||||
const mockData = generateMockAccountData();
|
const mockData = generateMockAccountData();
|
||||||
|
// 使用初始数据覆盖模拟数据的部分字段
|
||||||
|
if (initialData) {
|
||||||
|
mockData.avatar = initialData.avatar;
|
||||||
|
mockData.nickname = initialData.nickname;
|
||||||
|
mockData.status = initialData.status;
|
||||||
|
mockData.wechatId = initialData.wechatId;
|
||||||
|
mockData.deviceName = initialData.deviceName;
|
||||||
|
}
|
||||||
setAccount(mockData);
|
setAccount(mockData);
|
||||||
// 更新好友总数
|
// 更新好友总数
|
||||||
setFriendsTotal(mockData.friendCount);
|
setFriendsTotal(mockData.friendCount);
|
||||||
@@ -438,6 +476,14 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
|||||||
})
|
})
|
||||||
// 请求出错时使用模拟数据
|
// 请求出错时使用模拟数据
|
||||||
const mockData = generateMockAccountData();
|
const mockData = generateMockAccountData();
|
||||||
|
// 使用初始数据覆盖模拟数据的部分字段
|
||||||
|
if (initialData) {
|
||||||
|
mockData.avatar = initialData.avatar;
|
||||||
|
mockData.nickname = initialData.nickname;
|
||||||
|
mockData.status = initialData.status;
|
||||||
|
mockData.wechatId = initialData.wechatId;
|
||||||
|
mockData.deviceName = initialData.deviceName;
|
||||||
|
}
|
||||||
setAccount(mockData);
|
setAccount(mockData);
|
||||||
// 更新好友总数
|
// 更新好友总数
|
||||||
setFriendsTotal(mockData.friendCount);
|
setFriendsTotal(mockData.friendCount);
|
||||||
@@ -447,7 +493,7 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchAccount()
|
fetchAccount()
|
||||||
}, [params.id])
|
}, [params.id, initialData])
|
||||||
|
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return <div>加载中...</div>
|
return <div>加载中...</div>
|
||||||
@@ -534,7 +580,7 @@ export default function WechatAccountDetailPage({ params }: { params: { id: stri
|
|||||||
<AvatarFallback>{account.nickname[0]}</AvatarFallback>
|
<AvatarFallback>{account.nickname[0]}</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
{account.isVerified && (
|
{account.isVerified && (
|
||||||
<Badge variant="outline" className="absolute -top-2 -right-2 px-2 py-0.5 text-xs">
|
<Badge className="absolute -top-2 -right-2 px-2 py-0.5 text-xs bg-blue-500 text-white hover:bg-blue-600">
|
||||||
已认证
|
已认证
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -256,7 +256,17 @@ export default function WechatAccountsPage() {
|
|||||||
<Card
|
<Card
|
||||||
key={account.id}
|
key={account.id}
|
||||||
className="p-4 hover:shadow-lg transition-all cursor-pointer overflow-hidden"
|
className="p-4 hover:shadow-lg transition-all cursor-pointer overflow-hidden"
|
||||||
onClick={() => router.push(`/wechat-accounts/${account.id}`)}
|
onClick={() => {
|
||||||
|
// 将需要的数据编码为 URL 安全的字符串
|
||||||
|
const accountData = encodeURIComponent(JSON.stringify({
|
||||||
|
avatar: account.avatar,
|
||||||
|
nickname: account.nickname,
|
||||||
|
status: account.status,
|
||||||
|
wechatId: account.wechatId,
|
||||||
|
deviceName: account.deviceName,
|
||||||
|
}));
|
||||||
|
router.push(`/wechat-accounts/${account.id}?data=${accountData}`);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="flex items-start space-x-4">
|
<div className="flex items-start space-x-4">
|
||||||
<Avatar className="h-12 w-12 ring-2 ring-offset-2 ring-blue-500/20">
|
<Avatar className="h-12 w-12 ring-2 ring-offset-2 ring-blue-500/20">
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use think\facade\Route;
|
|||||||
|
|
||||||
// 定义RESTful风格的API路由
|
// 定义RESTful风格的API路由
|
||||||
Route::group('v1/', function () {
|
Route::group('v1/', function () {
|
||||||
|
|
||||||
// 设备管理相关
|
// 设备管理相关
|
||||||
Route::group('devices', function () {
|
Route::group('devices', function () {
|
||||||
Route::get('add-results', 'app\cunkebao\controller\device\GetAddResultedV1Controller@index'); // 更新设备任务配置
|
Route::get('add-results', 'app\cunkebao\controller\device\GetAddResultedV1Controller@index'); // 更新设备任务配置
|
||||||
@@ -24,10 +23,13 @@ Route::group('v1/', function () {
|
|||||||
// 设备微信相关
|
// 设备微信相关
|
||||||
Route::group('device/wechats', function () {
|
Route::group('device/wechats', function () {
|
||||||
Route::get('', 'app\cunkebao\controller\wechat\GetWechatsOnDevicesV1Controller@index'); // 获取在线微信账号列表
|
Route::get('', 'app\cunkebao\controller\wechat\GetWechatsOnDevicesV1Controller@index'); // 获取在线微信账号列表
|
||||||
|
Route::get(':id', 'app\cunkebao\controller\wechat\GetWechatOnDeviceSummarizeV1Controller@index'); // 获取微信号详情
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Route::get('friends', 'app\cunkebao\controller\DeviceWechat@getFriends'); // 获取微信好友列表
|
Route::get('friends', 'app\cunkebao\controller\DeviceWechat@getFriends'); // 获取微信好友列表
|
||||||
Route::get('count', 'app\cunkebao\controller\DeviceWechat@count'); // 获取在线微信账号数量
|
Route::get('count', 'app\cunkebao\controller\DeviceWechat@count'); // 获取在线微信账号数量
|
||||||
Route::get('device-count', 'app\cunkebao\controller\DeviceWechat@deviceCount'); // 获取有登录微信的设备数量
|
Route::get('device-count', 'app\cunkebao\controller\DeviceWechat@deviceCount'); // 获取有登录微信的设备数量
|
||||||
Route::get(':id', 'app\cunkebao\controller\DeviceWechat@detail'); // 获取微信号详情
|
|
||||||
Route::put('refresh', 'app\cunkebao\controller\DeviceWechat@refresh'); // 刷新设备微信状态
|
Route::put('refresh', 'app\cunkebao\controller\DeviceWechat@refresh'); // 刷新设备微信状态
|
||||||
Route::post('transfer-friends', 'app\cunkebao\controller\DeviceWechat@transferFriends'); // 微信好友转移
|
Route::post('transfer-friends', 'app\cunkebao\controller\DeviceWechat@transferFriends'); // 微信好友转移
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\cunkebao\controller\wechat;
|
||||||
|
|
||||||
|
use app\common\model\WechatAccount as WechatAccountModel;
|
||||||
|
use app\cunkebao\controller\BaseController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备微信控制器
|
||||||
|
*/
|
||||||
|
class GetWechatOnDeviceSummarizeV1Controller extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function getRegisterDate()
|
||||||
|
{
|
||||||
|
return date('Y-m-d');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected function getWechatAccount()
|
||||||
|
{
|
||||||
|
$aa = WechatAccountModel::find($this->request->param('id/d'));
|
||||||
|
|
||||||
|
|
||||||
|
dd(
|
||||||
|
|
||||||
|
$aa->toArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信号详情
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$this->getWechatAccount();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 获取微信号基本信息
|
||||||
|
$wechat = WechatAccountModel::where('id', $id)
|
||||||
|
->where('isDeleted', 0)
|
||||||
|
->find();
|
||||||
|
|
||||||
|
if (!$wechat) {
|
||||||
|
return json([
|
||||||
|
'code' => 404,
|
||||||
|
'msg' => '微信号不存在'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算账号年龄(从创建时间到现在)
|
||||||
|
$accountAge = 0;
|
||||||
|
if ($wechat['createTime']) {
|
||||||
|
$createTime = strtotime($wechat['createTime']);
|
||||||
|
$now = time();
|
||||||
|
$accountAge = floor(($now - $createTime) / (24 * 3600));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算活跃程度(根据消息数)
|
||||||
|
$activityLevel = '低';
|
||||||
|
if ($wechat['thirtyDayMsgCount'] > 1000) {
|
||||||
|
$activityLevel = '高';
|
||||||
|
} elseif ($wechat['thirtyDayMsgCount'] > 500) {
|
||||||
|
$activityLevel = '中';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 评估账号权重(示例算法)
|
||||||
|
$weight = 0;
|
||||||
|
// 基础权重
|
||||||
|
$weight += 10;
|
||||||
|
// 好友数量权重
|
||||||
|
$weight += min($wechat['totalFriend'] / 100, 20);
|
||||||
|
// 活跃度权重
|
||||||
|
$weight += min($wechat['thirtyDayMsgCount'] / 100, 20);
|
||||||
|
// 账号年龄权重
|
||||||
|
$weight += min($accountAge / 30, 10);
|
||||||
|
// 在线状态权重
|
||||||
|
if ($wechat['wechatAlive']) {
|
||||||
|
$weight += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取限制记录(示例数据,实际需要从数据库获取)
|
||||||
|
$restrictions = [
|
||||||
|
[
|
||||||
|
'type' => '添加好友限制',
|
||||||
|
'reason' => '频繁添加好友',
|
||||||
|
'startTime' => date('Y-m-d H:i:s', strtotime('-1 day')),
|
||||||
|
'endTime' => date('Y-m-d H:i:s', strtotime('+1 day'))
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
// 处理返回数据
|
||||||
|
$data = [
|
||||||
|
'basicInfo' => [
|
||||||
|
'id' => $wechat['id'],
|
||||||
|
'wechatId' => $wechat['wechatId'],
|
||||||
|
'nickname' => $wechat['nickname'] ?: $wechat['accountNickname'],
|
||||||
|
'avatar' => $wechat['avatar'],
|
||||||
|
'status' => $wechat['wechatAlive'] ? '在线' : '离线',
|
||||||
|
'deviceStatus' => $wechat['deviceAlive'] ? '在线' : '离线',
|
||||||
|
'deviceInfo' => $wechat['imei'] . ($wechat['deviceMemo'] ? " ({$wechat['deviceMemo']})" : ''),
|
||||||
|
'gender' => $wechat['gender'],
|
||||||
|
'region' => $wechat['region'],
|
||||||
|
'signature' => $wechat['signature']
|
||||||
|
],
|
||||||
|
'statistics' => [
|
||||||
|
'totalFriend' => $wechat['totalFriend'],
|
||||||
|
'maleFriend' => $wechat['maleFriend'],
|
||||||
|
'femaleFriend' => $wechat['femaleFriend'],
|
||||||
|
'canAddFriendCount' => 30 - (isset($wechat['yesterdayMsgCount']) ? intval($wechat['yesterdayMsgCount']) : 0),
|
||||||
|
'yesterdayMsgCount' => $wechat['yesterdayMsgCount'],
|
||||||
|
'sevenDayMsgCount' => $wechat['sevenDayMsgCount'],
|
||||||
|
'thirtyDayMsgCount' => $wechat['thirtyDayMsgCount']
|
||||||
|
],
|
||||||
|
'accountInfo' => [
|
||||||
|
'age' => $accountAge,
|
||||||
|
'activityLevel' => $activityLevel,
|
||||||
|
'weight' => round($weight, 2),
|
||||||
|
'createTime' => $wechat['createTime'],
|
||||||
|
'lastUpdateTime' => $wechat['updateTime']
|
||||||
|
],
|
||||||
|
'restrictions' => $restrictions,
|
||||||
|
];
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => 200,
|
||||||
|
'msg' => '获取成功',
|
||||||
|
'data' => $data
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return json([
|
||||||
|
'code' => 500,
|
||||||
|
'msg' => '获取失败:' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user