Skip to content

Commit

Permalink
perf: 优化工作汇报的搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Apr 7, 2022
1 parent 9755c59 commit d951a60
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 86 deletions.
61 changes: 34 additions & 27 deletions app/Http/Controllers/Api/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class ReportController extends AbstractController
* @apiGroup report
* @apiName my
*
* @apiParam {String} [type] 汇报类型,weekly:周报,daily:日报
* @apiParam {Array} [created_at] 汇报时间
* @apiParam {Object} [keys] 搜索条件
* - keys.type: 汇报类型,weekly:周报,daily:日报
* - keys.created_at: 汇报时间
* @apiParam {Number} [page] 当前页,默认:1
* @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:50
*
Expand All @@ -44,17 +45,19 @@ class ReportController extends AbstractController
public function my(): array
{
$user = User::auth();
// 搜索当前用户
//
$builder = Report::with(['receivesUser'])->whereUserid($user->userid);
$type = trim(Request::input('type'));
$createAt = Request::input('created_at');
in_array($type, [Report::WEEKLY, Report::DAILY]) && $builder->whereType($type);
$whereArray = [];
if (is_array($createAt)) {
if ($createAt[0] > 0) $whereArray[] = ['created_at', '>=', date('Y-m-d H:i:s', Base::dayTimeF($createAt[0]))];
if ($createAt[1] > 0) $whereArray[] = ['created_at', '<=', date('Y-m-d H:i:s', Base::dayTimeE($createAt[1]))];
$keys = Request::input('keys');
if (is_array($keys)) {
if (in_array($keys['type'], [Report::WEEKLY, Report::DAILY])) {
$builder->whereType($keys['type']);
}
if (is_array($keys['created_at'])) {
if ($keys['created_at'][0] > 0) $builder->where('created_at', '>=', date('Y-m-d H:i:s', Base::dayTimeF($keys['created_at'][0])));
if ($keys['created_at'][1] > 0) $builder->where('created_at', '<=', date('Y-m-d H:i:s', Base::dayTimeE($keys['created_at'][1])));
}
}
$list = $builder->where($whereArray)->orderByDesc('created_at')->paginate(Base::getPaginate(50, 20));
$list = $builder->orderByDesc('created_at')->paginate(Base::getPaginate(50, 20));
return Base::retSuccess('success', $list);
}

Expand All @@ -65,9 +68,10 @@ public function my(): array
* @apiGroup report
* @apiName receive
*
* @apiParam {String} [username] 会员名
* @apiParam {String} [type] 汇报类型,weekly:周报,daily:日报
* @apiParam {Array} [created_at] 汇报时间
* @apiParam {Object} [keys] 搜索条件
* - keys.key: 关键词
* - keys.type: 汇报类型,weekly:周报,daily:日报
* - keys.created_at: 汇报时间
* @apiParam {Number} [page] 当前页,默认:1
* @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:50
*
Expand All @@ -82,21 +86,24 @@ public function receive(): array
$builder->whereHas("receivesUser", function ($query) use ($user) {
$query->where("report_receives.userid", $user->userid);
});
$type = trim(Request::input('type'));
$createAt = Request::input('created_at');
$username = trim(Request::input('username', ''));
$builder->whereHas('sendUser', function ($query) use ($username) {
if (!empty($username)) {
$query->where("users.email", "LIKE", "%{$username}%");
$keys = Request::input('keys');
if (is_array($keys)) {
if ($keys['key']) {
$builder->where(function($query) use ($keys) {
$query->whereHas('sendUser', function ($q2) use ($keys) {
$q2->where("users.email", "LIKE", "%{$keys['key']}%");
})->orWhere("title", "LIKE", "%{$keys['key']}%");
});
}
if (in_array($keys['type'], [Report::WEEKLY, Report::DAILY])) {
$builder->whereType($keys['type']);
}
if (is_array($keys['created_at'])) {
if ($keys['created_at'][0] > 0) $builder->where('created_at', '>=', date('Y-m-d H:i:s', Base::dayTimeF($keys['created_at'][0])));
if ($keys['created_at'][1] > 0) $builder->where('created_at', '<=', date('Y-m-d H:i:s', Base::dayTimeE($keys['created_at'][1])));
}
});
in_array($type, [Report::WEEKLY, Report::DAILY]) && $builder->whereType($type);
$whereArray = [];
if (is_array($createAt)) {
if ($createAt[0] > 0) $whereArray[] = ['created_at', '>=', date('Y-m-d H:i:s', Base::dayTimeF($createAt[0]))];
if ($createAt[1] > 0) $whereArray[] = ['created_at', '<=', date('Y-m-d H:i:s', Base::dayTimeE($createAt[1]))];
}
$list = $builder->where($whereArray)->orderByDesc('created_at')->paginate(Base::getPaginate(50, 20));
$list = $builder->orderByDesc('created_at')->paginate(Base::getPaginate(50, 20));
if ($list->items()) {
foreach ($list->items() as $item) {
$item->receive_time = ReportReceive::query()->whereRid($item["id"])->whereUserid($user->userid)->value("receive_time");
Expand Down
45 changes: 16 additions & 29 deletions resources/assets/js/pages/manage/components/ReportMy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>
<div class="search-content">
<Select
v-model="reportType"
v-model="keys.type"
:placeholder="$L('全部')">
<Option v-for="item in reportTypeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
</Select>
Expand All @@ -21,7 +21,7 @@
</div>
<div class="search-content">
<DatePicker
v-model="createAt"
v-model="keys.created_at"
type="daterange"
split-panels
:placeholder="$L('请选择时间')"/>
Expand Down Expand Up @@ -82,11 +82,14 @@ export default {
listPage: 1,
listTotal: 0,
listPageSize: 20,
noDataText: "",
noDataText: "数据加载中.....",
createAt: [],
reportType: '',
reportTypeList: [],
keys: {},
reportTypeList: [
{value: "", label: this.$L('全部')},
{value: "weekly", label: this.$L('周报')},
{value: "daily", label: this.$L('日报')},
],
}
},
mounted() {
Expand All @@ -97,7 +100,6 @@ export default {
},
methods: {
initLanguage() {
this.noDataText = this.noDataText || "数据加载中.....";
this.columns = [{
title: this.$L("名称"),
key: 'title',
Expand All @@ -108,7 +110,7 @@ export default {
key: 'type',
align: 'center',
sortable: true,
width: 80,
width: 90,
}, {
title: this.$L("汇报时间"),
key: 'created_at',
Expand Down Expand Up @@ -147,11 +149,6 @@ export default {
});
},
}];
this.reportTypeList = [
{value: "", label: this.$L('全部')},
{value: "weekly", label: this.$L('周报')},
{value: "daily", label: this.$L('日报')},
]
},
onSearch() {
Expand All @@ -160,28 +157,26 @@ export default {
},
getLists() {
this.loadIng = 1;
this.loadIng++;
this.$store.dispatch("call", {
url: 'report/my',
data: {
keys: this.keys,
page: Math.max(this.listPage, 1),
pagesize: Math.max($A.runNum(this.listPageSize), 10),
created_at: this.createAt,
type: this.reportType
},
}).then(({data, msg}) => {
}).then(({data}) => {
// data 结果数据
this.lists = data.data;
this.listTotal = data.total;
if (this.lists.length <= 0) {
this.noDataText = this.$L("无数据");
}
this.noDataText = "没有相关的数据";
// msg 结果描述
}).catch(({msg}) => {
// msg 错误原因
$A.messageError(msg);
this.noDataText = '数据加载失败';
}).finally(() => {
this.loadIng = 0;
this.loadIng--;
});
},
Expand All @@ -197,17 +192,9 @@ export default {
}
},
searchTab() {
this.getLists();
},
addReport() {
this.$emit("on-edit", 0);
}
}
}
</script>

<style scoped>
</style>
48 changes: 18 additions & 30 deletions resources/assets/js/pages/manage/components/ReportReceive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<ul>
<li>
<div class="search-label">
{{ $L("汇报人") }}
{{ $L("关键词") }}
</div>
<div class="search-content">
<Input v-model="username" :placeholder="$L('请输入用户名')"/>
<Input v-model="keys.key" :placeholder="$L('输入关键词搜索')" clearable/>
</div>
</li>
<li>
Expand All @@ -16,7 +16,7 @@
</div>
<div class="search-content">
<Select
v-model="reportType"
v-model="keys.type"
:placeholder="$L('全部')">
<Option v-for="item in reportTypeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
</Select>
Expand All @@ -28,7 +28,7 @@
</div>
<div class="search-content">
<DatePicker
v-model="createAt"
v-model="keys.created_at"
type="daterange"
split-panels
:placeholder="$L('请选择时间')"/>
Expand Down Expand Up @@ -85,12 +85,14 @@ export default {
listPage: 1,
listTotal: 0,
listPageSize: 20,
noDataText: "",
noDataText: "数据加载中.....",
username: '',
reportType: '',
createAt: [],
reportTypeList: [],
keys: {},
reportTypeList: [
{value: "", label: this.$L('全部')},
{value: "weekly", label: this.$L('周报')},
{value: "daily", label: this.$L('日报')},
],
}
},
mounted() {
Expand All @@ -101,7 +103,6 @@ export default {
},
methods: {
initLanguage() {
this.noDataText = this.noDataText || "数据加载中.....";
this.columns = [{
title: this.$L("标题"),
key: 'title',
Expand Down Expand Up @@ -129,9 +130,8 @@ export default {
}, {
title: this.$L("类型"),
key: 'type',
align: 'center',
sortable: true,
width: 80,
width: 90,
}, {
title: this.$L("接收时间"),
key: 'receive_time',
Expand Down Expand Up @@ -171,11 +171,6 @@ export default {
});
},
}];
this.reportTypeList = [
{value: "", label: this.$L('全部')},
{value: "weekly", label: this.$L('周报')},
{value: "daily", label: this.$L('日报')},
]
},
onSearch() {
Expand All @@ -184,29 +179,26 @@ export default {
},
getLists() {
this.loadIng = 1;
this.loadIng++;
this.$store.dispatch("call", {
url: 'report/receive',
data: {
keys: this.keys,
page: Math.max(this.listPage, 1),
pagesize: Math.max($A.runNum(this.listPageSize), 10),
username: this.username,
created_at: this.createAt,
type: this.reportType
},
}).then(({data, msg}) => {
}).then(({data}) => {
// data 结果数据
this.lists = data.data;
this.listTotal = data.total;
if (this.lists.length <= 0) {
this.noDataText = this.$L("无数据");
}
this.noDataText = "没有相关的数据";
// msg 结果描述
}).catch(({msg}) => {
// msg 错误原因
$A.messageError(msg);
this.noDataText = '数据加载失败';
}).finally(() => {
this.loadIng = 0;
this.loadIng--;
});
},
Expand All @@ -224,7 +216,3 @@ export default {
}
}
</script>

<style scoped>
</style>

0 comments on commit d951a60

Please sign in to comment.