自定义表单功能优化修复

This commit is contained in:
2020-04-11 11:52:55 +08:00
parent 4e4aad4f93
commit 31810784ab
10 changed files with 126 additions and 97 deletions

View File

@@ -66,7 +66,12 @@ class Content extends Base {
*/
public function add() {
if ($this->request->isPost()) {
$result = $this->model->save($this->request->post());
$data = $this->request->post();
$data['create_time'] = time();
$data['update_time'] = time();
$data['uid'] = session('userInfo.uid');
$result = $this->model->save($data);
if ($result) {
return $this->success("添加成功!", url('/admin/'.$this->modelInfo['name'].'/index'));
} else {
@@ -98,7 +103,10 @@ class Content extends Base {
*/
public function edit($id) {
if ($this->request->isPost()) {
$result = $this->model->save($this->request->post());
$data = $this->request->post();
$data['update_time'] = time();
$result = $this->model->save($data);
if ($result !== false) {
return $this->success("更新成功!", url('/admin/'.$this->modelInfo['name'].'/index'));
} else {

View File

@@ -8,6 +8,7 @@
// +----------------------------------------------------------------------
namespace app\controller\admin;
use think\facade\Db;
use app\model\Form as FormM;
use app\model\FormAttr;
@@ -17,6 +18,15 @@ use app\model\FormAttr;
*/
class Form extends Base {
public $modelInfo = [];
public $model = null;
public function initialize() {
parent::initialize();
$this->modelInfo = FormM::where('id', $this->request->param('form_id'))->find();
$this->model = Db::name('Form'.ucfirst($this->modelInfo['name']));
}
/**
* @title 表单列表
*/
@@ -78,10 +88,15 @@ class Form extends Base {
* @title 删除表单
*/
public function del() {
$id = $this->getArrayParam('id');
$result = false;
if (false !== $result) {
return $this->success('删除成功');
$id = $this->request->param('id', 0);
if (!$id) {
return $this->error('非法操作');
}
$result = FormM::find($id)->delete();
if ($result) {
return $this->success('删除模型成功!');
} else {
return $this->error('删除失败!');
}
@@ -95,18 +110,17 @@ class Form extends Base {
* @return html 页面
*/
public function lists($form_id = '') {
$form = $this->model->where('id', $form_id)->find();
$form = $this->modelInfo;
$list = M($form['name'], 'form')->order('id desc')->paginate(25);
$list = $this->model->order('id desc')->paginate(25);
$data = array(
$this->data = array(
'meta_title' => $this->modelInfo['title'] . '列表',
'form_id' => $form_id,
'list' => $list,
'page' => $list->render()
);
$this->assign($data);
$this->setMeta('数据列表');
return $this->fetch('list_'.$form['name']);
return $this->fetch();
}
/**