Skip to content

Commit 58e0cb2

Browse files
committed
修复快捷搜索查询问题,将快捷搜索分组
1 parent 44f054e commit 58e0cb2

File tree

6 files changed

+45
-11
lines changed

6 files changed

+45
-11
lines changed

public/app.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,14 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
16071607
//
16081608
//
16091609
//
1610+
//
1611+
//
1612+
//
1613+
//
1614+
//
1615+
//
1616+
//
1617+
//
16101618

16111619

16121620

@@ -28365,7 +28373,7 @@ var render = function() {
2836528373
_vm._v(" "),
2836628374
_c(
2836728375
"div",
28368-
{ staticClass: "search-view" },
28376+
{ staticClass: "search-view mr-10" },
2836928377
[
2837028378
_vm.attrs.quickSearch
2837128379
? _c(
@@ -28417,6 +28425,18 @@ var render = function() {
2841728425
: _vm._e()
2841828426
],
2841928427
1
28428+
),
28429+
_vm._v(" "),
28430+
_c(
28431+
"div",
28432+
_vm._l(_vm.attrs.toolbars.left, function(component, index) {
28433+
return _c(component.componentName, {
28434+
key: component.componentName + index,
28435+
tag: "component",
28436+
attrs: { attrs: component }
28437+
})
28438+
}),
28439+
1
2842028440
)
2842128441
],
2842228442
1

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/app.js": "/app.js?id=7bccd6d48bd0882ab721",
2+
"/app.js": "/app.js?id=dec16533ce6d68ab6193",
33
"/manifest.js": "/manifest.js?id=d9708e48a6c10ccee4bb",
44
"/vendor.js": "/vendor.js?id=f4679ac178c0e413cb28"
55
}

resources/js/components/grid/Table.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
:rows="selectionRows"
1010
v-if="attrs.selection"
1111
/>
12-
<div class="search-view">
12+
<div class="search-view mr-10">
1313
<el-input
1414
v-model="quickSearch"
1515
:placeholder="attrs.quickSearch.placeholder"
@@ -23,6 +23,14 @@
2323
>
2424
</el-input>
2525
</div>
26+
<div>
27+
<component
28+
v-for="(component, index) in attrs.toolbars.left"
29+
:key="component.componentName + index"
30+
:is="component.componentName"
31+
:attrs="component"
32+
/>
33+
</div>
2634
</div>
2735
<div class="grid-top-container-right">
2836
<component

src/Grid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public function hideActions()
215215
public function data()
216216
{
217217

218-
$collection = $this->applyQuery();
218+
$this->applyQuery();
219219

220220
$data = $this->model->buildData();
221221
return [

src/Grid/Concerns/HasQuickSearch.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace SmallRuralDog\Admin\Grid\Concerns;
55

66

7-
use Illuminate\Support\Collection;
87
use SmallRuralDog\Admin\Grid\Column;
98
use SmallRuralDog\Admin\Grid\Model;
109
use SmallRuralDog\Admin\Grid\Tools\QuickSearch;
@@ -58,6 +57,7 @@ public function quickSearchPlaceholder($placeholder)
5857
*/
5958
protected function applyQuickSearch()
6059
{
60+
6161
if (!$this->quickSearch) {
6262
return;
6363
}
@@ -75,9 +75,12 @@ protected function applyQuickSearch()
7575
}
7676

7777
if (is_array($this->quickSearch->search)) {
78-
foreach ($this->quickSearch->search as $column) {
79-
$this->addWhereLikeBinding($column, true, '%' . $query . '%');
80-
}
78+
$this->model()->where(function ($queryW) use ($query) {
79+
foreach ($this->quickSearch->search as $key => $column) {
80+
$this->addWhereLikeBinding($queryW, $column, false, '%' . $query . '%');
81+
}
82+
});
83+
8184
} elseif (is_null($this->quickSearch->search)) {
8285
$this->addWhereBindings($query);
8386
}
@@ -165,18 +168,19 @@ protected function parseQueryBindings(array $queries)
165168
/**
166169
* Add where like binding to model query.
167170
*
171+
* @param $query
168172
* @param string $column
169173
* @param bool $or
170174
* @param string $pattern
171175
*/
172-
protected function addWhereLikeBinding(string $column, bool $or, string $pattern)
176+
protected function addWhereLikeBinding($query, string $column, bool $or, string $pattern)
173177
{
174178
$connectionType = $this->model()->eloquent()->getConnection()->getDriverName();
175179
$likeOperator = $connectionType == 'pgsql' ? 'ilike' : 'like';
176180

177181
$method = $or ? 'orWhere' : 'where';
178182

179-
$this->model()->{$method}($column, $likeOperator, $pattern);
183+
$query->{$method}($column, $likeOperator, $pattern);
180184
}
181185

182186
/**

src/Grid/Model.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ protected function displayData($data)
277277

278278
public function __call($method, $arguments)
279279
{
280+
280281
$this->queries->push([
281282
'method' => $method,
282283
'arguments' => $arguments,
283284
]);
284-
285285
return $this;
286286
}
287287

@@ -310,6 +310,8 @@ public function get()
310310
$this->setSort();
311311
$this->setPaginate();
312312

313+
//dd($this->queries);
314+
313315
$this->queries->unique()->each(function ($query) {
314316
$this->model = call_user_func_array([$this->model, $query['method']], $query['arguments']);
315317
});

0 commit comments

Comments
 (0)