完善表单功能

This commit is contained in:
2020-04-16 17:49:22 +08:00
parent c005714ea8
commit 5439ccd8fb
4 changed files with 123 additions and 3 deletions

View File

@@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\api;
use think\facade\Db;
use \app\model\Form as FormModel;
use \app\model\FormAttr;
class Form extends Base {
public function index(){
$id = $this->request->param('id');
$name = $this->request->param('name');
$map = [];
$map[] = ['id', '=', $id];
$info = FormModel::where($map)->find();
$attr = FormAttr::where('form_id', $info['id'])->select();
if ($info['relation'] && strpos($info['relation'], ":")) {
list($model, $relation) = explode(":", $info['relation']);
$relation = explode(",", $relation);
if (is_array($relation)) {
$rmap['id'] = ['IN', $relation];
}elseif (is_string($relation)) {
$rmap['id'] = $relation;
}
$info['relation_list'] = Db::name(ucfirst($model))->where($rmap)->order('sort desc, id asc')->select();
}
$this->data['data'] = [
'info' => $info,
'attr' => $attr
];
return $this->data;
}
public function save(){
$data = $this->request->post();
$id = $this->request->param('id');
$info = FormModel::where('id', $id)->find();
$result = Db::name(ucfirst($info['name']))->save($data);
if (false !== $result) {
$this->data['code'] = 1;
}else{
$this->data['code'] = 0;
}
return $this->data;
}
}

View File

@@ -8,6 +8,7 @@
// +----------------------------------------------------------------------
namespace app\controller\front;
use think\facade\Db;
use \app\model\Form as FormModel;
use \app\model\FormAttr;
@@ -19,7 +20,18 @@ class Form extends Base {
*/
public function index(){
if($this->request->isAjax()){
$data = $this->request->post();
$id = $this->request->param('id');
$info = FormModel::where('id', $id)->find();
$result = Db::name(ucfirst($info['name']))->save($data);
if (false !== $result) {
$url = (isset($info['redirect_url']) && $info['redirect_url']) ? $info['redirect_url'] : '';
return $this->success("提交成功!", $url);
}else{
return $this->error("提交失败!");
}
}else{
$id = $this->request->param('id');
$name = $this->request->param('name');
@@ -28,10 +40,23 @@ class Form extends Base {
$map[] = ['id', '=', $id];
$info = Form::where($map)->find();
$info = FormModel::where($map)->find();
$attr = FormAttr::where('form_id', $info['id'])->select();
if ($info['relation'] && strpos($info['relation'], ":")) {
list($model, $relation) = explode(":", $info['relation']);
$relation = explode(",", $relation);
if (is_array($relation)) {
$rmap['id'] = ['IN', $relation];
}elseif (is_string($relation)) {
$rmap['id'] = $relation;
}
$info['relation_list'] = Db::name(ucfirst($model))->where($rmap)->order('sort desc, id asc')->select();
}
$this->data = [
'info' => $info
'info' => $info,
'attr' => $attr
];
return $this->fetch();
}

View File

@@ -0,0 +1,35 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SentCMS网站管理系统</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
<!-- Styles -->
<style>
html, body {background-color: #fff; color: #636b6f; font-family: 'Raleway', sans-serif; font-weight: 100; height: 100vh; margin: 0;}
.top{text-align: right; line-height: 35px; padding: 0 20px;}
.top a{color: #333333; padding: 0 10px}
.full-height {height: 90vh;}
.flex-center {align-items: center;display: flex;justify-content: center;}
.position-ref {position: relative;}
.top-right {position: absolute;right: 10px;top: 18px;}
.content {text-align: center;}
.title {font-size: 84px;}
.links > a {color: #636b6f;padding: 0 25px; font-size: 12px;font-weight: 600;letter-spacing: .1rem;text-decoration: none;text-transform: uppercase;}
.m-b-md {margin-bottom: 30px;}
</style>
</head>
<body>
<div class="top">
<a href="{:url('/user/index/register')}">注册</a>
<a href="{:url('/user/index/login')}">登录</a>
</div>
<div class="flex-center position-ref full-height">
<div class="content">
</div>
</div>
</body>
</html>

View File

@@ -25,7 +25,7 @@ Route::rule('/', 'front.Index/index');
Route::rule('search', 'front.Content/search');
Route::rule('category', 'front.Content/category');
Route::rule('topic-:id', 'front.Content/topic');
Route::rule('form/:id/:name', 'front.Form/index');
Route::rule('form/:id/[:name]', 'front.Form/index');
Route::rule('front/:controller/:function', 'front.:controller/:function');
Route::group('admin', function () {