Compare commits

..

4 Commits

Author SHA1 Message Date
Karson 7c9841cee9 新增html转义函数
优化插件管理标题和描述
2024-03-27 17:40:08 +08:00
Karson a5e1fe9cb6 优化Http多维数组参数传递 2024-03-27 16:11:15 +08:00
Karson 1a31ac2dc9 新增无键名数组CRUD生成
优化注释判断
2024-03-27 15:09:05 +08:00
Karson 56b33f1514 移除冗余代码 2024-03-27 11:48:32 +08:00
7 changed files with 54 additions and 63 deletions

View File

@ -152,7 +152,7 @@ class Crud extends Command
/**
* JSON后缀
*/
protected $jsonSuffix = ['json'];
protected $jsonSuffix = ['json', 'array'];
/**
* 标签后缀
@ -879,7 +879,7 @@ class Crud extends Command
$formEditElement = Form::input('text', $fieldName, $editValue, $attrArr);
} elseif ($inputType == 'fieldlist') {
$itemArr = $this->getItemArray($itemArr, $field, $v['COLUMN_COMMENT']);
$templateName = !isset($itemArr['key']) && !isset($itemArr['value']) && count($itemArr) > 0 ? 'fieldlist-template' : 'fieldlist';
$templateName = !isset($itemArr['key']) && count($itemArr) > 0 ? (isset($itemArr['value']) && count($itemArr) === 1 ? 'fieldlist-array' : 'fieldlist-template') : 'fieldlist';
$itemKey = isset($itemArr['key']) ? ucfirst($itemArr['key']) : 'Key';
$itemValue = isset($itemArr['value']) ? ucfirst($itemArr['value']) : 'Value';
$theadListArr = $tbodyListArr = [];
@ -1542,7 +1542,7 @@ EOD;
{
$itemArr = [];
$comment = str_replace('', ',', $comment);
if (stripos($comment, ':') !== false && stripos($comment, ',') && stripos($comment, '=') !== false) {
if (stripos($comment, ':') !== false && stripos($comment, '=') !== false) {
list($fieldLang, $item) = explode(':', $comment);
$itemArr = [];
foreach (explode(',', $item) as $k => $v) {

View File

@ -0,0 +1,21 @@
<dl class="list-unstyled fieldlist" data-name="{%fieldName%}" data-template="{%fieldName%}tpl">
<dd>
<ins>{:__('{%itemValue%}')}</ins>
</dd>
<dd>
<ins><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></ins>
</dd>
</dl>
<textarea name="{%fieldName%}" class="form-control hide" cols="30" rows="5">{%fieldValue%}</textarea>
<script id="{%fieldName%}tpl" type="text/html">
<dd class="form-inline">
<ins><input type="text" name="<%=name%>[<%=index%>][value]" class="form-control" size="15" value="<%=row%>"/></ins>
<ins>
<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
<span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span>
</ins>
</dd>
</script>

View File

@ -399,7 +399,8 @@ CREATE TABLE `fa_test` (
`keywords` varchar(255) DEFAULT '' COMMENT '关键字',
`description` varchar(255) DEFAULT '' COMMENT '描述',
`city` varchar(100) DEFAULT '' COMMENT '省市',
`json` varchar(255) DEFAULT NULL COMMENT '配置:key=名称,value=值',
`array` varchar(255) DEFAULT '' COMMENT '数组:value=值',
`json` varchar(255) DEFAULT '' COMMENT '配置:key=名称,value=值',
`multiplejson` varchar(1500) DEFAULT '' COMMENT '二维数组:title=标题,intro=介绍,author=作者,age=年龄',
`price` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '价格',
`views` int(10) unsigned DEFAULT '0' COMMENT '点击',

View File

@ -248,9 +248,10 @@ if (!function_exists('addtion')) {
if ($v['model']) {
$model = new $v['model'];
} else {
$model = $v['name'] ? \think\Db::name($v['name']) : \think\Db::table($v['table']);
// 优先判断使用table的配置
$model = $v['table'] ? \think\Db::table($v['table']) : \think\Db::name($v['name']);
}
$primary = $v['primary'] ? $v['primary'] : $model->getPk();
$primary = $v['primary'] ?: $model->getPk();
$result[$v['field']] = isset($ids[$v['field']]) ? $model->where($primary, 'in', $ids[$v['field']])->column($v['column'], $primary) : [];
}
@ -279,60 +280,6 @@ if (!function_exists('var_export_short')) {
function var_export_short($data, $return = true)
{
return var_export($data, $return);
$replaced = [];
$count = 0;
//判断是否是对象
if (is_resource($data) || is_object($data)) {
return var_export($data, $return);
}
//判断是否有特殊的键名
$specialKey = false;
array_walk_recursive($data, function (&$value, &$key) use (&$specialKey) {
if (is_string($key) && (stripos($key, "\n") !== false || stripos($key, "array (") !== false)) {
$specialKey = true;
}
});
if ($specialKey) {
return var_export($data, $return);
}
array_walk_recursive($data, function (&$value, &$key) use (&$replaced, &$count, &$stringcheck) {
if (is_object($value) || is_resource($value)) {
$replaced[$count] = var_export($value, true);
$value = "##<{$count}>##";
} else {
if (is_string($value) && (stripos($value, "\n") !== false || stripos($value, "array (") !== false)) {
$index = array_search($value, $replaced);
if ($index === false) {
$replaced[$count] = var_export($value, true);
$value = "##<{$count}>##";
} else {
$value = "##<{$index}>##";
}
}
}
$count++;
});
$dump = var_export($data, true);
$dump = preg_replace('#(?:\A|\n)([ ]*)array \(#i', '[', $dump); // Starts
$dump = preg_replace('#\n([ ]*)\),#', "\n$1],", $dump); // Ends
$dump = preg_replace('#=> \[\n\s+\],\n#', "=> [],\n", $dump); // Empties
$dump = preg_replace('#\)$#', "]", $dump); //End
if ($replaced) {
$dump = preg_replace_callback("/'##<(\d+)>##'/", function ($matches) use ($replaced) {
return $replaced[$matches[1]] ?? "''";
}, $dump);
}
if ($return === true) {
return $dump;
} else {
echo $dump;
}
}
}

View File

@ -60,7 +60,7 @@ class Http
} else {
$defaults[CURLOPT_CUSTOMREQUEST] = $method;
}
$defaults[CURLOPT_POSTFIELDS] = $params;
$defaults[CURLOPT_POSTFIELDS] = is_array($params) && count(array_filter($params, 'is_array')) > 0 ? $query_string : $params;
}
$defaults[CURLOPT_HEADER] = false;

View File

@ -115,7 +115,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'cookie']
align: 'left',
formatter: Controller.api.formatter.title
},
{field: 'intro', title: __('Intro'), operate: 'LIKE', align: 'left', class: 'visible-lg'},
{
field: 'intro',
title: __('Intro'),
operate: 'LIKE',
align: 'left',
class: 'visible-lg',
formatter: Controller.api.formatter.intro
},
{
field: 'author',
title: __('Author'),
@ -710,12 +717,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'cookie']
if ($(".btn-switch.active").data("type") == "local") {
// return value;
}
var title = '<a class="title" href="' + row.url + '" data-toggle="tooltip" title="' + __('View addon home page') + '" target="_blank">' + value + '</a>';
var title = '<a class="title" href="' + row.url + '" data-toggle="tooltip" title="' + __('View addon home page') + '" target="_blank"><span class="' + Fast.api.escape(row.color) + '">' + value + '</span></a>';
if (row.screenshots && row.screenshots.length > 0) {
title += ' <a href="javascript:;" data-index="' + index + '" class="view-screenshots text-success" title="' + __('View addon screenshots') + '" data-toggle="tooltip"><i class="fa fa-image"></i></a>';
}
return title;
},
intro: function (value, row, index) {
return row.intro + (row.extend ? "<a href='" + Fast.api.escape(row.extend[1]) + "' class='" + Fast.api.escape(row.extend[2]) + "'>" + Fast.api.escape(row.extend[0]) + "</a>" : "");
},
operate: function (value, row, index) {
return Template("operatetpl", {item: row, index: index});
},

View File

@ -278,6 +278,18 @@ define(['jquery', 'bootstrap', 'toastr', 'layer', 'lang'], function ($, undefine
time: 2000
}, callback);
},
escape: function (text) {
if (typeof text === 'string') {
return text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
.replace(/`/g, '&#x60;');
}
return text;
},
toastr: Toastr,
layer: Layer
},