feat: 优化代码
This commit is contained in:
@@ -48,7 +48,10 @@ class Ajax extends AdminController
|
||||
/**
|
||||
* 文件上传
|
||||
* @return Response|void
|
||||
* @throws \Exception
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
@@ -72,7 +75,11 @@ class Ajax extends AdminController
|
||||
public function getImage(): Response
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$file = Upload::instance()->download(input('url'));
|
||||
$url = request()->post('url');
|
||||
if (empty($url)) {
|
||||
return $this->error('图片地址不能为空');
|
||||
}
|
||||
$file = Upload::instance()->download($url);
|
||||
if (!$file) {
|
||||
return $this->error(Upload::instance()->getError());
|
||||
}
|
||||
|
||||
@@ -12,9 +12,14 @@
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\service\AttachmentService;
|
||||
use app\AdminController;
|
||||
|
||||
use app\common\model\system\Attachment as AttachmentModel;
|
||||
use support\Response;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use Webman\Http\Request;
|
||||
|
||||
/**
|
||||
@@ -32,10 +37,8 @@ class Attachment extends AdminController
|
||||
|
||||
/**
|
||||
* 初始化函数
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* Attachment constructor.
|
||||
* @throws \Exception|\Psr\SimpleCache\InvalidArgumentException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -46,32 +49,18 @@ class Attachment extends AdminController
|
||||
|
||||
/**
|
||||
* 获取资源列表
|
||||
* @return Response
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function index()
|
||||
public function index(): Response
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
|
||||
// 生成查询条件
|
||||
$post = request()->post();
|
||||
$page = (int)input('page') ?: 1;
|
||||
$limit = (int)input('limit') ?: 10;
|
||||
$type = input('type','');
|
||||
|
||||
$where = [];
|
||||
if (!empty($post['filename'])) {
|
||||
$where[] = ['filename','like','%'.$post['filename'].'%'];
|
||||
}
|
||||
|
||||
if (!empty($type)) {
|
||||
$where[] = ['type','=',$type];
|
||||
}
|
||||
|
||||
$count = $this->model->where($where)->count();
|
||||
$page = ($count <= $limit) ? 1 : $page;
|
||||
|
||||
// 生成查询数据
|
||||
$list = $this->model->where($where)->order("id desc")->limit((int)$limit)->page((int)$page)->select()->toArray();
|
||||
return $this->success('查询成功', "", $list, $count);
|
||||
$params = request()->post();
|
||||
list($count, $list) = AttachmentService::dataList($params);
|
||||
return $this->success('查询成功', "/", $list, $count);
|
||||
}
|
||||
|
||||
return view('/system/attachment/index',[
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>查看消息</title>
|
||||
<include file="public:header"/>
|
||||
</head>
|
||||
<body>
|
||||
<layout name="layout:layout" />
|
||||
<style>
|
||||
|
||||
h1 {
|
||||
font-family: "helvetica neue", PingFangSC-Light, arial, "hiragino sans gb", "microsoft yahei ui", "microsoft yahei", simsun, sans-serif;
|
||||
font-size: 20px;
|
||||
@@ -28,19 +20,19 @@
|
||||
}
|
||||
|
||||
</style>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-fluid" style="margin-top: 15px">
|
||||
<div id="unread" data-count="{$unread|default='0'}"></div>
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">
|
||||
<h1>{$info.title}</h1>
|
||||
<p style="color: #3464ff">{$info.nickname|default='系统'} 于 {$info.create_time}</p>
|
||||
<h1>{$msgInfo.title}</h1>
|
||||
<p style="color: #3464ff">{$msgInfo.nickname|default='系统'} 于 {$msgInfo.create_time}</p>
|
||||
</div>
|
||||
<div class="layui-card-body layui-text">
|
||||
{$info.content|raw}
|
||||
{$msgInfo.content|raw}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
layui.use('jquery', function () {
|
||||
let $ = layui.jquery;
|
||||
@@ -54,5 +46,4 @@
|
||||
bellMessage(unread);
|
||||
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
</script>
|
||||
Reference in New Issue
Block a user