Compare commits

...

3 Commits

Author SHA1 Message Date
Karson aec4efe9e0 优化代码 2024-03-25 22:29:48 +08:00
Karson 0a5484b738 优化代码 2024-03-25 22:29:23 +08:00
Karson 9f2c08414a 优化后台管理日志记录 2024-03-25 22:28:43 +08:00
16 changed files with 52 additions and 38 deletions

View File

@ -4,7 +4,7 @@ namespace app\admin\behavior;
class AdminLog
{
public function run(&$params)
public function run(&$response)
{
//只记录POST请求的日志
if (request()->isPost() && config('fastadmin.auto_record_log')) {

View File

@ -121,7 +121,7 @@ if (!function_exists('build_toolbar')) {
$html = [];
foreach ($btns as $k => $v) {
//如果未定义或没有权限
if (!isset($btnAttr[$v]) || ($v !== 'refresh' && !$auth->check("{$controller}/{$v}"))) {
if (!isset($btnAttr[$v]) || ($v !== 'refresh' && !$auth->check("{$controller}/{$v}", $auth->id))) {
continue;
}
list($href, $class, $icon, $text, $title) = $btnAttr[$v];

View File

@ -53,6 +53,7 @@ class Adminlog extends Backend
$query->where('admin_id', 'in', $childrenAdminIds);
}
})
->field('content,useragent', true)
->order($sort, $order)
->paginate($limit);

View File

@ -391,7 +391,7 @@ trait Backend
}
//导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
$importHeadType = $this->importHeadType ?? 'comment';
$importHeadType = isset($this->importHeadType) ? $this->importHeadType : 'comment';
$table = $this->model->getQuery()->getTable();
$database = \think\Config::get('database.database');

View File

@ -41,8 +41,8 @@ class AdminLog extends Model
/**
* 记录日志
* @param string $title
* @param string $content
* @param string $title 日志标题
* @param string $content 日志内容
*/
public static function record($title = '', $content = '')
{
@ -50,6 +50,9 @@ class AdminLog extends Model
$admin_id = $auth->isLogin() ? $auth->id : 0;
$username = $auth->isLogin() ? $auth->username : __('Unknown');
// 设置过滤函数
request()->filter('trim,strip_tags,htmlspecialchars');
$controllername = Loader::parseName(request()->controller());
$actionname = strtolower(request()->action());
$path = str_replace('.', '/', $controllername) . '/' . $actionname;
@ -60,12 +63,12 @@ class AdminLog extends Model
}
}
}
$content = $content ? $content : self::$content;
$content = $content ?: self::$content;
if (!$content) {
$content = request()->param('', null, 'trim,strip_tags,htmlspecialchars');
$content = request()->param('') ?: file_get_contents("php://input");
$content = self::getPureContent($content);
}
$title = $title ? $title : self::$title;
$title = $title ?: self::$title;
if (!$title) {
$title = [];
$breadcrumb = Auth::instance()->getBreadcrumb($path);
@ -77,18 +80,18 @@ class AdminLog extends Model
self::create([
'title' => $title,
'content' => !is_scalar($content) ? json_encode($content, JSON_UNESCAPED_UNICODE) : $content,
'url' => substr(request()->url(), 0, 1500),
'url' => substr(xss_clean(strip_tags(request()->url())), 0, 1500),
'admin_id' => $admin_id,
'username' => $username,
'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255),
'ip' => request()->ip()
'ip' => xss_clean(strip_tags(request()->ip()))
]);
}
/**
* 获取已屏蔽关键信息的数据
* @param $content
* @return false|string
* @return array
*/
protected static function getPureContent($content)
{

View File

@ -28,7 +28,7 @@ class UserGroup extends Model
{
$value = $value ? $value : $data['status'];
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
return $list[$value] ?? '';
}
}

View File

@ -42,7 +42,7 @@ class UserRule extends Model
{
$value = $value ? $value : $data['status'];
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
return $list[$value] ?? '';
}
public static function getTreeList($selected = [])

View File

@ -28,7 +28,7 @@ class Ems
*
* @param int $email 邮箱
* @param string $event 事件
* @return Ems
* @return Ems|null
*/
public static function get($email, $event = 'default')
{
@ -36,7 +36,7 @@ class Ems
->order('id', 'DESC')
->find();
Hook::listen('ems_get', $ems, null, true);
return $ems ? $ems : null;
return $ems ?: null;
}
/**

View File

@ -36,7 +36,7 @@ class Sms
->order('id', 'DESC')
->find();
Hook::listen('sms_get', $sms, null, true);
return $sms ? $sms : null;
return $sms ?: null;
}
/**

View File

@ -150,7 +150,7 @@ class Token
/**
* 清除Token
* @access public
* @param int user_id 会员ID
* @param int $user_id 会员ID
* @return boolean
*/
public static function clear($user_id = null)

