文件管理,接入验证码

This commit is contained in:
augushong
2019-08-24 13:42:57 +08:00
parent 3968213bb4
commit b9f4379bc4
15 changed files with 387 additions and 26 deletions

View File

@@ -23,7 +23,7 @@
#### 最新演示
[在线演示](http://ulthon_admin.ulthon.com/admin)
[在线演示](http://ulthon-admin.ulthon.com/admin)
账号: admin 密码: 123456
@@ -36,7 +36,7 @@
- 账户管理(0.5h,已完成)
- 用户管理
- 权限管理
- 文件管理
- 文件管理(开发中)
### 开发注意

View File

@@ -0,0 +1,94 @@
<?php
namespace app\admin\controller;
use app\model\UploadFiles;
use think\facade\View;
use think\Request;
class File extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//
$type = $this->request->param('type',1);
$list = UploadFiles::where('type',$type)->order('id desc')->paginate();
View::assign('list',$list);
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
}
}

View File

@@ -28,7 +28,10 @@ class Login extends Common
$post_data = $this->request->post();
$validate = Validate::rule('account',Rule::isRequire())
->rule('password',Rule::isRequire());
->rule('password',Rule::isRequire())
->rule('captcha',function($value){
return \captcha_check($value)?true:'验证码错误';
});
if(!$validate->check($post_data)){
return json_message($validate->getError());

View File

@@ -0,0 +1,14 @@
<?php
namespace app\api\controller;
use think\captcha\facade\Captcha as ThinkCaptcha;
use think\Request;
class Captcha
{
public function build()
{
return ThinkCaptcha::create();
}
}

View File

@@ -35,8 +35,6 @@ function json_message($data = [],$code = 0,$msg = '')
function get_system_config($name = '',$default = '')
{
$list = Cache::get('system_config');
if(empty($list)){
@@ -138,4 +136,28 @@ function posturl($url,$data){
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}
function format_size($filesize) {
if($filesize >= 1073741824) {
$filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';
} elseif($filesize >= 1048576) {
$filesize = round($filesize / 1048576 * 100) / 100 . ' MB';
} elseif($filesize >= 1024) {
$filesize = round($filesize / 1024 * 100) / 100 . ' KB';
} else {
$filesize = $filesize . ' 字节';
}
return $filesize;
}

View File

@@ -19,4 +19,59 @@ class UploadFiles extends Model
{
return \get_source_link($this->getData('save_name'));
}
public function getTypeAttr($value)
{
return \config('upload_type.'.$value);
}
public function getUsedTimeAttr($value)
{
if($value == 0){
return '未使用';
}
return date('Y-m-d H:i:s',$value);
}
public function getDeleteTimeAttr($value)
{
if($value == 0){
return '未删除';
}
return date('Y-m-d H:i:s',$value);
}
public function getClearTimeAttr($value)
{
if($value == 0){
return '未清除';
}
return date('Y-m-d H:i:s',$value);
}
public function getStatusAttr($value,$data)
{
if($data['used_time'] == 0){
return '未使用(仅供预览)';
}
if($data['delete_time'] > 0){
return '已删除';
}
if($data['clear_time'] > 0){
return '已清除';
}
return '使用中';
}
public function getFileSizeAttr($value)
{
return format_size($value);
}
}

View File

@@ -9,7 +9,7 @@
"ulthon",
"admin"
],
"homepage": "http://ulthon_admin.ulthon.com/",
"homepage": "http://ulthon-admin.ulthon.com/",
"license": "Apache-2.0",
"authors": [
{
@@ -23,7 +23,8 @@
"topthink/think-orm": "2.0.*-dev",
"topthink/think-view": "^1.0",
"topthink/think-migration": "^3.0",
"topthink/think-helper": "^3.1"
"topthink/think-helper": "^3.1",
"topthink/think-captcha": "^3.0"
},
"require-dev": {
"symfony/var-dumper": "^4.2"

80
composer.lock generated
View File

@@ -4,20 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "2677b38b2ee3ca9b6481d8996041554b",
"content-hash": "0ce3c4389679ec95fb18c7578e5a0eca",
"packages": [
{
"name": "league/flysystem",
"version": "1.0.53",
"version": "1.0.54",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem.git",
"reference": "08e12b7628f035600634a5e76d95b5eb66cea674"
"reference": "c681ed22508947a941f113d6cf51bdcf4b84faf9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/08e12b7628f035600634a5e76d95b5eb66cea674",
"reference": "08e12b7628f035600634a5e76d95b5eb66cea674",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/c681ed22508947a941f113d6cf51bdcf4b84faf9",
"reference": "c681ed22508947a941f113d6cf51bdcf4b84faf9",
"shasum": "",
"mirrors": [
{
@@ -94,7 +94,7 @@
"sftp",
"storage"
],
"time": "2019-06-18T20:09:29+00:00"
"time": "2019-08-23T21:50:05+00:00"
},
{
"name": "league/flysystem-cached-adapter",
@@ -436,12 +436,12 @@
"source": {
"type": "git",
"url": "https://github.com/top-think/framework.git",
"reference": "caf09dd37b56208c15a8ca251c675ec44f815ba8"
"reference": "dbdaa91044bccbdeed564fbd672fd0ba24a3aadd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/framework/zipball/caf09dd37b56208c15a8ca251c675ec44f815ba8",
"reference": "caf09dd37b56208c15a8ca251c675ec44f815ba8",
"url": "https://api.github.com/repos/top-think/framework/zipball/dbdaa91044bccbdeed564fbd672fd0ba24a3aadd",
"reference": "dbdaa91044bccbdeed564fbd672fd0ba24a3aadd",
"shasum": "",
"mirrors": [
{
@@ -496,7 +496,59 @@
"orm",
"thinkphp"
],
"time": "2019-08-16T08:25:42+00:00"
"time": "2019-08-23T13:10:19+00:00"
},
{
"name": "topthink/think-captcha",
"version": "v3.0.1",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-captcha.git",
"reference": "9fc0c627d773f6a54a8dd142ebf358f746557a48"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-captcha/zipball/9fc0c627d773f6a54a8dd142ebf358f746557a48",
"reference": "9fc0c627d773f6a54a8dd142ebf358f746557a48",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"topthink/framework": "^6.0.0"
},
"type": "library",
"extra": {
"think": {
"services": [
"think\\captcha\\CaptchaService"
]
}
},
"autoload": {
"psr-4": {
"think\\captcha\\": "src/"
},
"files": [
"src/helper.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"description": "captcha package for thinkphp",
"time": "2019-06-06T07:16:01+00:00"
},
{
"name": "topthink/think-helper",
@@ -605,12 +657,12 @@
"source": {
"type": "git",
"url": "https://github.com/top-think/think-orm.git",
"reference": "6d8846be82c1a4cd09763f6b973355accb7f799b"
"reference": "e8987c69c7cd9b4bd8358edf58004f94abc736d3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/6d8846be82c1a4cd09763f6b973355accb7f799b",
"reference": "6d8846be82c1a4cd09763f6b973355accb7f799b",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/e8987c69c7cd9b4bd8358edf58004f94abc736d3",
"reference": "e8987c69c7cd9b4bd8358edf58004f94abc736d3",
"shasum": "",
"mirrors": [
{
@@ -647,7 +699,7 @@
"database",
"orm"
],
"time": "2019-08-15T13:53:39+00:00"
"time": "2019-08-23T13:16:17+00:00"
},
{
"name": "topthink/think-template",

6
config/upload_type.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
return [
1 => '系统LOGO',
2 => '管理员头像'
];

View File

@@ -40,7 +40,7 @@ class CreateTableUploadFiles extends Migrator
$table->addColumn('used_time','integer',['limit'=>10,'comment'=>'标记使用时间,如果为空,可能仅作为了预览图']);
$table->addColumn('delete_time','integer',['limit'=>10,'comment'=>'删除时间']);
$table->addColumn('clear_time','integer',['limit'=>10,'comment'=>'清空时间']);
$table->addColumn('type','integer',['limit'=>2,'default'=>1,'comment'=>'文件类型1系统logo;2:微信公众号授权二维码;3微信公众号授权头像;4:应用文章图片;5:应用封面']);
$table->addColumn('type','integer',['limit'=>2,'default'=>1,'comment'=>'文件类型1系统logo;2:管理员头像']);
$table->addIndex('save_name');
$table->addIndex('create_time');
$table->addIndex('used_time');

View File

@@ -78,7 +78,7 @@
elem:'.upload-admin-avatar',
url:'{:url("api/Files/save")}',
data:{
type:1,
type:2,
dir:'admin_avatar'
},
accept:'images',

View File

@@ -4,6 +4,7 @@
<ul class="layui-nav layui-layout-left">
<li class="layui-nav-item"><a href="{:url('admin/Index/index')}">首页</a></li>
<li class="layui-nav-item"><a href="">用户管理</a></li>
<li class="layui-nav-item"><a href="{:url('File/index')}">文件管理</a></li>
<li class="layui-nav-item"><a href="{:url('admin/System/index')}">系统设置</a></li>
</ul>
<ul class="layui-nav layui-layout-right">

View File

@@ -0,0 +1,15 @@
<div class="layui-side layui-bg-black">
<div class="layui-side-scroll">
<!-- 左侧导航区域可配合layui已有的垂直导航 -->
<ul class="layui-nav layui-nav-tree" lay-filter="test">
<li class="layui-nav-item layui-nav-itemed">
<a class="" href="javascript:;">文件管理</a>
<dl class="layui-nav-child">
{volist name=":config('upload_type')" id="vo"}
<dd><a href="{:url('File/index',['type'=>$key])}">{$vo}</a></dd>
{/volist}
</dl>
</li>
</ul>
</div>
</div>

View File

@@ -0,0 +1,92 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>文件管理</title>
{include file="common/_require"}
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
{include file="common/_header"}
{include file="common/left_file"}
<div class="layui-body">
<div style="padding:15px">
<div class="main-header">
<span class="layui-breadcrumb">
<a>首页</a>
<a><cite>文件管理</cite></a>
</span>
</div>
<div class="main-container">
<div>
</div>
<div>
<table class="layui-table">
<thead>
<tr>
<th>ID</th>
<th>预览</th>
<th>名称</th>
<th>文件信息</th>
<th>状态时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{php}$empty = '<tr><td colspan="10">暂无数据</td></tr>';{/php}
{volist name="list" id="vo" empty="$empty"}
<tr>
<td>{$vo.id}</td>
<td>
</td>
<td>
<p>保存名称:{$vo->getData('save_name')}</p>
<p>文件名:{$vo->getData('file_name')}</p>
</td>
<td>
<p>文件类型: {$vo.mime_type}</p>
<p>文件用途: <span style="color: red">{$vo.type}</span> </p>
<p>文件大小: {$vo.file_size}</p>
<p>文件指纹: {$vo.file_md5}</p>
</td>
<td>
<p style="color: red">{$vo.status}</p>
<p>上传时间:{$vo.create_time}</p>
<p>使用时间:{$vo.used_time}</p>
<p>清除时间:{$vo.delete_time}</p>
<p>清除时间:{$vo.clear_time}</p>
</td>
<td>
</td>
</tr>
{/volist}
</tbody>
</table>
<div>
{$list|raw}
</div>
</div>
</div>
</div>
</div>
{include file="common/_footer"}
</div>
</body>
</html>

View File

@@ -34,8 +34,6 @@
{:get_system_config('site_name')}
</div>
<div>
<form class="layui-form layui-form-pane" action="">
<div class="layui-form-item">
<label class="layui-form-label">用户名</label>
@@ -50,6 +48,14 @@
<input type="password" name="password" required lay-verify="required"
placeholder="请输入密码" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">验证码</label>
<div class="layui-input-block">
<input type="text" name="captcha" required lay-verify="required"
placeholder="请输入验证码" autocomplete="off" class="layui-input">
<img src="/api/Captcha/build" onclick="this.src = '/api/Captcha/build?v='+Math.random()" style="cursor: pointer" alt="">
</div>
</div>