Skip to content

Commit 40e3e20

Browse files
committed
添加Grid数据源请求方式method()
添加Grid数据源请求附加URL参数 添加Grid附加数据源字段方法appendFields() 添加Grid前端Route组件
1 parent 84526cc commit 40e3e20

File tree

9 files changed

+144
-6
lines changed

9 files changed

+144
-6
lines changed

public/app.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/app.js": "/app.js?id=3cbd88f2597a0c461aa4",
2+
"/app.js": "/app.js?id=52747b333ef4846d11ef",
33
"/manifest.js": "/manifest.js?id=8991394a854ee5cdffc3",
44
"/vendor.js": "/vendor.js?id=df0be4950fcb717193ba"
55
}

resources/js/components.js

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Vue.component("Link", require("./components/widgets/Grid/Link").default);
8282
Vue.component("IImage", require("./components/widgets/Grid/Image").default);
8383
Vue.component("Icon", require("./components/widgets/Grid/Icon").default);
8484
Vue.component("Boole", require("./components/widgets/Grid/Boole").default);
85+
Vue.component("GridRoute", require("./components/widgets/Grid/GridRoute").default);
8586

8687
//Actions
8788
Vue.component(

resources/js/components/grid/Table.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
</el-table-column>
212212
</el-table>
213213
</div>
214-
<div class="table-page padding-xs" v-if='!attrs.hidePage'>
214+
<div class="table-page padding-xs" v-if="!attrs.hidePage">
215215
<el-pagination
216216
:layout="attrs.pageLayout"
217217
:hide-on-single-page="false"
@@ -364,7 +364,7 @@ export default {
364364
getData() {
365365
this.loading = true;
366366
this.$http
367-
.get(this.attrs.dataUrl, {
367+
[this.attrs.method](this.attrs.dataUrl, {
368368
params: {
369369
get_data: true,
370370
page: this.page,
@@ -373,6 +373,7 @@ export default {
373373
...this.q_search,
374374
...this.filterFormData,
375375
...this.tabsSelectdata,
376+
...this.$route.query,
376377
},
377378
})
378379
.then(({ data }) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<template>
2+
<el-link
3+
:style="attrs.style"
4+
:class="attrs.className"
5+
@click="goRoute"
6+
:underline="false"
7+
:icon="attrs.icon"
8+
:type="attrs.type"
9+
v-html="value"
10+
></el-link>
11+
</template>
12+
<script>
13+
import { GridColumnComponent } from "@/mixins.js";
14+
export default {
15+
mixins: [GridColumnComponent],
16+
methods: {
17+
goRoute() {
18+
this.$router.push(this.uri);
19+
},
20+
},
21+
computed: {
22+
uri() {
23+
//替换变量
24+
let uri = this.attrs.uri;
25+
this._.forEach(this.row, (value, key) => {
26+
uri = this._.replace(uri, "{" + key + "}", value);
27+
});
28+
return uri;
29+
},
30+
},
31+
};
32+
</script>

resources/js/mixins.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const GridColumnComponent = {
22
props: {
33
attrs: Object,
44
row: Object,
5-
column_value: {
5+
columnValue: {
66
default: null
77
},
88
value: {

src/Components/Grid/Route.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
4+
namespace SmallRuralDog\Admin\Components\Grid;
5+
6+
7+
use SmallRuralDog\Admin\Components\GridComponent;
8+
9+
class Route extends GridComponent
10+
{
11+
protected $componentName = "GridRoute";
12+
13+
protected $uri;
14+
15+
protected $type;
16+
protected $icon;
17+
18+
public function __construct($uri)
19+
{
20+
$this->uri = $uri;
21+
}
22+
23+
24+
public static function make($url = "")
25+
{
26+
return new Route($url);
27+
}
28+
29+
/**
30+
* 类型
31+
* primary / success / warning / danger / info
32+
* @param mixed $type
33+
* @return $this
34+
*/
35+
public function type($type)
36+
{
37+
$this->type = $type;
38+
return $this;
39+
}
40+
41+
/**
42+
* 图标类名
43+
* @param mixed $icon
44+
* @return $this
45+
*/
46+
public function icon($icon)
47+
{
48+
$this->icon = $icon;
49+
return $this;
50+
}
51+
52+
53+
54+
55+
}

src/Grid.php

+46
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ class Grid extends Component
7272
private $top;
7373
private $bottom;
7474

75+
/**
76+
* 请求方式
77+
* @var string
78+
*/
79+
private $method = "get";
80+
81+
/**
82+
* 附加字段
83+
* @var array
84+
*/
85+
private $appendFields = [];
86+
7587

7688
/**
7789
* @var Form
@@ -127,6 +139,39 @@ public function dataUrl(string $dataUrl)
127139
return $this;
128140
}
129141

142+
/**
143+
* @param string $method
144+
* @return $this
145+
*/
146+
public function method(string $method)
147+
{
148+
$this->method = $method;
149+
return $this;
150+
}
151+
152+
/**
153+
* @return array
154+
*/
155+
public function getAppendFields(): array
156+
{
157+
return $this->appendFields;
158+
}
159+
160+
/**
161+
* 数据返回附加字段
162+
* @param array $appendFields
163+
* @return $this
164+
*/
165+
public function appendFields(array $appendFields)
166+
{
167+
$this->appendFields = $appendFields;
168+
return $this;
169+
}
170+
171+
172+
173+
174+
130175
/**
131176
* @return bool
132177
*/
@@ -376,6 +421,7 @@ public function jsonSerialize()
376421
$viewData['columnAttributes'] = $this->columnAttributes;
377422
$viewData['attributes'] = (array)$this->attributes;
378423
$viewData['dataUrl'] = $this->dataUrl;
424+
$viewData['method'] = $this->method;
379425
$viewData['hidePage'] = $this->isHidePage();
380426
$viewData['pageSizes'] = $this->pageSizes;
381427
$viewData['perPage'] = $this->perPage;

src/Grid/Model.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public function isUsePaginate(): bool
132132
}
133133

134134

135-
136135
public function getModel()
137136
{
138137
return $this->model;
@@ -404,6 +403,10 @@ public function displayData($data)
404403

405404
foreach ($data as $key => $row) {
406405
$item = [];
406+
407+
foreach ($this->grid->getAppendFields() as $field) {
408+
data_set($item, $field, data_get($row, $field));
409+
}
407410
foreach ($columns as $column) {
408411

409412
if (Str::contains($column->getName(), '.')) {

0 commit comments

Comments
 (0)