View File

@ -147,7 +147,7 @@ class Upload
$size = $matches ? $matches[1] : $this->config['maxsize'];
$type = $matches ? strtolower($matches[2]) : 'b';
$typeDict = ['b' => 0, 'k' => 1, 'kb' => 1, 'm' => 2, 'mb' => 2, 'gb' => 3, 'g' => 3];
$size = $size * pow(1024, $typeDict[$type] ?? 0);
$size = (int)($size * pow(1024, $typeDict[$type] ?? 0));
if ($this->fileInfo['size'] > $size) {
throw new UploadException(__(
'File is too big (%sMiB), Max filesize: %sMiB.',

View File

@ -29,7 +29,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'title', title: __('Title'), operate: 'LIKE %...%', placeholder: '模糊搜索'},
{field: 'url', title: __('Url'), formatter: Table.api.formatter.url},
{field: 'ip', title: __('IP'), events: Table.api.events.ip, formatter: Table.api.formatter.search},
{field: 'browser', title: __('Browser'), operate: false, formatter: Controller.api.formatter.browser},
{field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
{
field: 'operate', title: __('Operate'), table: table,

View File

@ -135,6 +135,10 @@ define(['jquery', 'bootstrap', 'toastr', 'layer', 'lang'], function ($, undefine
url = Fast.api.fixurl(url);
url = url + (url.indexOf("?") > -1 ? "&" : "?") + "dialog=1";
var area = Fast.config.openArea != undefined ? Fast.config.openArea : [$(window).width() > 800 ? '800px' : '95%', $(window).height() > 600 ? '600px' : '95%'];
var success = options && typeof options.success === 'function' ? options.success : $.noop;
if (options && typeof options.success === 'function') {
delete options.success;
}
options = $.extend({
type: 2,
title: title,
@ -188,6 +192,7 @@ define(['jquery', 'bootstrap', 'toastr', 'layer', 'lang'], function ($, undefine
height: $(window).height()
});
}
success.call(this, layero, index);
}
}, options ? options : {});
if ($(window).width() < 480 || (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream && top.$(".tab-pane.active").length > 0)) {

View File

@ -91,8 +91,10 @@ define(['jquery', 'bootstrap', 'upload', 'validator', 'validator-lang'], functio
$(".layer-footer [type=submit],.fixed-footer [type=submit],.normal-footer [type=submit]", form).removeClass("disabled");
//自定义关闭按钮事件
form.on("click", ".layer-close", function () {
var index = parent.Layer.getFrameIndex(window.name);
parent.Layer.close(index);
if (window.name) {
var index = parent.Layer.getFrameIndex(window.name);
parent.Layer.close(index);
}
return false;
});
},
@ -216,7 +218,7 @@ define(['jquery', 'bootstrap', 'upload', 'validator', 'validator-lang'], functio
};
var origincallback = function (start, end) {
$(this.element).val(start.format(this.locale.format) + " - " + end.format(this.locale.format));
$(this.element).trigger('blur');
$(this.element).trigger('change');
};
$(".datetimerange", form).each(function () {
var callback = typeof $(this).data('callback') == 'function' ? $(this).data('callback') : origincallback;
@ -224,7 +226,7 @@ define(['jquery', 'bootstrap', 'upload', 'validator', 'validator-lang'], functio
callback.call(picker, picker.startDate, picker.endDate);
});
$(this).on('cancel.daterangepicker', function (ev, picker) {
$(this).val('').trigger('blur');
$(this).val('').trigger('change');
});
$(this).daterangepicker($.extend(true, {}, options, $(this).data() || {}, $(this).data("daterangepicker-options") || {}));
});
@ -288,7 +290,7 @@ define(['jquery', 'bootstrap', 'upload', 'validator', 'validator-lang'], functio
}
var result = urlArr.join(",");
inputObj.val(result).trigger("change").trigger("validate");
} else {
} else if (input_id) {
var url = Config.upload.fullmode ? Fast.api.cdnurl(data.url) : data.url;
$("#" + input_id).val(url).trigger("change").trigger("validate");
}
@ -326,7 +328,7 @@ define(['jquery', 'bootstrap', 'upload', 'validator', 'validator-lang'], functio
if (keys.indexOf("value") > -1 && (keys.length === 1 || (keys.length === 2 && keys.indexOf("key") > -1))) {
if (keys.length === 2) {
if (j.key != '') {
result[j.key] = j.value;
result['__PLACEHOLDKEY__' + j.key] = j.value;
}
} else {
result.push(j.value);
@ -336,7 +338,7 @@ define(['jquery', 'bootstrap', 'upload', 'validator', 'validator-lang'], functio
}
}
});
textarea.val(JSON.stringify(result));
textarea.val(JSON.stringify(result).replace(/__PLACEHOLDKEY__/g, ''));
};
//追加一行数据
var append = function (container, row, initial) {
@ -410,11 +412,12 @@ define(['jquery', 'bootstrap', 'upload', 'validator', 'validator-lang'], functio
$("[fieldlist-item]", container).remove();
var json = {};
try {
json = JSON.parse(textarea.val());
var val = textarea.val().replace(/"(\d+)"\:/g, "\"__PLACEHOLDERKEY__$1\":");
json = JSON.parse(val);
} catch (e) {
}
$.each(json, function (i, j) {
append(container, {key: i, value: j}, true);
append(container, {key: i.toString().replace("__PLACEHOLDERKEY__", ""), value: j}, true);
});
});
//拖拽排序

View File

@ -441,7 +441,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
$(document).on('click', Table.config.restoreonebtn + ',' + Table.config.destroyonebtn, function () {
var that = this;
var url = $(that).data("url") ? $(that).data("url") : $(that).attr("href");
var row = Fast.api.getrowbyindex(table, $(that).data("row-index"));
var row = Table.api.getrowbyindex(table, $(that).data("row-index"));
Fast.api.ajax({
url: url,
data: {ids: row[options.pk]}
@ -562,7 +562,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
var target = $(".autocontent-item", this).get(0);
if (!target) return;
if (e.type === 'mouseenter') {
if (target.scrollWidth > target.offsetWidth) {
if (target.scrollWidth > target.offsetWidth && $(".autocontent-caret", this).length === 0) {
$(this).append("<div class='autocontent-caret'><i class='fa fa-chevron-down'></div>");
}
} else {

View File

@ -27,7 +27,7 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
if ($(button).data("multiple") && inputObj.val() !== "") {
urlArr.push(inputObj.val());
}
var url = Config.upload.fullmode ? Fast.api.cdnurl(data.url) : data.url;
var url = Config.upload.fullmode ? (data.fullurl ? data.fullurl : Fast.api.cdnurl(data.url)) : data.url;
urlArr.push(url);
inputObj.val(urlArr.join(",")).trigger("change").trigger("validate");
}
@ -351,9 +351,10 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
$(document.body).on("keyup change", "#" + input_id, function (e) {
var inputStr = $("#" + input_id).val();
var inputArr = inputStr.split(/\,/);
$("#" + preview_id).empty();
var tpl = $("#" + preview_id).data("template") ? $("#" + preview_id).data("template") : "";
var extend = $("#" + preview_id).next().is("textarea") ? $("#" + preview_id).next("textarea").val() : "{}";
var previewObj = $("#" + preview_id);
previewObj.empty();
var tpl = previewObj.data("template") ? previewObj.data("template") : "";
var extend = previewObj.next().is("textarea") ? previewObj.next("textarea").val() : "{}";
var json = {};
try {
json = JSON.parse(extend);
@ -365,13 +366,15 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
}
var suffix = /[\.]?([a-zA-Z0-9]+)$/.exec(j);
suffix = suffix ? suffix[1] : 'file';
j = Config.upload.fullmode ? Fast.api.cdnurl(j) : j;
var btnData = $(that).data();
var fullurl = typeof btnData.cdnurl!=='undefined' ? Fast.api.cdnurl(j, btnData.cdnurl) : Fast.api.cdnurl(j);
j = Config.upload.fullmode ? fullurl : j;
var value = (json && typeof json[i] !== 'undefined' ? json[i] : null);
var data = {url: j, fullurl: Fast.api.cdnurl(j), data: $(that).data(), key: i, index: i, value: value, row: value, suffix: suffix};
var data = {url: j, fullurl: fullurl, data: btnData, key: i, index: i, value: value, row: value, suffix: suffix};
var html = tpl ? Template(tpl, data) : Template.render(Upload.config.previewtpl, data);
$("#" + preview_id).append(html);
previewObj.append(html);
});
refresh($("#" + preview_id).data("name"));
refresh(previewObj.data("name"));
});
$("#" + input_id).trigger("change");
}