diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php
index 69459497..d5846b60 100644
--- a/application/admin/command/Crud.php
+++ b/application/admin/command/Crud.php
@@ -217,6 +217,9 @@ class Crud extends Command
try
{
Form::setEscapeHtml(false);
+ $setAttrArr = [];
+ $getAttrArr = [];
+ $appendAttrList = [];
//循环所有字段,开始构造视图的HTML和JS信息
foreach ($columnList as $k => $v)
@@ -257,6 +260,7 @@ class Crud extends Command
//如果状态类型不是enum或set
$itemArr = !$itemArr ? ['normal', 'hidden'] : $itemArr;
$inputType = 'radio';
+ $this->getAttr($getAttrArr, $field);
}
if ($inputType == 'select')
{
@@ -270,6 +274,10 @@ class Crud extends Command
$attrStr = $this->getArrayString($attrArr);
$itemArr = $this->getLangArray($itemArr, FALSE);
$itemString = $this->getArrayString($itemArr);
+
+ //添加一个获取器
+ $this->getAttr($getAttrArr, $field, $itemArr, $v['DATA_TYPE'] == 'set' ? 'multiple' : 'select');
+ $this->appendAttr($appendAttrList, $field);
$formAddElement = "{:build_select('{$fieldName}', [{$itemString}], '{$defaultValue}', [{$attrStr}])}";
$formEditElement = "{:build_select('{$fieldName}', [{$itemString}], \$row.{$field}, [{$attrStr}])}";
}
@@ -302,6 +310,9 @@ class Crud extends Command
break;
default:
$fieldFunc = 'datetime';
+ $this->getAttr($getAttrArr, $field, '', $inputType);
+ $this->setAttr($setAttrArr, $field, '', $inputType);
+ $this->appendAttr($appendAttrList, $field);
break;
}
$defaultDateTime = "{:date('{$phpFormat}')}";
@@ -316,6 +327,9 @@ class Crud extends Command
$fieldName .= "[]";
$itemArr = $this->getLangArray($itemArr, FALSE);
$itemString = $this->getArrayString($itemArr);
+ //添加一个获取器
+ $this->getAttr($getAttrArr, $field, $itemArr, $inputType);
+ $this->appendAttr($appendAttrList, $field);
$formAddElement = "{:build_checkboxs('{$fieldName}', [{$itemString}], '{$defaultValue}')}";
$formEditElement = "{:build_checkboxs('{$fieldName}', [{$itemString}], \$row.{$field})}";
}
@@ -324,6 +338,9 @@ class Crud extends Command
$itemArr = $this->getLangArray($itemArr, FALSE);
$itemString = $this->getArrayString($itemArr);
$defaultValue = $defaultValue ? $defaultValue : key($itemArr);
+ //添加一个获取器
+ $this->getAttr($getAttrArr, $field, $itemArr, $inputType);
+ $this->appendAttr($appendAttrList, $field);
$formAddElement = "{:build_radios('{$fieldName}', [{$itemString}], '{$defaultValue}')}";
$formEditElement = "{:build_radios('{$fieldName}', [{$itemString}], \$row.{$field})}";
}
@@ -477,6 +494,9 @@ class Crud extends Command
'relationPrimaryKey' => '',
'relationSearch' => $relation ? 'true' : 'false',
'controllerIndex' => '',
+ 'appendAttrList' => implode(",\n", $appendAttrList),
+ 'getAttrList' => implode("\n\n", $getAttrArr),
+ 'setAttrList' => implode("\n\n", $setAttrArr),
'modelMethod' => '',
];
@@ -526,6 +546,79 @@ class Crud extends Command
$output->writeln("Build Successed");
}
+ protected function getAttr(&$getAttr, $field, $itemArr = '', $inputType = '')
+ {
+ if (!in_array($inputType, ['datetime', 'select', 'multiple', 'checkbox', 'radio']))
+ return;
+ $attrField = ucfirst($field);
+ if ($inputType == 'datetime')
+ {
+ $return = <<getArrayString($itemArr);
+ $return = << \$v)
+ {
+ if (isset(\$arr[\$v]))
+ {
+ \$resultArr[] = \$arr[\$v];
+ }
+ }
+ return implode(',', \$resultArr);
+EOD;
+ }
+ else
+ {
+ $itemString = $this->getArrayString($itemArr);
+ $return = <<order($sort, $order)
->limit($offset, $limit)
->select();
+
$result = array("total" => $total, "rows" => $list);
return json($result);
@@ -44,10 +45,27 @@ trait Backend
foreach ($params as $k => &$v)
{
$v = is_array($v) ? implode(',', $v) : $v;
- $v = substr($k, -4) == 'time' && !is_numeric($v) ? strtotime($v) : $v;
}
- $this->model->create($params);
- $this->code = 1;
+ try
+ {
+ $result = $this->model->create($params);
+ if ($result !== false)
+ {
+ $this->code = 1;
+ }
+ else
+ {
+ $this->msg = $this->model->getError();
+ }
+ }
+ catch (think\Exception $e)
+ {
+ $this->msg = $e->getMessage();
+ }
+ }
+ else
+ {
+ $this->msg = __('Parameter %s can not be empty', '');
}
return;
@@ -72,10 +90,27 @@ trait Backend
foreach ($params as $k => &$v)
{
$v = is_array($v) ? implode(',', $v) : $v;
- $v = substr($k, -4) == 'time' && !is_numeric($v) ? strtotime($v) : $v;
}
- $row->save($params);
- $this->code = 1;
+ try
+ {
+ $result = $row->save($params);
+ if ($result !== false)
+ {
+ $this->code = 1;
+ }
+ else
+ {
+ $this->msg = $row->getError();
+ }
+ }
+ catch (think\Exception $e)
+ {
+ $this->msg = $e->getMessage();
+ }
+ }
+ else
+ {
+ $this->msg = __('Parameter %s can not be empty', '');
}
return;
@@ -126,7 +161,7 @@ trait Backend
}
else
{
- $this->code = 1;
+ $this->msg = __('Parameter %s can not be empty', '');
}
}
diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php
index 198e247e..c243449b 100644
--- a/application/common/controller/Backend.php
+++ b/application/common/controller/Backend.php
@@ -92,7 +92,7 @@ class Backend extends Controller
!defined('IS_AJAX') && define('IS_AJAX', $this->request->isAjax());
// 非选项卡时重定向
- if (!IS_AJAX && !IS_ADDTABS && $controllername != 'index' && $actionname == 'index')
+ if (!IS_AJAX && !IS_ADDTABS && !IS_DIALOG && $path !== "/{$modulename}/index/index" && $controllername != 'ajax')
{
$url = $this->request->url();
$this->redirect('index/index', [], 302, ['referer' => $url]);
diff --git a/public/assets/js/backend.js b/public/assets/js/backend.js
index 42fc3109..f934c6c9 100755
--- a/public/assets/js/backend.js
+++ b/public/assets/js/backend.js
@@ -246,7 +246,7 @@ define(['jquery', 'bootstrap', 'toastr', 'layer', 'lang', 'moment'], function ($
});
},
addtabs: function (url, title, icon) {
- var dom = ".sidebar-menu li a[url='{url}']"
+ var dom = "a[url='{url}']"
var leftlink = top.window.$(dom.replace(/\{url\}/, url));
if (leftlink.size() > 0) {
leftlink.trigger("click");
@@ -273,7 +273,7 @@ define(['jquery', 'bootstrap', 'toastr', 'layer', 'lang', 'moment'], function ($
var id = Math.floor(new Date().valueOf() * Math.random());
icon = typeof icon != 'undefined' ? icon : 'fa fa-circle-o';
title = typeof title != 'undefined' ? title : '';
- top.window.$("").append(' ' + title + '').prop("href", url).attr({url: url, addtabs: id}).appendTo(top.window.document.body).trigger("click");
+ top.window.$("").append(' ' + title + '').prop("href", url).attr({url: url, addtabs: id}).addClass("hide").appendTo(top.window.document.body).trigger("click");
}
}
}
diff --git a/public/assets/js/require-form.js b/public/assets/js/require-form.js
index 807ecba1..147ddd4c 100755
--- a/public/assets/js/require-form.js
+++ b/public/assets/js/require-form.js
@@ -76,9 +76,9 @@ define(['jquery', 'bootstrap', 'backend', 'toastr', 'upload', 'validator'], func
stopOnError: true,
valid: function (ret) {
//验证通过提交表单
- Form.api.submit(form, onBeforeSubmit, function (data) {
+ Form.api.submit($(ret), onBeforeSubmit, function (data) {
if (typeof onAfterSubmit == 'function') {
- if (!onAfterSubmit.call(form, data)) {
+ if (!onAfterSubmit.call($(ret), data)) {
return false;
}
}
@@ -239,7 +239,7 @@ define(['jquery', 'bootstrap', 'backend', 'toastr', 'upload', 'validator'], func
$(document).on('click', ".fachoose", function () {
var multiple = $(this).data("multiple") ? $(this).data("multiple") : false;
var mimetype = $(this).data("mimetype") ? $(this).data("mimetype") : '';
- Backend.api.open("general/attachment/select?callback=refreshchoose&element_id=" + $(this).attr("id") + "&multiple=" + multiple + "&mimetype="+mimetype, __('Choose'));
+ Backend.api.open("general/attachment/select?callback=refreshchoose&element_id=" + $(this).attr("id") + "&multiple=" + multiple + "&mimetype=" + mimetype, __('Choose'));
return false;
});