Skip to content

Commit e9a00a5

Browse files
author
hikki
committed
兼容问题
1 parent a2cafa3 commit e9a00a5

File tree

5 files changed

+75
-25
lines changed

5 files changed

+75
-25
lines changed

src/CascadeDot.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace DLP;
44

5-
use Encore\Admin\Form\Field;
65

7-
class CascadeDot extends Field
6+
class CascadeDot extends DLPField
87
{
98
protected $view = 'dlp::component';
109

@@ -14,10 +13,7 @@ public function render()
1413
$height = isset($this->attributes['height']) ? $this->attributes['height'] : '200px';
1514
$this->addVariables(['height'=>$height]);
1615
$select = json_encode($this->options, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
17-
$selected = array_map(function ($v) {
18-
return (int)$v;
19-
}, array_values($this->checked));
20-
$selected = json_encode($selected);
16+
$selected = json_encode($this->checked);
2117
$this->script = <<<EOT
2218
new ComponentCascadeDot("{$id}",JSON.parse('{$selected}'),JSON.parse('{$select}'));
2319
EOT;

src/DLPField.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
namespace DLP;
3+
4+
use Encore\Admin\Form\Field;
5+
use Illuminate\Contracts\Support\Arrayable;
6+
7+
class DLPField extends Field
8+
{
9+
protected $view = 'dlp::component';
10+
11+
/**
12+
* Set the field options.
13+
*
14+
* @param array $options
15+
*
16+
* @return $this
17+
*/
18+
public function options($options = [])
19+
{
20+
if ($options instanceof Arrayable) {
21+
$options = $options->toArray();
22+
}
23+
24+
$this->options = $options;
25+
return $this;
26+
}
27+
28+
/**
29+
* Set the field option checked.
30+
*
31+
* @param array $checked
32+
*
33+
* @return $this
34+
*/
35+
public function checked($checked = [])
36+
{
37+
if ($checked instanceof Arrayable) {
38+
$checked = $checked->toArray();
39+
}
40+
41+
$this->checked = array_map(function ($v) {
42+
return (int)$v;
43+
}, array_values($checked));;
44+
return $this;
45+
}
46+
47+
/**
48+
* Set the field option checked.
49+
*
50+
* @param array $columns
51+
*
52+
* @return $this
53+
*/
54+
public function columns($columns)
55+
{
56+
if ($columns instanceof Arrayable) {
57+
$columns = $columns->toArray();
58+
}
59+
60+
$this->columns = $columns;;
61+
return $this;
62+
}
63+
}

src/Dot.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace DLP;
44

5-
use Encore\Admin\Form\Field;
65

7-
class Dot extends Field
6+
class Dot extends DLPField
87
{
98
protected $view = 'dlp::component';
109

@@ -14,10 +13,7 @@ public function render()
1413
$height = isset($this->attributes['height']) ? $this->attributes['height'] : '200px';
1514
$this->addVariables(['height'=>$height]);
1615
$select = json_encode($this->options, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
17-
$selected = array_map(function ($v) {
18-
return (int)$v;
19-
}, array_values($this->checked));
20-
$selected = json_encode($selected);
16+
$selected = json_encode($this->checked);
2117
$this->script = <<<EOT
2218
new ComponentDot("{$id}",JSON.parse('{$selected}'),JSON.parse('{$select}'));
2319
EOT;

src/Linear.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
namespace DLP;
44

5-
use Encore\Admin\Form\Field;
65

7-
class Linear extends Field
6+
class Linear extends DLPField
87
{
98
protected $view = 'dlp::component';
109

1110
public function render()
1211
{
1312
$id = $this->formatName($this->id);
14-
if(isset($this->attributes['columns'])){
15-
$columns = json_encode($this->attributes['columns']);
13+
if(isset($this->columns)){
14+
$columns = json_encode($this->columns);
1615
}else{
1716
$columns = [];
1817
foreach (array_keys(current($this->options)) as $key){
1918
$columns[$key] = ['name'=>$key,'type' => 'text'];
2019
}
2120
$columns = json_encode($columns);
2221
}
23-
$this->attributes['columns'] = null;
2422
$options = isset($this->attributes['options']) ? json_encode($this->attributes['options']) : json_encode(['sortable'=>true,'delete'=>true]);
2523
$height = isset($this->attributes['height']) ? $this->attributes['height'] : '360px';
2624
$this->addVariables(['height'=>$height]);

test/example.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ protected function form($id)
132132
* attribute.height 设置高度 默认200px
133133
*/
134134
$form->Dot('dot','标签选择器')
135-
->options([1=>'松下紗栄子',2=>'上原亜衣',3=>'白石茉莉奈',4=>'美谷朱里',5=>'沖田杏梨',
136-
6=>'由愛可奈',7=>'七瀬あいり',8=>'五十嵐星蘭',9=>'仲里紗羽',10=>'波多野結衣'])
135+
->options([1=>'松下紗栄子',2=>'上原亜衣',3=>'白石茉莉奈',4=>'美谷朱里',5=>'沖田杏梨',6=>'由愛可奈',7=>'七瀬あいり',8=>'五十嵐星蘭',9=>'仲里紗羽',10=>'波多野結衣'])
137136
->checked([1,2,3])
138137
->attribute(['height'=>'200px']);
139138

@@ -150,7 +149,7 @@ protected function form($id)
150149
*/
151150
$form->CascadeDot('cascadeDot','级联标签选择器')
152151
->options($this->cascadeData())
153-
->checked([614,377,550,543,544])
152+
->checked([614,550,543])
154153
->attribute(['height'=>'200px']);
155154

156155

@@ -166,16 +165,14 @@ protected function form($id)
166165
['name'=>'01','meta'=>'test info1','url'=>'1','time'=>'2021-05-15 00:00:00','is-small'=>1,'is-warning'=>1],
167166
['name'=>'02','meta'=>'test info2','url'=>'2','time'=>'2021-05-15 00:00:00','is-small'=>1,'is-warning'=>1],
168167
['name'=>'03','meta'=>'test info3','url'=>'3','time'=>'2021-05-15 00:00:00','is-small'=>1,'is-warning'=>1]])
169-
->attribute([
170-
'columns' => [
168+
->columns([
171169
'name' => ['name' => '名称', 'type' => 'input'],
172170
'meta' => ['name' => '信息', 'type' => 'input'],
173171
'url' => ['name' => '链接', 'type' => 'input'],
174172
'time' => ['name' => '更新时间', 'type' => 'text'],
175173
'is-small' => ['name' => '高清[1是 2否]', 'type' => 'input', 'style' => 'width:60px'],
176-
'is-warning' => ['name' => '含字幕[1是 2否]', 'type' => 'input', 'style' => 'width:60px'],
177-
'tooltip' => ['name' => '可下载[1是 2否]', 'type' => 'input', 'style' => 'width:60px']]
178-
]);
174+
'is-warning' => ['name' => '含字幕[1是 2否]', 'type' => 'input', 'style' => 'width:60px']
175+
]);
179176
return $form;
180177
}
181178

0 commit comments

Comments
 (0)