Commit 1404b31a by 汪伟伟

1

parent 49374f28
......@@ -5,12 +5,11 @@ namespace App\Admin\Controllers;
use App\Admin\Repositories\Task;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Http\JsonResponse;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Row;
use Illuminate\Http\Request;
use Dcat\Admin\Widgets\Tab;
use SuperEggs\DcatDistpicker\DcatDistpickerHelper;
class TaskController extends AdminController
......@@ -20,19 +19,23 @@ class TaskController extends AdminController
*
* @return Grid
*/
protected function grid()
protected function getData($tab = 0)
{
return Grid::make(new Task(), function (Grid $grid) {
return Grid::make(new Task(), function (Grid $grid) use ($tab) {
if ($tab) {
$grid->model()->where('status', $tab);
}
$grid->column('id')->sortable();
$grid->column('name');
$grid->column('level');
$grid->column('area');
$grid->column('city_id')->distpicker();
$grid->column('year');
$grid->column('refer');
$grid->column('guide');
// $grid->column('guide');
// $grid->column('status');
$grid->column('created_at');
$grid->column('updated_at')->sortable();
// $grid->column('created_at');
// $grid->column('updated_at')->sortable();
$grid->filter(function (Grid\Filter $filter) {
// $filter->equal('id');
......@@ -42,6 +45,18 @@ class TaskController extends AdminController
});
}
protected function grid()
{
$tab = Tab::make();
// $tab->add('选项卡1', view('...'));
$tab->add('全部任务', $this->getData());
$tab->add('已经领取任务', 'html2');
$tab->add('已经完成任务', 'html3');
return $tab;
}
/**
* Make a show builder.
*
......@@ -51,17 +66,19 @@ class TaskController extends AdminController
*/
protected function detail($id)
{
return Show::make($id, new Task(), function (Show $show) {
return Show::make($id, new Task(), function (Show $show)use ($id) {
$show->field('id');
$show->field('name');
$show->field('level');
$show->field('area');
$show->field('city_id')->value(DcatDistpickerHelper::getAreaName(\App\Models\Task::query()->find($id)->city_id));
$show->field('year');
$show->field('refer');
$show->field('guide');
// $show->field('status');
$show->field('created_at');
$show->field('updated_at');
// $show->field('created_at');
// $show->field('updated_at');
});
}
......@@ -72,36 +89,54 @@ class TaskController extends AdminController
*/
protected function form()
{
$data = json_decode(file_get_contents(base_path('app/china_all_area.json')),true);
foreach ($data as $datum){
foreach ($datum as $k=>$d){
$arr[$k]=$d;
}
}
// dd(array_values($data));
return Form::make(new Task(), function (Form $form)use ($arr) {
// $data = json_decode(file_get_contents(base_path('app/china_all_area.json')), true);
// foreach ($data as $key=>$datum) {
// if (array_key_exists($key, $data['100000'])) {
// foreach ($datum as $k => $d) {
// $arr[$k] = $d;
// }
// }
// }
return Form::make(new Task(), function (Form $form) {
$form->display('id');
$form->text('name');
$form->select('level')->options([1=>1,2=>2,3=>3,4=>4,5=>5]);
$form->multipleSelect('area','选择地区')->options($arr);
// $form->distpicker([
// 'province_id' => '省',
// ],'地区');
$form->text('name')->required();
$form->select('level')->options([1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5])->required();
// $form->multipleSelect('area', '选择地区')->options($arr)->value('110000')->required();
$form->distpicker([
'province_id' => '省',
'city_id' => '市',
], '选择地区')->required();
// $form->timeRange('year','year','选择时间');
$form->multipleSelect('year','选择时间')->options(function (){
$year=(int)date('Y');
for ($i=$year;$i>1900;$i--){
$years[$i]=$i;
$form->multipleSelect('year', '选择时间')->options(function () {
$year = (int)date('Y');
for ($i = $year; $i > 1900; $i--) {
$years[$i] = $i;
}
return $years;
});
$form->text('refer','参考信源');
$form->editor('guide','收集指南');
})->value(2024)->required();
$form->text('refer', '参考信源')->required();
$form->editor('guide', '收集指南')->required();
// $form->text('status');
$form->display('created_at');
$form->display('updated_at');
// $form->display('created_at');
// $form->display('updated_at');
// // 在表单提交前调用
// $form->submitted(function (Form $form) {
// //...
// });
// //保存前回调
// $form->saving(function (Form $form) {
// dump($form->year);
//
// });
//保存后回调
// $form->saved(function (Form $form) {
// dump($form->name);
// });
});
}
......@@ -113,8 +148,38 @@ class TaskController extends AdminController
public function store()
{
$request = \request();
$request->validate([
'name' => 'required',
'level' => 'required',
'year' => 'required|array',
'refer' => 'required',
'guide' => 'required',
], [
'name.required' => '名称不能为空'
]);
// dd($request->input());
$param = $request->input();
$query = \App\Models\Task::query();
foreach ($param['year'] as $y) {
if ($y) {
$insertData = [
'name' => $param['name'],
'level' => $param['level'],
'province_id' => $param['province_id'],
'city_id' => $param['city_id'],
'year' => [$y],
'refer' => $param['refer'],
'guide' => $param['guide'],
];
$query->create($insertData);
}
}
$form = Form::make();
dd($request->input());
return $form->response()->success('操作成功')->redirect('tasks');
}
......
......@@ -4,9 +4,53 @@ namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class Task extends Model
{
use HasDateTimeFormatter;
use HasDateTimeFormatter, HasFactory, Notifiable;
protected $table = 'tasks';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'level',
'province_id',
'city_id',
'year',
'refer',
'guide',
'price',
'status',
'created_at',
'updated_at',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [];
// public function getYearAttribute($value)
// {
// return explode(',', $value);
// }
public function setYearAttribute($value)
{
$this->attributes['year'] = implode(',', $value);
}
}
......@@ -6,7 +6,7 @@ services:
- '8383:80'
environment:
TZ: 'Asia/Shanghai'
WEBROOT: '/var/www/html/laravel-box/public'
WEBROOT: '/var/www/html/data-collect/public'
# PHP_REDIS_SESSION_HOST: 'redis'
CREATE_LARAVEL_STORAGE: '1'
volumes:
......
......@@ -7,7 +7,7 @@ return [
'fields' => [
'name' => '指标名称',
'level' => '难度等级',
'area' => '地区',
'city_id' => '地区',
'year' => '时间',
'refer' => '信源',
'guide' => '参考指南',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment