自定义表单优化
This commit is contained in:
@@ -72,7 +72,7 @@ class Form extends Admin {
|
||||
*/
|
||||
public function edit(\think\Request $request) {
|
||||
if ($this->request->isPost()) {
|
||||
$result = $this->model->validate('Form')->save($request->post(), array('id' => $request->post('id')));
|
||||
$result = $this->model->validate('Form.edit')->save($request->post(), array('id' => $request->post('id')));
|
||||
if (false !== $result) {
|
||||
return $this->success('修改成功!', url('admin/form/index'));
|
||||
} else {
|
||||
@@ -116,13 +116,14 @@ class Form extends Admin {
|
||||
$list = M($form['name'], 'form')->order('id desc')->paginate(25);
|
||||
|
||||
$data = array(
|
||||
'grid_list' => $form['grid_list'],
|
||||
'form_id' => $form_id,
|
||||
'list' => $list,
|
||||
'page' => $list->render()
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta('数据列表');
|
||||
return $this->fetch('list_'.$form['name']);
|
||||
return $this->fetch('list');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,20 +148,28 @@ class Form extends Admin {
|
||||
public function outxls($form_id = '') {
|
||||
$form = $this->model->where('id', $form_id)->find();
|
||||
|
||||
$attr = $this->Fattr->where('form_id', $form_id)->where('is_show', 1)->select();
|
||||
foreach ($attr as $key => $value) {
|
||||
$title[$value['name']] = $value['title'];
|
||||
}
|
||||
$attr = $this->Fattr->where('form_id', $form_id)->column('*', 'name');
|
||||
|
||||
$data[] = $title;
|
||||
// $data[] = $title;
|
||||
$list = [];
|
||||
$res = M($form['name'], 'form')->order('id desc')->select();
|
||||
|
||||
foreach ($res as $key => $value) {
|
||||
$data[] = $value;
|
||||
foreach ($res as $value) {
|
||||
$item = [];
|
||||
foreach ($value as $key => $value) {
|
||||
if (isset($attr[$key])) {
|
||||
$item[$attr[$key]['title']] = $value;
|
||||
}else{
|
||||
$item[$key] = $value;
|
||||
}
|
||||
}
|
||||
$list[] = $item;
|
||||
}
|
||||
|
||||
$out = new \com\Outxls($data, date('Y-m-d'));
|
||||
$out->out();
|
||||
$data = [
|
||||
'data' => $list,
|
||||
'file_name' => $form['title'] . time(),
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,6 +277,7 @@ class Form extends Admin {
|
||||
array('name' => 'length', 'title' => '字段长度', 'help' => '字段的长度值', 'type' => 'text'),
|
||||
array('name' => 'extra', 'title' => '参数', 'help' => '布尔、枚举、多选字段类型的定义数据', 'type' => 'textarea'),
|
||||
array('name' => 'value', 'title' => '默认值', 'help' => '字段的默认值', 'type' => 'text'),
|
||||
array('name' => 'sort', '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' => '是')),
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
<a href="{:url('admin/form/edit?id='.$item['id'])}">编辑</a>
|
||||
<a href="{:url('admin/form/del?id='.$item['id'])}" class="confirm ajax-get">删除</a>
|
||||
<a href="{:url('admin/form/lists?form_id='.$item['id'])}">数据</a>
|
||||
<a href="{:url('index/form/index', ['id'=>$item['id'], 'name'=>$item['show_title']])}" target="_blank">浏览</a>
|
||||
</td>
|
||||
</tr>
|
||||
{/volist}
|
||||
|
||||
85
application/admin/view/form/list.html
Normal file
85
application/admin/view/form/list.html
Normal file
@@ -0,0 +1,85 @@
|
||||
{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-primary" data-action="out" data-href="{:url('admin/form/outxls?form_id='.$form_id)}" target="_blank">导出</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>
|
||||
{volist name="grid_list" id="item"}
|
||||
<th>{$item['title']}</th>
|
||||
{/volist}
|
||||
<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>
|
||||
{volist name="grid_list" id="grid"}
|
||||
<td>{$item[$grid['field']]|default=''}</td>
|
||||
{/volist}
|
||||
<td>
|
||||
<a href="{:url('deldata',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="/static/js/xlsx.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$('a[data-action=out]').click(function(e){
|
||||
e.preventDefault();
|
||||
outXlsx($(this).data('href'), 1)
|
||||
});
|
||||
})
|
||||
|
||||
var outList = [];
|
||||
function outXlsx(url, page = 1){
|
||||
var data = $('form').serialize();
|
||||
var pagesize = $('select.pagesize').val() || 30;
|
||||
data = data + '&out=1&pagesize='+pagesize+'&page='+page
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: data,
|
||||
type: 'get',
|
||||
beforeSend: function(){
|
||||
layer.load();
|
||||
layer.msg('正在导出第'+page+'页,请耐心等待,不要关闭浏览器');
|
||||
},
|
||||
error: function(){
|
||||
layer.msg('导出失败!');
|
||||
},
|
||||
success:function(res){
|
||||
outList = outList.concat(res.data);
|
||||
if (res.last_page > page) {
|
||||
outXlsx(url, page+1)
|
||||
}else{
|
||||
xls.downloadExl(outList,res.file_name);
|
||||
layer.msg('导出完成!');
|
||||
setTimeout(function(){
|
||||
layer.closeAll('loading');
|
||||
}, 3000);
|
||||
}
|
||||
},
|
||||
dataType: 'json'
|
||||
})
|
||||
}
|
||||
</script>
|
||||
{/block}
|
||||
Reference in New Issue
Block a user