自定义表单功能
This commit is contained in:
@@ -12,20 +12,26 @@ use app\common\controller\Admin;
|
|||||||
|
|
||||||
class Form extends Admin {
|
class Form extends Admin {
|
||||||
|
|
||||||
public function _initialize(){
|
public function _initialize() {
|
||||||
parent::_initialize();
|
parent::_initialize();
|
||||||
$this->model = model('Form');
|
$this->model = model('Form');
|
||||||
|
$this->Fattr = model('FormAttr');
|
||||||
|
//遍历属性列表
|
||||||
|
foreach (get_attribute_type() as $key => $value) {
|
||||||
|
$this->attr[$key] = $value[0];
|
||||||
|
}
|
||||||
|
$this->field = $this->getField();
|
||||||
}
|
}
|
||||||
|
|
||||||
//自定义表单
|
//自定义表单
|
||||||
public function index(){
|
public function index() {
|
||||||
$map = array();
|
$map = array();
|
||||||
$order = "id desc";
|
$order = "id desc";
|
||||||
$list = $this->model->where($map)->order($order)->paginate(25);
|
$list = $this->model->where($map)->order($order)->paginate(25);
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
'page' => $list->render()
|
'page' => $list->render(),
|
||||||
);
|
);
|
||||||
$this->setMeta('自定义表单');
|
$this->setMeta('自定义表单');
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
@@ -35,17 +41,17 @@ class Form extends Admin {
|
|||||||
/**
|
/**
|
||||||
* 添加表单
|
* 添加表单
|
||||||
*/
|
*/
|
||||||
public function add(\think\Request $request){
|
public function add(\think\Request $request) {
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$result = $this->model->validate('Form')->save($request->post());
|
$result = $this->model->validate('Form')->save($request->post());
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $this->success('添加成功!', url('admin/form/index'));
|
return $this->success('添加成功!', url('admin/form/index'));
|
||||||
}else{
|
} else {
|
||||||
return $this->error($this->model->getError());
|
return $this->error($this->model->getError());
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$data = array(
|
$data = array(
|
||||||
'keyList' => $this->model->addField
|
'keyList' => $this->model->addField,
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
$this->setMeta('添加表单');
|
$this->setMeta('添加表单');
|
||||||
@@ -56,19 +62,19 @@ class Form extends Admin {
|
|||||||
/**
|
/**
|
||||||
* 编辑表单
|
* 编辑表单
|
||||||
*/
|
*/
|
||||||
public function edit(\think\Request $request){
|
public function edit(\think\Request $request) {
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$result = $this->model->validate('Form')->save($request->post(), array('id'=> $request->post('id')));
|
$result = $this->model->validate('Form')->save($request->post(), array('id' => $request->post('id')));
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $this->success('修改成功!', url('admin/form/index'));
|
return $this->success('修改成功!', url('admin/form/index'));
|
||||||
}else{
|
} else {
|
||||||
return $this->error($this->model->getError());
|
return $this->error($this->model->getError());
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$info = $this->model->where('id', $request->param('id'))->find();
|
$info = $this->model->where('id', $request->param('id'))->find();
|
||||||
$data = array(
|
$data = array(
|
||||||
'info' => $info,
|
'info' => $info,
|
||||||
'keyList' => $this->model->editField
|
'keyList' => $this->model->editField,
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
$this->setMeta('编辑表单');
|
$this->setMeta('编辑表单');
|
||||||
@@ -79,12 +85,12 @@ class Form extends Admin {
|
|||||||
/**
|
/**
|
||||||
* 删除表单
|
* 删除表单
|
||||||
*/
|
*/
|
||||||
public function del(){
|
public function del() {
|
||||||
$id = $this->getArrayParam('id');
|
$id = $this->getArrayParam('id');
|
||||||
$result = false;
|
$result = false;
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $this->success('删除成功!');
|
return $this->success('删除成功!');
|
||||||
}else{
|
} else {
|
||||||
return $this->error('删除失败!');
|
return $this->error('删除失败!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,9 +102,101 @@ class Form extends Admin {
|
|||||||
* @DateTime 2017-06-30
|
* @DateTime 2017-06-30
|
||||||
* @return html 页面
|
* @return html 页面
|
||||||
*/
|
*/
|
||||||
public function lists(){
|
public function lists() {
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attr(){}
|
public function attr($form_id = '') {
|
||||||
|
$map = array();
|
||||||
|
$order = "id desc";
|
||||||
|
$list = $this->Fattr->where($map)->order($order)->paginate(25);
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'list' => $list,
|
||||||
|
'form_id' => $form_id,
|
||||||
|
'page' => $list->render(),
|
||||||
|
);
|
||||||
|
$this->setMeta('表单字段');
|
||||||
|
$this->assign($data);
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addattr(\think\Request $request){
|
||||||
|
$form_id = isset($this->param['form_id']) ? $this->param['form_id'] : '';
|
||||||
|
if (!$form_id) {
|
||||||
|
return $this->error('非法操作!');
|
||||||
|
}
|
||||||
|
if (IS_POST) {
|
||||||
|
$data = $request->post();
|
||||||
|
$result = $this->Fattr->save($data);
|
||||||
|
if (false !== $result) {
|
||||||
|
return $this->success('添加成功!', url('admin/form/attr?form_id='.$form_id));
|
||||||
|
}else{
|
||||||
|
return $this->error($this->Fattr->getError());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$data = array(
|
||||||
|
'keyList' => $this->field
|
||||||
|
);
|
||||||
|
$this->assign($data);
|
||||||
|
$this->setMeta('添加字段');
|
||||||
|
return $this->fetch('public/edit');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function editattr(\think\Request $request){
|
||||||
|
$form_id = isset($this->param['form_id']) ? $this->param['form_id'] : '';
|
||||||
|
$id = isset($this->param['id']) ? $this->param['id'] : '';
|
||||||
|
if (!$form_id || !$id) {
|
||||||
|
return $this->error('非法操作!');
|
||||||
|
}
|
||||||
|
if (IS_POST) {
|
||||||
|
$data = $request->post();
|
||||||
|
$result = $this->Fattr->save($data, array('id'=>$data['id']));
|
||||||
|
if (false !== $result) {
|
||||||
|
return $this->success('修改成功!', url('admin/form/attr?form_id='.$form_id));
|
||||||
|
}else{
|
||||||
|
return $this->error($this->Fattr->getError());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$info = $this->Fattr->where('id', $id)->find();
|
||||||
|
$data = array(
|
||||||
|
'info' => $info,
|
||||||
|
'keyList' => $this->field
|
||||||
|
);
|
||||||
|
$this->assign($data);
|
||||||
|
$this->setMeta('添加字段');
|
||||||
|
return $this->fetch('public/edit');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delattr(\think\Request $request){
|
||||||
|
$id = isset($this->param['id']) ? $this->param['id'] : 0;
|
||||||
|
if (!$id) {
|
||||||
|
return $this->error('非法操作!');
|
||||||
|
}
|
||||||
|
$result = $this->Fattr->where('id', $id)->delete();
|
||||||
|
if (false !== $result) {
|
||||||
|
return $this->success('添加成功!');
|
||||||
|
}else{
|
||||||
|
return $this->error($this->Fattr->getError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function getField(){
|
||||||
|
return array(
|
||||||
|
array('name' => 'id', 'title' => 'id', 'help' => '', 'type' => 'hidden'),
|
||||||
|
array('name' => 'form_id', 'title' => 'model_id', 'help' => '', 'type' => 'hidden'),
|
||||||
|
array('name' => 'name', 'title' => '字段名', 'help' => '英文字母开头,长度不超过30', 'type' => 'text'),
|
||||||
|
array('name' => 'title', 'title' => '字段标题', 'help' => '请输入字段标题,用于表单显示', 'type' => 'text'),
|
||||||
|
array('name' => 'type', 'title' => '字段类型', 'help' => '用于表单中的展示方式', 'type' => 'select', 'option' => $this->attr, 'help' => ''),
|
||||||
|
array('name' => 'length', 'title' => '字段长度', 'help' => '字段的长度值', 'type' => 'text'),
|
||||||
|
array('name' => 'extra', 'title' => '参数', 'help' => '布尔、枚举、多选字段类型的定义数据', 'type' => 'textarea'),
|
||||||
|
array('name' => 'value', 'title' => '默认值', 'help' => '字段的默认值', 'type' => 'text'),
|
||||||
|
array('name' => 'remark', 'title' => '字段备注', 'help' => '用于表单中的提示', 'type' => 'text'),
|
||||||
|
array('name' => 'is_show', 'title' => '是否显示', 'help' => '是否显示在表单中', 'type' => 'select', 'option' => array('1' => '始终显示', '2' => '新增显示', '3' => '编辑显示', '0' => '不显示'), 'value' => 1),
|
||||||
|
array('name' => 'is_must', 'title' => '是否必填', 'help' => '用于自动验证', 'type' => 'select', 'option' => array('0' => '否', '1' => '是')),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ th.visible-xxs,td.visible-xxs {
|
|||||||
margin-top:0;
|
margin-top:0;
|
||||||
margin-bottom:0;
|
margin-bottom:0;
|
||||||
position:relative;
|
position:relative;
|
||||||
min-height:903px;
|
min-height:600px;
|
||||||
padding:15px 15px 35px 15px;
|
padding:15px 15px 35px 15px;
|
||||||
margin-left:220px;
|
margin-left:220px;
|
||||||
}
|
}
|
||||||
|
|||||||
64
application/admin/view/form/attr.html
Normal file
64
application/admin/view/form/attr.html
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
{extend name="public/base"/}
|
||||||
|
{block name="body"}
|
||||||
|
<div class="main-box clearfix">
|
||||||
|
<header class="main-box-header clearfix">
|
||||||
|
<div class="pull-left">
|
||||||
|
<h2>{$meta_title}</h2>
|
||||||
|
</div>
|
||||||
|
<div class="pull-right">
|
||||||
|
<a class="btn btn-danger" href="{:url('addattr',array('form_id'=>$form_id))}"><i class="fa fa-plus"></i> 新 增</a>
|
||||||
|
<!-- <button class="btn btn-danger ajax-post confirm" url="{:url('del')}" target-form="ids"><i class="fa fa-remove"></i> 删 除</button> -->
|
||||||
|
<a class="btn btn-warning" href="{:url('Form/index')}"><i class="fa fa-reply"></i> 返回</a>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<div class="main-box-body clearfix">
|
||||||
|
<div class="table-responsive clearfix">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><input class="checkbox check-all" type="checkbox"></th>
|
||||||
|
<th>表单标题</th>
|
||||||
|
<th>字段名</th>
|
||||||
|
<th>字段类型</th>
|
||||||
|
<th>字段长度</th>
|
||||||
|
<th>默认值</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{volist name="list" id="item"}
|
||||||
|
<tr>
|
||||||
|
<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$item['id']}"></td>
|
||||||
|
<td>{$item['title']}</td>
|
||||||
|
<td>{$item['name']}</td>
|
||||||
|
<td>{$item['type_text']}</td>
|
||||||
|
<td>{$item['length']}</td>
|
||||||
|
<td>{$item['value']}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{:url('editattr',array('id'=>$item['id'], 'form_id'=>$form_id))}">编辑</a>
|
||||||
|
<a href="{:url('delattr',array('id'=>$item['id'], 'form_id'=>$form_id))}" class="confirm ajax-get">删除</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/volist}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{$page}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/block}
|
||||||
|
{block name="script"}
|
||||||
|
<script type="text/javascript" src="__PUBLIC__/plugs/layer/layer.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function(){
|
||||||
|
$('.openDilog').click(function(){
|
||||||
|
layer.open({
|
||||||
|
type: 2,
|
||||||
|
title: false,
|
||||||
|
area: ['900px', '560px'],
|
||||||
|
content: $('.openDilog').attr('url')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{/block}
|
||||||
@@ -13,7 +13,13 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="__CSS__/style.css"/>
|
<link rel="stylesheet" type="text/css" href="__CSS__/style.css"/>
|
||||||
<script src="__PUBLIC__/js/jquery.js"></script>
|
<script src="__PUBLIC__/js/jquery.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var BASE_URL = "{:config('base_url')}"; //根目录地址
|
var BASE_URL = "{:config('base_url')}"; //根目录地址
|
||||||
|
$(function(){
|
||||||
|
var height = $(window).height();
|
||||||
|
if ($('#content-wrapper').height() < height) {
|
||||||
|
$('#content-wrapper').height($(window).height()-100);
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
<script src="__PUBLIC__/js/html5shiv.js"></script>
|
<script src="__PUBLIC__/js/html5shiv.js"></script>
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class Admin extends Base {
|
|||||||
// 是否开发者模式
|
// 是否开发者模式
|
||||||
$where['is_dev'] = 0;
|
$where['is_dev'] = 0;
|
||||||
}
|
}
|
||||||
$row = db('menu')->field('id,title,url,icon,"" as style')->where($where)->select();
|
$row = db('menu')->field('id,title,url,icon,"" as style')->where($where)->order('sort asc')->select();
|
||||||
foreach ($row as $key => $value) {
|
foreach ($row as $key => $value) {
|
||||||
//此处用来做权限判断
|
//此处用来做权限判断
|
||||||
if (!IS_ROOT && !$this->checkRule($value['url'], 2, null)) {
|
if (!IS_ROOT && !$this->checkRule($value['url'], 2, null)) {
|
||||||
@@ -156,7 +156,7 @@ class Admin extends Base {
|
|||||||
$map['pid'] = $pid;
|
$map['pid'] = $pid;
|
||||||
$map['hide'] = 0;
|
$map['hide'] = 0;
|
||||||
$map['type'] = 'admin';
|
$map['type'] = 'admin';
|
||||||
$row = db('menu')->field('id,title,url,icon,group,pid,"" as style')->where($map)->select();
|
$row = db('menu')->field('id,title,url,icon,group,pid,"" as style')->where($map)->order('sort asc')->select();
|
||||||
foreach ($row as $key => $value) {
|
foreach ($row as $key => $value) {
|
||||||
if (IS_ROOT || $this->checkRule($value['url'], 2, null)) {
|
if (IS_ROOT || $this->checkRule($value['url'], 2, null)) {
|
||||||
if ($controller == $value['url']) {
|
if ($controller == $value['url']) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class FormAttr extends Base{
|
|||||||
protected $type = array(
|
protected $type = array(
|
||||||
'id' => 'integer',
|
'id' => 'integer',
|
||||||
);
|
);
|
||||||
|
|
||||||
protected static function init(){
|
protected static function init(){
|
||||||
self::afterInsert(function($data){
|
self::afterInsert(function($data){
|
||||||
if ($data['form_id']) {
|
if ($data['form_id']) {
|
||||||
|
|||||||
Reference in New Issue
Block a user