1
0
Fork 0
internet-everythings-agricu.../app/Admin/Components.php

235 lines
7.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Admin;
use App\Models\Keyword;
use Slowlyo\OwlAdmin\Renderers\BaseRenderer;
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);
}
/**
* 排序字段
*/
public function sortControl($name ='sort', $label = '排序'){
return amisMake()->NumberControl()
->name($name)->label($label)
->displayMode('enhance')
->value(0)
->min(0);
}
/**
* 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 = '内容', $uploadUrl = ''){
return amisMake()->RichTextControl()->vendor('tinymce')
->options([
"menubar" => false,
"min_height" => 500,
"plugins" => 'image link table lists charmap emoticons code table fullscreen',
"toolbar" => "undo redo | bold italic underline strikethrough | fontfamily fontsize blocks | alignleft aligncenter alignright alignjustify | image link | outdent indent | numlist bullist table | forecolor backcolor removeformat | charmap emoticons | code fullscreen",
"toolbar_mode" => "wrap",
"help_tabs" => [],
"convert_urls" => false,
// "quickbars_selection_toolbar" => "fontsize forecolor backcolor",
// "quickbars_insert_toolbar" => false,
])
->receiver(admin_url('upload_rich'))
->name($name)
->label($label);
//froala去除授权提示但是保存会有额外内容需要处理
//<style type="text/css">
// a[href="https://froala.com/wysiwyg-editor"], a[href="https://www.froala.com/wysiwyg-editor?k=u"]{
// display: none !important;
// position: absolute;
// top: -99999999px;
// }
// </style>
}
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'));
}
public function keywordsTagControl($name = 'tags', $label= '标签', $typeKey = ''){
return amisMake()->TagControl()
->name($name)->label($label)
->options(Keyword::getByParentKey($typeKey)->pluck('name', 'id')->toArray());
}
public function keywordsTag($label = '标签'){
return amisMake()->Tag()->label($label)->displayMode('rounded')->color('inactive');
}
/**
* 生成统计图config
* 折线图或者柱状图
*/
public function chartLineBarConfig($title = '', array $x , array $y){
$yAxisData = [];
$seriesData = [];
$color = [];
if(!isset($y[0])){
$_y = $y;
$y = [0=>$_y];
}
$i = 0;
$tips = '{b0}';
foreach($y as $item) {
//调色盘
$color[] = $item['color'];
//tips
$tips.= '<br/> {a'.$i.'}: {c'.$i.'}'.($item['unit'] ?? '');
//纵坐标
$yAxisData[] = [
'name'=>($item['unit'] ?? ''),
'type' =>'value',
'axisTick' => true,
'alignTicks' => true,
'axisLine' => [
'show' => true,
'lineStyle' => [
'color' => $item['color'] ?? ''
]
],
'axisLabel'=> [
'formatter'=>'{value} '
]
];
//数据
$_series = [
'name' => $item['name'] ?? '',
'data' => $item['data'] ?? [],
'type' => $item['type'] ?? 'line',
'yAxisIndex' => $i,
];
switch($item['type']){
case 'line':
$_series = array_merge($_series, [
'smooth'=> true,
'symbol'=> 'none',
'lineStyle' => [
'color' => $item['color'] ?? ''
],
'areaStyle' => [
'color' => $item['color'] ?? ''
],
]);
break;
case 'bar':
$_series = array_merge($_series, [
]);
break;
}
$seriesData[] = $_series;
$i++;
}
return [
'color' => $color,
'title' => [
'text' => $title,
],
"tooltip" => [//提示
'trigger'=>'axis',//坐标轴触发
'axisPointer' => [
'type' => 'cross'
],
// 'formatter' => $tips
],
'grid' => [
'left' => '8%',
'right' => '8%',
],
'xAxis' => [
'type' => 'category',
'data' => $x,
],
'yAxis' => $yAxisData,
'series' => $seriesData
];
}
/**
* 散点图
*/
public function chartScatterConfig($title = '', array $x , array $y, array $yData = null){
$yAxisData = [];
$seriesData = [];
$color = [];
if($yData){
$yAxisData = [
'type' =>'category',
// 'splitLine'=>[
// 'show'=>true,
// 'lineStyle'=>[
// 'type'=>'dashed'
// ]
// ],
'axisTick' => [
'alignWithLabel'=>true
],
'data'=> $yData
];
}
$seriesData = $y;
return [
'color' => $color,
'title' => [
'text' => $title,
],
"tooltip" => [//提示
'trigger'=>'axis',//坐标轴触发
'axisPointer' => [
'type' => 'cross'
],
],
'xAxis' => [
'type' => 'category',
'data' => $x,
],
'yAxis' => $yAxisData,
'series' => $seriesData
];
}
/**
* 生成饼状图config
* -todo
*/
public function chartPieConfig(){
return ;
}
}