招标
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

94 lines
2.6 KiB

<?php
/**
*
* RequestMerge.php
* User: ChenLong <vip_chenlong@163.com>
* DateTime: 2020/6/18 11:59
*/
namespace app\common\traits\admin;
use app\common\BasePage;
use sdModule\common\Sc;
use sdModule\layui\defaultForm\Form;
use think\Request;
/**
* 请求合并,方便权限设置,如需拆开即可
* @property-read Request $request
* @method BasePage getPage()
* Trait RequestMerge
* @package app\common\controller\traits
*/
trait RequestMerge
{
/**
* 列表页数据
* @return mixed
*/
public function index()
{
if ($this->request->isPost() || $this->request->isAjax()) {
return method_exists($this, 'listData') ? $this->listData() : $this->listsRequest();
}
return $this->lists();
}
/**
* 数据新增
* @return mixed
* @throws \ReflectionException
* @throws \app\common\SdException
*/
public function create()
{
if ($this->request->isPost()) {
return $this->dataHandle();
}
if (method_exists($this, 'add')) {
return Sc::reflex()->invoke($this, 'add');
}
return $this->fetch($this->getPage()->form_template, [
'form' => Form::create($this->getPage()->formData(), 'add')
->setShortFrom($this->getPage()->shortInput())
->setCustomMd($this->getPage()->md)
->setSkinToPane($this->getPage()->setFormSkin())
->setJs($this->getPage()->formJs())->complete()
]);
}
/**
* 数据更新
* @return mixed
* @throws \ReflectionException
* @throws \app\common\SdException
*/
public function update()
{
$page = 'edit';
if ($this->request->isPost()) {
return $this->dataHandle($page);
}
if (method_exists($this, $page)) {
return Sc::reflex()->invoke($this, $page, [$this->primary => $this->request->param('id', 0)]);
}
$data = $this->getModel()::getDataById($this->request->param('id', 0))->getData();
$default_filter = $this->getPage()->getOnlyFieldVal($page) and $data = data_only($data, $default_filter);
return $this->fetch($this->getPage()->form_template, [
'form' => Form::create($this->getPage()->formData(), $page)
->setDefaultData($data)
->setShortFrom($this->getPage()->shortInput())
->setCustomMd($this->getPage()->md)
->setSkinToPane($this->getPage()->setFormSkin())
->setJs($this->getPage()->formJs())->complete()
]);
}
}