From b9f4379bc4b917b0c9667d5eecf54483dbb58591 Mon Sep 17 00:00:00 2001 From: augushong Date: Sat, 24 Aug 2019 13:42:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86,=E6=8E=A5?= =?UTF-8?q?=E5=85=A5=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- app/admin/controller/File.php | 94 +++++++++++++++++++ app/admin/controller/Login.php | 5 +- app/api/controller/Captcha.php | 14 +++ app/common.php | 28 +++++- app/model/UploadFiles.php | 55 +++++++++++ composer.json | 5 +- composer.lock | 80 +++++++++++++--- config/upload_type.php | 6 ++ ...190728015455_create_table_upload_files.php | 2 +- view/admin/admin/edit.html | 2 +- view/admin/common/_header.html | 1 + view/admin/common/left_file.html | 15 +++ view/admin/file/index.html | 92 ++++++++++++++++++ view/admin/login/index.html | 10 +- 15 files changed, 387 insertions(+), 26 deletions(-) create mode 100644 app/admin/controller/File.php create mode 100644 app/api/controller/Captcha.php create mode 100644 config/upload_type.php create mode 100644 view/admin/common/left_file.html create mode 100644 view/admin/file/index.html diff --git a/README.md b/README.md index 3342ff6..1f46f68 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ #### 最新演示 -[在线演示](http://ulthon_admin.ulthon.com/admin) +[在线演示](http://ulthon-admin.ulthon.com/admin) 账号: admin 密码: 123456 @@ -36,7 +36,7 @@ - 账户管理(0.5h,已完成) - 用户管理 - 权限管理 -- 文件管理 +- 文件管理(开发中) ### 开发注意 diff --git a/app/admin/controller/File.php b/app/admin/controller/File.php new file mode 100644 index 0000000..da19f4c --- /dev/null +++ b/app/admin/controller/File.php @@ -0,0 +1,94 @@ +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) + { + // + } +} diff --git a/app/admin/controller/Login.php b/app/admin/controller/Login.php index 7d55082..20668e5 100644 --- a/app/admin/controller/Login.php +++ b/app/admin/controller/Login.php @@ -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()); diff --git a/app/api/controller/Captcha.php b/app/api/controller/Captcha.php new file mode 100644 index 0000000..8962e89 --- /dev/null +++ b/app/api/controller/Captcha.php @@ -0,0 +1,14 @@ += 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; + +} diff --git a/app/model/UploadFiles.php b/app/model/UploadFiles.php index 60f63bd..946a5c5 100644 --- a/app/model/UploadFiles.php +++ b/app/model/UploadFiles.php @@ -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); + } + + } diff --git a/composer.json b/composer.json index 14eeec9..7deba8c 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/composer.lock b/composer.lock index a3730f1..3d4c6d7 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/config/upload_type.php b/config/upload_type.php new file mode 100644 index 0000000..65d745f --- /dev/null +++ b/config/upload_type.php @@ -0,0 +1,6 @@ + '系统LOGO', + 2 => '管理员头像' +]; \ No newline at end of file diff --git a/database/migrations/20190728015455_create_table_upload_files.php b/database/migrations/20190728015455_create_table_upload_files.php index 286a704..52fbae9 100644 --- a/database/migrations/20190728015455_create_table_upload_files.php +++ b/database/migrations/20190728015455_create_table_upload_files.php @@ -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'); diff --git a/view/admin/admin/edit.html b/view/admin/admin/edit.html index bd0500b..2f0b71e 100644 --- a/view/admin/admin/edit.html +++ b/view/admin/admin/edit.html @@ -78,7 +78,7 @@ elem:'.upload-admin-avatar', url:'{:url("api/Files/save")}', data:{ - type:1, + type:2, dir:'admin_avatar' }, accept:'images', diff --git a/view/admin/common/_header.html b/view/admin/common/_header.html index 0875f7c..8467850 100644 --- a/view/admin/common/_header.html +++ b/view/admin/common/_header.html @@ -4,6 +4,7 @@