增加日志功能
This commit is contained in:
parent
11fe0b4357
commit
b947009126
@ -7,7 +7,7 @@ use app\admin\controller\Base;
|
|||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
use app\common\service\LogService;
|
use app\admin\controller\Log;
|
||||||
|
|
||||||
class Article extends Base
|
class Article extends Base
|
||||||
{
|
{
|
||||||
@ -131,8 +131,10 @@ class Article extends Base
|
|||||||
|
|
||||||
$insert = Db::table('yz_article')->insert($data);
|
$insert = Db::table('yz_article')->insert($data);
|
||||||
if (empty($insert)) {
|
if (empty($insert)) {
|
||||||
|
Log::record('添加文章', 0, '添加文章失败', '文章管理');
|
||||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('添加文章', 1, '', '文章管理');
|
||||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||||
} else {
|
} else {
|
||||||
$lists = Db::table('yz_article')
|
$lists = Db::table('yz_article')
|
||||||
@ -166,7 +168,12 @@ class Article extends Base
|
|||||||
];
|
];
|
||||||
|
|
||||||
$update = Db::table('yz_article')->where('id', $id)->update($data);
|
$update = Db::table('yz_article')->where('id', $id)->update($data);
|
||||||
return json(['code' => $update === false ? 1 : 0, 'msg' => $update === false ? '更新失败' : '更新成功', 'data' => []]);
|
if ($update === false) {
|
||||||
|
Log::record('编辑文章', 0, '编辑文章失败', '文章管理');
|
||||||
|
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
|
||||||
|
}
|
||||||
|
Log::record('编辑文章', 1, '', '文章管理');
|
||||||
|
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||||
} else {
|
} else {
|
||||||
$id = input('get.id');
|
$id = input('get.id');
|
||||||
$info = Db::table('yz_article')->where('id', $id)->find();
|
$info = Db::table('yz_article')->where('id', $id)->find();
|
||||||
@ -207,8 +214,10 @@ class Article extends Base
|
|||||||
];
|
];
|
||||||
$delete = Db::table('yz_article')->where('id', $id)->update($data);
|
$delete = Db::table('yz_article')->where('id', $id)->update($data);
|
||||||
if ($delete === false) {
|
if ($delete === false) {
|
||||||
|
Log::record('删除文章', 0, '删除文章失败', '文章管理');
|
||||||
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('删除文章', 1, '', '文章管理');
|
||||||
return json(['code' => 0, 'msg' => '删除成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '删除成功', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,8 +313,10 @@ class Article extends Base
|
|||||||
|
|
||||||
$insert = Db::table('yz_article_category')->insert($data);
|
$insert = Db::table('yz_article_category')->insert($data);
|
||||||
if (empty($insert)) {
|
if (empty($insert)) {
|
||||||
|
Log::record('添加文章分类', 0, '添加文章分类失败', '文章分类');
|
||||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('添加文章分类', 1, '', '文章分类');
|
||||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||||
} else {
|
} else {
|
||||||
// 获取所有可选的父级分类
|
// 获取所有可选的父级分类
|
||||||
@ -346,8 +357,10 @@ class Article extends Base
|
|||||||
->update($data);
|
->update($data);
|
||||||
|
|
||||||
if ($update === false) {
|
if ($update === false) {
|
||||||
|
Log::record('编辑文章分类', 0, '更新文章分类失败', '文章分类');
|
||||||
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('编辑文章分类', 1, '', '文章分类');
|
||||||
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||||
} else {
|
} else {
|
||||||
$id = input('get.id');
|
$id = input('get.id');
|
||||||
@ -400,6 +413,7 @@ class Article extends Base
|
|||||||
->find();
|
->find();
|
||||||
|
|
||||||
if ($hasChildren) {
|
if ($hasChildren) {
|
||||||
|
Log::record('删除文章分类', 0, '该分类下有子分类,无法删除', '文章分类');
|
||||||
return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]);
|
return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,8 +422,10 @@ class Article extends Base
|
|||||||
->update(['delete_time' => time()]);
|
->update(['delete_time' => time()]);
|
||||||
|
|
||||||
if ($delete === false) {
|
if ($delete === false) {
|
||||||
|
Log::record('删除文章分类', 0, '删除文章分类失败', '文章分类');
|
||||||
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('删除文章分类', 1, '', '文章分类');
|
||||||
return json(['code' => 0, 'msg' => '删除成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '删除成功', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ use app\admin\controller\Base;
|
|||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
|
use think\facade\Cookie;
|
||||||
|
|
||||||
class Log extends Base
|
class Log extends Base
|
||||||
{
|
{
|
||||||
@ -62,43 +63,38 @@ class Log extends Base
|
|||||||
*/
|
*/
|
||||||
public function operation()
|
public function operation()
|
||||||
{
|
{
|
||||||
if (Request::isPost()) {
|
$params = input();
|
||||||
$page = input('post.page', 1);
|
$page = $params['page'] ?? 1;
|
||||||
$limit = input('post.limit', 10);
|
$limit = $params['limit'] ?? 10;
|
||||||
$username = input('post.username');
|
|
||||||
$module = input('post.module');
|
$query = Db::name('yz_logs_operation');
|
||||||
$operation = input('post.operation');
|
|
||||||
$status = input('post.status');
|
// 构建搜索条件
|
||||||
$startTime = input('post.start_time');
|
$searchFields = [
|
||||||
$endTime = input('post.end_time');
|
'username' => ['field' => 'username', 'type' => 'like'],
|
||||||
|
'module' => ['field' => 'module', 'type' => 'like'],
|
||||||
|
'operation' => ['field' => 'operation', 'type' => 'like'],
|
||||||
|
'status' => ['field' => 'status', 'type' => '='],
|
||||||
|
'start_time' => ['field' => 'operation_time', 'type' => '>='],
|
||||||
|
'end_time' => ['field' => 'operation_time', 'type' => '<=']
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($searchFields as $param => $config) {
|
||||||
|
if (!empty($params[$param])) {
|
||||||
|
$value = $params[$param];
|
||||||
|
if ($config['type'] === 'like') {
|
||||||
|
$value = "%{$value}%";
|
||||||
|
}
|
||||||
|
$query = $query->where($config['field'], $config['type'], $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$query = Db::name('yz_logs_operation');
|
$count = $query->count();
|
||||||
|
$list = $query->order('id desc')
|
||||||
// 搜索条件
|
->page($page, $limit)
|
||||||
if ($username) {
|
->select();
|
||||||
$query = $query->where('username', 'like', "%{$username}%");
|
|
||||||
}
|
|
||||||
if ($module) {
|
|
||||||
$query = $query->where('module', 'like', "%{$module}%");
|
|
||||||
}
|
|
||||||
if ($operation) {
|
|
||||||
$query = $query->where('operation', 'like', "%{$operation}%");
|
|
||||||
}
|
|
||||||
if ($status !== '') {
|
|
||||||
$query = $query->where('status', $status);
|
|
||||||
}
|
|
||||||
if ($startTime) {
|
|
||||||
$query = $query->where('operation_time', '>=', $startTime);
|
|
||||||
}
|
|
||||||
if ($endTime) {
|
|
||||||
$query = $query->where('operation_time', '<=', $endTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
$count = $query->count();
|
|
||||||
$list = $query->order('id desc')
|
|
||||||
->page($page, $limit)
|
|
||||||
->select();
|
|
||||||
|
|
||||||
|
if (Request::isAjax()) {
|
||||||
return json([
|
return json([
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => '获取成功',
|
'msg' => '获取成功',
|
||||||
@ -112,12 +108,16 @@ class Log extends Base
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 记录操作日志
|
* 记录操作日志
|
||||||
|
* @param string $operation 操作名称
|
||||||
|
* @param int $status 状态 1成功 0失败
|
||||||
|
* @param string $error_message 错误信息
|
||||||
|
* @param string $module 模块名称
|
||||||
*/
|
*/
|
||||||
protected function recordOperation($operation, $status = 1, $error_message = '')
|
public static function record($operation, $status = 1, $error_message = '', $module = '')
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'username' => session('admin_username'),
|
'username' => Cookie::get('admin_name') ?: '未知用户',
|
||||||
'module' => '日志管理',
|
'module' => $module ?: '系统管理',
|
||||||
'operation' => $operation,
|
'operation' => $operation,
|
||||||
'request_method' => Request::method(),
|
'request_method' => Request::method(),
|
||||||
'request_url' => Request::url(true),
|
'request_url' => Request::url(true),
|
||||||
@ -133,76 +133,28 @@ class Log extends Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除登录日志
|
* 获取操作日志详情
|
||||||
*/
|
*/
|
||||||
public function deleteLogin()
|
public function getOperationDetail()
|
||||||
{
|
{
|
||||||
$id = input('post.id');
|
$id = input('id/d', 0);
|
||||||
try {
|
if (!$id) {
|
||||||
if (Db::name('yz_logs_login')->delete($id)) {
|
return json(['code' => 1, 'msg' => '参数错误']);
|
||||||
$this->recordOperation('删除登录日志');
|
|
||||||
return json(['code' => 0, 'msg' => '删除成功']);
|
|
||||||
}
|
|
||||||
$this->recordOperation('删除登录日志', 0, '删除失败');
|
|
||||||
return json(['code' => 1, 'msg' => '删除失败']);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->recordOperation('删除登录日志', 0, $e->getMessage());
|
|
||||||
return json(['code' => 1, 'msg' => '删除失败:' . $e->getMessage()]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$info = Db::name('yz_logs_operation')
|
||||||
* 删除操作日志
|
->where('id', $id)
|
||||||
*/
|
->find();
|
||||||
public function deleteOperation()
|
|
||||||
{
|
if (!$info) {
|
||||||
$id = input('post.id');
|
return json(['code' => 1, 'msg' => '日志不存在']);
|
||||||
try {
|
|
||||||
if (Db::name('yz_logs_operation')->delete($id)) {
|
|
||||||
$this->recordOperation('删除操作日志');
|
|
||||||
return json(['code' => 0, 'msg' => '删除成功']);
|
|
||||||
}
|
|
||||||
$this->recordOperation('删除操作日志', 0, '删除失败');
|
|
||||||
return json(['code' => 1, 'msg' => '删除失败']);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->recordOperation('删除操作日志', 0, $e->getMessage());
|
|
||||||
return json(['code' => 1, 'msg' => '删除失败:' . $e->getMessage()]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// 格式化请求参数
|
||||||
* 清空登录日志
|
if (!empty($info['request_params'])) {
|
||||||
*/
|
$info['request_params'] = json_decode($info['request_params'], true);
|
||||||
public function clearLogin()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
if (Db::name('yz_logs_login')->where('1=1')->delete()) {
|
|
||||||
$this->recordOperation('清空登录日志');
|
|
||||||
return json(['code' => 0, 'msg' => '清空成功']);
|
|
||||||
}
|
|
||||||
$this->recordOperation('清空登录日志', 0, '清空失败');
|
|
||||||
return json(['code' => 1, 'msg' => '清空失败']);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->recordOperation('清空登录日志', 0, $e->getMessage());
|
|
||||||
return json(['code' => 1, 'msg' => '清空失败:' . $e->getMessage()]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return json(['code' => 0, 'msg' => '获取成功', 'data' => $info]);
|
||||||
* 清空操作日志
|
|
||||||
*/
|
|
||||||
public function clearOperation()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
if (Db::name('yz_logs_operation')->where('1=1')->delete()) {
|
|
||||||
$this->recordOperation('清空操作日志');
|
|
||||||
return json(['code' => 0, 'msg' => '清空成功']);
|
|
||||||
}
|
|
||||||
$this->recordOperation('清空操作日志', 0, '清空失败');
|
|
||||||
return json(['code' => 1, 'msg' => '清空失败']);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->recordOperation('清空操作日志', 0, $e->getMessage());
|
|
||||||
return json(['code' => 1, 'msg' => '清空失败:' . $e->getMessage()]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7,6 +7,7 @@ use app\admin\controller\Base;
|
|||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
|
use app\admin\controller\Log;
|
||||||
|
|
||||||
class Resources extends Base
|
class Resources extends Base
|
||||||
{
|
{
|
||||||
@ -129,8 +130,10 @@ class Resources extends Base
|
|||||||
|
|
||||||
$insert = Db::table('yz_resources')->insert($data);
|
$insert = Db::table('yz_resources')->insert($data);
|
||||||
if (empty($insert)) {
|
if (empty($insert)) {
|
||||||
|
Log::record('添加资源', 0, '添加资源失败', '资源管理');
|
||||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('添加资源', 1, '', '资源管理');
|
||||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||||
} else {
|
} else {
|
||||||
$lists = Db::table('yz_resources')
|
$lists = Db::table('yz_resources')
|
||||||
@ -156,8 +159,10 @@ class Resources extends Base
|
|||||||
];
|
];
|
||||||
$delete = Db::table('yz_resources')->where('id', $id)->update($data);
|
$delete = Db::table('yz_resources')->where('id', $id)->update($data);
|
||||||
if ($delete === false) {
|
if ($delete === false) {
|
||||||
|
Log::record('删除资源', 0, '删除资源失败', '资源管理');
|
||||||
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('删除资源', 1, '', '资源管理');
|
||||||
return json(['code' => 0, 'msg' => '删除成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '删除成功', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,8 +258,10 @@ class Resources extends Base
|
|||||||
|
|
||||||
$insert = Db::table('yz_resources_category')->insert($data);
|
$insert = Db::table('yz_resources_category')->insert($data);
|
||||||
if (empty($insert)) {
|
if (empty($insert)) {
|
||||||
|
Log::record('添加资源分类', 0, '添加资源分类失败', '资源分类');
|
||||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('添加资源分类', 1, '', '资源分类');
|
||||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||||
} else {
|
} else {
|
||||||
// 获取所有可选的父级分类
|
// 获取所有可选的父级分类
|
||||||
@ -295,8 +302,10 @@ class Resources extends Base
|
|||||||
->update($data);
|
->update($data);
|
||||||
|
|
||||||
if ($update === false) {
|
if ($update === false) {
|
||||||
|
Log::record('编辑资源分类', 0, '更新资源分类失败', '资源分类');
|
||||||
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('编辑资源分类', 1, '', '资源分类');
|
||||||
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||||
} else {
|
} else {
|
||||||
$id = input('get.id');
|
$id = input('get.id');
|
||||||
@ -349,6 +358,7 @@ class Resources extends Base
|
|||||||
->find();
|
->find();
|
||||||
|
|
||||||
if ($hasChildren) {
|
if ($hasChildren) {
|
||||||
|
Log::record('删除资源分类', 0, '该分类下有子分类,无法删除', '资源分类');
|
||||||
return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]);
|
return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,8 +367,10 @@ class Resources extends Base
|
|||||||
->update(['delete_time' => time()]);
|
->update(['delete_time' => time()]);
|
||||||
|
|
||||||
if ($delete === false) {
|
if ($delete === false) {
|
||||||
|
Log::record('删除资源分类', 0, '删除资源分类失败', '资源分类');
|
||||||
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
Log::record('删除资源分类', 1, '', '资源分类');
|
||||||
return json(['code' => 0, 'msg' => '删除成功', 'data' => []]);
|
return json(['code' => 0, 'msg' => '删除成功', 'data' => []]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,6 +381,7 @@ class Resources extends Base
|
|||||||
{
|
{
|
||||||
$id = input('id/d', 0);
|
$id = input('id/d', 0);
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
|
Log::record('获取资源详情', 0, '参数错误', '资源管理');
|
||||||
return json(['code' => 1, 'msg' => '参数错误']);
|
return json(['code' => 1, 'msg' => '参数错误']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,6 +391,7 @@ class Resources extends Base
|
|||||||
->find();
|
->find();
|
||||||
|
|
||||||
if (!$resource) {
|
if (!$resource) {
|
||||||
|
Log::record('获取资源详情', 0, '资源不存在', '资源管理');
|
||||||
return json(['code' => 1, 'msg' => '资源不存在']);
|
return json(['code' => 1, 'msg' => '资源不存在']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,9 +405,7 @@ class Resources extends Base
|
|||||||
$resource['cate_name'] = $cateInfo['name'];
|
$resource['cate_name'] = $cateInfo['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调试输出
|
Log::record('获取资源详情', 1, '', '资源管理');
|
||||||
trace('Resource data: ' . json_encode($resource), 'debug');
|
|
||||||
|
|
||||||
return json(['code' => 0, 'msg' => '获取成功', 'data' => $resource]);
|
return json(['code' => 0, 'msg' => '获取成功', 'data' => $resource]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,6 +419,7 @@ class Resources extends Base
|
|||||||
$id = input('id/d', 0);
|
$id = input('id/d', 0);
|
||||||
|
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
|
Log::record('编辑资源', 0, '参数错误', '资源管理');
|
||||||
return json(['code' => 1, 'msg' => '参数错误']);
|
return json(['code' => 1, 'msg' => '参数错误']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,19 +438,23 @@ class Resources extends Base
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
|
Log::record('编辑资源', 1, '', '资源管理');
|
||||||
return json(['code' => 0, 'msg' => '编辑成功']);
|
return json(['code' => 0, 'msg' => '编辑成功']);
|
||||||
} else {
|
} else {
|
||||||
|
Log::record('编辑资源', 0, '编辑资源失败', '资源管理');
|
||||||
return json(['code' => 1, 'msg' => '编辑失败']);
|
return json(['code' => 1, 'msg' => '编辑失败']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = input('id/d', 0);
|
$id = input('id/d', 0);
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
|
Log::record('编辑资源', 0, '参数错误', '资源管理');
|
||||||
$this->error('参数错误');
|
$this->error('参数错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource = Db::table('yz_resources')->where('id', $id)->find();
|
$resource = Db::table('yz_resources')->where('id', $id)->find();
|
||||||
if (!$resource) {
|
if (!$resource) {
|
||||||
|
Log::record('编辑资源', 0, '资源不存在', '资源管理');
|
||||||
$this->error('资源不存在');
|
$this->error('资源不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use think\facade\Db;
|
|||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
use app\admin\model\YzAdminConfig;
|
use app\admin\model\YzAdminConfig;
|
||||||
|
use app\admin\controller\Log;
|
||||||
|
|
||||||
class Yunzer extends Base{
|
class Yunzer extends Base{
|
||||||
# 菜单列表
|
# 菜单列表
|
||||||
@ -25,6 +26,7 @@ class Yunzer extends Base{
|
|||||||
if ($req->isPost()) {
|
if ($req->isPost()) {
|
||||||
$data['label'] = trim(input('post.label'));
|
$data['label'] = trim(input('post.label'));
|
||||||
if (empty($data['label'])) {
|
if (empty($data['label'])) {
|
||||||
|
Log::record('添加菜单', 0, '请输入菜单名称', '菜单管理');
|
||||||
$this->returnCode(1, '请输入菜单名称');
|
$this->returnCode(1, '请输入菜单名称');
|
||||||
}
|
}
|
||||||
$data['icon_class'] = trim(input('post.icon_class'));
|
$data['icon_class'] = trim(input('post.icon_class'));
|
||||||
@ -34,11 +36,13 @@ class Yunzer extends Base{
|
|||||||
if ($data['type'] == 1) {
|
if ($data['type'] == 1) {
|
||||||
$data['src'] = trim(input('post.src1'));
|
$data['src'] = trim(input('post.src1'));
|
||||||
if (empty($data['src'])) {
|
if (empty($data['src'])) {
|
||||||
|
Log::record('添加菜单', 0, '请输入内部跳转地址', '菜单管理');
|
||||||
$this->returnCode(1, '请输入内部跳转地址');
|
$this->returnCode(1, '请输入内部跳转地址');
|
||||||
}
|
}
|
||||||
} else if ($data['type'] == 2) {
|
} else if ($data['type'] == 2) {
|
||||||
$data['src'] = trim(input('post.src2'));
|
$data['src'] = trim(input('post.src2'));
|
||||||
if (empty($data['src'])) {
|
if (empty($data['src'])) {
|
||||||
|
Log::record('添加菜单', 0, '请输入超链接地址', '菜单管理');
|
||||||
$this->returnCode(1, '请输入超链接地址');
|
$this->returnCode(1, '请输入超链接地址');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -47,6 +51,7 @@ class Yunzer extends Base{
|
|||||||
// 保存菜单
|
// 保存菜单
|
||||||
$res = Db::table('yz_admin_sys_menu')->insert($data);
|
$res = Db::table('yz_admin_sys_menu')->insert($data);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
|
Log::record('添加菜单', 0, '添加菜单失败', '菜单管理');
|
||||||
$this->returnCode(1, '添加菜单失败');
|
$this->returnCode(1, '添加菜单失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +78,7 @@ class Yunzer extends Base{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::record('添加菜单', 1, '', '菜单管理');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
} else {
|
} else {
|
||||||
$iconfont = Db::table('yz_z_iconfont')->where('status', 1)->select();
|
$iconfont = Db::table('yz_z_iconfont')->where('status', 1)->select();
|
||||||
@ -89,6 +95,7 @@ class Yunzer extends Base{
|
|||||||
$smid = (int)input('post.smid');
|
$smid = (int)input('post.smid');
|
||||||
$data['label'] = trim(input('post.label'));
|
$data['label'] = trim(input('post.label'));
|
||||||
if(!$data['label']){
|
if(!$data['label']){
|
||||||
|
Log::record('编辑菜单', 0, '请输入菜单名称', '菜单管理');
|
||||||
$this->returnCode(1, '请输入菜单名称');
|
$this->returnCode(1, '请输入菜单名称');
|
||||||
}
|
}
|
||||||
$data['icon_class'] = trim(input('post.icon_class'));
|
$data['icon_class'] = trim(input('post.icon_class'));
|
||||||
@ -98,11 +105,13 @@ class Yunzer extends Base{
|
|||||||
if($data['type'] == 1){
|
if($data['type'] == 1){
|
||||||
$data['src'] = trim(input('post.src1'));
|
$data['src'] = trim(input('post.src1'));
|
||||||
if(empty($data['src'])){
|
if(empty($data['src'])){
|
||||||
|
Log::record('编辑菜单', 0, '请输入内部跳转地址', '菜单管理');
|
||||||
$this->returnCode(1, '请输入内部跳转地址');
|
$this->returnCode(1, '请输入内部跳转地址');
|
||||||
}
|
}
|
||||||
}else if($data['type'] == 2){
|
}else if($data['type'] == 2){
|
||||||
$data['src'] = trim(input('post.src2'));
|
$data['src'] = trim(input('post.src2'));
|
||||||
if(empty($data['src'])){
|
if(empty($data['src'])){
|
||||||
|
Log::record('编辑菜单', 0, '请输入超链接地址', '菜单管理');
|
||||||
$this->returnCode(1, '请输入超链接地址');
|
$this->returnCode(1, '请输入超链接地址');
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@ -111,8 +120,10 @@ class Yunzer extends Base{
|
|||||||
// 保存用户
|
// 保存用户
|
||||||
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->update($data);
|
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->update($data);
|
||||||
if(!$res){
|
if(!$res){
|
||||||
|
Log::record('编辑菜单', 0, '修改菜单失败', '菜单管理');
|
||||||
$this->returnCode(1, '修改菜单失败');
|
$this->returnCode(1, '修改菜单失败');
|
||||||
}
|
}
|
||||||
|
Log::record('编辑菜单', 1, '', '菜单管理');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
}else{
|
}else{
|
||||||
$smid = (int)input('get.smid');
|
$smid = (int)input('get.smid');
|
||||||
@ -130,12 +141,15 @@ class Yunzer extends Base{
|
|||||||
$smid = (int)input('post.smid');
|
$smid = (int)input('post.smid');
|
||||||
$count = Db::table('yz_admin_sys_menu')->where('parent_id',$smid)->count();
|
$count = Db::table('yz_admin_sys_menu')->where('parent_id',$smid)->count();
|
||||||
if($count > 0){
|
if($count > 0){
|
||||||
|
Log::record('删除菜单', 0, '该菜单下还有子菜单,不能删除', '菜单管理');
|
||||||
$this->returnCode(1, '该菜单下还有子菜单,不能删除');
|
$this->returnCode(1, '该菜单下还有子菜单,不能删除');
|
||||||
}
|
}
|
||||||
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->delete();
|
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->delete();
|
||||||
if(empty($res)){
|
if(empty($res)){
|
||||||
|
Log::record('删除菜单', 0, '删除菜单失败', '菜单管理');
|
||||||
$this->returnCode(1, '删除菜单失败');
|
$this->returnCode(1, '删除菜单失败');
|
||||||
}
|
}
|
||||||
|
Log::record('删除菜单', 1, '', '菜单管理');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
}
|
}
|
||||||
# 按钮管理
|
# 按钮管理
|
||||||
@ -173,6 +187,7 @@ class Yunzer extends Base{
|
|||||||
$smid = (int)input('post.smid');
|
$smid = (int)input('post.smid');
|
||||||
$data['label'] = trim(input('post.label'));
|
$data['label'] = trim(input('post.label'));
|
||||||
if(!$data['label']){
|
if(!$data['label']){
|
||||||
|
Log::record('添加按钮', 0, '请输入按钮名称', '按钮管理');
|
||||||
$this->returnCode(1, '请输入按钮名称');
|
$this->returnCode(1, '请输入按钮名称');
|
||||||
}
|
}
|
||||||
$data['icon_class'] = trim(input('post.icon_class'));
|
$data['icon_class'] = trim(input('post.icon_class'));
|
||||||
@ -180,24 +195,29 @@ class Yunzer extends Base{
|
|||||||
$data['status'] = (int)trim(input('post.status'));
|
$data['status'] = (int)trim(input('post.status'));
|
||||||
$data['type'] = (int)trim(input('post.type'));
|
$data['type'] = (int)trim(input('post.type'));
|
||||||
if(empty($data['type'])){
|
if(empty($data['type'])){
|
||||||
|
Log::record('添加按钮', 0, '请选择按钮类型', '按钮管理');
|
||||||
$this->returnCode(1, '请选择按钮类型');
|
$this->returnCode(1, '请选择按钮类型');
|
||||||
}
|
}
|
||||||
if($data['type'] == 1){
|
if($data['type'] == 1){
|
||||||
$data['src'] = trim(input('post.src1'));
|
$data['src'] = trim(input('post.src1'));
|
||||||
if(empty($data['src'])){
|
if(empty($data['src'])){
|
||||||
|
Log::record('添加按钮', 0, '请输入内部跳转地址', '按钮管理');
|
||||||
$this->returnCode(1, '请输入内部跳转地址');
|
$this->returnCode(1, '请输入内部跳转地址');
|
||||||
}
|
}
|
||||||
}else if($data['type'] == 2){
|
}else if($data['type'] == 2){
|
||||||
$data['src'] = trim(input('post.src2'));
|
$data['src'] = trim(input('post.src2'));
|
||||||
if(empty($data['src'])){
|
if(empty($data['src'])){
|
||||||
|
Log::record('添加按钮', 0, '请输入超链接地址', '按钮管理');
|
||||||
$this->returnCode(1, '请输入超链接地址');
|
$this->returnCode(1, '请输入超链接地址');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$data['parent_id'] = $smid;
|
$data['parent_id'] = $smid;
|
||||||
$res = Db::table('yz_admin_sys_menu')->insert($data);
|
$res = Db::table('yz_admin_sys_menu')->insert($data);
|
||||||
if(!$res){
|
if(!$res){
|
||||||
|
Log::record('添加按钮', 0, '添加按钮失败', '按钮管理');
|
||||||
$this->returnCode(1, '添加按钮失败');
|
$this->returnCode(1, '添加按钮失败');
|
||||||
}
|
}
|
||||||
|
Log::record('添加按钮', 1, '', '按钮管理');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
}else{
|
}else{
|
||||||
$smid = (int)input('get.smid');
|
$smid = (int)input('get.smid');
|
||||||
@ -216,6 +236,7 @@ class Yunzer extends Base{
|
|||||||
$smid = (int)input('post.smid');
|
$smid = (int)input('post.smid');
|
||||||
$data['label'] = trim(input('post.label'));
|
$data['label'] = trim(input('post.label'));
|
||||||
if(!$data['label']){
|
if(!$data['label']){
|
||||||
|
Log::record('编辑按钮', 0, '请输入按钮名称', '按钮管理');
|
||||||
$this->returnCode(1, '请输入按钮名称');
|
$this->returnCode(1, '请输入按钮名称');
|
||||||
}
|
}
|
||||||
$data['icon_class'] = trim(input('post.icon_class'));
|
$data['icon_class'] = trim(input('post.icon_class'));
|
||||||
@ -223,23 +244,28 @@ class Yunzer extends Base{
|
|||||||
$data['status'] = (int)trim(input('post.status'));
|
$data['status'] = (int)trim(input('post.status'));
|
||||||
$data['type'] = (int)trim(input('post.type'));
|
$data['type'] = (int)trim(input('post.type'));
|
||||||
if(empty($data['type'])){
|
if(empty($data['type'])){
|
||||||
|
Log::record('编辑按钮', 0, '请选择按钮类型', '按钮管理');
|
||||||
$this->returnCode(1, '请选择按钮类型');
|
$this->returnCode(1, '请选择按钮类型');
|
||||||
}
|
}
|
||||||
if($data['type'] == 1){
|
if($data['type'] == 1){
|
||||||
$data['src'] = trim(input('post.src1'));
|
$data['src'] = trim(input('post.src1'));
|
||||||
if(empty($data['src'])){
|
if(empty($data['src'])){
|
||||||
|
Log::record('编辑按钮', 0, '请输入内部跳转地址', '按钮管理');
|
||||||
$this->returnCode(1, '请输入内部跳转地址');
|
$this->returnCode(1, '请输入内部跳转地址');
|
||||||
}
|
}
|
||||||
}else if($data['type'] == 2){
|
}else if($data['type'] == 2){
|
||||||
$data['src'] = trim(input('post.src2'));
|
$data['src'] = trim(input('post.src2'));
|
||||||
if(empty($data['src'])){
|
if(empty($data['src'])){
|
||||||
|
Log::record('编辑按钮', 0, '请输入超链接地址', '按钮管理');
|
||||||
$this->returnCode(1, '请输入超链接地址');
|
$this->returnCode(1, '请输入超链接地址');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->update($data);
|
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->update($data);
|
||||||
if(!$res){
|
if(!$res){
|
||||||
|
Log::record('编辑按钮', 0, '修改按钮失败', '按钮管理');
|
||||||
$this->returnCode(1, '修改按钮失败');
|
$this->returnCode(1, '修改按钮失败');
|
||||||
}
|
}
|
||||||
|
Log::record('编辑按钮', 1, '', '按钮管理');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
}else{
|
}else{
|
||||||
$smid = (int)input('get.smid');
|
$smid = (int)input('get.smid');
|
||||||
@ -257,8 +283,10 @@ class Yunzer extends Base{
|
|||||||
$smid = (int)input('post.smid');
|
$smid = (int)input('post.smid');
|
||||||
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->delete();
|
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->delete();
|
||||||
if(empty($res)){
|
if(empty($res)){
|
||||||
|
Log::record('删除按钮', 0, '删除按钮失败', '按钮管理');
|
||||||
$this->returnCode(1, '删除按钮失败');
|
$this->returnCode(1, '删除按钮失败');
|
||||||
}
|
}
|
||||||
|
Log::record('删除按钮', 1, '', '按钮管理');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
}
|
}
|
||||||
# 配置列表
|
# 配置列表
|
||||||
@ -280,10 +308,12 @@ class Yunzer extends Base{
|
|||||||
if($req->isPost()){
|
if($req->isPost()){
|
||||||
$data['config_name'] = trim(input('post.config_name'));
|
$data['config_name'] = trim(input('post.config_name'));
|
||||||
if(empty($data['config_name'])){
|
if(empty($data['config_name'])){
|
||||||
|
Log::record('添加配置', 0, '请输入关键词', '系统配置');
|
||||||
$this->returnCode(1,'请输入关键词');
|
$this->returnCode(1,'请输入关键词');
|
||||||
}
|
}
|
||||||
$data['config_info'] = trim(input('post.config_info'));
|
$data['config_info'] = trim(input('post.config_info'));
|
||||||
if(empty($data['config_info'])){
|
if(empty($data['config_info'])){
|
||||||
|
Log::record('添加配置', 0, '请输入作用', '系统配置');
|
||||||
$this->returnCode(1,'请输入作用');
|
$this->returnCode(1,'请输入作用');
|
||||||
}
|
}
|
||||||
$data['config_type'] = trim(input('post.config_type'));
|
$data['config_type'] = trim(input('post.config_type'));
|
||||||
@ -292,8 +322,10 @@ class Yunzer extends Base{
|
|||||||
$data['config_sort'] = trim(input('post.config_sort'));
|
$data['config_sort'] = trim(input('post.config_sort'));
|
||||||
$res = Db::table('yz_admin_config')->insert($data);
|
$res = Db::table('yz_admin_config')->insert($data);
|
||||||
if(empty($res)){
|
if(empty($res)){
|
||||||
|
Log::record('添加配置', 0, '添加配置失败', '系统配置');
|
||||||
$this->returnCode(1, '添加配置失败');
|
$this->returnCode(1, '添加配置失败');
|
||||||
}
|
}
|
||||||
|
Log::record('添加配置', 1, '', '系统配置');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
}else{
|
}else{
|
||||||
return View::fetch();
|
return View::fetch();
|
||||||
@ -305,14 +337,17 @@ class Yunzer extends Base{
|
|||||||
if($req->isPost()){
|
if($req->isPost()){
|
||||||
$config_id = (int)input('post.config_id');
|
$config_id = (int)input('post.config_id');
|
||||||
if(empty($config_id)){
|
if(empty($config_id)){
|
||||||
|
Log::record('编辑配置', 0, '请选择一条数据', '系统配置');
|
||||||
$this->returnCode(1,'请选择一条数据');
|
$this->returnCode(1,'请选择一条数据');
|
||||||
}
|
}
|
||||||
$data['config_name'] = trim(input('post.config_name'));
|
$data['config_name'] = trim(input('post.config_name'));
|
||||||
if(empty($data['config_name'])){
|
if(empty($data['config_name'])){
|
||||||
|
Log::record('编辑配置', 0, '请输入关键词', '系统配置');
|
||||||
$this->returnCode(1,'请输入关键词');
|
$this->returnCode(1,'请输入关键词');
|
||||||
}
|
}
|
||||||
$data['config_info'] = trim(input('post.config_info'));
|
$data['config_info'] = trim(input('post.config_info'));
|
||||||
if(empty($data['config_info'])){
|
if(empty($data['config_info'])){
|
||||||
|
Log::record('编辑配置', 0, '请输入作用', '系统配置');
|
||||||
$this->returnCode(1,'请输入作用');
|
$this->returnCode(1,'请输入作用');
|
||||||
}
|
}
|
||||||
$data['config_type'] = trim(input('post.config_type'));
|
$data['config_type'] = trim(input('post.config_type'));
|
||||||
@ -321,8 +356,10 @@ class Yunzer extends Base{
|
|||||||
$data['config_sort'] = trim(input('post.config_sort'));
|
$data['config_sort'] = trim(input('post.config_sort'));
|
||||||
$res = Db::table('yz_admin_config')->where('config_id',$config_id)->update($data);
|
$res = Db::table('yz_admin_config')->where('config_id',$config_id)->update($data);
|
||||||
if(empty($res)){
|
if(empty($res)){
|
||||||
|
Log::record('编辑配置', 0, '修改配置失败', '系统配置');
|
||||||
$this->returnCode(1, '修改配置失败');
|
$this->returnCode(1, '修改配置失败');
|
||||||
}
|
}
|
||||||
|
Log::record('编辑配置', 1, '', '系统配置');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
}else{
|
}else{
|
||||||
$config_id = (int)input('get.config_id');
|
$config_id = (int)input('get.config_id');
|
||||||
@ -337,12 +374,15 @@ class Yunzer extends Base{
|
|||||||
public function configdel(){
|
public function configdel(){
|
||||||
$config_id = (int)input('post.config_id');
|
$config_id = (int)input('post.config_id');
|
||||||
if(empty($config_id)){
|
if(empty($config_id)){
|
||||||
|
Log::record('删除配置', 0, '请选择一条数据', '系统配置');
|
||||||
$this->returnCode(1,'请选择一条数据');
|
$this->returnCode(1,'请选择一条数据');
|
||||||
}
|
}
|
||||||
$res = Db::table('yz_admin_config')->where('config_id',$config_id)->delete();
|
$res = Db::table('yz_admin_config')->where('config_id',$config_id)->delete();
|
||||||
if(empty($res)){
|
if(empty($res)){
|
||||||
|
Log::record('删除配置', 0, '删除配置失败', '系统配置');
|
||||||
$this->returnCode(1, '删除配置失败');
|
$this->returnCode(1, '删除配置失败');
|
||||||
}
|
}
|
||||||
|
Log::record('删除配置', 1, '', '系统配置');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
}
|
}
|
||||||
# 配置值
|
# 配置值
|
||||||
@ -351,13 +391,16 @@ class Yunzer extends Base{
|
|||||||
if($req->isPost()){
|
if($req->isPost()){
|
||||||
$post = input('post.');
|
$post = input('post.');
|
||||||
if(empty($post)){
|
if(empty($post)){
|
||||||
|
Log::record('更新配置值', 0, '数据不能为空', '系统配置');
|
||||||
$this->returnCode(1,'数据不能为空');
|
$this->returnCode(1,'数据不能为空');
|
||||||
}
|
}
|
||||||
$oConfig = new YzAdminConfig();
|
$oConfig = new YzAdminConfig();
|
||||||
$updateAll = $oConfig->updateAll($post);
|
$updateAll = $oConfig->updateAll($post);
|
||||||
if(empty($updateAll)){
|
if(empty($updateAll)){
|
||||||
|
Log::record('更新配置值', 0, '更新配置值失败', '系统配置');
|
||||||
$this->returnCode(1, '更新配置值失败');
|
$this->returnCode(1, '更新配置值失败');
|
||||||
}
|
}
|
||||||
|
Log::record('更新配置值', 1, '', '系统配置');
|
||||||
$this->returnCode(0);
|
$this->returnCode(0);
|
||||||
}else{
|
}else{
|
||||||
$lists = Db::table('yz_admin_config')->order('config_sort DESC,config_id')->select();
|
$lists = Db::table('yz_admin_config')->order('config_sort DESC,config_id')->select();
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use app\admin\controller\Base;
|
|||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
|
use app\admin\controller\Log;
|
||||||
|
|
||||||
class Yunzeradmin extends Base
|
class Yunzeradmin extends Base
|
||||||
{
|
{
|
||||||
@ -23,6 +24,7 @@ class Yunzeradmin extends Base
|
|||||||
if (Request::isPost()) {
|
if (Request::isPost()) {
|
||||||
$data['group_name'] = trim(input('post.group_name'));
|
$data['group_name'] = trim(input('post.group_name'));
|
||||||
if (!$data['group_name']) {
|
if (!$data['group_name']) {
|
||||||
|
Log::record('添加角色', 0, '角色名称不能为空', '角色管理');
|
||||||
return json(['code' => 1, 'msg' => '角色名称不能为空']);
|
return json(['code' => 1, 'msg' => '角色名称不能为空']);
|
||||||
}
|
}
|
||||||
$data['status'] = (int) trim(input('post.status'));
|
$data['status'] = (int) trim(input('post.status'));
|
||||||
@ -33,8 +35,10 @@ class Yunzeradmin extends Base
|
|||||||
}
|
}
|
||||||
$res = Db::table('yz_admin_user_group')->insert($data);
|
$res = Db::table('yz_admin_user_group')->insert($data);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
|
Log::record('添加角色', 0, '添加角色失败', '角色管理');
|
||||||
return json(['code' => 1, 'msg' => '添加角色失败']);
|
return json(['code' => 1, 'msg' => '添加角色失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('添加角色', 1, '', '角色管理');
|
||||||
return json(['code' => 0, 'msg' => '添加成功']);
|
return json(['code' => 0, 'msg' => '添加成功']);
|
||||||
} else {
|
} else {
|
||||||
$menus = Db::table('yz_admin_sys_menu')->order('type,sort desc')->where('status', '=', 1)->select();
|
$menus = Db::table('yz_admin_sys_menu')->order('type,sort desc')->where('status', '=', 1)->select();
|
||||||
@ -69,6 +73,7 @@ class Yunzeradmin extends Base
|
|||||||
$group_id = (int) trim(input('post.group_id'));
|
$group_id = (int) trim(input('post.group_id'));
|
||||||
$data['group_name'] = trim(input('post.group_name'));
|
$data['group_name'] = trim(input('post.group_name'));
|
||||||
if (!$data['group_name']) {
|
if (!$data['group_name']) {
|
||||||
|
Log::record('编辑角色', 0, '角色名称不能为空', '角色管理');
|
||||||
return json(['code' => 1, 'msg' => '角色名称不能为空']);
|
return json(['code' => 1, 'msg' => '角色名称不能为空']);
|
||||||
}
|
}
|
||||||
$data['status'] = (int) trim(input('post.status'));
|
$data['status'] = (int) trim(input('post.status'));
|
||||||
@ -80,8 +85,10 @@ class Yunzeradmin extends Base
|
|||||||
}
|
}
|
||||||
$res = Db::table('yz_admin_user_group')->where('group_id', $group_id)->update($data);
|
$res = Db::table('yz_admin_user_group')->where('group_id', $group_id)->update($data);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
|
Log::record('编辑角色', 0, '更新角色失败', '角色管理');
|
||||||
return json(['code' => 1, 'msg' => '更新角色失败']);
|
return json(['code' => 1, 'msg' => '更新角色失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('编辑角色', 1, '', '角色管理');
|
||||||
return json(['code' => 0, 'msg' => '更新成功']);
|
return json(['code' => 0, 'msg' => '更新成功']);
|
||||||
} else {
|
} else {
|
||||||
$group_id = (int) input('get.group_id');
|
$group_id = (int) input('get.group_id');
|
||||||
@ -122,8 +129,10 @@ class Yunzeradmin extends Base
|
|||||||
$group_id = (int) input('post.group_id');
|
$group_id = (int) input('post.group_id');
|
||||||
$res = Db::table('yz_admin_user_group')->where('group_id', $group_id)->delete();
|
$res = Db::table('yz_admin_user_group')->where('group_id', $group_id)->delete();
|
||||||
if (empty($res)) {
|
if (empty($res)) {
|
||||||
|
Log::record('删除角色', 0, '删除角色失败', '角色管理');
|
||||||
return json(['code' => 1, 'msg' => '删除角色失败']);
|
return json(['code' => 1, 'msg' => '删除角色失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('删除角色', 1, '', '角色管理');
|
||||||
return json(['code' => 0, 'msg' => '删除成功']);
|
return json(['code' => 0, 'msg' => '删除成功']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,14 +158,17 @@ class Yunzeradmin extends Base
|
|||||||
if (Request::isPost()) {
|
if (Request::isPost()) {
|
||||||
$data['account'] = trim(input('post.account'));
|
$data['account'] = trim(input('post.account'));
|
||||||
if (empty($data['account'])) {
|
if (empty($data['account'])) {
|
||||||
|
Log::record('添加管理员', 0, '账号不能为空', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '账号不能为空']);
|
return json(['code' => 1, 'msg' => '账号不能为空']);
|
||||||
}
|
}
|
||||||
$pattern = "/^([0-9A-Za-z-_.]+)@([0-9a-z]+.[a-z]{2,3}(.[a-z]{2})?)$/i";
|
$pattern = "/^([0-9A-Za-z-_.]+)@([0-9a-z]+.[a-z]{2,3}(.[a-z]{2})?)$/i";
|
||||||
if (!preg_match($pattern, $data['account'])) {
|
if (!preg_match($pattern, $data['account'])) {
|
||||||
|
Log::record('添加管理员', 0, '邮箱格式不正确', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '邮箱格式不正确']);
|
return json(['code' => 1, 'msg' => '邮箱格式不正确']);
|
||||||
}
|
}
|
||||||
$item = Db::table('yz_admin_user')->where('account', $data['account'])->find();
|
$item = Db::table('yz_admin_user')->where('account', $data['account'])->find();
|
||||||
if ($item) {
|
if ($item) {
|
||||||
|
Log::record('添加管理员', 0, '该账号已存在', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '该账号已存在']);
|
return json(['code' => 1, 'msg' => '该账号已存在']);
|
||||||
}
|
}
|
||||||
$data['name'] = trim(input('post.name'));
|
$data['name'] = trim(input('post.name'));
|
||||||
@ -167,15 +179,19 @@ class Yunzeradmin extends Base
|
|||||||
$data['status'] = (int) (input('post.status'));
|
$data['status'] = (int) (input('post.status'));
|
||||||
$password = trim(input('post.password'));
|
$password = trim(input('post.password'));
|
||||||
if (empty($data['name'])) {
|
if (empty($data['name'])) {
|
||||||
|
Log::record('添加管理员', 0, '姓名不能为空', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '姓名不能为空']);
|
return json(['code' => 1, 'msg' => '姓名不能为空']);
|
||||||
}
|
}
|
||||||
if (empty($data['phone'])) {
|
if (empty($data['phone'])) {
|
||||||
|
Log::record('添加管理员', 0, '手机号不能为空', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '手机号不能为空']);
|
return json(['code' => 1, 'msg' => '手机号不能为空']);
|
||||||
}
|
}
|
||||||
if (empty($data['group_id'])) {
|
if (empty($data['group_id'])) {
|
||||||
|
Log::record('添加管理员', 0, '请选择角色', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '请选择角色']);
|
return json(['code' => 1, 'msg' => '请选择角色']);
|
||||||
}
|
}
|
||||||
if (empty($password)) {
|
if (empty($password)) {
|
||||||
|
Log::record('添加管理员', 0, '密码不能为空', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '密码不能为空']);
|
return json(['code' => 1, 'msg' => '密码不能为空']);
|
||||||
} else {
|
} else {
|
||||||
$data['password'] = md5($password);
|
$data['password'] = md5($password);
|
||||||
@ -184,8 +200,10 @@ class Yunzeradmin extends Base
|
|||||||
$data['update_time'] = time();
|
$data['update_time'] = time();
|
||||||
$res = Db::table('yz_admin_user')->insert($data);
|
$res = Db::table('yz_admin_user')->insert($data);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
|
Log::record('添加管理员', 0, '添加管理员失败', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '添加管理员失败']);
|
return json(['code' => 1, 'msg' => '添加管理员失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('添加管理员', 1, '', '管理员管理');
|
||||||
return json(['code' => 0, 'msg' => '添加成功']);
|
return json(['code' => 0, 'msg' => '添加成功']);
|
||||||
} else {
|
} else {
|
||||||
$group = [];
|
$group = [];
|
||||||
@ -212,19 +230,23 @@ class Yunzeradmin extends Base
|
|||||||
$data['sex'] = (int) (input('post.sex'));
|
$data['sex'] = (int) (input('post.sex'));
|
||||||
$data['status'] = (int) (input('post.status'));
|
$data['status'] = (int) (input('post.status'));
|
||||||
if (empty($data['name'])) {
|
if (empty($data['name'])) {
|
||||||
|
Log::record('编辑管理员', 0, '姓名不能为空', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '姓名不能为空']);
|
return json(['code' => 1, 'msg' => '姓名不能为空']);
|
||||||
}
|
}
|
||||||
if (empty($data['phone'])) {
|
if (empty($data['phone'])) {
|
||||||
|
Log::record('编辑管理员', 0, '手机号不能为空', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '手机号不能为空']);
|
return json(['code' => 1, 'msg' => '手机号不能为空']);
|
||||||
}
|
}
|
||||||
if (empty($data['group_id'])) {
|
if (empty($data['group_id'])) {
|
||||||
|
Log::record('编辑管理员', 0, '请选择角色', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '请选择角色']);
|
return json(['code' => 1, 'msg' => '请选择角色']);
|
||||||
}
|
}
|
||||||
// 保存用户
|
|
||||||
$res = Db::table('yz_admin_user')->where('uid', $uid)->update($data);
|
$res = Db::table('yz_admin_user')->where('uid', $uid)->update($data);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
|
Log::record('编辑管理员', 0, '更新管理员信息失败', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '更新管理员信息失败']);
|
return json(['code' => 1, 'msg' => '更新管理员信息失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('编辑管理员', 1, '', '管理员管理');
|
||||||
return json(['code' => 0, 'msg' => '更新成功']);
|
return json(['code' => 0, 'msg' => '更新成功']);
|
||||||
} else {
|
} else {
|
||||||
$uid = (int) input('get.uid');
|
$uid = (int) input('get.uid');
|
||||||
@ -250,8 +272,10 @@ class Yunzeradmin extends Base
|
|||||||
$uid = (int) input('post.uid');
|
$uid = (int) input('post.uid');
|
||||||
$res = Db::table('yz_admin_user')->where('uid', $uid)->delete();
|
$res = Db::table('yz_admin_user')->where('uid', $uid)->delete();
|
||||||
if (empty($res)) {
|
if (empty($res)) {
|
||||||
|
Log::record('删除管理员', 0, '删除管理员失败', '管理员管理');
|
||||||
return json(['code' => 1, 'msg' => '删除管理员失败']);
|
return json(['code' => 1, 'msg' => '删除管理员失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('删除管理员', 1, '', '管理员管理');
|
||||||
return json(['code' => 0, 'msg' => '删除成功']);
|
return json(['code' => 0, 'msg' => '删除成功']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,6 +285,7 @@ class Yunzeradmin extends Base
|
|||||||
if (Request::isPost()) {
|
if (Request::isPost()) {
|
||||||
$find = Db::table('yz_admin_user')->where('uid', $this->adminId)->find();
|
$find = Db::table('yz_admin_user')->where('uid', $this->adminId)->find();
|
||||||
if (empty($find)) {
|
if (empty($find)) {
|
||||||
|
Log::record('修改个人信息', 0, '当前账户不存在', '个人信息');
|
||||||
return json(['code' => 1, 'msg' => '当前账户不存在']);
|
return json(['code' => 1, 'msg' => '当前账户不存在']);
|
||||||
}
|
}
|
||||||
$data['name'] = trim(input('post.name'));
|
$data['name'] = trim(input('post.name'));
|
||||||
@ -268,9 +293,11 @@ class Yunzeradmin extends Base
|
|||||||
$data['qq'] = (int) trim(input('post.qq'));
|
$data['qq'] = (int) trim(input('post.qq'));
|
||||||
$data['sex'] = (int) (input('post.sex'));
|
$data['sex'] = (int) (input('post.sex'));
|
||||||
if (empty($data['name'])) {
|
if (empty($data['name'])) {
|
||||||
|
Log::record('修改个人信息', 0, '姓名不能为空', '个人信息');
|
||||||
return json(['code' => 1, 'msg' => '姓名不能为空']);
|
return json(['code' => 1, 'msg' => '姓名不能为空']);
|
||||||
}
|
}
|
||||||
if (empty($data['phone'])) {
|
if (empty($data['phone'])) {
|
||||||
|
Log::record('修改个人信息', 0, '手机号不能为空', '个人信息');
|
||||||
return json(['code' => 1, 'msg' => '手机号不能为空']);
|
return json(['code' => 1, 'msg' => '手机号不能为空']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,16 +306,18 @@ class Yunzeradmin extends Base
|
|||||||
$new_pw = trim(input('post.new_pw'));
|
$new_pw = trim(input('post.new_pw'));
|
||||||
if (!empty($old_pw) && !empty($new_pw)) {
|
if (!empty($old_pw) && !empty($new_pw)) {
|
||||||
if (md5($old_pw) != $find['password']) {
|
if (md5($old_pw) != $find['password']) {
|
||||||
|
Log::record('修改个人信息', 0, '原密码错误', '个人信息');
|
||||||
return json(['code' => 1, 'msg' => '原密码错误']);
|
return json(['code' => 1, 'msg' => '原密码错误']);
|
||||||
}
|
}
|
||||||
$data['password'] = md5($new_pw);
|
$data['password'] = md5($new_pw);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存用户
|
|
||||||
$res = Db::table('yz_admin_user')->where('uid', $this->adminId)->update($data);
|
$res = Db::table('yz_admin_user')->where('uid', $this->adminId)->update($data);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
|
Log::record('修改个人信息', 0, '更新管理员信息失败', '个人信息');
|
||||||
return json(['code' => 1, 'msg' => '更新管理员信息失败']);
|
return json(['code' => 1, 'msg' => '更新管理员信息失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('修改个人信息', 1, '', '个人信息');
|
||||||
return json(['code' => 0, 'msg' => '更新成功']);
|
return json(['code' => 0, 'msg' => '更新成功']);
|
||||||
} else {
|
} else {
|
||||||
return View::fetch();
|
return View::fetch();
|
||||||
@ -352,8 +381,10 @@ class Yunzeradmin extends Base
|
|||||||
|
|
||||||
$res = Db::table('yz_banner')->insert($data);
|
$res = Db::table('yz_banner')->insert($data);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
|
Log::record('添加Banner', 0, '添加Banner失败', 'Banner管理');
|
||||||
return json(['code' => 1, 'msg' => '添加Banner失败']);
|
return json(['code' => 1, 'msg' => '添加Banner失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('添加Banner', 1, '', 'Banner管理');
|
||||||
return json(['code' => 0, 'msg' => '添加成功']);
|
return json(['code' => 0, 'msg' => '添加成功']);
|
||||||
}
|
}
|
||||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||||
@ -365,6 +396,7 @@ class Yunzeradmin extends Base
|
|||||||
if (Request::isPost()) {
|
if (Request::isPost()) {
|
||||||
$id = input('post.id');
|
$id = input('post.id');
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
|
Log::record('编辑Banner', 0, 'ID不能为空', 'Banner管理');
|
||||||
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,8 +410,10 @@ class Yunzeradmin extends Base
|
|||||||
|
|
||||||
$res = Db::table('yz_banner')->where('id', $id)->update($data);
|
$res = Db::table('yz_banner')->where('id', $id)->update($data);
|
||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
|
Log::record('编辑Banner', 0, '更新Banner失败', 'Banner管理');
|
||||||
return json(['code' => 1, 'msg' => '更新Banner失败']);
|
return json(['code' => 1, 'msg' => '更新Banner失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('编辑Banner', 1, '', 'Banner管理');
|
||||||
return json(['code' => 0, 'msg' => '更新成功']);
|
return json(['code' => 0, 'msg' => '更新成功']);
|
||||||
}
|
}
|
||||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||||
@ -391,13 +425,16 @@ class Yunzeradmin extends Base
|
|||||||
if (Request::isPost()) {
|
if (Request::isPost()) {
|
||||||
$id = input('post.id');
|
$id = input('post.id');
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
|
Log::record('删除Banner', 0, 'ID不能为空', 'Banner管理');
|
||||||
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = Db::table('yz_banner')->where('id', $id)->update(['delete_time' => time()]);
|
$res = Db::table('yz_banner')->where('id', $id)->update(['delete_time' => time()]);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
|
Log::record('删除Banner', 0, '删除Banner失败', 'Banner管理');
|
||||||
return json(['code' => 1, 'msg' => '删除Banner失败']);
|
return json(['code' => 1, 'msg' => '删除Banner失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('删除Banner', 1, '', 'Banner管理');
|
||||||
return json(['code' => 0, 'msg' => '删除成功']);
|
return json(['code' => 0, 'msg' => '删除成功']);
|
||||||
}
|
}
|
||||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||||
@ -411,13 +448,16 @@ class Yunzeradmin extends Base
|
|||||||
$status = input('post.status');
|
$status = input('post.status');
|
||||||
|
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
|
Log::record('修改Banner状态', 0, 'ID不能为空', 'Banner管理');
|
||||||
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = Db::table('yz_banner')->where('id', $id)->update(['status' => $status]);
|
$res = Db::table('yz_banner')->where('id', $id)->update(['status' => $status]);
|
||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
|
Log::record('修改Banner状态', 0, '更新状态失败', 'Banner管理');
|
||||||
return json(['code' => 1, 'msg' => '更新状态失败']);
|
return json(['code' => 1, 'msg' => '更新状态失败']);
|
||||||
}
|
}
|
||||||
|
Log::record('修改Banner状态', 1, '', 'Banner管理');
|
||||||
return json(['code' => 0, 'msg' => '更新成功']);
|
return json(['code' => 0, 'msg' => '更新成功']);
|
||||||
}
|
}
|
||||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||||
|
|||||||
@ -53,24 +53,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/html" id="tableToolbar">
|
|
||||||
<div class="layui-btn-container">
|
|
||||||
<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="clearAll">
|
|
||||||
<i class="layui-icon layui-icon-delete"></i> 清空日志
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script type="text/html" id="tableBar">
|
|
||||||
<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="/static/layui/layui.js"></script>
|
<script src="/static/layui/layui.js"></script>
|
||||||
<script>
|
<script>
|
||||||
layui.use(['table', 'form', 'laydate'], function(){
|
layui.use(['table', 'form', 'laydate', 'layer'], function(){
|
||||||
var table = layui.table;
|
var table = layui.table;
|
||||||
var form = layui.form;
|
var form = layui.form;
|
||||||
var laydate = layui.laydate;
|
var laydate = layui.laydate;
|
||||||
|
var layer = layui.layer;
|
||||||
|
|
||||||
// 初始化时间范围选择器
|
// 初始化时间范围选择器
|
||||||
laydate.render({
|
laydate.render({
|
||||||
@ -83,35 +72,30 @@
|
|||||||
table.render({
|
table.render({
|
||||||
elem: '#operationLogTable',
|
elem: '#operationLogTable',
|
||||||
url: '{:url("log/operation")}',
|
url: '{:url("log/operation")}',
|
||||||
method: 'post',
|
method: 'get',
|
||||||
toolbar: '#tableToolbar',
|
|
||||||
defaultToolbar: ['filter', 'exports', 'print'],
|
defaultToolbar: ['filter', 'exports', 'print'],
|
||||||
parseData: function(res) {
|
parseData: function(res) {
|
||||||
return {
|
return {
|
||||||
"code": res.code === 0 ? 0 : 1,
|
"code": 0,
|
||||||
"msg": res.msg,
|
"msg": res.msg || '获取成功',
|
||||||
"count": res.count,
|
"count": res.count || 0,
|
||||||
"data": res.data
|
"data": res.data || []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
cols: [[
|
cols: [[
|
||||||
{field: 'id', title: 'ID', width: 80, sort: true},
|
{field: 'id', title: 'ID', width: 80, sort: true, align: 'center'},
|
||||||
{field: 'username', title: '用户名', width: 120},
|
{field: 'username', title: '操作人', width: 120, align: 'center'},
|
||||||
{field: 'module', title: '模块', width: 120},
|
{field: 'module', title: '模块', width: 120, align: 'center'},
|
||||||
{field: 'operation', title: '操作', width: 120},
|
{field: 'operation', title: '操作', width: 150, align: 'center'},
|
||||||
{field: 'request_method', title: '请求方法', width: 100},
|
{field: 'request_method', title: '请求方法', width: 100, align: 'center'},
|
||||||
{field: 'request_url', title: '请求URL', width: 200},
|
{field: 'request_url', title: '请求地址', align: 'center'},
|
||||||
{field: 'request_params', title: '请求参数', width: 200},
|
{field: 'ip_address', title: 'IP地址', width: 120, align: 'center'},
|
||||||
{field: 'ip_address', title: 'IP地址', width: 130},
|
{field: 'status', title: '状态', width: 100, align: 'center', templet: function(d){
|
||||||
{field: 'status', title: '状态', width: 100, templet: function(d){
|
return d.status == 1 ? '<span class="layui-badge layui-bg-green">成功</span>' : '<span class="layui-badge layui-bg-red">失败</span>';
|
||||||
return d.status == 1 ?
|
|
||||||
'<span class="layui-badge layui-bg-green">成功</span>' :
|
|
||||||
'<span class="layui-badge layui-bg-red">失败</span>';
|
|
||||||
}},
|
}},
|
||||||
{field: 'error_message', title: '错误信息', width: 150},
|
{field: 'operation_time', title: '操作时间', width: 180, align: 'center'},
|
||||||
{field: 'operation_time', title: '操作时间', width: 180, sort: true},
|
{field: 'execution_time', title: '执行时间(ms)', width: 120, align: 'center'},
|
||||||
{field: 'execution_time', title: '执行时间(ms)', width: 120, sort: true},
|
{title: '操作', width: 120, toolbar: '#operationBar', fixed: 'right', align: 'center'}
|
||||||
{title: '操作', toolbar: '#tableBar', width: 80, fixed: 'right'}
|
|
||||||
]],
|
]],
|
||||||
page: true,
|
page: true,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
@ -138,38 +122,52 @@
|
|||||||
// 监听工具条
|
// 监听工具条
|
||||||
table.on('tool(operationLogTable)', function(obj){
|
table.on('tool(operationLogTable)', function(obj){
|
||||||
var data = obj.data;
|
var data = obj.data;
|
||||||
if(obj.event === 'del'){
|
if(obj.event === 'detail'){
|
||||||
layer.confirm('确定删除这条日志吗?', function(index){
|
// 获取详情
|
||||||
$.post('{:url("log/deleteOperation")}', {id: data.id}, function(res){
|
$.ajax({
|
||||||
|
url: '{:url("log/getOperationDetail")}',
|
||||||
|
type: 'GET',
|
||||||
|
data: {id: data.id},
|
||||||
|
success: function(res){
|
||||||
if(res.code === 0){
|
if(res.code === 0){
|
||||||
layer.msg(res.msg, {icon: 1});
|
var detail = res.data;
|
||||||
obj.del();
|
var content = '<div class="layui-card">' +
|
||||||
}else{
|
'<div class="layui-card-body">' +
|
||||||
layer.msg(res.msg, {icon: 2});
|
'<table class="layui-table" lay-skin="nob">' +
|
||||||
|
'<colgroup><col width="100"><col></colgroup>' +
|
||||||
|
'<tbody>' +
|
||||||
|
'<tr><td>操作人:</td><td>' + detail.username + '</td></tr>' +
|
||||||
|
'<tr><td>模块:</td><td>' + detail.module + '</td></tr>' +
|
||||||
|
'<tr><td>操作:</td><td>' + detail.operation + '</td></tr>' +
|
||||||
|
'<tr><td>请求方法:</td><td>' + detail.request_method + '</td></tr>' +
|
||||||
|
'<tr><td>请求地址:</td><td>' + detail.request_url + '</td></tr>' +
|
||||||
|
'<tr><td>请求参数:</td><td><pre>' + JSON.stringify(detail.request_params, null, 2) + '</pre></td></tr>' +
|
||||||
|
'<tr><td>IP地址:</td><td>' + detail.ip_address + '</td></tr>' +
|
||||||
|
'<tr><td>状态:</td><td>' + (detail.status == 1 ? '成功' : '失败') + '</td></tr>' +
|
||||||
|
'<tr><td>错误信息:</td><td>' + (detail.error_message || '无') + '</td></tr>' +
|
||||||
|
'<tr><td>操作时间:</td><td>' + detail.operation_time + '</td></tr>' +
|
||||||
|
'<tr><td>执行时间:</td><td>' + detail.execution_time + 'ms</td></tr>' +
|
||||||
|
'</tbody></table></div></div>';
|
||||||
|
|
||||||
|
layer.open({
|
||||||
|
type: 1,
|
||||||
|
title: '操作日志详情',
|
||||||
|
area: ['800px', '600px'],
|
||||||
|
content: content
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
layer.msg(res.msg);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
layer.close(index);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 监听头工具栏事件
|
|
||||||
table.on('toolbar(operationLogTable)', function(obj){
|
|
||||||
if(obj.event === 'clearAll'){
|
|
||||||
layer.confirm('确定要清空所有操作日志吗?', function(index){
|
|
||||||
$.post('{:url("log/clearOperation")}', function(res){
|
|
||||||
if(res.code === 0){
|
|
||||||
layer.msg(res.msg, {icon: 1});
|
|
||||||
table.reload('operationLogTable');
|
|
||||||
}else{
|
|
||||||
layer.msg(res.msg, {icon: 2});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
layer.close(index);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- 表格工具栏模板 -->
|
||||||
|
<script type="text/html" id="operationBar">
|
||||||
|
<a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
409
runtime/admin/temp/19f310fa6c5fb9bf679d1f5703436071.php
Normal file
409
runtime/admin/temp/19f310fa6c5fb9bf679d1f5703436071.php
Normal file
@ -0,0 +1,409 @@
|
|||||||
|
<?php /*a:3:{s:55:"E:\Demo\PHP\yunzer\app\admin\view\yunzer\configlist.php";i:1747402501;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;s:49:"E:\Demo\PHP\yunzer\app\admin\view\public\tail.php";i:1745855804;}*/ ?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title><?php echo htmlentities((string) $config['admin_name']); ?></title>
|
||||||
|
<meta name="renderer" content="webkit">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||||
|
<style type="text/css">
|
||||||
|
.header span{background:#009688;margin-left:30px;padding:10px;color:#ffffff;}
|
||||||
|
.header div{border-bottom:solid 2px #009688;margin-top: 8px;}
|
||||||
|
.header button{float:right;margin-top:-5px;}
|
||||||
|
.pagination {
|
||||||
|
display: inline-block;
|
||||||
|
padding-left: 0;
|
||||||
|
margin: 20px 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
.pagination > li {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
.pagination > li > a,
|
||||||
|
.pagination > li > span {
|
||||||
|
position: relative;
|
||||||
|
float: left;
|
||||||
|
padding: 6px 12px;
|
||||||
|
margin-left: -1px;
|
||||||
|
line-height: 1.42857143;
|
||||||
|
color: #337ab7;
|
||||||
|
text-decoration: none;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
.pagination > li:first-child > a,
|
||||||
|
.pagination > li:first-child > span {
|
||||||
|
margin-left: 0;
|
||||||
|
border-top-left-radius: 4px;
|
||||||
|
border-bottom-left-radius: 4px;
|
||||||
|
}
|
||||||
|
.pagination > li:last-child > a,
|
||||||
|
.pagination > li:last-child > span {
|
||||||
|
border-top-right-radius: 4px;
|
||||||
|
border-bottom-right-radius: 4px;
|
||||||
|
}
|
||||||
|
.pagination > li > a:hover,
|
||||||
|
.pagination > li > span:hover,
|
||||||
|
.pagination > li > a:focus,
|
||||||
|
.pagination > li > span:focus {
|
||||||
|
z-index: 2;
|
||||||
|
color: #23527c;
|
||||||
|
background-color: #eee;
|
||||||
|
border-color: #ddd;
|
||||||
|
}
|
||||||
|
.pagination > .active > a,
|
||||||
|
.pagination > .active > span,
|
||||||
|
.pagination > .active > a:hover,
|
||||||
|
.pagination > .active > span:hover,
|
||||||
|
.pagination > .active > a:focus,
|
||||||
|
.pagination > .active > span:focus {
|
||||||
|
z-index: 3;
|
||||||
|
color: #fff;
|
||||||
|
cursor: default;
|
||||||
|
background-color: #337ab7;
|
||||||
|
border-color: #337ab7;
|
||||||
|
}
|
||||||
|
.pagination > .disabled > span,
|
||||||
|
.pagination > .disabled > span:hover,
|
||||||
|
.pagination > .disabled > span:focus,
|
||||||
|
.pagination > .disabled > a,
|
||||||
|
.pagination > .disabled > a:hover,
|
||||||
|
.pagination > .disabled > a:focus {
|
||||||
|
color: #777;
|
||||||
|
cursor: not-allowed;
|
||||||
|
background-color: #fff;
|
||||||
|
border-color: #ddd;
|
||||||
|
}
|
||||||
|
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||||
|
</style>
|
||||||
|
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||||
|
layer = layui.layer; // layui 弹框
|
||||||
|
form = layui.form; // layui form表单
|
||||||
|
table = layui.table; // layui 表格
|
||||||
|
laydate = layui.laydate; // layui 时间框
|
||||||
|
element = layui.element; // layui element
|
||||||
|
upload = layui.upload; // layui 上传
|
||||||
|
$ = layui.jquery; // layui jquery
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body style="padding:10px; box-sizing: border-box;">
|
||||||
|
<style>
|
||||||
|
.config-container {
|
||||||
|
padding: 20px;
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 8px;
|
||||||
|
/* box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08); */
|
||||||
|
}
|
||||||
|
.config-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
padding-bottom: 15px;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
}
|
||||||
|
.config-header span {
|
||||||
|
font-size: 18px;
|
||||||
|
color: #2c3e50;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-right: 20px;
|
||||||
|
}
|
||||||
|
.config-header a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.config-header a span {
|
||||||
|
padding: 6px 15px;
|
||||||
|
background: #f8f9fa;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #606266;
|
||||||
|
font-size: 14px;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
.config-header a span:hover {
|
||||||
|
background: #e9ecef;
|
||||||
|
color: #409EFF;
|
||||||
|
}
|
||||||
|
.action-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
.layui-btn {
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
||||||
|
transition: all 0.3s;
|
||||||
|
height: 32px;
|
||||||
|
line-height: 32px;
|
||||||
|
padding: 0 16px;
|
||||||
|
}
|
||||||
|
.layui-btn:hover {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
|
||||||
|
}
|
||||||
|
.layui-btn .layui-icon {
|
||||||
|
margin-right: 4px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
.layui-table {
|
||||||
|
margin: 15px 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.layui-table thead tr {
|
||||||
|
background-color: #fafafa;
|
||||||
|
}
|
||||||
|
.layui-table tbody tr:hover {
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
}
|
||||||
|
.layui-table-cell {
|
||||||
|
height: 40px;
|
||||||
|
line-height: 40px;
|
||||||
|
}
|
||||||
|
.layui-badge {
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
.layui-badge.layui-bg-green {
|
||||||
|
background-color: #67C23A !important;
|
||||||
|
}
|
||||||
|
.layui-badge.layui-bg-gray {
|
||||||
|
background-color: #909399 !important;
|
||||||
|
}
|
||||||
|
.layui-layer {
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="config-container">
|
||||||
|
<div class="config-header">
|
||||||
|
<span>站点管理</span>
|
||||||
|
<!-- <a href="<?php echo htmlentities((string) $config['admin_route']); ?>Yunzer/configvalue">
|
||||||
|
<span>站点配置</span>
|
||||||
|
</a> -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="layui-card-body" style="padding: 0;">
|
||||||
|
<div class="action-buttons">
|
||||||
|
<button type="button" class="layui-btn layui-btn-normal" id="btn-add">
|
||||||
|
<i class="layui-icon layui-icon-add-1"></i>添加
|
||||||
|
</button>
|
||||||
|
<button type="button" class="layui-btn layui-btn-normal" id="btn-edit">
|
||||||
|
<i class="layui-icon layui-icon-edit"></i>修改
|
||||||
|
</button>
|
||||||
|
<button type="button" class="layui-btn layui-btn-danger" id="btn-del">
|
||||||
|
<i class="layui-icon layui-icon-delete"></i>删除
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<table class="layui-table" id="lists" lay-filter="lists"></table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
layui.use(['layer', 'table', 'element'], function () {
|
||||||
|
var table = layui.table;
|
||||||
|
var layer = layui.layer;
|
||||||
|
var element = layui.element;
|
||||||
|
var $ = layui.jquery;
|
||||||
|
|
||||||
|
// 初始化表格
|
||||||
|
function initTable() {
|
||||||
|
table.render({
|
||||||
|
elem: '#lists',
|
||||||
|
method: 'post',
|
||||||
|
url: "<?php echo htmlentities((string) $config['admin_route']); ?>yunzer/configlist",
|
||||||
|
title: '配置列表',
|
||||||
|
page: true,
|
||||||
|
skin: 'line',
|
||||||
|
even: true,
|
||||||
|
size: 'lg',
|
||||||
|
cols: [[
|
||||||
|
{ type: 'radio', fixed: 'left', width: 50 },
|
||||||
|
{ field: 'config_id', width: 80, title: 'ID', sort: true, align: 'center' },
|
||||||
|
{ field: 'config_sort', width: 120, title: '排序', sort: true, align: 'center' },
|
||||||
|
{ field: 'config_name', width: 150, title: '关键词' },
|
||||||
|
{ field: 'config_info', width: 150, title: '作用' },
|
||||||
|
{ field: 'config_desc', minWidth: 300, title: '说明' },
|
||||||
|
{
|
||||||
|
field: 'config_status', width: 100, title: '状态', align: 'center', templet: function (res) {
|
||||||
|
if (res.config_status == 1) {
|
||||||
|
return '<span class="layui-badge layui-bg-green">开启</span>';
|
||||||
|
} else {
|
||||||
|
return '<span class="layui-badge layui-bg-gray">关闭</span>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]],
|
||||||
|
limit: 15,
|
||||||
|
limits: [15, 30, 50, 100],
|
||||||
|
height: 'full-180'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载表格数据
|
||||||
|
initTable();
|
||||||
|
|
||||||
|
// 行点击事件
|
||||||
|
table.on('row(lists)', function (obj) {
|
||||||
|
obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
|
||||||
|
obj.tr.find("div.layui-unselect.layui-form-radio")[0].click();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 添加按钮事件
|
||||||
|
$('#btn-add').on('click', function () {
|
||||||
|
layer.open({
|
||||||
|
title: '<i class="layui-icon layui-icon-add-1"></i> 添加配置',
|
||||||
|
type: 2,
|
||||||
|
content: '<?php echo htmlentities((string) $config["admin_route"]); ?>yunzer/configadd',
|
||||||
|
maxmin: true,
|
||||||
|
area: ['700px', '550px'],
|
||||||
|
skin: 'layui-layer-molv',
|
||||||
|
btn: ['确定', '取消'],
|
||||||
|
yes: function (index, layero) {
|
||||||
|
var form = layero.find('iframe')[0].contentWindow;
|
||||||
|
var button = {
|
||||||
|
config_name: form.config_name.value,
|
||||||
|
config_info: form.config_info.value,
|
||||||
|
config_type: form.config_type.value,
|
||||||
|
config_desc: form.config_desc.value,
|
||||||
|
config_sort: form.config_sort.value,
|
||||||
|
config_status: form.config_status.value
|
||||||
|
};
|
||||||
|
|
||||||
|
var loadIndex = layer.load(1, {
|
||||||
|
shade: [0.1,'#fff']
|
||||||
|
});
|
||||||
|
|
||||||
|
$.post('<?php echo htmlentities((string) $config["admin_route"]); ?>yunzer/configadd', button, function (res) {
|
||||||
|
layer.close(loadIndex);
|
||||||
|
if (res.code > 0) {
|
||||||
|
layer.msg(res.msg, { icon: 2, time: 2000 });
|
||||||
|
} else {
|
||||||
|
layer.msg(res.msg, { icon: 1, time: 1000 });
|
||||||
|
initTable();
|
||||||
|
layer.close(index);
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 编辑按钮事件
|
||||||
|
$('#btn-edit').on('click', function () {
|
||||||
|
var checkStatus = table.checkStatus('lists');
|
||||||
|
var data = checkStatus.data;
|
||||||
|
|
||||||
|
if (data.length === 0) {
|
||||||
|
layer.msg('请选择一条数据进行编辑', { icon: 0 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
layer.open({
|
||||||
|
title: '<i class="layui-icon layui-icon-edit"></i> 修改配置',
|
||||||
|
type: 2,
|
||||||
|
content: '<?php echo htmlentities((string) $config["admin_route"]); ?>yunzer/configedit?config_id=' + data[0].config_id,
|
||||||
|
maxmin: true,
|
||||||
|
area: ['700px', '550px'],
|
||||||
|
skin: 'layui-layer-molv',
|
||||||
|
btn: ['确定', '取消'],
|
||||||
|
yes: function (index, layero) {
|
||||||
|
var form = layero.find('iframe')[0].contentWindow;
|
||||||
|
var button = {
|
||||||
|
config_id: data[0].config_id,
|
||||||
|
config_name: form.config_name.value,
|
||||||
|
config_info: form.config_info.value,
|
||||||
|
config_type: form.config_type.value,
|
||||||
|
config_desc: form.config_desc.value,
|
||||||
|
config_sort: form.config_sort.value,
|
||||||
|
config_status: form.config_status.value
|
||||||
|
};
|
||||||
|
|
||||||
|
var loadIndex = layer.load(1, {
|
||||||
|
shade: [0.1,'#fff']
|
||||||
|
});
|
||||||
|
|
||||||
|
$.post('<?php echo htmlentities((string) $config["admin_route"]); ?>yunzer/configedit', button, function (res) {
|
||||||
|
layer.close(loadIndex);
|
||||||
|
if (res.code > 0) {
|
||||||
|
layer.msg(res.msg, { icon: 2, time: 2000 });
|
||||||
|
} else {
|
||||||
|
layer.msg(res.msg, { icon: 1, time: 1000 });
|
||||||
|
initTable();
|
||||||
|
layer.close(index);
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 删除按钮事件
|
||||||
|
$('#btn-del').on('click', function () {
|
||||||
|
var checkStatus = table.checkStatus('lists');
|
||||||
|
var data = checkStatus.data;
|
||||||
|
|
||||||
|
if (data.length === 0) {
|
||||||
|
layer.msg('请选择一条数据进行删除', { icon: 0 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
layer.confirm('确定要删除该配置吗?', {
|
||||||
|
icon: 3,
|
||||||
|
title: '删除确认',
|
||||||
|
skin: 'layui-layer-molv',
|
||||||
|
btn: ['确定', '取消']
|
||||||
|
}, function () {
|
||||||
|
var loadIndex = layer.load(1, {
|
||||||
|
shade: [0.1,'#fff']
|
||||||
|
});
|
||||||
|
|
||||||
|
$.post('<?php echo htmlentities((string) $config["admin_route"]); ?>yunzer/configdel', { 'config_id': data[0].config_id }, function (res) {
|
||||||
|
layer.close(loadIndex);
|
||||||
|
if (res.code > 0) {
|
||||||
|
layer.msg(res.msg, { icon: 2, time: 2000 });
|
||||||
|
} else {
|
||||||
|
layer.msg(res.msg, { icon: 1, time: 1000 });
|
||||||
|
initTable();
|
||||||
|
}
|
||||||
|
}, 'json');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<script type="text/javascript">
|
||||||
|
// 显示图片
|
||||||
|
function show_img(obj){
|
||||||
|
var imgurl = $(obj).attr('src');
|
||||||
|
var res = getMousePos();
|
||||||
|
var html = '<div style="background:#fff;position:absolute;width:200px;border:solid 1px #cdcdcd;border-radius:6px;padding:2px;left:'+res.x+'px;top:'+res.y+'px;z-index:1000" id="preview">\
|
||||||
|
<img style="width:100%;border-radius:6px;" src="'+imgurl+'">\
|
||||||
|
</div>';
|
||||||
|
$('body').append(html);
|
||||||
|
}
|
||||||
|
// 隐藏图片
|
||||||
|
function hide_img(){
|
||||||
|
$('#preview').remove();
|
||||||
|
}
|
||||||
|
// 图片位置计算
|
||||||
|
function getMousePos(event) {
|
||||||
|
var e = event || window.event;
|
||||||
|
var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
|
||||||
|
var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
|
||||||
|
var x = e.pageX || e.clientX + scrollX;
|
||||||
|
var y = e.pageY || e.clientY + scrollY;
|
||||||
|
return { 'x': x, 'y': y };
|
||||||
|
}
|
||||||
|
// 删除图片
|
||||||
|
function deleteImage(path,obj){
|
||||||
|
$(obj).closest('.upload_pic_li').remove();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@ -1,4 +1,4 @@
|
|||||||
<?php /*a:2:{s:51:"E:\Demo\PHP\yunzer\app\admin\view\log\operation.php";i:1747584845;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
<?php /*a:2:{s:51:"E:\Demo\PHP\yunzer\app\admin\view\log\operation.php";i:1747589059;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@ -161,10 +161,11 @@
|
|||||||
|
|
||||||
<script src="/static/layui/layui.js"></script>
|
<script src="/static/layui/layui.js"></script>
|
||||||
<script>
|
<script>
|
||||||
layui.use(['table', 'form', 'laydate'], function(){
|
layui.use(['table', 'form', 'laydate', 'layer'], function(){
|
||||||
var table = layui.table;
|
var table = layui.table;
|
||||||
var form = layui.form;
|
var form = layui.form;
|
||||||
var laydate = layui.laydate;
|
var laydate = layui.laydate;
|
||||||
|
var layer = layui.layer;
|
||||||
|
|
||||||
// 初始化时间范围选择器
|
// 初始化时间范围选择器
|
||||||
laydate.render({
|
laydate.render({
|
||||||
@ -177,35 +178,31 @@
|
|||||||
table.render({
|
table.render({
|
||||||
elem: '#operationLogTable',
|
elem: '#operationLogTable',
|
||||||
url: '<?php echo url("log/operation"); ?>',
|
url: '<?php echo url("log/operation"); ?>',
|
||||||
method: 'post',
|
method: 'get',
|
||||||
toolbar: '#tableToolbar',
|
toolbar: '#tableToolbar',
|
||||||
defaultToolbar: ['filter', 'exports', 'print'],
|
defaultToolbar: ['filter', 'exports', 'print'],
|
||||||
parseData: function(res) {
|
parseData: function(res) {
|
||||||
return {
|
return {
|
||||||
"code": res.code === 0 ? 0 : 1,
|
"code": 0,
|
||||||
"msg": res.msg,
|
"msg": res.msg || '获取成功',
|
||||||
"count": res.count,
|
"count": res.count || 0,
|
||||||
"data": res.data
|
"data": res.data || []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
cols: [[
|
cols: [[
|
||||||
{field: 'id', title: 'ID', width: 80, sort: true},
|
{field: 'id', title: 'ID', width: 80, sort: true, align: 'center'},
|
||||||
{field: 'username', title: '用户名', width: 120},
|
{field: 'username', title: '操作人', width: 120, align: 'center'},
|
||||||
{field: 'module', title: '模块', width: 120},
|
{field: 'module', title: '模块', width: 120, align: 'center'},
|
||||||
{field: 'operation', title: '操作', width: 120},
|
{field: 'operation', title: '操作', width: 150, align: 'center'},
|
||||||
{field: 'request_method', title: '请求方法', width: 100},
|
{field: 'request_method', title: '请求方法', width: 100, align: 'center'},
|
||||||
{field: 'request_url', title: '请求URL', width: 200},
|
{field: 'request_url', title: '请求地址', align: 'center'},
|
||||||
{field: 'request_params', title: '请求参数', width: 200},
|
{field: 'ip_address', title: 'IP地址', width: 120, align: 'center'},
|
||||||
{field: 'ip_address', title: 'IP地址', width: 130},
|
{field: 'status', title: '状态', width: 100, align: 'center', templet: function(d){
|
||||||
{field: 'status', title: '状态', width: 100, templet: function(d){
|
return d.status == 1 ? '<span class="layui-badge layui-bg-green">成功</span>' : '<span class="layui-badge layui-bg-red">失败</span>';
|
||||||
return d.status == 1 ?
|
|
||||||
'<span class="layui-badge layui-bg-green">成功</span>' :
|
|
||||||
'<span class="layui-badge layui-bg-red">失败</span>';
|
|
||||||
}},
|
}},
|
||||||
{field: 'error_message', title: '错误信息', width: 150},
|
{field: 'operation_time', title: '操作时间', width: 180, align: 'center'},
|
||||||
{field: 'operation_time', title: '操作时间', width: 180, sort: true},
|
{field: 'execution_time', title: '执行时间(ms)', width: 120, align: 'center'},
|
||||||
{field: 'execution_time', title: '执行时间(ms)', width: 120, sort: true},
|
{title: '操作', width: 120, toolbar: '#operationBar', fixed: 'right', align: 'center'}
|
||||||
{title: '操作', toolbar: '#tableBar', width: 80, fixed: 'right'}
|
|
||||||
]],
|
]],
|
||||||
page: true,
|
page: true,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
@ -245,6 +242,45 @@
|
|||||||
layer.close(index);
|
layer.close(index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if(obj.event === 'detail'){
|
||||||
|
// 获取详情
|
||||||
|
$.ajax({
|
||||||
|
url: '<?php echo url("log/getOperationDetail"); ?>',
|
||||||
|
type: 'GET',
|
||||||
|
data: {id: data.id},
|
||||||
|
success: function(res){
|
||||||
|
if(res.code === 0){
|
||||||
|
var detail = res.data;
|
||||||
|
var content = '<div class="layui-card">' +
|
||||||
|
'<div class="layui-card-body">' +
|
||||||
|
'<table class="layui-table" lay-skin="nob">' +
|
||||||
|
'<colgroup><col width="100"><col></colgroup>' +
|
||||||
|
'<tbody>' +
|
||||||
|
'<tr><td>操作人:</td><td>' + detail.username + '</td></tr>' +
|
||||||
|
'<tr><td>模块:</td><td>' + detail.module + '</td></tr>' +
|
||||||
|
'<tr><td>操作:</td><td>' + detail.operation + '</td></tr>' +
|
||||||
|
'<tr><td>请求方法:</td><td>' + detail.request_method + '</td></tr>' +
|
||||||
|
'<tr><td>请求地址:</td><td>' + detail.request_url + '</td></tr>' +
|
||||||
|
'<tr><td>请求参数:</td><td><pre>' + JSON.stringify(detail.request_params, null, 2) + '</pre></td></tr>' +
|
||||||
|
'<tr><td>IP地址:</td><td>' + detail.ip_address + '</td></tr>' +
|
||||||
|
'<tr><td>状态:</td><td>' + (detail.status == 1 ? '成功' : '失败') + '</td></tr>' +
|
||||||
|
'<tr><td>错误信息:</td><td>' + (detail.error_message || '无') + '</td></tr>' +
|
||||||
|
'<tr><td>操作时间:</td><td>' + detail.operation_time + '</td></tr>' +
|
||||||
|
'<tr><td>执行时间:</td><td>' + detail.execution_time + 'ms</td></tr>' +
|
||||||
|
'</tbody></table></div></div>';
|
||||||
|
|
||||||
|
layer.open({
|
||||||
|
type: 1,
|
||||||
|
title: '操作日志详情',
|
||||||
|
area: ['800px', '600px'],
|
||||||
|
content: content
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
layer.msg(res.msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听头工具栏事件
|
// 监听头工具栏事件
|
||||||
@ -265,5 +301,10 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- 表格工具栏模板 -->
|
||||||
|
<script type="text/html" id="operationBar">
|
||||||
|
<a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -1,4 +1,4 @@
|
|||||||
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlecate.php";i:1747325751;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlecate.php";i:1747402501;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@ -94,325 +94,200 @@
|
|||||||
</head>
|
</head>
|
||||||
<body style="padding:10px; box-sizing: border-box;">
|
<body style="padding:10px; box-sizing: border-box;">
|
||||||
<div class="config-container">
|
<div class="config-container">
|
||||||
<div class="config-header" style="display:flex;justify-content: space-between;">
|
<!-- 页面头部样式 -->
|
||||||
<div style="display: flex; align-items: center;">
|
<div class="config-header" style="display: flex;flex-direction: column;flex-wrap: wrap;align-items: flex-start;">
|
||||||
<span>文章分类</span>
|
<div class="maintitle">
|
||||||
|
<i class="layui-icon layui-icon-app"></i>
|
||||||
|
<span>文章分类管理</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div style="display: flex;align-items: flex-start;flex-direction: column;gap: 15px;margin-bottom: 10px;">
|
||||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="add()">
|
<div>
|
||||||
<i class="layui-icon layui-icon-add-1"></i>添加
|
<button type="button" class="layui-btn layui-btn-normal" onclick="add()">
|
||||||
</button>
|
<i class="layui-icon layui-icon-add-1"></i>添加分类
|
||||||
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="refresh()">
|
</button>
|
||||||
<i class="layui-icon layui-icon-refresh"></i>刷新
|
<button type="button" class="layui-btn layui-btn-primary layui-border-blue" onclick="refresh()">
|
||||||
</button>
|
<i class="layui-icon layui-icon-refresh"></i>刷新
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="layui-row" style="margin-top: 15px;">
|
<!-- 主要内容区 -->
|
||||||
<div class="layui-col-md6">
|
<div class="main-content">
|
||||||
<div class="layui-card">
|
<div class="layui-row layui-col-space20">
|
||||||
<div class="layui-card-header">分类列表</div>
|
<!-- 左侧分类列表 -->
|
||||||
<div class="layui-card-body">
|
<div class="layui-col-md7">
|
||||||
<div id="categoryList"></div>
|
<div class="layui-card">
|
||||||
|
<div class="layui-card-header">
|
||||||
|
<span>分类列表</span>
|
||||||
|
<small class="text-muted">支持两级分类结构</small>
|
||||||
|
</div>
|
||||||
|
<div class="layui-card-body">
|
||||||
|
<div id="categoryList" class="category-tree"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="layui-col-md4"">
|
<!-- 右侧分类信息 -->
|
||||||
<div class="layui-card">
|
<div class="layui-col-md5">
|
||||||
<div class="layui-card-header">分类信息</div>
|
<div class="layui-card">
|
||||||
<div class="layui-card-body">
|
<div class="layui-card-header">
|
||||||
<div id="defaultTip" style="text-align: center; padding: 50px 0; color: #999;">
|
<span>分类信息</span>
|
||||||
<i class="layui-icon layui-icon-face-surprised" style="font-size: 30px;"></i>
|
|
||||||
<p style="margin-top: 10px;">请选择左侧分类</p>
|
|
||||||
</div>
|
</div>
|
||||||
<form class="layui-form" lay-filter="categoryForm" style="display: none;">
|
<div class="layui-card-body">
|
||||||
<input type="hidden" name="id" id="categoryId">
|
<!-- 默认提示 -->
|
||||||
<div class="layui-form-item">
|
<div id="defaultTip" class="empty-tip">
|
||||||
<label class="layui-form-label">分类名称</label>
|
<i class="layui-icon layui-icon-face-surprised"></i>
|
||||||
<div class="layui-input-block">
|
<p>请选择左侧分类或点击新增按钮</p>
|
||||||
<input type="text" name="name" required lay-verify="required" placeholder="请输入分类名称"
|
|
||||||
autocomplete="off" class="layui-input">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
|
||||||
<label class="layui-form-label">父级分类</label>
|
<!-- 分类表单 -->
|
||||||
<div class="layui-input-block">
|
<form class="layui-form category-form" lay-filter="categoryForm" style="display: none;">
|
||||||
<select name="cid" lay-verify="required">
|
<input type="hidden" name="id" id="categoryId">
|
||||||
<option value="0">顶级分类</option>
|
|
||||||
</select>
|
<div class="layui-form-item">
|
||||||
</div>
|
<label class="layui-form-label">分类名称</label>
|
||||||
</div>
|
<div class="layui-input-block">
|
||||||
<div class="layui-form-item">
|
<input type="text" name="name" required lay-verify="required" placeholder="请输入分类名称"
|
||||||
<label class="layui-form-label">封面图片</label>
|
autocomplete="off" class="layui-input">
|
||||||
<div class="layui-input-block">
|
|
||||||
<input type="text" name="image" placeholder="请输入图片地址" autocomplete="off"
|
|
||||||
class="layui-input" id="imageInput">
|
|
||||||
<div class="layui-upload" style="margin-top: 20px;">
|
|
||||||
<div>
|
|
||||||
<button type="button" class="layui-btn" id="uploadImage">上传图片</button>
|
|
||||||
<span style="color: #999; margin-left: 10px;">建议尺寸:250px*140px</span>
|
|
||||||
</div>
|
|
||||||
<div class="layui-upload-list">
|
|
||||||
<img class="layui-upload-img" id="imagePreview" style="margin-top: 10px;">
|
|
||||||
<i class="layui-icon layui-icon-close delete-image"
|
|
||||||
style="display: none; position: absolute; top: 0; right: 0; cursor: pointer; color: #FF5722;"></i>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">排序</label>
|
<label class="layui-form-label">父级分类</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="number" name="sort" value="0" class="layui-input">
|
<select name="cid" lay-verify="required">
|
||||||
|
<option value="0">顶级分类</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">状态</label>
|
<label class="layui-form-label">封面图片</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="radio" name="status" value="1" title="正常" checked>
|
<div class="layui-upload-drag" id="uploadImage">
|
||||||
<input type="radio" name="status" value="0" title="禁用">
|
<i class="layui-icon layui-icon-upload"></i>
|
||||||
|
<p>点击上传或拖拽图片至此处</p>
|
||||||
|
<div class="layui-hide" id="uploadPreview">
|
||||||
|
<hr>
|
||||||
|
<img src="" alt="封面图片" style="max-width: 100%">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" name="image" id="imageInput">
|
||||||
|
<div class="layui-form-mid layui-word-aux">建议尺寸:250px * 140px</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<div class="layui-input-block">
|
<label class="layui-form-label">排序</label>
|
||||||
<button class="layui-btn" lay-submit lay-filter="saveCategory">保存</button>
|
<div class="layui-input-block">
|
||||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
<input type="number" name="sort" value="0" class="layui-input"
|
||||||
<button type="button" class="layui-btn layui-btn-danger" id="deleteBtn"
|
placeholder="数字越大越靠前">
|
||||||
style="display: none;">删除</button>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</form>
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">状态</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<input type="radio" name="status" value="1" title="正常" checked>
|
||||||
|
<input type="radio" name="status" value="0" title="禁用">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="layui-form-item form-actions">
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<button class="layui-btn" lay-submit lay-filter="saveCategory">保存</button>
|
||||||
|
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||||
|
<button type="button" class="layui-btn layui-btn-danger" id="deleteBtn"
|
||||||
|
style="display: none;">删除</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
layui.use(['layer', 'form', 'util', 'upload'], function () {
|
|
||||||
var layer = layui.layer;
|
|
||||||
var $ = layui.jquery;
|
|
||||||
var form = layui.form;
|
|
||||||
var util = layui.util;
|
|
||||||
var upload = layui.upload;
|
|
||||||
|
|
||||||
// 初始化分类列表
|
|
||||||
function initCategoryList() {
|
|
||||||
$.ajax({
|
|
||||||
url: '/admin/article/articlecate',
|
|
||||||
type: 'POST',
|
|
||||||
success: function (res) {
|
|
||||||
if (res.code === 0) {
|
|
||||||
var html = '';
|
|
||||||
res.data.forEach(function (item) {
|
|
||||||
html += renderCategory(item);
|
|
||||||
});
|
|
||||||
$('#categoryList').html(html);
|
|
||||||
bindEvents();
|
|
||||||
} else {
|
|
||||||
layer.msg('获取分类数据失败', { icon: 2 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
layer.msg('请求失败,请重试', { icon: 2 });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 渲染分类
|
|
||||||
function renderCategory(category, level = 0) {
|
|
||||||
var html = '<div class="category-item" data-id="' + category.id + '">';
|
|
||||||
html += '<div class="category-header">';
|
|
||||||
html += '<span class="category-name">' + category.title + '</span>';
|
|
||||||
html += '<div class="category-actions">';
|
|
||||||
// 只有一级分类才显示添加按钮
|
|
||||||
if (level === 0) {
|
|
||||||
html += '<i class="layui-icon layui-icon-add-1 add-child" title="添加子分类"></i>';
|
|
||||||
}
|
|
||||||
html += '</div>';
|
|
||||||
html += '</div>';
|
|
||||||
|
|
||||||
if (category.children && category.children.length > 0) {
|
|
||||||
html += '<div class="category-children">';
|
|
||||||
category.children.forEach(function (child) {
|
|
||||||
html += renderCategory(child, level + 1);
|
|
||||||
});
|
|
||||||
html += '</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
html += '</div>';
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 绑定事件
|
|
||||||
function bindEvents() {
|
|
||||||
// 点击分类
|
|
||||||
$('.category-name').off('click').on('click', function () {
|
|
||||||
var id = $(this).closest('.category-item').data('id');
|
|
||||||
loadCategoryInfo(id);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 点击添加子分类
|
|
||||||
$('.add-child').off('click').on('click', function (e) {
|
|
||||||
e.stopPropagation();
|
|
||||||
var id = $(this).closest('.category-item').data('id');
|
|
||||||
$('#categoryId').val('');
|
|
||||||
$('select[name="cid"]').val(id);
|
|
||||||
$('#deleteBtn').hide();
|
|
||||||
form.render();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载分类信息
|
|
||||||
function loadCategoryInfo(id) {
|
|
||||||
$('#defaultTip').hide();
|
|
||||||
$('form.layui-form').show();
|
|
||||||
|
|
||||||
$.get('/admin/article/cateedit?id=' + id, function (res) {
|
|
||||||
if (res.code === 0) {
|
|
||||||
// 更新父级分类选项
|
|
||||||
var $select = $('select[name="cid"]');
|
|
||||||
$select.empty();
|
|
||||||
$select.append('<option value="0">顶级分类</option>');
|
|
||||||
res.data.parentOptions.forEach(function (item) {
|
|
||||||
$select.append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
||||||
});
|
|
||||||
|
|
||||||
// 填充表单数据
|
|
||||||
form.val('categoryForm', res.data.info);
|
|
||||||
|
|
||||||
// 显示图片预览
|
|
||||||
if (res.data.info.image) {
|
|
||||||
$('#imagePreview').attr('src', res.data.info.image);
|
|
||||||
$('.delete-image').show();
|
|
||||||
} else {
|
|
||||||
$('#imagePreview').attr('src', '');
|
|
||||||
$('.delete-image').hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示删除按钮
|
|
||||||
$('#deleteBtn').show();
|
|
||||||
|
|
||||||
// 重新渲染表单
|
|
||||||
form.render();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化
|
|
||||||
initCategoryList();
|
|
||||||
|
|
||||||
// 默认显示提示信息
|
|
||||||
$('#defaultTip').show();
|
|
||||||
$('form.layui-form').hide();
|
|
||||||
|
|
||||||
// 监听表单提交
|
|
||||||
form.on('submit(saveCategory)', function (data) {
|
|
||||||
var url = data.field.id ? '/admin/article/cateedit' : '/admin/article/cateadd';
|
|
||||||
$.post(url, data.field, function (res) {
|
|
||||||
if (res.code === 0) {
|
|
||||||
layer.msg(res.msg, { icon: 1 });
|
|
||||||
initCategoryList();
|
|
||||||
} else {
|
|
||||||
layer.msg(res.msg, { icon: 2 });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 监听删除按钮点击
|
|
||||||
$('#deleteBtn').on('click', function () {
|
|
||||||
var id = $('input[name="id"]').val();
|
|
||||||
if (!id) return;
|
|
||||||
|
|
||||||
layer.confirm('确定要删除该分类吗?', {
|
|
||||||
btn: ['确定', '取消']
|
|
||||||
}, function () {
|
|
||||||
$.post('/admin/article/catedel', { id: id }, function (res) {
|
|
||||||
if (res.code == 0) {
|
|
||||||
layer.msg(res.msg, { icon: 1 });
|
|
||||||
initCategoryList();
|
|
||||||
// 重置表单
|
|
||||||
form.val('categoryForm', {
|
|
||||||
id: '',
|
|
||||||
name: '',
|
|
||||||
cid: '0',
|
|
||||||
image: '',
|
|
||||||
sort: 0,
|
|
||||||
status: 1
|
|
||||||
});
|
|
||||||
$('#imagePreview').attr('src', '');
|
|
||||||
$('#deleteBtn').hide();
|
|
||||||
form.render();
|
|
||||||
} else {
|
|
||||||
layer.msg(res.msg, { icon: 2 });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 图片上传
|
|
||||||
upload.render({
|
|
||||||
elem: '#uploadImage',
|
|
||||||
url: '/admin/upload/image', // 替换为实际的上传接口
|
|
||||||
accept: 'images',
|
|
||||||
acceptMime: 'image/*',
|
|
||||||
done: function (res) {
|
|
||||||
if (res.code === 0) {
|
|
||||||
$('#imageInput').val(res.data.url);
|
|
||||||
$('#imagePreview').attr('src', res.data.url);
|
|
||||||
layer.msg('上传成功');
|
|
||||||
} else {
|
|
||||||
layer.msg('上传失败');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 监听图片输入框变化
|
|
||||||
$('#imageInput').on('input', function () {
|
|
||||||
var url = $(this).val();
|
|
||||||
if (url) {
|
|
||||||
$('#imagePreview').attr('src', url);
|
|
||||||
$('.delete-image').show();
|
|
||||||
} else {
|
|
||||||
$('#imagePreview').attr('src', '');
|
|
||||||
$('.delete-image').hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 监听图片删除按钮点击
|
|
||||||
$(document).on('click', '.delete-image', function () {
|
|
||||||
$('#imageInput').val('');
|
|
||||||
$('#imagePreview').attr('src', '');
|
|
||||||
$(this).hide();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function add() {
|
|
||||||
$('#defaultTip').hide();
|
|
||||||
$('form.layui-form').show();
|
|
||||||
|
|
||||||
// 重置表单
|
|
||||||
layui.form.val('categoryForm', {
|
|
||||||
id: '',
|
|
||||||
name: '',
|
|
||||||
cid: '0',
|
|
||||||
image: '',
|
|
||||||
sort: 0,
|
|
||||||
status: 1
|
|
||||||
});
|
|
||||||
$('#imagePreview').attr('src', '');
|
|
||||||
$('.delete-image').hide();
|
|
||||||
$('#deleteBtn').hide();
|
|
||||||
layui.form.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
function refresh() {
|
|
||||||
initCategoryList();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
/* 页面整体样式 */
|
||||||
|
.config-container {
|
||||||
|
padding: 15px;
|
||||||
|
/* background: #f2f2f2; */
|
||||||
|
}
|
||||||
|
|
||||||
|
.layui-col-md7 .layui-btn-primary {
|
||||||
|
border-color: #d2d2d2;
|
||||||
|
background: 0 0;
|
||||||
|
color: #5f5f5f
|
||||||
|
}
|
||||||
|
|
||||||
|
.layui-col-md7 .layui-btn-primary:hover {
|
||||||
|
background-color: #1e9fff;
|
||||||
|
color: #efefef
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 页面头部样式 */
|
||||||
|
.page-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
padding: 10px 15px;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 2px;
|
||||||
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-title .layui-icon {
|
||||||
|
margin-right: 8px;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-actions .layui-btn {
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 主要内容区样式 */
|
||||||
|
.main-content {
|
||||||
|
min-height: calc(100vh - 170px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layui-card {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layui-card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
height: auto;
|
||||||
|
padding: 12px 15px;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-muted {
|
||||||
|
margin-left: 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: normal;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 分类树样式 */
|
||||||
|
.category-tree {
|
||||||
|
padding: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
.category-item {
|
.category-item {
|
||||||
margin: 5px 0;
|
margin: 5px 0;
|
||||||
}
|
}
|
||||||
@ -421,9 +296,10 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding: 8px 10px;
|
padding: 10px 15px;
|
||||||
background-color: #f8f8f8;
|
background-color: #f8f8f8;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
transition: all 0.3s;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,67 +307,313 @@
|
|||||||
background-color: #f2f2f2;
|
background-color: #f2f2f2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.category-header.active {
|
||||||
|
background-color: #e6f7ff;
|
||||||
|
border-right: 3px solid #1890ff;
|
||||||
|
}
|
||||||
|
|
||||||
.category-name {
|
.category-name {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-actions {
|
.category-actions {
|
||||||
display: none;
|
/* opacity: 0; */
|
||||||
|
transition: opacity 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-header:hover .category-actions {
|
.category-header:hover .category-actions {
|
||||||
display: block;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-children {
|
.category-children {
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
padding-left: 10px;
|
padding-left: 15px;
|
||||||
border-left: 1px solid #e6e6e6;
|
border-left: 1px dashed #e6e6e6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.add-child {
|
.add-child {
|
||||||
color: #1E9FFF;
|
padding: 3px 8px;
|
||||||
font-size: 14px;
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-child .layui-icon {
|
||||||
|
font-size: 12px;
|
||||||
|
margin-right: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 空状态提示 */
|
||||||
|
.empty-tip {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 40px 0;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-tip .layui-icon {
|
||||||
|
font-size: 32px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 表单样式优化 */
|
||||||
|
.category-form {
|
||||||
|
padding: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layui-form-label {
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layui-input-block {
|
||||||
|
margin-left: 130px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-actions {
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layui-upload-drag {
|
||||||
|
padding: 20px;
|
||||||
|
border: 1px dashed #e2e2e2;
|
||||||
|
background-color: #fff;
|
||||||
|
text-align: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin-left: 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.add-child:hover {
|
.layui-upload-drag:hover {
|
||||||
color: #0C7CD5;
|
border-color: #009688;
|
||||||
}
|
}
|
||||||
|
|
||||||
.layui-upload-list {
|
.layui-upload-drag img {
|
||||||
margin-top: 10px;
|
max-width: 100%;
|
||||||
position: relative;
|
margin: 10px 0;
|
||||||
display: inline-block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.delete-image {
|
.layui-btn-xs {
|
||||||
position: absolute;
|
height: 30px;
|
||||||
top: 0;
|
line-height: 25px;
|
||||||
right: 0;
|
font-size: 12px;
|
||||||
cursor: pointer;
|
}
|
||||||
color: #FF5722;
|
</style>
|
||||||
font-size: 20px;
|
|
||||||
background: rgba(255, 255, 255, 0.8);
|
<script>
|
||||||
border-radius: 50%;
|
// 定义全局变量和函数
|
||||||
padding: 2px;
|
var categoryManager = {
|
||||||
|
init: function () {
|
||||||
|
this.initLayui();
|
||||||
|
},
|
||||||
|
|
||||||
|
initLayui: function () {
|
||||||
|
var that = this;
|
||||||
|
layui.use(['layer', 'form', 'upload'], function () {
|
||||||
|
var layer = layui.layer;
|
||||||
|
var form = layui.form;
|
||||||
|
var upload = layui.upload;
|
||||||
|
var $ = layui.jquery;
|
||||||
|
|
||||||
|
// 初始化分类列表
|
||||||
|
that.initCategoryList = function () {
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/article/articlecate',
|
||||||
|
type: 'POST',
|
||||||
|
success: function (res) {
|
||||||
|
if (res.code === 0) {
|
||||||
|
var html = '';
|
||||||
|
res.data.forEach(function (item) {
|
||||||
|
html += that.renderCategory(item);
|
||||||
|
});
|
||||||
|
$('#categoryList').html(html);
|
||||||
|
that.bindEvents();
|
||||||
|
} else {
|
||||||
|
layer.msg('获取分类数据失败', { icon: 2 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 渲染分类项
|
||||||
|
that.renderCategory = function (category, level = 0) {
|
||||||
|
var html = '<div class="category-item" data-id="' + category.id + '">';
|
||||||
|
html += '<div class="category-header">';
|
||||||
|
html += '<div class="category-name">' + category.title + '</div>';
|
||||||
|
if (level === 0) {
|
||||||
|
html += '<div class="category-actions">';
|
||||||
|
html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs add-child">';
|
||||||
|
html += '<i class="layui-icon layui-icon-add-1"></i>添加子分类</button>';
|
||||||
|
html += '</div>';
|
||||||
|
}
|
||||||
|
html += '</div>';
|
||||||
|
|
||||||
|
if (category.children && category.children.length > 0) {
|
||||||
|
html += '<div class="category-children">';
|
||||||
|
category.children.forEach(function (child) {
|
||||||
|
html += that.renderCategory(child, level + 1);
|
||||||
|
});
|
||||||
|
html += '</div>';
|
||||||
|
}
|
||||||
|
html += '</div>';
|
||||||
|
return html;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 绑定事件
|
||||||
|
that.bindEvents = function () {
|
||||||
|
// 点击分类项加载编辑信息
|
||||||
|
$('.category-header').off('click').on('click', function (e) {
|
||||||
|
if (!$(e.target).closest('.add-child').length) {
|
||||||
|
var id = $(this).closest('.category-item').data('id');
|
||||||
|
that.loadCategoryInfo(id);
|
||||||
|
|
||||||
|
// 添加选中效果
|
||||||
|
$('.category-header').removeClass('active');
|
||||||
|
$(this).addClass('active');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 添加子分类
|
||||||
|
$('.add-child').off('click').on('click', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
var parentId = $(this).closest('.category-item').data('id');
|
||||||
|
that.showCategoryForm(parentId);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 加载分类信息
|
||||||
|
that.loadCategoryInfo = function (id) {
|
||||||
|
$.get('/admin/article/cateedit?id=' + id, function (res) {
|
||||||
|
if (res.code === 0) {
|
||||||
|
that.showCategoryForm(0, res.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 显示分类表单
|
||||||
|
that.showCategoryForm = function (parentId = 0, data = null) {
|
||||||
|
$('#defaultTip').hide();
|
||||||
|
$('.category-form').show();
|
||||||
|
|
||||||
|
// 重置表单
|
||||||
|
form.val('categoryForm', {
|
||||||
|
id: data ? data.info.id : '',
|
||||||
|
name: data ? data.info.name : '',
|
||||||
|
cid: data ? data.info.cid : parentId,
|
||||||
|
sort: data ? data.info.sort : 0,
|
||||||
|
status: data ? data.info.status : 1
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更新父级分类选项
|
||||||
|
var $select = $('select[name="cid"]');
|
||||||
|
$select.empty().append('<option value="0">顶级分类</option>');
|
||||||
|
// 获取所有分类作为父级选项
|
||||||
|
$.ajax({
|
||||||
|
url: '/admin/article/articlecate',
|
||||||
|
type: 'POST',
|
||||||
|
async: false,
|
||||||
|
success: function (res) {
|
||||||
|
if (res.code === 0) {
|
||||||
|
// 当前编辑的分类ID
|
||||||
|
var currentId = data ? data.info.id : 0;
|
||||||
|
// 递归构建分类选项
|
||||||
|
function buildOptions(categories, level) {
|
||||||
|
categories.forEach(function (category) {
|
||||||
|
// 不能选择自己或自己的子分类作为父级
|
||||||
|
if (category.id != currentId) {
|
||||||
|
var prefix = new Array(level + 1).join('├─ ');
|
||||||
|
$select.append('<option value="' + category.id + '">' + prefix + category.title + '</option>'); if (category.children && category.children.length > 0) { buildOptions(category.children, level + 1); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} buildOptions(res.data, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 设置选中的父级分类
|
||||||
|
if (data && data.info.cid) {
|
||||||
|
$select.val(data.info.cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新图片预览
|
||||||
|
if (data && data.info.image) {
|
||||||
|
$('#uploadPreview').removeClass('layui-hide').find('img').attr('src', data.info.image);
|
||||||
|
$('#imageInput').val(data.info.image);
|
||||||
|
} else {
|
||||||
|
$('#uploadPreview').addClass('layui-hide').find('img').attr('src', '');
|
||||||
|
$('#imageInput').val('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示/隐藏删除按钮
|
||||||
|
$('#deleteBtn')[data ? 'show' : 'hide']();
|
||||||
|
|
||||||
|
form.render();
|
||||||
|
};
|
||||||
|
|
||||||
|
// 初始化上传组件
|
||||||
|
upload.render({
|
||||||
|
elem: '#uploadImage',
|
||||||
|
url: '/admin/upload/image',
|
||||||
|
accept: 'images',
|
||||||
|
acceptMime: 'image/*',
|
||||||
|
done: function (res) {
|
||||||
|
if (res.code === 0) {
|
||||||
|
$('#uploadPreview').removeClass('layui-hide').find('img').attr('src', res.data.url);
|
||||||
|
$('#imageInput').val(res.data.url);
|
||||||
|
layer.msg('上传成功');
|
||||||
|
} else {
|
||||||
|
layer.msg('上传失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听表单提交
|
||||||
|
form.on('submit(saveCategory)', function (data) {
|
||||||
|
var url = data.field.id ? '/admin/article/cateedit' : '/admin/article/cateadd';
|
||||||
|
$.post(url, data.field, function (res) {
|
||||||
|
if (res.code === 0) {
|
||||||
|
layer.msg(res.msg, { icon: 1 });
|
||||||
|
that.initCategoryList();
|
||||||
|
} else {
|
||||||
|
layer.msg(res.msg, { icon: 2 });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听删除按钮
|
||||||
|
$('#deleteBtn').on('click', function () {
|
||||||
|
var id = $('#categoryId').val();
|
||||||
|
if (!id) return;
|
||||||
|
|
||||||
|
layer.confirm('确定要删除该分类吗?', function (index) {
|
||||||
|
$.post('/admin/article/catedel', { id: id }, function (res) {
|
||||||
|
if (res.code === 0) {
|
||||||
|
layer.msg(res.msg, { icon: 1 });
|
||||||
|
that.initCategoryList();
|
||||||
|
$('#defaultTip').show();
|
||||||
|
$('.category-form').hide();
|
||||||
|
} else {
|
||||||
|
layer.msg(res.msg, { icon: 2 });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
layer.close(index);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 初始化页面
|
||||||
|
that.initCategoryList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
categoryManager.init();
|
||||||
|
|
||||||
|
// 新增分类
|
||||||
|
function add() {
|
||||||
|
categoryManager.showCategoryForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
.delete-image:hover {
|
// 刷新列表
|
||||||
color: #FF0000;
|
function refresh() {
|
||||||
|
categoryManager.initCategoryList();
|
||||||
}
|
}
|
||||||
|
</script>
|
||||||
.layui-card {
|
|
||||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
|
|
||||||
}
|
|
||||||
|
|
||||||
.layui-col-md4{
|
|
||||||
width: 40%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.layui-col-md6{
|
|
||||||
width: 60%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
Loading…
x
Reference in New Issue
Block a user