优化代码 handleWinClick(e) { if (e.target.matches) { if ( this.istopSearch == true && !e.target.matches('#my-km-popper') && this.zhName === '综合' && !e.target.matches('#ywbd-km-popper') ) { this.istopSearch = false; this.isHistyqry = false; } } else { // 兼容ie if ( this.istopSearch == true && !e.target.msMatchesSelector('#my-km-popper') && this.zhName === '综合' && !e.target.msMatchesSelector('#ywbd-km-popper') ) { this.istopSearch = false; this.isHistyqry = false; } } // 新tab搜索 if (e.target.matches) { if ( this.isMenuTabshow == true && this.zhName === '综合' && !e.target.matches('#my-km-popper') && !e.target.matches('#ywbd-km-popper') && e.target.className.indexOf('el-tabs__item') < 0 ) { this.isMenuTabshow = false; } } else { if ( this.isMenuTabshow == true && this.zhName === '综合' && !e.target.msMatchesSelector('#my-km-popper') && !e.target.msMatchesSelector('#ywbd-km-popper') && !e.target.msMatchesSelector('#tab') && e.target.className.indexOf('el-tabs__item') < 0 ) { this.isMenuTabshow = false; } } }, defaultType() { let parmas = { region: '^GET_CUR_REGION', paraType: 'QUERY_MENU_FLAG', paraCode: 'QUERY_MENU_FLAG', }; this.$http .post('hallCommon_IBusiCommCSV_qryBsParaDetail', parmas) .then(({ bsParaDetail = [] }) => { if (!isNull(bsParaDetail)) { if (bsParaDetail[0].para1 == 'Y') { //默认是综合 this.zhName = '综合'; } else { this.zhName = '菜单'; } } else { this.zhName = '菜单'; } }); },
时间: 2024-02-10 19:09:20 浏览: 122
优化代码
可以将重复的判断条件提取出来,避免重复代码。同时可以使用三元运算符来简化代码。重构后的代码如下:
```
const isZhName = this.zhName === '综合';
const isMyKmPopper = e.target.matches('#my-km-popper') || e.target.msMatchesSelector('#my-km-popper');
const isYwbdKmPopper = e.target.matches('#ywbd-km-popper') || e.target.msMatchesSelector('#ywbd-km-popper');
const isElTabsItem = e.target.className.indexOf('el-tabs__item') < 0;
// 处理 istopSearch
if (e.target.matches ? (!isMyKmPopper && isZhName && !isYwbdKmPopper && this.istopSearch) : (!isMyKmPopper && isZhName && !isYwbdKmPopper && this.istopSearch)) {
this.istopSearch = false;
this.isHistyqry = false;
}
// 处理 isMenuTabshow
if (e.target.matches ? (!isMyKmPopper && !isYwbdKmPopper && !isElTabsItem && isZhName && this.isMenuTabshow) : (!isMyKmPopper && !isYwbdKmPopper && !e.target.msMatchesSelector('#tab') && !isElTabsItem && isZhName && this.isMenuTabshow)) {
this.isMenuTabshow = false;
}
// 处理 defaultType
const parmas = {
region: '^GET_CUR_REGION',
paraType: 'QUERY_MENU_FLAG',
paraCode: 'QUERY_MENU_FLAG',
};
this.$http.post('hallCommon_IBusiCommCSV_qryBsParaDetail', parmas).then(({ bsParaDetail = [] }) => {
if (!isNull(bsParaDetail)) {
this.zhName = bsParaDetail[0].para1 === 'Y' ? '综合' : '菜单';
} else {
this.zhName = '菜单';
}
});
```
阅读全文