網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
- 與:有假則假,全真為真
- 或:有真則真,全假為假
- 且:filterCondition === ‘a(chǎn)ndContain’ || filterCondition === ‘a(chǎn)ndNotContain’ || filterCondition === ‘a(chǎn)ndFuzzyContain’
- 三元表達(dá)式:const age = 18;const isAdult = age >= 18 ? true : false; console.log(isAdult); // true
與和或應(yīng)該是兩個(gè)條件進(jìn)行查詢,其余則是一個(gè)條件
<div>
<!-- 與/或 -->
<template v-if="filterCondition === 'orContain' || filterCondition === 'orNotContain'">
<el-input v-model="keyword1" placeholder="輸入關(guān)鍵字1進(jìn)行篩選" style="width: 25%;"></el-input>
<el-input v-model="keyword2" placeholder="輸入關(guān)鍵字2進(jìn)行篩選" style="width: 25%;"></el-input>
</template>
<!-- 包含/不包含/模糊查詢/非 -->
<template
v-else="filterCondition === 'andContain' || filterCondition === 'andNotContain' || filterCondition === 'andFuzzyContain'">
<el-input v-model="keyword" placeholder="輸入關(guān)鍵字進(jìn)行篩選" style="width: 25%;"></el-input>
</template>
<el-select v-model="filterCondition" placeholder="選擇篩選條件" style="margin-left: 30px;">
<el-option v-for="condition in filterConditions" :key="condition.value" :label="condition.label"
:value="condition.value"></el-option>
</el-select>
<el-button style="margin-left: 30px;" type="primary" @click="filter">篩選</el-button>
</div>
</el-form>
<el-table :data="filteredData" style="width: 70%;margin-top: 30px;" :header-cell-style="{
backgroundColor: '#d7e9fa',
color: '#5e5f5f',
textAlign: 'center',
}" :cell-style="{ textAlign: 'center' }">
<el-table-column label="工況名稱" prop="name"></el-table-column>
<el-table-column label="測(cè)點(diǎn)號(hào)" prop="age"></el-table-column>
<el-table-column label="測(cè)點(diǎn)名稱" prop="gender"></el-table-column>
<el-table-column label="幅值(g)" prop="amplitude"></el-table-column>
<el-table-column label="頻率(Hz)" prop="frequency"></el-table-column>
</el-table>
</div>
<script>
export default {
data() {
return {
formInline: {
user: '',
region: '',
date1: '',
date2: ''
},
keyword: "",
keyword1: "",
keyword2: "",
filterCondition: "",
filteredData: [],
filterConditions: [
{ label: "包含", value: "andContain" },
{ label: "不包含", value: "andNotContain" },
{ label: "包含(模糊查詢)", value: "andFuzzyContain" },
{ label: "與", value: "orContain" },
{ label: "或", value: "orNotContain" },
{ label: "非", value: "notContain" },
],
data: [
{ id: 1, name: "A01-MCRO-Time-K-J-02-66-90D", age: '3:A104Z', gender: "3:A104Z", amplitude: '-0.000454102', frequency: '120.013' },
{ id: 2, name: "A01-MCRO-Time-K-J-02-67-90D", age: '4:A104Y', gender: '4:A104Y', amplitude: '0.000567725', frequency: '129.268' },
{ id: 3, name: "A01-MCRO-Time-K-J-02-68-90D", age: '5:A104X', gender: '5:A104X', amplitude: '-0.00793945', frequency: '248.102' },
{ id: 4, name: "A01-MCRO-Time-K-J-02-69-90D", age: '6:A121X', gender: '6:A121X', amplitude: '0.01036', frequency: '312.637' },
{ id: 5, name: "A01-MCRO-Time-K-J-02-70-90D", age: '7:A104Z', gender: "7:A104Z", amplitude: '-0.000454102', frequency: '120.013' },
{ id: 6, name: "A01-MCRO-Time-K-J-02-71-90D", age: '8:A104Y', gender: '8:A104Y', amplitude: '0.000567725', frequency: '129.268' },
{ id: 7, name: "A01-MCRO-Time-K-J-02-72-90D", age: '9:A104X', gender: '9:A104X', amplitude: '-0.00793945', frequency: '248.102' },
{ id: 8, name: "A01-MCRO-Time-K-J-02-73-90D", age: '10:A121X', gender: '10:A121X', amplitude: '0.01036', frequency: '312.637' },
],
};
},
mounted() {
this.filteredData = [...this.data];
},
methods: {
onSubmit() {
console.log('submit!');
},
filter() {
const filterCondition = this.filterCondition;
const data = this.data;
// 包含
if (filterCondition === "andContain") {
this.filteredData = data.filter((item) =>
Object.values(item).some((value) =>
String(value).toLowerCase().includes(this.keyword.trim().toLowerCase())
)
);
// 不包含
} else if (filterCondition === "andNotContain") {
this.filteredData = data.filter((item) =>
Object.values(item).every((value) =>
!String(value).toLowerCase().includes(this.keyword.trim().toLowerCase())
)
);
// 模糊查詢(=包含)
} else if (filterCondition === "andFuzzyContain") {
this.filteredData = data.filter((item) =>
Object.values(item).some((value) =>
String(value).toLowerCase().includes(this.keyword.trim().toLowerCase())
)
);
// 與
} else if (filterCondition === "orContain") {
this.filteredData = data.filter((item) => {
const keywords = [this.keyword1, this.keyword2].map(keyword => keyword.trim().toLowerCase());
return keywords.some(keyword => {
return Object.values(item).some(value => {
return String(value).toLowerCase().includes(keyword);
});
});
});
// 或
} else if (filterCondition === "orNotContain") {
const keyword1 = this.keyword1.trim().toLowerCase();
const keyword2 = this.keyword2.trim().toLowerCase();
if (keyword1 === "" && keyword2 === "") {
this.filteredData = [];
} else {
this.filteredData = data.filter((item) =>
Object.values(item).some((value) =>
String(value).toLowerCase().includes(keyword1) ||
String(value).toLowerCase().includes(keyword2)
)
);
}
// 非
} else if (filterCondition === "notContain") {
this.filteredData = data.filter((item) =>
Object.values(item).every((value) =>
!String(value).toLowerCase().includes(this.keyword.trim().toLowerCase())
)
);
}
},
},
};
</script>
原文鏈接:https://blog.csdn.net/Ybittersweet/article/details/131758879
- 上一篇:沒(méi)有了
- 下一篇:沒(méi)有了
相關(guān)推薦
- 2022-11-16 解決Oracle模擬事務(wù)提交、表鎖,處理表鎖問(wèn)題_oracle
- 2022-07-09 kernel利用pt?regs劫持seq?operations的遷移過(guò)程詳解_C 語(yǔ)言
- 2023-07-09 echarts的series已經(jīng)為空但是還加載出數(shù)據(jù)
- 2022-06-14 ASP.NET?Core?MVC中的局部視圖用法_基礎(chǔ)應(yīng)用
- 2022-05-29 Linux系統(tǒng)通過(guò)Docker安裝SQL?Server數(shù)據(jù)庫(kù)_docker
- 2022-08-23 在Asp.net?core中實(shí)現(xiàn)websocket通信_(tái)實(shí)用技巧
- 2022-11-17 詳解C/C++實(shí)現(xiàn)各種字符轉(zhuǎn)換方法合集_C 語(yǔ)言
- 2022-04-05 android使用shape自定義Switch組件
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支