generated from panliang/owl-admin-starter
125 lines
3.7 KiB
PHP
125 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin;
|
|
|
|
use Slowlyo\OwlAdmin\Renderers\BaseRenderer;
|
|
use Slowlyo\OwlAdmin\Renderers\WangEditor;
|
|
|
|
class Components extends BaseRenderer
|
|
{
|
|
/**
|
|
* 父级选择器
|
|
*/
|
|
public function parentControl($apiUrl = '', $name = 'parent_id', $label = '父级', $labelField = 'name', $valueField = 'id')
|
|
{
|
|
return amisMake()->TreeSelectControl()
|
|
->name($name)
|
|
->label($label)
|
|
->showIcon(false)
|
|
->labelField($labelField)
|
|
->valueField($valueField)
|
|
->source($apiUrl);
|
|
}
|
|
|
|
/**
|
|
* 排序字段
|
|
*
|
|
* @param string $name 表单name
|
|
* @param string $label 表单label
|
|
* @param string $scene 场景 {table: 表格行内修改, form: 单行表单, show: 静态展示}
|
|
*/
|
|
public function sortControl($name, $label, $scene = 'form')
|
|
{
|
|
$formItem = amisMake()->NumberControl()
|
|
->name($name)
|
|
->label($label)
|
|
->displayMode('enhance')
|
|
->value(0)
|
|
->min(0)
|
|
->saveImmediately(true);
|
|
if ($scene == 'table') {
|
|
return amisMake()->TableColumn()
|
|
->align('center')
|
|
->name($name)
|
|
->label($label)
|
|
->quickEdit($formItem);
|
|
} elseif ($scene == 'show') {
|
|
return amisMake()->textControl()->name($name)->label($label)->static(true);
|
|
} else {
|
|
return $formItem;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 2位小数输入框
|
|
*/
|
|
public function decimalControl($name = 'decimal', $label = '数值')
|
|
{
|
|
return amisMake()->NumberControl()
|
|
->name($name)->label($label)
|
|
->kilobitSeparator(true)
|
|
->percision(2)
|
|
->step(0.01)
|
|
->value(0.00)
|
|
->min(0);
|
|
}
|
|
|
|
/**
|
|
* 富文本编辑器
|
|
*/
|
|
public function fuEditorControl($name = 'content', $label = '内容')
|
|
{
|
|
return WangEditor::make()
|
|
->name($name)
|
|
->label($label)
|
|
->height('500px')
|
|
->uploadImageServer(url('/admin-api/upload_rich'))
|
|
->excludeKeys(['group-video']);
|
|
}
|
|
|
|
/**
|
|
* switch
|
|
*
|
|
* @param string $scene 场景 {table: 表格行内修改, form: 单行表单, show: 详细页展示, static: 静态展示}
|
|
*/
|
|
public function switchControl($scene = 'table')
|
|
{
|
|
if ($scene == 'table') {
|
|
return amisMake()
|
|
->TableColumn()
|
|
->type('switch')
|
|
->quickEdit(amisMake()->SwitchControl()->saveImmediately(true)->mode('inline'));
|
|
} elseif ($scene == 'form') {
|
|
return amisMake()
|
|
->SwitchControl()
|
|
->value(false);
|
|
} elseif ($scene == 'show') {
|
|
return amisMake()
|
|
->TextControl()
|
|
->static(true)
|
|
->staticSchema(amisMake()->Status()->source([
|
|
['icon' => 'fa fa-close', 'color' => '#cc292e'],
|
|
['icon' => 'fa fa-check', 'color' => '#30bf13'],
|
|
]));
|
|
} elseif ($scene == 'static') {
|
|
return amisMake()->Status()->source([
|
|
['icon' => 'fa fa-close', 'color' => '#cc292e'],
|
|
['icon' => 'fa fa-check', 'color' => '#30bf13'],
|
|
]);
|
|
}
|
|
|
|
return amisMake()->SwitchControl();
|
|
}
|
|
|
|
public function enableControl($name = 'is_enable', $label = '状态', $mode = 'horizontal')
|
|
{
|
|
return amisMake()
|
|
->SwitchControl()
|
|
->name($name)
|
|
->label($label)
|
|
->mode($mode)
|
|
->onText(__('admin.extensions.status_map.enabled'))
|
|
->offText(__('admin.extensions.status_map.disabled'));
|
|
}
|
|
}
|