input事件是实时监听输入内容的变化,这就造成重复触发的问题。
searchInput(e) {
let that = this
let _parm = ''
if (typeof e != 'undefined') {
_parm = e;
console.log('ee',e,that.searchContent)
}
clearTimeout(this.timer);// 清除
that.timer = setTimeout(() => {
that.$store
.dispatch('home_panel_list', { searchContent: that.searchContent })
.then((res) => {
console.log(res)
if(res && res['result'] && Array.isArray(res.result) && res.result.length > 0){
let _panelList = res.result;
_panelList.map(function(item, index){
item['moduleId'] = item['id'];
item['moduleName'] = item['plateName'];
item['moduleKey'] = item['plateKey'];
// item['moduleIcon'] = that.getModuleIcon(item['plateKey']);
if(item['permissionsSubset']){//权限
let _permissionsSubset = eval('(' + item.permissionsSubset + ')');
if(item.moduleKey === 'logical_subject' || item.moduleKey === 'system_setup' || item['plateKey'] == 'relationship'){//系统配置、档案管理
item['permissionsArr'] = _permissionsSubset;
if(item.moduleKey === 'logical_subject'){
that.archiveArr = item.permissionsArr;
//存储进localStorage里面,刷新的时候,也去localStorage里面取出来
Utils.setLocalCache(TYPES.COOKIE_PERMISSION_UNIT + '_' + that.user_info['userId'], that.archiveArr);
that.goToArchive();//获取archiveStr
}
if(item.moduleKey === 'system_setup') item['pathName'] = that.$router.options.getRoute(item.moduleKey);
}else if(_permissionsSubset.length === 1){//项目用户的项目一览也是1,如何区分?
item['permissionsStr'] = _permissionsSubset[0];
// let key = that.getKey(_permissionsSubset[0]);
// item['pathName'] = that.$router.options.getRoute(key);
// console.log(key, item.pathName);
}/*else if(item['plateKey'] == 'relationship'){
item['permissionsStr'] = '';
}*/
}
if('undefined' !== typeof item['classifyId']){
if(that.funcModules[item.classifyId] && that.funcModules[item.classifyId]['typeArr']
&& 'undefined' !== typeof item['isShow'] && item.isShow === 1){
if(item['plateKey'] != 'Console') that.funcModules[item.classifyId]['typeArr'].push(item)
}
}
return item;
});
that.funcModules.map(function(item){
if(item['typeArr'] && Array.isArray(item.typeArr) && item.typeArr.length > 0){
item.typeArr.sort(Utils.sortBy('orderSort', false, parseInt));
}
return item;
})
that.menuRecommend = _panelList;
}
})
.catch((err) => {
console.log(err)
})
}, 800);
},
使用clearTimeout来清除之前的请求,settimeout时间可以根据需求自己设定。