Commit 7c0b7b85 authored by “yiyousong”'s avatar “yiyousong”

perf: 优化用户管理搜索

parent 421d923a
...@@ -8,10 +8,19 @@ ...@@ -8,10 +8,19 @@
</div> </div>
<div class="search_btn"> <div class="search_btn">
<a-space> <a-space>
<a-select
v-model="userform.type"
placeholder="请选择类型"
style="width: 150px"
>
<a-select-option :value="1">按用户名</a-select-option>
<a-select-option :value="2">按用户姓名</a-select-option>
<a-select-option :value="3">按电话</a-select-option>
</a-select>
<a-input <a-input
v-model="userform.searchVal" v-model="userform.searchVal"
style="width: 250px" style="width: 250px"
placeholder="请输入用户姓名/手机号搜索" placeholder="请输入关键字搜索"
> >
<a-icon slot="prefix" type="search" /> <a-icon slot="prefix" type="search" />
</a-input> </a-input>
...@@ -172,6 +181,7 @@ export default { ...@@ -172,6 +181,7 @@ export default {
sourceInfoForm: {}, sourceInfoForm: {},
userDict: {}, // 角色数据 userDict: {}, // 角色数据
userform: { userform: {
type: 1,
roleId: undefined, roleId: undefined,
searchVal: undefined, searchVal: undefined,
}, },
...@@ -197,11 +207,14 @@ export default { ...@@ -197,11 +207,14 @@ export default {
this.tableLoading = true; this.tableLoading = true;
let realName = ""; let realName = "";
let mobile = ""; let mobile = "";
let loginName = "";
if (this.userform.searchVal) { if (this.userform.searchVal) {
if (/^[\d]+$/.test(this.userform.searchVal)) { if (this.userform.type == 1) {
mobile = "%" + this.userform.searchVal + "%"; loginName = "%" + this.userform.searchVal + "%";
} else { } else if (this.userform.type == 2) {
realName = "%" + this.userform.searchVal + "%"; realName = "%" + this.userform.searchVal + "%";
} else if (this.userform.type == 3) {
mobile = "%" + this.userform.searchVal + "%";
} }
} }
let res = await userList({ let res = await userList({
...@@ -210,24 +223,27 @@ export default { ...@@ -210,24 +223,27 @@ export default {
roleId: this.userform.roleId, roleId: this.userform.roleId,
realName, realName,
mobile, mobile,
loginName,
}); });
let { dict, data, total } = res.data; if (res.code == 1) {
let { roleId } = dict; let { dict, data, total } = res.data;
if (!data.length && this.tablePagination.current > 1) { let { roleId } = dict;
this.tablePagination.current -= 1; if (!data.length && this.tablePagination.current > 1) {
this.getUserList(); this.tablePagination.current -= 1;
} this.getUserList();
this.userDict = roleId; }
let { loginName } = this.userData; this.userDict = roleId;
if (this.loginNames.includes(loginName)) { let { loginName } = this.userData;
this.tableSourceData = data; if (this.loginNames.includes(loginName)) {
this.tablePagination.total = total; this.tableSourceData = data;
} else { this.tablePagination.total = total;
this.tableSourceData = data.filter((v) => { } else {
return !this.loginNames.includes(v.loginName); this.tableSourceData = data.filter((v) => {
}); return !this.loginNames.includes(v.loginName);
});
this.tablePagination.total = total - 3; this.tablePagination.total = total - this.loginNames.length;
}
} }
this.tableLoading = false; this.tableLoading = false;
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment