Files
xiaomubiao-master/CLEAR_OTHER_EQUIPMENT_DATA.md
2026-05-22 16:13:20 +08:00

203 lines
6.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 删除其他装备数据的方法
## 🗑️ **删除数据的几种方式**
### **方法1: 浏览器控制台命令 (推荐)**
在浏览器控制台中运行以下命令:
#### **完全清空所有数据**
```javascript
// 1. 清空内存数据
otherEquipmentList.value = [];
// 2. 清空localStorage存储
localStorage.removeItem("index-otherEquipmentList");
// 3. 重置设备计数
otherEquipmentCount.value = 0;
// 4. 确认清空成功
console.log('数据已清空,当前设备数量:', otherEquipmentList.value.length);
```
#### **删除特定设备**
```javascript
// 删除指定ID的设备 (例如删除 "dy04")
const targetId = "dy04";
const beforeCount = otherEquipmentList.value.length;
otherEquipmentList.value = otherEquipmentList.value.filter(
device => device.equipmentId !== targetId
);
// 保存到localStorage
localStorage.setItem("index-otherEquipmentList", JSON.stringify(otherEquipmentList.value));
// 更新计数
otherEquipmentCount.value = otherEquipmentList.value.length;
console.log(`删除设备 ${targetId},删除前: ${beforeCount},删除后: ${otherEquipmentList.value.length}`);
```
#### **删除特定类型的设备**
```javascript
// 删除所有QB303设备
const beforeCount = otherEquipmentList.value.length;
otherEquipmentList.value = otherEquipmentList.value.filter(
device => device.equipmentType !== "QB303设备"
);
// 保存更改
localStorage.setItem("index-otherEquipmentList", JSON.stringify(otherEquipmentList.value));
otherEquipmentCount.value = otherEquipmentList.value.length;
console.log(`删除QB303设备删除前: ${beforeCount},删除后: ${otherEquipmentList.value.length}`);
```
### **方法2: 开发者工具 Application 面板**
1. **打开浏览器开发者工具** (F12)
2. **切换到 Application 标签页**
3. **在左侧找到 Storage → Local Storage**
4. **选择您的域名**
5. **找到键名 `index-otherEquipmentList`**
6. **右键点击 → Delete**
7. **刷新页面** (F5)
### **方法3: 一键清理函数**
我为您创建了一个专门的清理函数:
```javascript
// 一键清理所有其他装备数据
function clearAllOtherEquipmentData() {
console.log('🗑️ 开始清理其他装备数据...');
// 记录清理前的状态
const beforeCount = otherEquipmentList.value.length;
const beforeLocalStorage = localStorage.getItem("index-otherEquipmentList");
console.log('清理前状态:');
console.log('- 内存设备数量:', beforeCount);
console.log('- localStorage数据大小:', beforeLocalStorage ? beforeLocalStorage.length : 0);
// 执行清理
otherEquipmentList.value = [];
localStorage.removeItem("index-otherEquipmentList");
// 确认清理结果
console.log('✅ 清理完成!');
console.log('清理后状态:');
console.log('- 内存设备数量:', otherEquipmentList.value.length);
console.log('- localStorage数据:', localStorage.getItem("index-otherEquipmentList"));
return {
success: true,
beforeCount: beforeCount,
afterCount: otherEquipmentList.value.length,
message: `成功清理 ${beforeCount} 个设备`
};
}
// 调用清理函数
clearAllOtherEquipmentData();
```
### **方法4: 选择性删除**
#### **删除离线设备**
```javascript
// 只保留在线设备
const beforeCount = otherEquipmentList.value.length;
otherEquipmentList.value = otherEquipmentList.value.filter(
device => device.online_status === true
);
localStorage.setItem("index-otherEquipmentList", JSON.stringify(otherEquipmentList.value));
otherEquipmentCount.value = otherEquipmentList.value.length;
console.log(`删除离线设备,删除前: ${beforeCount},删除后: ${otherEquipmentList.value.length}`);
```
#### **删除旧数据**
```javascript
// 删除1小时前的数据
const oneHourAgo = Date.now() - (60 * 60 * 1000);
const beforeCount = otherEquipmentList.value.length;
otherEquipmentList.value = otherEquipmentList.value.filter(
device => device.lastUpdateTime > oneHourAgo
);
localStorage.setItem("index-otherEquipmentList", JSON.stringify(otherEquipmentList.value));
otherEquipmentCount.value = otherEquipmentList.value.length;
console.log(`删除1小时前的数据删除前: ${beforeCount},删除后: ${otherEquipmentList.value.length}`);
```
## 🔄 **删除后重置**
### **重新初始化数据**
```javascript
// 清空后重新初始化为默认状态
async function resetOtherEquipmentData() {
// 清空现有数据
otherEquipmentList.value = [];
localStorage.removeItem("index-otherEquipmentList");
// 重新运行初始化
await otherEquipmentInit();
console.log('✅ 数据已重置为初始状态');
}
resetOtherEquipmentData();
```
### **删除后刷新页面**
```javascript
// 清空数据并刷新页面
function clearAndReload() {
localStorage.removeItem("index-otherEquipmentList");
location.reload();
}
clearAndReload();
```
## ⚠️ **注意事项**
1. **数据无法恢复**: 删除后的数据无法恢复,请谨慎操作
2. **影响范围**: 删除操作只影响其他装备数据,不影响无人机和无人车数据
3. **页面刷新**: 删除内存数据后建议刷新页面确保UI更新
4. **备份建议**: 删除前可以先导出备份
### **数据备份**
```javascript
// 删除前备份数据
const backup = JSON.stringify(otherEquipmentList.value, null, 2);
console.log('备份数据:', backup);
// 或者下载备份文件
const blob = new Blob([backup], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `other-equipment-backup-${new Date().toISOString().slice(0,10)}.json`;
a.click();
```
## 🚀 **快速执行**
**如果您想立即清空所有数据,直接在控制台运行:**
```javascript
// 一行代码清空所有数据
otherEquipmentList.value = []; localStorage.removeItem("index-otherEquipmentList"); console.log("✅ 所有其他装备数据已清空");
```
选择最适合您需求的方法来删除数据!