自定义表单优化
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' => '是')),
|
||||
|
||||
Reference in New Issue
Block a user