Skip to content

Commit ba88ce6

Browse files
author
hikki
committed
v3.6
1 parent 4befbe8 commit ba88ce6

File tree

2 files changed

+88
-72
lines changed

2 files changed

+88
-72
lines changed

src/Widget/CascadeLine.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ public function render()
1919
$width = isset($this->attributes['width']) ? $this->attributes['width'] : '100%';
2020
$height = isset($this->attributes['height']) ? $this->attributes['height'] : '230px';
2121
$this->addVariables(['width'=>$width,'height' => $height]);
22-
$select = json_encode($this->options, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
22+
$list = json_encode($this->list, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
2323
$xhr = $this->xhr ?? '';
2424
$options = isset($this->attributes['options']) ? json_encode($this->attributes['options']) : json_encode(['movable' => true,'exchange' => true,'insert' => true,'update' => true,'delete' => true]);
2525
$this->script = <<<EOT
26-
new ComponentCascadeLine("{$id}",JSON.parse('{$select}'),'{$xhr}');
26+
new ComponentCascadeLine("{$id}",JSON.parse('{$list}'),'{$xhr}');
2727
EOT;
2828
return parent::render();
2929
}
3030

3131
/**
3232
* 直接调用ComponentCascadeLine组件
3333
* @param string $name 名称
34-
* @param array $select 全部选项
34+
* @param array $list 数据集
3535
* @param string $xhr ajax接口地址
3636
* @param array $style 组件样式设置 宽:width 高:height
3737
* @param array $options
@@ -42,9 +42,9 @@ public function render()
4242
* options.delete bool 可删除
4343
* @return string
4444
*/
45-
public static function panel($name,array $select,string $xhr,array $style=[],array $options=[])
45+
public static function panel($name,array $list,string $xhr,array $style=[],array $options=[])
4646
{
47-
$select = json_encode($select, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
47+
$list = json_encode($list, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
4848
$style = array_merge(['width'=>'100%','height'=>'230px'],$style);
4949
$style_string = '';
5050
$options = json_encode(array_merge([
@@ -58,7 +58,7 @@ public static function panel($name,array $select,string $xhr,array $style=[],arr
5858
}
5959

6060
return <<<EOF
61-
<div id="{$name}" style="$style_string"></div><script>new ComponentCascadeLine("{$name}",JSON.parse('{$select}'),'{$xhr}',JSON.parse('{$options}'));</script>
61+
<div id="{$name}" style="$style_string"></div><script>new ComponentCascadeLine("{$name}",JSON.parse('{$list}'),'{$xhr}',JSON.parse('{$options}'));</script>
6262
EOF;
6363
}
6464
}

test/example.php

Lines changed: 82 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Admin\Controllers;
44

55
use DLP\Tool\Assistant;
6-
use DLP\Tool\FormPanel;
76
use DLP\Widget\Plane;
87
use Encore\Admin\Admin;
98
use Encore\Admin\Controllers\AdminController;
@@ -46,7 +45,7 @@ protected function grid()
4645
* url 弹窗页地址
4746
* xhr_url 表单提交地址
4847
* method 提交方式 POST PUT GET ...
49-
* callback ajax请求回调函数
48+
* callback ajax请求回调js函数 (字符串方式书写)
5049
* function(response){
5150
* alert(response);
5251
* }
@@ -59,7 +58,7 @@ protected function grid()
5958
* url 弹窗页地址 {id}反向匹配当前行id
6059
* xhr_url 表单提交地址 {id}反向匹配当前行id
6160
* method 提交方式 POST PUT GET ...
62-
* callback ajax请求回调函数
61+
* callback ajax请求回调js函数 (字符串方式书写)
6362
* function(response){
6463
* alert(response);
6564
* }
@@ -128,9 +127,13 @@ protected function form($id)
128127

129128
/**
130129
* 点组件
131-
* options 设置数据集 一维数组 格式 [value1=>text1,value2=>text2...]
132-
* checked 已选择 一维数组 值类型integer
130+
* options 设置数据集 一维数组 格式 [value1=>text1,value2=>text2...]
131+
* checked 已选择 一维数组 值类型integer
132+
* attribute.width 设置宽度 默认100%
133133
* attribute.height 设置高度 默认200px
134+
* attribute.limit 选择限制数 默认0:无限
135+
* attribute.mode 组件模式设置 false:默认模式 true:下拉列表模式
136+
* attribute.placeholder 下拉列表模式 默认未选择占位
134137
*/
135138
$form->Dot('dot','标签选择器')
136139
->options([1=>'松下紗栄子',2=>'上原亜衣',3=>'白石茉莉奈',4=>'美谷朱里',5=>'沖田杏梨',6=>'由愛可奈',7=>'七瀬あいり',8=>'五十嵐星蘭',9=>'仲里紗羽',10=>'波多野結衣'])
@@ -141,93 +144,106 @@ protected function form($id)
141144
* 级联点组件
142145
* options 设置数据集 多维数组 格式[[key=>key1,val=>value1,nodes=>[...]],...]
143146
* 链表结构数据辅助组装
144-
* 1.倒排父节点查询
145-
* $select = Model::orderBy('parent_id','DESC')->select('id as key','name as val','parent_id as par')->get()->toArray();
147+
* 1.倒排父节点查询 注:id name parent_id 必须命别名 key val par
148+
* $select = Model::orderBy('par','DESC')->select('id as key','name as val','parent_id as par')->get()->toArray();
146149
* 2.辅助函数dimension 组装后的结构参考$this->cascadeData()的示例数据
147150
* DLPHelper::dimension($select);
148-
* checked 已选择 一维数组 值类型integer
151+
* checked 已选择 一维数组 值类型integer
152+
* attribute.width 设置宽度 默认100%
149153
* attribute.height 设置高度 默认200px
154+
* attribute.limit 选择限制数 默认0:无限
150155
*/
151-
$form->CascadeDot('cascadeDot','级联标签选择器')
152-
->options($this->cascadeData())
156+
$form->CascadeDot('cascadeDot','级联选择器')
157+
->options($this->cascadeExampleData())
153158
->checked([614,550,543])
154159
->attribute(['height'=>'200px']);
155160

156161
/**
157162
* 线组件
158-
* columns 设置列表head名称 row字段输出格式input,text,hidden
159-
* options 设置数据集 二维数组
160-
* attribute.height 设置高度 默认360px
161-
* attribute.options 设置操作列 默认开启['sortable'=>true,'delete'=>true]
163+
* columns[column...] 列数据格式配置
164+
* column.name 列表头名称
165+
* column.type 列数据 输出格式input,text,hidden,datetime,date,select,image,file
166+
* column.insert_type 增加列格式(不填时默认等同于type值) hidden表示置空
167+
* column.options insert_type或type为select时 多选项
168+
* column.options_limit insert_type或type为select时 多选项选择限制数 默认0:无限制
169+
* column.style 自定义style格式
170+
* list 设置数据集 二维数组列表格式
171+
* attribute.width 设置宽度 默认100%
172+
* attribute.height 设置高度 默认355px
173+
* attribute.options 设置操作列 默认开启:可排序/可删除/可新增['sortable' => true, 'delete' => true, 'insert' => true]
162174
*/
163-
$form->Linear('flux_linkage', '磁力链接')
175+
$form->Linear('line', '列表管理器')
164176
->columns([
165177
'name' => ['name' => '名称', 'type' => 'input'],
166-
'meta' => ['name' => '信息', 'type' => 'input'],
167-
'url' => ['name' => '链接', 'type' => 'input'],
168-
'time' => ['name' => '更新时间', 'type' => 'text'],
169-
'is-small' => ['name' => '高清[1是 2否]', 'type' => 'input', 'style' => 'width:60px'],
170-
'is-warning' => ['name' => '含字幕[1是 2否]', 'type' => 'input', 'style' => 'width:60px']
178+
'meta' => ['name' => '信息', 'type' => 'input','insert_type'=>'hidden'],
179+
'url' => ['name' => '链接', 'type' => 'image'],
180+
'time' => ['name' => '更新时间', 'type' => 'text','insert_type'=>'datetime'],
181+
'is-small' => ['name' => '高清', 'type' => 'select','options'=>[1=>'',2=>''],'options_limit'=>1, 'style' => 'width:60px']
171182
])
172-
->options([
173-
['name'=>'01','meta'=>'test info1','url'=>'1','time'=>'2021-05-15 00:00:00','is-small'=>1,'is-warning'=>1],
174-
['name'=>'02','meta'=>'test info2','url'=>'2','time'=>'2021-05-15 00:00:00','is-small'=>1,'is-warning'=>1],
175-
['name'=>'03','meta'=>'test info3','url'=>'3','time'=>'2021-05-15 00:00:00','is-small'=>1,'is-warning'=>1]]);
183+
->list([
184+
['name'=>'01','meta'=>'test info1','url'=>'1','time'=>'2021-05-15 00:00:00','is-small'=>1],
185+
['name'=>'02','meta'=>'test info2','url'=>'2','time'=>'2021-05-15 00:00:00','is-small'=>1],
186+
['name'=>'03','meta'=>'test info3','url'=>'3','time'=>'2021-05-15 00:00:00','is-small'=>1]])
187+
->attribute(['height' => '360px','options'=>['sortable' => true, 'delete' => true, 'insert' => true]]);
176188

177189
/**
178190
* 级联线组件
179-
* options 设置数据集 多维数组 格式[[key=>key1,val=>value1,nodes=>[...]],...]
191+
* list 设置数据集 多维数组 格式[[key=>key1,val=>value1,nodes=>[...]],...]
180192
* 链表结构数据辅助组装
181-
* 1.倒排父节点查询
193+
* 1.倒排父节点查询 注:id name parent_id 必须命别名 key val par
182194
* $select = Model::orderBy('parent_id','DESC')->select('id as key','name as val','parent_id as par')->get()->toArray();
183195
* 2.辅助函数dimension 组装后的$select结构参考$this->cascadeExampleData()返回数据
184196
* DLPHelper::dimension($select);
185-
* xhr 接口地址 编码参见:test\CascadeLineController
186-
* attribute.height 设置高度 默认200px
197+
* xhr 接口地址 编码参见文件:test\CascadeLineController 路由配置$router->resource('xhr地址', 'CascadeLineController')
198+
* attribute.width 设置宽度 默认100%
199+
* attribute.height 设置高度 默认200px
200+
* attribute.options 设置 可迁移(迁移该节点与其子集到其他节点下)/可交换(节点与其后代节点交换位置)/可新增/可修改/可删除
201+
* ['movable' => true,'exchange' => true,'insert' => true,'update' => true,'delete' => true]
187202
*/
188-
$form->CascadeLine('cascadeLine','级联标签管理器')
189-
->options($this->cascadeExampleData())
190-
->xhr('route-to-CascadeLineController');
203+
$form->CascadeLine('cascadeLine','级联管理器')
204+
->list($this->cascadeExampleData())
205+
->xhr('.../xhr地址')
206+
->attribute(['height' => '200px','options'=>['movable' => true,'exchange' => true,'insert' => true,'update' => true,'delete' => true]]);
191207
return $form;
192208
}
193209

194210
public function blank()
195-
{
196-
$title = '<h1>松下紗栄子</h1>';
197-
/*弹窗模式 渲染自定义页模板 Plane::html*/
198-
$panel = new FormPanel();
199-
$panel->input('id','序号');
200-
$panel->textarea('descript','描述');
201-
$panel->select('status','状态',[0],[0=>'开启',1=>'关闭',2=>'删除'],1);
202-
$panel->datepicker('time','时间');
203-
$panel->html('test','自定义','<p>松下紗栄子</p>');
204-
/*多图/文件 上传样例*/
205-
$settings = [
206-
'uploadUrl' => 'https://...upload.file.url...',
207-
'uploadExtraData' => [
208-
'_token' => csrf_token(),
209-
'uploadAsync' => true,
210-
/*自定义加传参*/
211-
],
212-
'deleteUrl' => 'https://...delete.file.url...',
213-
'deleteExtraData' => [
214-
'_token' => csrf_token(),
215-
'uploadAsync' => true,
216-
/*自定义加传参*/
217-
],
218-
'maxFileCount' => 10,
219-
'maxFileSize' => 800 //单图限制800kb
220-
];
221-
$images = ['/image1...','/image2...','/image3...'];
222-
$panel->fileInput('photo','艳照',$settings,
223-
['files' => $images, 'url' => '/image.server...'],
224-
"accept='image/*'");
225-
226-
$html = $panel->compile();
227-
return Plane::html($title.$html);
228-
}
211+
{
212+
$title = '<h1>松下紗栄子</h1>';
213+
/*弹窗模式 渲染自定义页模板 Plane::html*/
214+
$panel = new FormPanel();
215+
$panel->input('id','序号');
216+
$panel->textarea('description','描述');
217+
$panel->select('status','状态',[0],[0=>'开启',1=>'关闭',2=>'删除'],1);
218+
$panel->datepicker('time','时间');
219+
$panel->html('test','自定义html','<p>松下紗栄子</p>');
220+
/*多图上传样例*/
221+
$settings = [
222+
'uploadUrl' => 'https://...upload.file.url...',
223+
'uploadExtraData' => [
224+
'_token' => csrf_token(),
225+
'uploadAsync' => true,
226+
/*自定义加传参*/
227+
],
228+
'deleteUrl' => 'https://...delete.file.url...',
229+
'deleteExtraData' => [
230+
'_token' => csrf_token(),
231+
'uploadAsync' => true,
232+
/*自定义加传参*/
233+
],
234+
'maxFileCount' => 10,
235+
'maxFileSize' => 800 //单图限制800kb
236+
];
237+
$images = ['/image1...','/image2...','/image3...'];
238+
$panel->fileInput('photo','艳照',$settings,
239+
['files' => $images, 'url' => '/image.server...'],
240+
"accept='image/*'");
241+
242+
$html = $panel->compile();
243+
return Plane::html($title.$html);
244+
}
229245

230-
private function cascadeData()
246+
private function cascadeExampleData()
231247
{
232248
return [
233249
["key" => "3", "val" => "基本", "nodes" => [

0 commit comments

Comments
 (0)