存客宝 - 前端存储登录数据额外返回的 s2_accountId 字段参数,用于操盘手添加设备
This commit is contained in:
@@ -171,8 +171,6 @@ export default function DevicesPage() {
|
|||||||
setIsLoadingQRCode(true)
|
setIsLoadingQRCode(true)
|
||||||
setQrCodeImage("") // 清空当前二维码
|
setQrCodeImage("") // 清空当前二维码
|
||||||
|
|
||||||
console.log("正在请求二维码...");
|
|
||||||
|
|
||||||
// 发起请求获取二维码 - 直接使用fetch避免api工具添加基础URL
|
// 发起请求获取二维码 - 直接使用fetch避免api工具添加基础URL
|
||||||
const response = await fetch('http://yi.54word.com/v1/api/device/add', {
|
const response = await fetch('http://yi.54word.com/v1/api/device/add', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -183,8 +181,6 @@ export default function DevicesPage() {
|
|||||||
body: JSON.stringify({})
|
body: JSON.stringify({})
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log("二维码请求响应状态:", response.status);
|
|
||||||
|
|
||||||
// 保存原始响应文本以便调试
|
// 保存原始响应文本以便调试
|
||||||
const responseText = await response.text();
|
const responseText = await response.text();
|
||||||
console.log("原始响应内容:", responseText);
|
console.log("原始响应内容:", responseText);
|
||||||
@@ -499,6 +495,43 @@ export default function DevicesPage() {
|
|||||||
router.push(`/devices/${deviceId}`);
|
router.push(`/devices/${deviceId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理添加设备
|
||||||
|
const handleAddDevice = async () => {
|
||||||
|
try {
|
||||||
|
const s2_accountId = localStorage.getItem('s2_accountId');
|
||||||
|
if (!s2_accountId) {
|
||||||
|
toast.error('未获取到用户信息,请重新登录');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch('/api/devices', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
imei: deviceImei,
|
||||||
|
memo: deviceName,
|
||||||
|
s2_accountId: s2_accountId,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
if (data.code === 200) {
|
||||||
|
toast.success('添加设备成功');
|
||||||
|
setIsAddDeviceOpen(false);
|
||||||
|
// 刷新设备列表
|
||||||
|
loadDevices(1, true);
|
||||||
|
} else {
|
||||||
|
toast.error(data.msg || '添加设备失败');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('添加设备失败:', error);
|
||||||
|
toast.error('添加设备失败,请稍后重试');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex-1 bg-gray-50 min-h-screen">
|
<div className="flex-1 bg-gray-50 min-h-screen">
|
||||||
<header className="sticky top-0 z-10 bg-white border-b">
|
<header className="sticky top-0 z-10 bg-white border-b">
|
||||||
@@ -748,15 +781,10 @@ export default function DevicesPage() {
|
|||||||
取消
|
取消
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleAddDeviceByImei}
|
onClick={handleAddDevice}
|
||||||
disabled={isSubmittingImei || !deviceImei.trim()}
|
disabled={!deviceImei.trim() || !deviceName.trim()}
|
||||||
>
|
>
|
||||||
{isSubmittingImei ? (
|
添加
|
||||||
<>
|
|
||||||
<div className="w-4 h-4 mr-2 rounded-full border-2 border-white border-t-transparent animate-spin"></div>
|
|
||||||
提交中...
|
|
||||||
</>
|
|
||||||
) : "添加"}
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -98,17 +98,14 @@ export default function LoginPage() {
|
|||||||
const response = await loginApi.login(form.phone, form.password)
|
const response = await loginApi.login(form.phone, form.password)
|
||||||
|
|
||||||
if (response.code === 200 && response.data) {
|
if (response.code === 200 && response.data) {
|
||||||
// 获取用户信息和token
|
// 保存登录信息
|
||||||
const { token, token_expired, member } = response.data
|
localStorage.setItem('token', response.data.token)
|
||||||
|
localStorage.setItem('token_expired', response.data.token_expired)
|
||||||
|
localStorage.setItem('s2_accountId', response.data.member.s2_accountId)
|
||||||
|
|
||||||
|
// 保存用户信息
|
||||||
|
localStorage.setItem('userInfo', JSON.stringify(response.data.member))
|
||||||
|
|
||||||
// 保存token和用户信息
|
|
||||||
login(token, {
|
|
||||||
id: member.id,
|
|
||||||
username: member.username || member.account || '',
|
|
||||||
account: member.account,
|
|
||||||
avatar: member.avatar
|
|
||||||
})
|
|
||||||
|
|
||||||
// 显示成功提示
|
// 显示成功提示
|
||||||
toast({
|
toast({
|
||||||
title: "登录成功",
|
title: "登录成功",
|
||||||
|
|||||||
Reference in New Issue
Block a user