@@ -229,7 +229,9 @@ export default {
name: 'home',
data() {
return {
- serach: '',
+ serach: '', // 搜索框输入内容
+ deviceList: [], // 原始设备列表
+ filteredDeviceList: [], // 过滤后的设备列表
switchValue: false,
addDeviceDialogVisible: false,
deviceCode: "",
@@ -250,8 +252,7 @@ export default {
}],
userInfo: {
mobile: '' // 初始化用户信息
- },
- deviceList:[]
+ }
};
},
methods: {
@@ -270,14 +271,30 @@ export default {
// 获取已绑设备
getList(){
Api.user.getHomeList(({data})=>{
- console.log(data.data)
- this.deviceList = data.data
+ this.deviceList = data.data; // 保存原始设备列表
+ this.filteredDeviceList = data.data; // 初始化过滤后的设备列表
})
- }
+ },
+ // 处理搜索
+ handleSearch() {
+ if (this.serach.trim() === '') {
+ // 如果搜索框为空,显示全部设备
+ this.filteredDeviceList = this.deviceList;
+ } else {
+ // 过滤设备列表
+ this.filteredDeviceList = this.deviceList.filter(device => {
+ return (
+ device.list[0]?.mac_address?.includes(this.serach) || // 匹配MAC地址
+ device.list[0]?.device_type?.includes(this.serach) || // 匹配设备型号
+ device.list[0]?.app_version?.includes(this.serach) // 匹配APP版本
+ );
+ });
+ }
+ },
},
mounted() {
this.fetchUserInfo(); // 组件加载时获取用户信息
- this.getList()
+ this.getList(); // 初始化设备列表
}
}