switch语句
handleStatus(row, type) {
getFairStatus({ ids: [row.id], issueStatus: type }).then(response => {
this.$message.success(type == 1 ? '发布成功' : '取消发布成功');
this.getList();
});
},
// 获取checked列表
handleSelectionChange(val) {
this.multipleSelection = val;
},
// 下拉框批量操作
handleCommand(command) {
if (this.multipleSelection.length === 0) {
this.$message.error('至少选择一项操作')
return
}
//三元表达式:逻辑较强
// let cmdText = '1' == command ? cmdText = "置顶" : '2'==command ?
// "取消置顶" : '3' == command ? "发布" : "取消发布";
(switch语句自己很少用得多试试)
Switch语句:
switch (command) {
case '1':
cmdText = "置顶";
break;
case '2':
cmdText = "取消置顶";
break;
case '3':
cmdText = "发布";
break;
case '4':
cmdText = "取消发布";
break;
}
this.ids = [];
this.multipleSelection.forEach(element => {
// 如果command=1并且它的置顶状态为0 再把它的ID放入新的数组中。
if ('1' == command && element.isTop === 0) {
this.ids.push(element.id);
} else if ('2' == command && element.isTop === 1) {
this.ids.push(element.id);
} else if ('3' == command && element.issueStatus === 0) {
this.ids.push(element.id);
} else if ('4' == command && element.issueStatus === 1) {
this.ids.push(element.id);
}
});
if (this.ids.length == 0) {
this.$message.error('所选文章已' + cmdText + ',无需重复操作');
return
}
if ('1' == command || '2' == command) {
cntArticleTop({ ids: this.ids, isTop: '1' == command ? 1 : 0 }).then(response => {
this.getList();
});
} else {
cntArticleStatus({ ids: this.ids, issueStatus: '3' == command ? 1 : 0 }).then(response => {
this.getList();
});
}
},