save
This commit is contained in:
parent
6e38a9c7d5
commit
af6197dfd1
@ -703,7 +703,7 @@ EOF;
|
|||||||
$info['control_args'] = '';
|
$info['control_args'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$props = Util::getProps($control, $info['control_args']);
|
$props = Util::getControlProps($control, $info['control_args']);
|
||||||
// 增加修改记录验证必填项
|
// 增加修改记录验证必填项
|
||||||
if ($filter == 'form_show' && !isset($props['lay-verify']) && !$columns[$key]['nullable'] && $default === null && ($field !== 'password' || $type === 'insert')) {
|
if ($filter == 'form_show' && !isset($props['lay-verify']) && !$columns[$key]['nullable'] && $default === null && ($field !== 'password' || $type === 'insert')) {
|
||||||
$props['lay-verify'] = 'required';
|
$props['lay-verify'] = 'required';
|
||||||
@ -762,7 +762,7 @@ EOF;
|
|||||||
$control = strtolower($info['control']);
|
$control = strtolower($info['control']);
|
||||||
switch ($control) {
|
switch ($control) {
|
||||||
case 'switch':
|
case 'switch':
|
||||||
$props = Util::getProps($info['control'], $info['control_args']);
|
$props = Util::getControlProps($info['control'], $info['control_args']);
|
||||||
$lay_text = $props['lay-text'] ?? '';
|
$lay_text = $props['lay-text'] ?? '';
|
||||||
$templet = <<<EOF
|
$templet = <<<EOF
|
||||||
|
|
||||||
@ -815,7 +815,7 @@ EOF;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($control, ['select', 'selectmulti', 'treeselect', 'treeselectmulti'])) {
|
if (in_array($control, ['select', 'selectmulti', 'treeselect', 'treeselectmulti'])) {
|
||||||
$props = Util::getProps($info['control'], $info['control_args']);
|
$props = Util::getControlProps($info['control'], $info['control_args']);
|
||||||
|
|
||||||
if (isset($props['url'])) {
|
if (isset($props['url'])) {
|
||||||
$api .= "apis.push([\"$field\", \"{$props['url']}\"]);\r\n";
|
$api .= "apis.push([\"$field\", \"{$props['url']}\"]);\r\n";
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace plugin\admin\app\common;
|
namespace plugin\admin\app\common;
|
||||||
|
|
||||||
|
use Illuminate\Database\Connection;
|
||||||
|
use Illuminate\Database\Schema\Builder;
|
||||||
use plugin\admin\app\model\Option;
|
use plugin\admin\app\model\Option;
|
||||||
use support\Db;
|
use support\Db;
|
||||||
use Support\Exception\BusinessException;
|
use Support\Exception\BusinessException;
|
||||||
@ -10,27 +12,58 @@ use function config;
|
|||||||
|
|
||||||
class Util
|
class Util
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 密码哈希
|
||||||
|
* @param $password
|
||||||
|
* @param $algo
|
||||||
|
* @return false|string|null
|
||||||
|
*/
|
||||||
static public function passwordHash($password, $algo = PASSWORD_DEFAULT)
|
static public function passwordHash($password, $algo = PASSWORD_DEFAULT)
|
||||||
{
|
{
|
||||||
return password_hash($password, $algo);
|
return password_hash($password, $algo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function db()
|
/**
|
||||||
{
|
* 验证密码哈希
|
||||||
return Db::connection('plugin.admin.mysql');
|
* @param $password
|
||||||
}
|
* @param $hash
|
||||||
|
* @return bool
|
||||||
static function schema()
|
*/
|
||||||
{
|
static public function passwordVerify($password, $hash): bool
|
||||||
return Db::schema('plugin.admin.mysql');
|
|
||||||
}
|
|
||||||
|
|
||||||
static public function passwordVerify($password, $hash)
|
|
||||||
{
|
{
|
||||||
return password_verify($password, $hash);
|
return password_verify($password, $hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 获取webman-admin数据库连接
|
||||||
|
* @return Connection
|
||||||
|
*/
|
||||||
|
static function db(): Connection
|
||||||
|
{
|
||||||
|
return Db::connection('plugin.admin.mysql');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SchemaBuilder
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
static function schema(): Builder
|
||||||
|
{
|
||||||
|
return Db::schema('plugin.admin.mysql');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库字符串转义
|
||||||
|
* @param $var
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
|
static public function pdoQuote($var)
|
||||||
|
{
|
||||||
|
return Util::db()->getPdo()->quote($var, \PDO::PARAM_STR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查表名是否合法
|
||||||
* @param string $table
|
* @param string $table
|
||||||
* @return string
|
* @return string
|
||||||
* @throws BusinessException
|
* @throws BusinessException
|
||||||
@ -78,15 +111,7 @@ class Util
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $var
|
* 检测是否是合法URL Path
|
||||||
* @return false|string
|
|
||||||
*/
|
|
||||||
static public function pdoQuote($var)
|
|
||||||
{
|
|
||||||
return Util::db()->getPdo()->quote($var, \PDO::PARAM_STR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $var
|
* @param $var
|
||||||
* @return string
|
* @return string
|
||||||
* @throws BusinessException
|
* @throws BusinessException
|
||||||
@ -98,9 +123,13 @@ class Util
|
|||||||
}
|
}
|
||||||
return $var;
|
return $var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static public function camel($value)
|
/**
|
||||||
|
* 转换为驼峰
|
||||||
|
* @param string $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static public function camel(string $value): string
|
||||||
{
|
{
|
||||||
static $cache = [];
|
static $cache = [];
|
||||||
$key = $value;
|
$key = $value;
|
||||||
@ -114,11 +143,21 @@ class Util
|
|||||||
return $cache[$key] = str_replace(' ', '', $value);
|
return $cache[$key] = str_replace(' ', '', $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function smCamel($value)
|
/**
|
||||||
|
* 转换为小驼峰
|
||||||
|
* @param $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static public function smCamel($value): string
|
||||||
{
|
{
|
||||||
return lcfirst(static::camel($value));
|
return lcfirst(static::camel($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取注释中第一行
|
||||||
|
* @param $comment
|
||||||
|
* @return false|mixed|string
|
||||||
|
*/
|
||||||
static public function getCommentFirstLine($comment)
|
static public function getCommentFirstLine($comment)
|
||||||
{
|
{
|
||||||
if ($comment === false) {
|
if ($comment === false) {
|
||||||
@ -132,7 +171,11 @@ class Util
|
|||||||
return $comment;
|
return $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function methodControlMap()
|
/**
|
||||||
|
* 表单类型到插件的映射
|
||||||
|
* @return \string[][]
|
||||||
|
*/
|
||||||
|
static public function methodControlMap(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
//method=>[控件]
|
//method=>[控件]
|
||||||
@ -171,7 +214,12 @@ class Util
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function typeToControl($type)
|
/**
|
||||||
|
* 数据库类型到插件的转换
|
||||||
|
* @param $type
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static public function typeToControl($type): string
|
||||||
{
|
{
|
||||||
if (stripos($type, 'int') !== false) {
|
if (stripos($type, 'int') !== false) {
|
||||||
return 'InputNumber';
|
return 'InputNumber';
|
||||||
@ -188,6 +236,12 @@ class Util
|
|||||||
return 'Input';
|
return 'Input';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库类型到表单类型的转换
|
||||||
|
* @param $type
|
||||||
|
* @param $unsigned
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
static public function typeToMethod($type, $unsigned = false)
|
static public function typeToMethod($type, $unsigned = false)
|
||||||
{
|
{
|
||||||
if (stripos($type, 'int') !== false) {
|
if (stripos($type, 'int') !== false) {
|
||||||
@ -206,10 +260,10 @@ class Util
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 按表获取摘要
|
* 按表获取摘要
|
||||||
*
|
|
||||||
* @param $table
|
* @param $table
|
||||||
* @param $section
|
* @param null $section
|
||||||
* @return array|mixed
|
* @return array|mixed
|
||||||
|
* @throws BusinessException
|
||||||
*/
|
*/
|
||||||
static public function getSchema($table, $section = null)
|
static public function getSchema($table, $section = null)
|
||||||
{
|
{
|
||||||
@ -282,6 +336,11 @@ class Util
|
|||||||
return $section ? $data[$section] : $data;
|
return $section ? $data[$section] : $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字段长度或默认值
|
||||||
|
* @param $schema
|
||||||
|
* @return mixed|string
|
||||||
|
*/
|
||||||
static public function getLengthValue($schema)
|
static public function getLengthValue($schema)
|
||||||
{
|
{
|
||||||
$type = $schema->DATA_TYPE;
|
$type = $schema->DATA_TYPE;
|
||||||
@ -302,7 +361,13 @@ class Util
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function getProps($control, $control_args)
|
/**
|
||||||
|
* 获取控件参数
|
||||||
|
* @param $control
|
||||||
|
* @param $control_args
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
static public function getControlProps($control, $control_args): array
|
||||||
{
|
{
|
||||||
if (!$control_args) {
|
if (!$control_args) {
|
||||||
return [];
|
return [];
|
||||||
@ -339,8 +404,7 @@ class Util
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reload webman
|
* reload webman (不支持windows)
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
static public function reloadWebman()
|
static public function reloadWebman()
|
||||||
|
@ -699,7 +699,7 @@ EOF;
|
|||||||
* @param $controller_class_with_namespace
|
* @param $controller_class_with_namespace
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function createTemplate($template_file_path, $table, $template_path, $url_path_base, $primary_key, $controller_class_with_namespace)
|
protected function createTemplate($template_file_path, $table, $template_path, $url_path_base, $primary_key)
|
||||||
{
|
{
|
||||||
$this->mkdir($template_file_path . '/index.html');
|
$this->mkdir($template_file_path . '/index.html');
|
||||||
$form = LayuiForm::buildForm($table, 'search');
|
$form = LayuiForm::buildForm($table, 'search');
|
||||||
@ -730,7 +730,6 @@ EOF
|
|||||||
$html = str_replace("\n", "\n" . str_repeat(' ', 2), $html);
|
$html = str_replace("\n", "\n" . str_repeat(' ', 2), $html);
|
||||||
$js = $form->js(3);
|
$js = $form->js(3);
|
||||||
$table_js = LayuiForm::buildTable($table, 4);
|
$table_js = LayuiForm::buildTable($table, 4);
|
||||||
$controller_class_with_namespace = str_replace('\\', '\\\\', $controller_class_with_namespace);
|
|
||||||
$template_content = <<<EOF
|
$template_content = <<<EOF
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@ -776,7 +775,6 @@ EOF
|
|||||||
|
|
||||||
// 相关常量
|
// 相关常量
|
||||||
const PRIMARY_KEY = "$primary_key";
|
const PRIMARY_KEY = "$primary_key";
|
||||||
const CONTROLLER = "$controller_class_with_namespace";
|
|
||||||
const SELECT_API = "$url_path_base/$template_path/select";
|
const SELECT_API = "$url_path_base/$template_path/select";
|
||||||
const UPDATE_API = "$url_path_base/$template_path/update";
|
const UPDATE_API = "$url_path_base/$template_path/update";
|
||||||
const DELETE_API = "$url_path_base/$template_path/delete";
|
const DELETE_API = "$url_path_base/$template_path/delete";
|
||||||
|
@ -219,7 +219,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// 获取选择组件配置项
|
// 获取选择组件配置项
|
||||||
function getProps(control_args)
|
function getControlProps(control_args)
|
||||||
{
|
{
|
||||||
if (!control_args) {
|
if (!control_args) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
let control = item.control.toLowerCase();
|
let control = item.control.toLowerCase();
|
||||||
// switch 可以直接编辑
|
// switch 可以直接编辑
|
||||||
if (control === "switch") {
|
if (control === "switch") {
|
||||||
let props = getProps(item.control_args);
|
let props = getControlProps(item.control_args);
|
||||||
let layText = props["lay-text"] || "";
|
let layText = props["lay-text"] || "";
|
||||||
schema.templet = function (d) {
|
schema.templet = function (d) {
|
||||||
form.on("switch("+field+")", function (data) {
|
form.on("switch("+field+")", function (data) {
|
||||||
@ -133,7 +133,7 @@
|
|||||||
return '<img src="'+encodeURI(d[field])+'" style="max-width:32px;max-height:32px;" />';
|
return '<img src="'+encodeURI(d[field])+'" style="max-width:32px;max-height:32px;" />';
|
||||||
};
|
};
|
||||||
} else if (["select", "selectmulti", "treeselect", "treeselectmulti"].indexOf(control) !== -1) {
|
} else if (["select", "selectmulti", "treeselect", "treeselectmulti"].indexOf(control) !== -1) {
|
||||||
let props = getProps(item.control_args);
|
let props = getControlProps(item.control_args);
|
||||||
apiResults[field] = [];
|
apiResults[field] = [];
|
||||||
if (props.url) {
|
if (props.url) {
|
||||||
apis.push([field, props.url]);
|
apis.push([field, props.url]);
|
||||||
@ -327,7 +327,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// 获取选择组件配置项
|
// 获取选择组件配置项
|
||||||
function getProps(control_args)
|
function getControlProps(control_args)
|
||||||
{
|
{
|
||||||
if (!control_args) {
|
if (!control_args) {
|
||||||
return {};
|
return {};
|
||||||
|
Loading…
Reference in New Issue
Block a user