保险前后端,养殖端和保险端小程序
This commit is contained in:
@@ -319,60 +319,73 @@ const fetchData = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
|
||||
// 模拟数据
|
||||
const mockData = [
|
||||
{
|
||||
id: 1,
|
||||
deviceId: 'AN001',
|
||||
animalName: '牛001',
|
||||
model: 'SmartAnklet-V1',
|
||||
status: 'active',
|
||||
stepCount: 2456,
|
||||
heartRate: 75,
|
||||
temperature: 38.5,
|
||||
lastUpdate: '2025-01-18 10:30:00'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
deviceId: 'AN002',
|
||||
animalName: '牛002',
|
||||
model: 'SmartAnklet-V1',
|
||||
status: 'standby',
|
||||
stepCount: 1823,
|
||||
heartRate: 68,
|
||||
temperature: 38.2,
|
||||
lastUpdate: '2025-01-18 09:15:00'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
deviceId: 'AN003',
|
||||
animalName: '羊001',
|
||||
model: 'SmartAnklet-V2',
|
||||
status: 'active',
|
||||
stepCount: 3124,
|
||||
heartRate: 82,
|
||||
temperature: 39.1,
|
||||
lastUpdate: '2025-01-18 10:25:00'
|
||||
// 构建查询参数
|
||||
const params = new URLSearchParams({
|
||||
page: pagination.current.toString(),
|
||||
limit: pagination.pageSize.toString(),
|
||||
_t: Date.now().toString()
|
||||
})
|
||||
|
||||
// 添加搜索条件
|
||||
if (searchValue.value.trim()) {
|
||||
params.append('search', searchValue.value.trim())
|
||||
}
|
||||
|
||||
// 调用API获取脚环数据
|
||||
const response = await fetch(`/api/smart-devices/public/anklets?${params}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
anklets.value = mockData
|
||||
pagination.total = mockData.length
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`)
|
||||
}
|
||||
|
||||
// 更新统计数据
|
||||
stats.total = mockData.length
|
||||
stats.active = mockData.filter(item => item.status === 'active').length
|
||||
stats.standby = mockData.filter(item => item.status === 'standby').length
|
||||
stats.fault = mockData.filter(item => item.status === 'fault').length
|
||||
const result = await response.json()
|
||||
|
||||
if (result.success) {
|
||||
anklets.value = result.data.list || []
|
||||
pagination.total = result.data.pagination?.total || 0
|
||||
|
||||
// 更新统计数据
|
||||
if (result.data.stats) {
|
||||
stats.total = result.data.stats.total || 0
|
||||
stats.active = result.data.stats.active || 0
|
||||
stats.standby = result.data.stats.standby || 0
|
||||
stats.fault = result.data.stats.fault || 0
|
||||
} else {
|
||||
// 如果没有统计数据,从数据中计算
|
||||
stats.total = anklets.value.length
|
||||
stats.active = anklets.value.filter(item => item.status === 'active').length
|
||||
stats.standby = anklets.value.filter(item => item.status === 'standby').length
|
||||
stats.fault = anklets.value.filter(item => item.status === 'fault').length
|
||||
}
|
||||
} else {
|
||||
throw new Error(result.message || '获取脚环数据失败')
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('获取数据失败:', error)
|
||||
message.error('获取数据失败')
|
||||
message.error('获取数据失败: ' + error.message)
|
||||
anklets.value = []
|
||||
pagination.total = 0
|
||||
resetStats()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 重置统计信息
|
||||
const resetStats = () => {
|
||||
stats.total = 0
|
||||
stats.active = 0
|
||||
stats.standby = 0
|
||||
stats.fault = 0
|
||||
}
|
||||
|
||||
// 刷新数据
|
||||
const refreshData = () => {
|
||||
fetchData()
|
||||
|
||||
@@ -537,90 +537,81 @@ const fetchData = async (showMessage = false, customAlertType = null) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 生成模拟数据
|
||||
const generateMockData = () => {
|
||||
const mockAlerts = [
|
||||
{
|
||||
id: 1,
|
||||
collarNumber: 'COLLAR001',
|
||||
alertType: 'battery',
|
||||
alertLevel: 'high',
|
||||
alertTime: '2025-01-18 10:30:00',
|
||||
battery: 12,
|
||||
temperature: 38.5,
|
||||
gpsSignal: '弱',
|
||||
wearStatus: '已佩戴',
|
||||
description: '设备电量低于20%,需要及时充电',
|
||||
longitude: 116.3974,
|
||||
latitude: 39.9093
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
collarNumber: 'COLLAR002',
|
||||
alertType: 'offline',
|
||||
alertLevel: 'high',
|
||||
alertTime: '2025-01-18 09:15:00',
|
||||
battery: 0,
|
||||
temperature: 0,
|
||||
gpsSignal: '无',
|
||||
wearStatus: '未知',
|
||||
description: '设备已离线超过30分钟',
|
||||
longitude: 0,
|
||||
latitude: 0
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
collarNumber: 'COLLAR003',
|
||||
alertType: 'temperature',
|
||||
alertLevel: 'medium',
|
||||
alertTime: '2025-01-18 08:45:00',
|
||||
battery: 85,
|
||||
temperature: 42.3,
|
||||
gpsSignal: '强',
|
||||
wearStatus: '已佩戴',
|
||||
description: '设备温度异常,超过正常范围',
|
||||
longitude: 116.4074,
|
||||
latitude: 39.9193
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
collarNumber: 'COLLAR004',
|
||||
alertType: 'location',
|
||||
alertLevel: 'high',
|
||||
alertTime: '2025-01-18 07:20:00',
|
||||
battery: 92,
|
||||
temperature: 39.1,
|
||||
gpsSignal: '无',
|
||||
wearStatus: '已佩戴',
|
||||
description: 'GPS信号丢失,无法获取位置信息',
|
||||
longitude: 0,
|
||||
latitude: 0
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
collarNumber: 'COLLAR005',
|
||||
alertType: 'wear',
|
||||
alertLevel: 'medium',
|
||||
alertTime: '2025-01-18 06:10:00',
|
||||
battery: 78,
|
||||
temperature: 37.8,
|
||||
gpsSignal: '中',
|
||||
wearStatus: '未佩戴',
|
||||
description: '设备佩戴状态异常,可能已脱落',
|
||||
longitude: 116.4174,
|
||||
latitude: 39.9293
|
||||
// 从API获取预警数据
|
||||
const fetchAlertData = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
|
||||
// 构建查询参数
|
||||
const params = new URLSearchParams({
|
||||
page: pagination.current.toString(),
|
||||
limit: pagination.pageSize.toString(),
|
||||
_t: Date.now().toString()
|
||||
})
|
||||
|
||||
// 添加筛选条件
|
||||
if (searchValue.value.trim()) {
|
||||
params.append('search', searchValue.value.trim())
|
||||
}
|
||||
]
|
||||
|
||||
alerts.value = mockAlerts
|
||||
pagination.total = mockAlerts.length
|
||||
|
||||
// 更新统计数据
|
||||
stats.lowBattery = mockAlerts.filter(alert => alert.alertType === 'battery').length
|
||||
stats.offline = mockAlerts.filter(alert => alert.alertType === 'offline').length
|
||||
stats.highTemperature = mockAlerts.filter(alert => alert.alertType === 'temperature').length
|
||||
stats.abnormalMovement = mockAlerts.filter(alert => alert.alertType === 'movement').length
|
||||
stats.wearOff = mockAlerts.filter(alert => alert.alertType === 'wear').length
|
||||
if (alertTypeFilter.value) {
|
||||
params.append('alertType', alertTypeFilter.value)
|
||||
}
|
||||
|
||||
// 调用API获取预警数据
|
||||
const response = await fetch(`/api/smart-alerts/public/collar?${params}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`
|
||||
}
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`)
|
||||
}
|
||||
|
||||
const result = await response.json()
|
||||
|
||||
if (result.success) {
|
||||
alerts.value = result.data.list || []
|
||||
pagination.total = result.data.pagination?.total || 0
|
||||
|
||||
// 更新统计数据
|
||||
if (result.data.stats) {
|
||||
stats.lowBattery = result.data.stats.lowBattery || 0
|
||||
stats.offline = result.data.stats.offline || 0
|
||||
stats.highTemperature = result.data.stats.highTemperature || 0
|
||||
stats.abnormalMovement = result.data.stats.abnormalMovement || 0
|
||||
stats.wearOff = result.data.stats.wearOff || 0
|
||||
} else {
|
||||
// 如果没有统计数据,从数据中计算
|
||||
stats.lowBattery = alerts.value.filter(alert => alert.alertType === 'battery').length
|
||||
stats.offline = alerts.value.filter(alert => alert.alertType === 'offline').length
|
||||
stats.highTemperature = alerts.value.filter(alert => alert.alertType === 'temperature').length
|
||||
stats.abnormalMovement = alerts.value.filter(alert => alert.alertType === 'movement').length
|
||||
stats.wearOff = alerts.value.filter(alert => alert.alertType === 'wear').length
|
||||
}
|
||||
} else {
|
||||
throw new Error(result.message || '获取预警数据失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取预警数据失败:', error)
|
||||
message.error('获取预警数据失败: ' + error.message)
|
||||
alerts.value = []
|
||||
pagination.total = 0
|
||||
resetStats()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 重置统计信息
|
||||
const resetStats = () => {
|
||||
stats.lowBattery = 0
|
||||
stats.offline = 0
|
||||
stats.highTemperature = 0
|
||||
stats.abnormalMovement = 0
|
||||
stats.wearOff = 0
|
||||
}
|
||||
|
||||
// 更新搜索值
|
||||
|
||||
@@ -445,75 +445,59 @@ const fetchData = async (showMessage = false, customAlertType = null) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 生成模拟数据
|
||||
const generateMockData = () => {
|
||||
const mockAlerts = [
|
||||
{
|
||||
id: 1,
|
||||
eartagNumber: 'EARTAG001',
|
||||
alertType: 'battery',
|
||||
alertLevel: 'high',
|
||||
alertTime: '2025-01-18 10:30:00',
|
||||
battery: 15,
|
||||
temperature: 38.5,
|
||||
gpsSignal: '强',
|
||||
movementStatus: '正常',
|
||||
description: '设备电量低于20%,需要及时充电',
|
||||
longitude: 116.3974,
|
||||
latitude: 39.9093
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
eartagNumber: 'EARTAG002',
|
||||
alertType: 'offline',
|
||||
alertLevel: 'high',
|
||||
alertTime: '2025-01-18 09:15:00',
|
||||
battery: 0,
|
||||
temperature: 0,
|
||||
gpsSignal: '无',
|
||||
movementStatus: '静止',
|
||||
description: '设备已离线超过30分钟',
|
||||
longitude: 0,
|
||||
latitude: 0
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
eartagNumber: 'EARTAG003',
|
||||
alertType: 'temperature',
|
||||
alertLevel: 'medium',
|
||||
alertTime: '2025-01-18 08:45:00',
|
||||
battery: 85,
|
||||
temperature: 42.3,
|
||||
gpsSignal: '强',
|
||||
movementStatus: '正常',
|
||||
description: '设备温度异常,超过正常范围',
|
||||
longitude: 116.4074,
|
||||
latitude: 39.9193
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
eartagNumber: 'EARTAG004',
|
||||
alertType: 'movement',
|
||||
alertLevel: 'low',
|
||||
alertTime: '2025-01-18 07:20:00',
|
||||
battery: 92,
|
||||
temperature: 39.1,
|
||||
gpsSignal: '强',
|
||||
movementStatus: '异常',
|
||||
description: '运动量异常,可能发生异常行为',
|
||||
longitude: 116.4174,
|
||||
latitude: 39.9293
|
||||
// 从API获取预警数据
|
||||
const fetchAlertData = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
|
||||
// 构建查询参数
|
||||
const params = {
|
||||
page: pagination.current,
|
||||
limit: pagination.pageSize,
|
||||
alertType: alertTypeFilter.value,
|
||||
search: searchValue.value.trim()
|
||||
}
|
||||
]
|
||||
|
||||
alerts.value = mockAlerts
|
||||
pagination.total = mockAlerts.length
|
||||
|
||||
// 更新统计数据
|
||||
stats.lowBattery = mockAlerts.filter(alert => alert.alertType === 'battery').length
|
||||
stats.offline = mockAlerts.filter(alert => alert.alertType === 'offline').length
|
||||
stats.highTemperature = mockAlerts.filter(alert => alert.alertType === 'temperature').length
|
||||
stats.abnormalMovement = mockAlerts.filter(alert => alert.alertType === 'movement').length
|
||||
|
||||
// 调用API获取预警数据
|
||||
const response = await api.get('/smart-alerts/public/eartag', { params })
|
||||
|
||||
if (response && response.success) {
|
||||
alerts.value = response.data || []
|
||||
pagination.total = response.total || 0
|
||||
|
||||
// 更新统计数据
|
||||
updateStatsFromData(alerts.value)
|
||||
} else {
|
||||
console.error('获取预警数据失败:', response)
|
||||
alerts.value = []
|
||||
pagination.total = 0
|
||||
resetStats()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取预警数据失败:', error)
|
||||
message.error('获取预警数据失败: ' + error.message)
|
||||
alerts.value = []
|
||||
pagination.total = 0
|
||||
resetStats()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 从数据更新统计信息
|
||||
const updateStatsFromData = (data) => {
|
||||
stats.lowBattery = data.filter(alert => alert.alertType === 'battery').length
|
||||
stats.offline = data.filter(alert => alert.alertType === 'offline').length
|
||||
stats.highTemperature = data.filter(alert => alert.alertType === 'temperature').length
|
||||
stats.abnormalMovement = data.filter(alert => alert.alertType === 'movement').length
|
||||
}
|
||||
|
||||
// 重置统计信息
|
||||
const resetStats = () => {
|
||||
stats.lowBattery = 0
|
||||
stats.offline = 0
|
||||
stats.highTemperature = 0
|
||||
stats.abnormalMovement = 0
|
||||
}
|
||||
|
||||
// 更新搜索值
|
||||
|
||||
@@ -593,21 +593,69 @@ const handleTableChange = (pag) => {
|
||||
// 导出数据
|
||||
const exportData = async () => {
|
||||
try {
|
||||
if (!hosts.value || hosts.value.length === 0) {
|
||||
console.log('=== 开始导出智能主机数据 ===')
|
||||
|
||||
message.loading('正在获取所有设备数据...', 0)
|
||||
|
||||
// 构建查询参数,获取所有数据
|
||||
const params = new URLSearchParams({
|
||||
page: '1',
|
||||
limit: '10000', // 设置一个很大的限制值来获取所有数据
|
||||
_t: Date.now().toString()
|
||||
})
|
||||
|
||||
// 如果有搜索条件,添加到参数中
|
||||
if (searchValue.value.trim()) {
|
||||
params.append('search', searchValue.value.trim())
|
||||
console.log('导出搜索条件:', searchValue.value.trim())
|
||||
}
|
||||
|
||||
// 调用API获取所有智能主机数据
|
||||
const apiUrl = `/api/smart-devices/hosts?${params}`
|
||||
console.log('导出API请求URL:', apiUrl)
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`
|
||||
}
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`)
|
||||
}
|
||||
|
||||
const result = await response.json()
|
||||
console.log('API响应结果:', result)
|
||||
|
||||
if (!result.success || !result.data || result.data.length === 0) {
|
||||
message.destroy()
|
||||
message.warning('没有数据可导出')
|
||||
return
|
||||
}
|
||||
|
||||
const allHosts = result.data || []
|
||||
console.log('获取到所有设备数据:', allHosts.length, '条记录')
|
||||
console.log('原始数据示例:', allHosts[0])
|
||||
|
||||
// 后端已经处理了大部分格式化,直接使用
|
||||
const exportData = allHosts
|
||||
|
||||
console.log('导出设备数据示例:', exportData[0])
|
||||
console.log('导出设备数据总数:', exportData.length)
|
||||
|
||||
message.destroy()
|
||||
message.loading('正在导出数据...', 0)
|
||||
|
||||
const result = ExportUtils.exportDeviceData(hosts.value, 'host')
|
||||
const result_export = ExportUtils.exportDeviceData(exportData, 'host')
|
||||
|
||||
if (result.success) {
|
||||
if (result_export.success) {
|
||||
message.destroy()
|
||||
message.success(`导出成功!文件:${result.filename}`)
|
||||
message.success(`导出成功!文件:${result_export.filename}`)
|
||||
} else {
|
||||
message.destroy()
|
||||
message.error(result.message)
|
||||
message.error(result_export.message)
|
||||
}
|
||||
} catch (error) {
|
||||
message.destroy()
|
||||
|
||||
Reference in New Issue
Block a user