文件管理,接入验证码

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

@@ -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);
}
}