huwhois 2 rokov pred
rodič
commit
0d9d7076e1

+ 48 - 12
app/common/service/FileService.php

@@ -14,34 +14,70 @@ namespace app\common\service;
 use think\Image;
 use think\Exception;
 use think\File;
+use think\image\Exception as ImageException;
+use think\facade\Config;
 
 class FileService
 {
+    /**
+     * 图片添加水印
+     * @param File $file  要处理的文件
+     * @param int $type  水印类型 0 图片水印, 1 文字水印 
+     * @param string $waterimg  图片水印内容
+     * @param string $watertext  文字水印内容
+     * @param string $fonttype  水印文字类型
+     * @param int $fontsize  水印文字大小
+     * @param string $fontcolor  水印文字颜色
+     * @return Image  返回图片对象
+     */
+    public static function waterMark(File $file, int $type = 0, string $watermark = '', string $watertext = '', 
+        string $fonttype = '', int $fontsize = 0, string $fontcolor = '#ffffff30'): Image
+    {
+        $image = Image::open($file);
+
+        if ($type == 0) {
+            $watermark = $watermark ?: Config::get('filesystem.water.watermark');
+            $image->water($watermark);
+        } else {
+            $watetext = $watertext ?: Config::get('filesystem.water.watertext');
+            $fonttype = $fonttype ?: Config::get('filesystem.water.fonttype');
+            $fontsize = $fontsize ?: (int) Config::get('filesystem.water.fontsize');
+            $fontcolor = $fontcolor ?: (int) Config::get('filesystem.water.fontcolor');
+
+            $image->text($watetext, $fonttype, $fontsize, $fontcolor);
+        }
+
+        return $image;
+    }
+
     /**
      * 生成缩略图
-     * @param string $filename 必须参数, 图片路径名(相对or绝对)(/public/uploads/...)
+     * @param File $file  要处理的文件
      * @param int $width 缩略图宽值, 默认 384px;
      * @param int $height 缩略图高值, 默认 224px;
-     * @param int $type 缩略图裁剪方式, 默认值 1, 固定尺寸缩放; 其他: 1, 等比例缩放;
-     * 2, 缩放后填充; 3, 居中裁剪; 4, 左上角裁剪; 5, 右下角裁剪
-     * @return string $thumbname 缩略图文件名
+     * @param int $type 缩略图裁剪方式, 默认值 1,固定尺寸缩放; 其他: 1,等比例缩放;2,缩放后填充;3,居中裁剪;4,左上角裁剪;5,右下角裁剪
+     * @param string $t_suffix  缩略图后缀
+     * @return Image  返回图片对象
      */
-    public static function makeThumb($filename, $width = 384, $height = 224, $type = 1, $t_suffix = "thumb")
+    public static function thumbnail(File $file, int $width = 384, int $height = 224, int $type = 1, string $t_suffix = "thumb")
     {
-        $file = './storage/' . str_replace('\\', '/', $filename);
+        $image = Image::open($file);
 
-        $ext = pathinfo($file, PATHINFO_EXTENSION);
+        $ext = $file->getExtension();
 
-        $thumbname = str_replace('.' . $ext, '', str_replace('\\', '/', $filename)) . $t_suffix . '.' . $ext;
+        $filename = $file->getFilename();
 
-        $image = Image::open($file);
+        $thumbname = str_replace('.' . $ext, '', str_replace('\\', '/', $filename)) . $t_suffix . '.' . $ext;
 
-        $result = $image->thumb($width, $height, $type)->save('./storage/' . $thumbname);
+        $image->thumb($width, $height, $type)->save('./storage/' . $thumbname);
 
-        return $result ? $thumbname : '';
+        return $image;
     }
 
-    public function urlImg($url)
+    /**
+     * 保存远程图片到本地
+     */
+    public function downloadUrlImg(string $url)
     {
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_HEADER, 0);

+ 1 - 1
app/sys/controller/Article.php

@@ -112,7 +112,7 @@ class Article extends Base
         $img_arrays = array_unique ($img_array[1]);
 
         foreach ($img_arrays as $value) {
-            $file = $fileService->urlImg($value);
+            $file = $fileService->downloadUrlImg($value);
             
             $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
             

+ 333 - 368
app/sys/controller/FileManager.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 /**
@@ -12,38 +13,28 @@ declare(strict_types=1);
 namespace app\sys\controller;
 
 use Exception;
+use UnexpectedValueException;
+use DirectoryIterator;
 use think\facade\View;
 use think\File;
 use think\Image;
 use think\facade\Config;
+use think\exception\ValidateException;
 
 use app\common\service\FileService;
 use app\common\model\FileManager as FileManagerModel;
+use think\file\UploadedFile;
 
 class FileManager extends Base
 {
+    protected $modelName = 'FileManager';
     protected $t_suffix = '_thumb';
     protected $width = 400;  // 缩略图高度
     protected $height = 300;
-
-    /**
-     * 图片列表
-     */
-    // public function index($mod=0)
-    // {
-
-    // }
+    protected $storage_path = 'public/storage';
 
     public function index()
     {
-        // $data = $this->explorer();
-
-        // View::assign('dirs', $data['dirs']);
-        // View::assign('files', $data['files']);
-        // View::assign('counts', $data['counts']);
-        // View::assign('activeurl', $data['activeurl']);
-        // View::assign('activepath', $data['activepath']);
-
         $param = $this->request->param();
 
         $param['limit'] = isset($param['limit']) ? (int) $param['limit'] : Config::get('app.page_size');
@@ -55,19 +46,294 @@ class FileManager extends Base
         return View::fetch();
     }
 
+    /**
+     * 浏览文件
+     */
+    public function explorer()
+    {
+        $param = $this->request->param();
+
+        $activepath =  isset($param['activepath']) ? $param['activepath'] : '';
+
+        $realpath = $this->app->getRootPath() . $this->storage_path . $activepath;
+
+        try {
+            $dirhandle = new DirectoryIterator($realpath);
+
+            $dirs = $files = [];
+
+            foreach ($dirhandle as $fileInfo) {
+                if($fileInfo->isDot() || $fileInfo->getFilename() == '.gitignore') {
+                    continue;
+                } elseif ($fileInfo->isDir()) {
+                    $dirs[] = $fileInfo->getFilename();
+                } elseif ($fileInfo->isFile()) {
+                    $files[] = [
+                        'filename'  => $fileInfo->getFilename(),
+                        'extension' => strtolower($fileInfo->getExtension()),
+                        'size' => format_bytes($fileInfo->getSize()),
+                        'time' => $fileInfo->getCTime(),
+                    ];
+                }
+            }
+            
+            $counts = count($dirs) + count($files);
+
+            $activeurl = preg_replace("#[\/][^\/]*$#i", "", $activepath);
+
+            View::assign([
+                'dirs'      => $dirs,
+                'files'     => $files,
+                'counts'    => $counts,
+                'activeurl' => $activeurl,
+                'activepath' => $activepath,
+            ]);
+
+            return View::fetch();
+        } catch(UnexpectedValueException $uve) {
+            $this->error($uve->getMessage());
+        }
+    }
+
+    /**
+     * 附件上传
+     */
     public function uploadFile()
     {
+        $activepath = $this->request->has('activepath') ? $this->request->param('activepath') : '';
+
         $files = $this->request->file('upload_file');
 
-        $savename = [];
-        
-        foreach($files as $file){
-            $savename[] = \think\facade\Filesystem::disk('public')->putFile('/', $file);
+        if ($files) {
+            try {
+                validate(
+                    [
+                        'file' => [
+                            // 限制文件大小(单位b),这里限制为10M
+                            'fileSize' => 10 * 1024 * 1024,
+                            // 限制文件后缀,多个后缀以英文逗号分割
+                            'fileExt'  => 'jpg,png,gif,jpeg,webp,jfif,pdf,doc,docx,xls,xlsx,ppt,pptx,txt'
+                        ]
+                    ],
+                    [
+                        'file.fileSize' => '文件太大',
+                        'file.fileExt' => '不支持的文件后缀',
+                    ]
+                )->check(['file' => $files]);
+
+                $savenames = [];
+
+                $uploadFiles = [];
+                
+                if (!is_array($files) && $files instanceof UploadedFile) {
+                    $uploadFiles[] = $files;
+                } else {
+                    $uploadFiles = $files;
+                }
+
+                $url = Config::get('filesystem.disks.public.url');
+
+                foreach ($uploadFiles as $file) {
+                    $fileinfo = new FileManagerModel();
+                    
+                    $fileinfo->title         = $file->getOriginalName();
+                    $fileinfo->filesize      = $file->getSize();
+                    $fileinfo->filetime      = $file->getCTime();
+                    $fileinfo->fileextension = $file->extension();
+                    $fileinfo->username      = $this->getSysUser()->username;
+                    $fileinfo->hash_md5      = $file->md5();
+
+                    if (empty($activepath)) {
+                        $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);                
+                        
+                        $fileinfo->filepath = $url . '/' . $savename;
+                        $fileinfo->filename = basename($savename);  
+                    } else {
+                        $savename = $activepath . '/' . $file->hashName();
+                        $savepath = $this->app->getRootPath() . $this->storage_path . $savename;
+                        
+                        $file = $file->move($this->app->getRootPath() . $this->storage_path . $activepath, $savepath);
+
+                        $fileinfo->filepath = $url . $savename;
+                        $fileinfo->filename = $file->hashName();
+                    }
+
+                    $fileinfo->save();
+
+                    $savenames[] = $fileinfo->filepath;
+                }
+
+                return json(['code' => 0, 'msg'=>'上传成功', 'filename'=>$savenames]);
+            } catch (ValidateException $e) {
+                $this->error($e->getMessage());
+            }
+        } else {
+            $this->error('图片不能为空');
+        }
+    }
+
+    /**
+     * 修改文件title
+     */
+    public function updateFileTitle($id = 0, $filetitle = '')
+    {
+        $fileInfo = FileManagerModel::find($id);
+        if ($fileInfo == null) {
+            return json(['code'=>1, 'fileid='.$id.'不存在']);
+        }
+
+        $fileInfo->title = $filetitle;
+
+        if ($fileInfo->save()) {
+            return json(['code'=>0, 'msg'=>'success']);
+        } else {
+            return json(['code'=>1, 'msg'=>'failed']);
+        }
+    }
+
+    /**
+     * 删除
+     * @param int|array $id  info id
+     * @return array
+     */
+    public function delete($id)
+    {
+        if ($this->request->isPost()) {
+            $whereOp = '=';
+
+            if (is_array($id)) {
+                $whereOp = 'IN';
+            }
+
+            $list = FileManagerModel::where('fileid', $whereOp, $id)->select();
+
+            foreach ($list as $value) {
+                $file = $this->app->getRootPath() . 'public' . $value->filepath;
+                if (file_exists($file)) {
+                    unlink($file);
+                }
+            }
+  
+            if (FileManagerModel::destroy($id)) {
+                return ['code' => 0,'msg'=>'删除成功'];
+            } else {
+                return ['code' => 1,'msg'=>'删除失败'];
+            }
+        }
+    }
+
+    /**
+     * 删除空目录
+     */
+    public function deldir()
+    {
+        if ($this->request->isPost()) {
+            $dir = str_replace('/', DIRECTORY_SEPARATOR, $this->request->param('dir'));
+
+            $dir_name = $this->app->getRootPath() . $this->storage_path . DIRECTORY_SEPARATOR . $dir;
+
+            try {
+                rmdir($dir_name);
+                return ['code' => 0, 'msg' => 'success'];
+            } catch (Exception $e) {
+                return ['code' => 1, 'msg' => 'failed, 目录不为空'];
+            }
+        }
+    }
+
+    /**
+     * 删除文件
+     */
+    public function delfile()
+    {
+        if ($this->request->isPost()) {
+            $filename = str_replace('/', DIRECTORY_SEPARATOR, $this->request->param('filename'));
+
+            $filepath = $this->app->getRootPath() . $this->storage_path . DIRECTORY_SEPARATOR . $filename;
+
+            if (unlink($filepath)) {
+                return ['code' => 0, 'msg' => 'success'];
+            } else {
+                return ['code' => 1, 'msg' => 'failed'];
+            }
         }
     }
 
     /**
-     * 图片上传
+     * 处理上传的图片
+     */
+    protected function dealUploadImg(File $file, $water, $thumb, $width, $height, $overwrite)
+    {
+        $savename = "";
+        $thumbname = "";
+
+        if ($water == true || $thumb == true) {
+            $image = Image::open($file);
+
+            if ($water) {
+                $type = $this->system->water_type ?: Config::get('filesystem.water.type');
+
+                if ($type == 'water') {
+                    $watemark = $this->system->watermark ?: Config::get('filesystem.water.watermark');
+                    $image->water($watemark);
+                } else {
+                    $watetext = $this->system->watertext ?: Config::get('filesystem.water.watertext');
+                    $image->text($watetext, Config::get('filesystem.water.waterfont'), 30, '#ffffff30');
+                }
+            }
+
+            $savename = $file->hashName();
+            $realPath = Config::get('filesystem.disks.public.root') . '/' . $savename;
+
+            if ($thumb == true) {
+                if ($overwrite == true) {
+                    $image->thumb($width, $height, 1);
+
+                    $image->save($realPath);
+                } else {
+                    $image->save($realPath);
+
+                    $image->thumb($width, $height, 1);
+
+                    $ext = $file->extension();
+
+                    $thumbname = str_replace('.' . $ext, '', str_replace('\\', '/', $savename)) . $this->t_suffix . '.' . $ext;
+
+                    $image->save(Config::get('filesystem.disks.public.root') . '/' . $thumbname);
+                }
+            } else {
+                $image->save($realPath);
+            }
+            unset($image);
+        } else {
+            $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
+        }
+
+        return [
+            'picname'   => str_replace('\\', '/', $savename),
+            'thumbname' => $thumbname
+        ];
+    }
+
+    /**
+     * 图片上传(iframe 页面)
+     */
+    public function uploadimg(string $img_id = 'picture', $water = false, $thumb = false, $width = 400, $height = 300, $overwrite = false)
+    {
+        View::assign([
+            'img_id' => $img_id,
+            'water'  => $water,
+            'thumb'  => $thumb,
+            'width'  => $width,
+            'height' => $height,
+            'overwrite' => $overwrite
+        ]);
+
+        return View::fetch();
+    }
+
+    /**
+     * 本地图片上传
      * @file upload_file   上传的文件
      * @param string  $img_id   图片ipnut text id 默认值 picture
      * @param boolean $water    是否添加水印
@@ -76,7 +342,7 @@ class FileManager extends Base
      * @param int $height       缩略图最大高
      * @param bool $overwrite   生成缩略图后是否保存原图
      */
-    public function uploadimg(string $img_id = 'picture', $water = false, $thumb = false, $width = 400, $height = 300, $overwrite = false)
+    public function uploadLocalImg(string $img_id = 'picture', $water = false, $thumb = false, $width = 400, $height = 300, $overwrite = false)
     {
         if ($this->request->isPost()) {
             $file = $this->request->file('upload_file');
@@ -96,35 +362,30 @@ class FileManager extends Base
                             'file.fileExt' => '不支持的文件后缀',
                         ]
                     )->check(['file' => $file]);
-
+                
                     $arr = $this->dealUploadImg($file, $water, $thumb, $width, $height, $overwrite);
 
-                    return array_merge([
-                        'code' => 0,
-                        'img_id' => $img_id,
-                        'picture_url' => Config::get('filesystem.disks.public.url') . '/']
-                        , $arr);
-                } catch (\think\exception\ValidateException $e) {
+                    return array_merge(
+                        [
+                            'code' => 0,
+                            'img_id' => $img_id,
+                            'picture_url' => Config::get('filesystem.disks.public.url') . '/'
+                        ],
+                        $arr
+                    );
+
+                } catch (ValidateException $e) {
                     $this->error($e->getMessage());
                 }
             } else {
                 $this->error('图片不能为空');
             }
-        } else {
-            View::assign('img_id', $img_id);
-            View::assign('water', $water);
-            View::assign('thumb', $thumb);
-            View::assign('width', $width);
-            View::assign('height', $height);
-            View::assign('overwrite', $overwrite);
-
-            return View::fetch();
         }
     }
 
     /**
-     * 图片上传
-     * @file upload_file   上传的文件
+     * 网络图片上传
+     * @paran string url_file   网络图片地址
      * @param string  $img_id   图片ipnut text id 默认值 picture
      * @param boolean $water    是否添加水印
      * @param boolean $thumb    是否制作缩略图
@@ -132,7 +393,7 @@ class FileManager extends Base
      * @param int $height       缩略图最大高
      * @param bool $overwrite   生成缩略图后是否保存原图
      */
-    public function uploadurlimg(string $img_id = 'picture', $water = false, $thumb = false, $width = 400, $height = 300, $overwrite = false)
+    public function uploadUrlImg(string $img_id = 'picture', $water = false, $thumb = false, $width = 400, $height = 300, $overwrite = false)
     {
         if ($this->request->isPost()) {
             $urlImg = $this->request->param('url_file');
@@ -141,17 +402,20 @@ class FileManager extends Base
                 try {
                     $fileService = new FileService();
 
-                    $file = $fileService->urlImg($urlImg);
+                    $file = $fileService->downloadUrlImg($urlImg);
 
                     $arr = $this->dealUploadImg($file, $water, $thumb, $width, $height, $overwrite);
 
                     @unlink($file->realPath);
 
-                    return array_merge([
-                        'code' => 0,
-                        'img_id' => $img_id,
-                        'picture_url' => Config::get('filesystem.disks.public.url') . '/']
-                        , $arr);
+                    return array_merge(
+                        [
+                            'code' => 0,
+                            'img_id' => $img_id,
+                            'picture_url' => Config::get('filesystem.disks.public.url') . '/'
+                        ],
+                        $arr
+                    );
                 } catch (\think\exception\ValidateException $e) {
                     $this->error($e->getMessage());
                 }
@@ -161,6 +425,16 @@ class FileManager extends Base
         }
     }
 
+    /**
+     * 选择服务器图片
+     * @paran string online_file  服务器图片地址
+     * @param string  $img_id   图片ipnut text id 默认值 picture
+     * @param boolean $water    是否添加水印
+     * @param boolean $thumb    是否制作缩略图
+     * @param int $width        缩略图最大宽
+     * @param int $height       缩略图最大高
+     * @param bool $overwrite   生成缩略图后是否保存原图
+     */
     public function uploadonlineimg(string $img_id = 'picture', $water = false, $thumb = false, $width = 400, $height = 300, $overwrite = false)
     {
         if ($this->request->isPost()) {
@@ -170,23 +444,23 @@ class FileManager extends Base
 
                 $picname = $pathImg;
                 $thumbname = "";
-                
+
                 if ($thumb) {
                     if (stripos($picname, $this->t_suffix)) {
                         $thumbname = $pathImg;
                     } else {
                         try {
                             $file = new File($this->app->getRootPath() . "public"  . $pathImg);
-    
+
                             $ext = $file->getExtension();
-                            
+
                             $thumbname = str_replace('.' . $ext, '', str_replace('\\', '/', $picname)) . $this->t_suffix . '.' . $ext;
 
                             if (!file_exists($thumbname)) {
                                 $image = Image::open($file);
-        
+
                                 $image->thumb($width, $height, 1);
-            
+
                                 $image->save($this->app->getRootPath() . "public"  .  $thumbname);
                                 unset($image);
                             }
@@ -225,278 +499,25 @@ class FileManager extends Base
             ));
         }
         /* 获取指定范围的列表 */
-        $page = $page-1 < 0 ? 0 : (int)$page - 1;
+        $page = $page - 1 < 0 ? 0 : (int)$page - 1;
         $size = 20;
         $start = $page * $size;
         $end = $start + $size;
 
         $len = count($files);
 
-        for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--){
+        for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--) {
             $list[] = $files[$i];
         }
 
-        return json([ "code" => 0,
+        return json([
+            "code" => 0,
             "list" => $list,
-            "page" => $page+1,
+            "page" => $page + 1,
             "total" => count($files)
         ]);
     }
 
-
-
-    /**
-     * 获取当前文件相关信息
-     * @return array $data 文件信息数据组
-     */
-    protected function explorer()
-    {
-        $param = $this->request->param();
-
-        $activepath =  isset($param['activepath']) ? $param['activepath'] : '';
-
-        $inpath = "";
-
-        $inpath = $this->img_path . $activepath;
-
-        $dirhandle = scandir($inpath);
-
-        $dirs = $files = [];
-
-        define('BKM', 1024);
-
-        foreach ($dirhandle as $val) {
-            if ($val == "." || $val == "..") {
-                continue;
-            } elseif (is_dir($inpath . DIRECTORY_SEPARATOR . $val)) {
-                $dirs[] = $val;
-            } else {
-                $arr = [];
-                $file = '';
-                $file = $inpath . DIRECTORY_SEPARATOR . $val;
-
-                $arr['name'] = $val;
-
-                $arr['extension'] = pathinfo($file, PATHINFO_EXTENSION);
-
-                $filesize = floatval(filesize($file));
-                if ($filesize > BKM) {
-                    $filesize =  round($filesize / BKM, 2);
-
-                    if ($filesize > BKM) {
-                        $filesize = round($filesize / BKM, 2);
-
-                        $filesize .= "M";
-                    } else {
-                        $filesize .= "K";
-                    }
-                } else {
-                    $filesize .= "B";
-                }
-                $arr['size'] = $filesize;
-
-                $filetime = filemtime("$file");
-                $arr['time'] = date("Y-m-d H:i:s", $filetime);
-
-                $files[] = $arr;
-            }
-        }
-        $counts = count($dirs) + count($files);
-
-        $activeurl = preg_replace("#[\/][^\/]*$#i", "", $activepath);
-
-        $data = [
-            'dirs'      => $dirs,
-            'files'     => $files,
-            'counts'    => $counts,
-            'activeurl' => $activeurl,
-            'activepath' => $activepath,
-        ];
-
-        return $data;
-    }
-
-    public function delDir()
-    {
-        if ($this->request->isAjax()) {
-            $activepath = $this->request->param('activepath');
-            $activepath = str_replace('/', DIRECTORY_SEPARATOR, $activepath);
-            $dir = $this->request->param('dir');
-
-            $dir_name = app()->getRootPath . 'public' . DIRECTORY_SEPARATOR . $activepath . DIRECTORY_SEPARATOR . $dir;
-
-            if (count(scandir($dir_name)) > 2) {
-                return ['status' => 1, 'msg' => '不可删除非空目录'];
-            }
-
-            if (rmdir($dir_name)) {
-                return ['status' => 2, 'msg' => 'success'];
-            } else {
-                return ['status' => 0, 'msg' => 'failed'];
-            }
-        }
-    }
-
-    public function del()
-    {
-        if ($this->request->isAjax()) {
-            $activepath = $this->request->param('activepath');
-            $activepath = str_replace('/', DIRECTORY_SEPARATOR, $activepath);
-            $filename = $this->request->param('filename');
-
-            if (unlink(app()->getRootPath . 'public' . DIRECTORY_SEPARATOR . $activepath . DIRECTORY_SEPARATOR . $filename)) {
-                return ['status' => 1, 'msg' => 'success'];
-            } else {
-                return ['status' => 0, 'msg' => 'failed'];
-            }
-        }
-    }
-
-    // public function upload()
-    // {
-    //     if ($this->request->isGet()) {
-    //         return View::fetch()();
-    //     } else {
-    //         $isthumb = $this->request->has('isthumb', 'post') ? $this->request->post('isthumb') : 0;
-    //         $mode = $this->request->has('formername', 'post') ? $this->request->post('formername') : 0;
-    //         $file = request()->file('image');
-
-    //         $info = $this->saveUpload($file, $mode);
-
-    //         if (!$info) {
-    //             $this->error($info->getError());
-    //         }
-
-    //         $filename = $info->getSaveName();
-    //         unset($info);
-    //         if ($isthumb == 1) {
-    //             $width = $this->request->has('width', 'post') ? $this->request->post('width') : $this->t_width;
-    //             $height = $this->request->has('height', 'post') ? $this->request->post('height') : $this->t_height;
-
-    //             $thumbname = $this->makeThumb($filename, $width, $height);
-
-    //             if (!$thumbname) {
-    //                 $this->error('缩略图生成失败');
-    //             }
-    //         } else {
-    //             $thumbname = '';
-    //         }
-
-    //         if ($this->request->isAjax()) {
-    //             return ['code'=>2, 'picname' => $filename, 'thumbname'=>$thumbname];
-    //         } else {
-    //             $this->success('上传成功', '/file_manager/index');
-    //         }
-    //     }
-    // }
-
-    /**
-     * 保存上传的图片
-     * @param object $file 获取的上传对象
-     * @param boolean $mode 是否保存原文件名 0(false), 生成新名称; 1(true), 保留原名
-     * @return object 返回文件保存对象
-     */
-    protected function saveUpload($file, $mode)
-    {
-        $validate = ['size' => 2097152, 'ext' => 'jpg,png,gif,jpeg'];
-
-        if ($mode) {
-            $upload = $file->validate($validate)->move(app()->getRootPath . 'public' . DIRECTORY_SEPARATOR . 'uploads', '');
-        } else {
-            $upload = $file->validate($validate)->move(app()->getRootPath . 'public' . DIRECTORY_SEPARATOR . 'uploads');
-        }
-
-        return $upload;
-    }
-
-    /**
-     * 站内选择
-     * @return void
-     */
-    public function selectPicture()
-    {
-        $data = $this->explorer();
-
-        View::assign('data', $data);
-        return View::fetch()();
-    }
-
-    public function uploadPicture()
-    {
-        return View::fetch()();
-    }
-
-    // public function onlinePicture()
-    // {
-    //     if ($this->request->isAjax()) {
-    //         $param = $this->request->param();
-    //         $urlimg = $param['filename'];
-    //         $download = $param['download'];
-    //         $isthumb = $param['isthumb'];
-    //         $formername = $param['formername'];
-
-    //         $res = \mylib\GetImageByurl::isImg($urlimg);
-    //         if (!$res) {
-    //             $this->error('该图片不合法');
-    //         } else {
-    //             if (!$download) {
-    //                 return ['code'=>2,'filename'=>$urlimg];
-    //             } else {
-    //                 $basepath = \config('url_domain_root') . '/uploads';
-    //                 // var_dump($param);
-
-    //                 if ($isthumb!=1  &&  preg_match("#" . $basepath . "#i", $urlimg)) {
-    //                     $this->error('图片已在服务其中, 可直接选用');
-    //                 }
-
-    //                 // 按文件夹日期夹存放图片
-    //                 $today = date('Ymd', time());
-    //                 $savePath = $this->img_path . $today;
-    //                 if (!is_dir($savePath)) {
-    //                     if (mkdir($savePath) == false) {
-    //                         $this->error('下载失败, 请稍后重试');
-    //                     }
-    //                 }
-
-    //                 if ($formername==1) {
-    //                     // 获取原文件名
-    //                     $fileinfo = pathinfo($urlimg);
-    //                     if (!isset($fileinfo['extension']) || !in_array($fileinfo['extension'], ['jpg', 'jpeg', 'png', 'gif'])) {
-    //                         $ext = \mylib\GetImageByurl::getEXTENSION($urlimg);
-    //                     }
-    //                     $filename = $fileinfo['basename'] . '.' . $ext;
-    //                 } else {
-    //                     $filename = '';
-    //                 }
-
-    //                 $filename = \mylib\GetImageByurl::getImageByurl($urlimg, $filename, $savePath);
-
-    //                 if ($filename) {
-    //                     // 生成缩略图
-    //                     if ($isthumb==1) {
-    //                         $width = $this->request->has('width', 'post') ? $this->request->post('width') : $this->t_width;
-    //                         $height = $this->request->has('height', 'post') ? $this->request->post('height') : $this->t_height;
-
-    //                         $thumbname = $this->makeThumb($today . DIRECTORY_SEPARATOR . $filename, $width, $height);
-
-    //                         if (!$thumbname) {
-    //                             $this->error('缩略图生成失败');
-    //                         }
-    //                     } else {
-    //                         $thumbname = '';
-    //                     }
-
-    //                     return ['code'=>2, 'filename' => $today . DIRECTORY_SEPARATOR . $filename, 'thumbname'=>$thumbname];
-    //                 } else {
-    //                     $this->error('图片下载失败');
-    //                 }
-    //             }
-    //         }   
-    //     } else {
-    //         return View::fetch()();
-    //     }
-    // }
-
     /**
      * 判断(远程)文件是否为图片
      */
@@ -514,62 +535,6 @@ class FileManager extends Base
     //     }
     // }
 
-        /**
-     * 处理上传的图片
-     */
-    protected function dealUploadImg(File $file, $water, $thumb, $width, $height, $overwrite)
-    {
-        $savename = "";
-        $thumbname = "";
-
-        if ($water == true || $thumb == true) {
-            $image = Image::open($file);
-
-            if ($water) {
-                $type = $this->system->water_type ?: Config::get('filesystem.water.type');
-
-                if ($type == 'water') {
-                    $watemark = $this->system->watermark ?: Config::get('filesystem.water.watermark');
-                    $image->water($watemark);
-                } else {
-                    $watetext = $this->system->watertext ?: Config::get('filesystem.water.watertext');
-                    $image->text($watetext, Config::get('filesystem.water.waterfont'), 30, '#ffffff30');
-                }
-            }
-
-            $savename = $file->hashName();
-            $realPath = Config::get('filesystem.disks.public.root') . '/' . $savename;
-
-            if ($thumb == true) {
-                if ($overwrite == true) {
-                    $image->thumb($width, $height, 1);
-
-                    $image->save($realPath);
-                } else {
-                    $image->save($realPath);
-
-                    $image->thumb($width, $height, 1);
-
-                    $ext = $file->extension();
-
-                    $thumbname = str_replace('.' . $ext, '', str_replace('\\', '/', $savename)) . $this->t_suffix . '.' . $ext;
-                    // halt(Config::get('filesystem.disks.public.root') .'/' . $thumbname);
-                    $image->save(Config::get('filesystem.disks.public.root') . '/' . $thumbname);
-                }
-            } else {
-                $image->save($realPath);
-            }
-            unset($image);
-        } else {
-            $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
-        }
-
-        return [
-            'picname'   => str_replace('\\', '/', $savename),
-            'thumbname' => $thumbname
-        ];
-    }
-
     /**
      * ckeditor 富文本编辑器上传图片
      */
@@ -605,13 +570,13 @@ class FileManager extends Base
                     $this->error($e->getMessage());
                     return json([
                         'uploaded' => 1,
-                        'error' =>  ['message'=>$e->getMessage()]
+                        'error' =>  ['message' => $e->getMessage()]
                     ]);
                 }
             } else {
                 return json([
                     'uploaded' => 1,
-                    'error' =>  ['message'=>'图片不能为空']
+                    'error' =>  ['message' => '图片不能为空']
                 ]);
             }
         }

+ 230 - 0
view/sys/file_manager/explorer.html

@@ -0,0 +1,230 @@
+<style>
+    .progress {
+        width: 600px;
+        height: 10px;
+        border: 1px solid #ccc;
+        border-radius: 10px;
+        margin: 10px 0px;
+        overflow: hidden;
+        display: -webkit-inline-box;
+    }
+
+    /* 初始状态设置进度条宽度为0px */
+    .progress>div {
+        width: 0px;
+        height: 100%;
+        background-color: yellowgreen;
+        transition: all .3s ease;
+    }
+</style>
+
+<article class="cl pd-20">
+    <div class="cl pd-5 bg-1 bk-gray">
+        <span class="l">
+            <a class="btn radius btn-default" href="{:url('index')}"><i
+                    class="Hui-iconfont Hui-iconfont-pages"></i>数据库模式</a>
+            <a class="btn radius btn-secondary"><i class="Hui-iconfont Hui-iconfont-jifen"></i> 目录模式 </a>
+            <a class="btn btn-primary radius" onclick="uploadFile();"><i
+                    class="Hui-iconfont Hui-iconfont-add"></i>上传附件</a>
+            <input type="file" id="upload_file" hidden multiple onchange="fileChange()">
+            <input type="hidden" id="activepath" name="activepath" value="{$activepath}">
+            <div class="progress">
+                <div></div>
+            </div>
+        </span>
+        <span class="r">共有:
+            <strong>{$counts}</strong> 个对象</span>
+    </div>
+    <div class="cl mt-20">
+        <table class="table table-border table-bordered table-bg">
+            <thead>
+                <tr class="text-c">
+                    <th width="25%">
+                        <strong>文件名</strong>
+                    </th>
+                    <th width="16%">
+                        <strong>文件大小</strong>
+                    </th>
+                    <th width="22%">
+                        <strong>最后修改时间</strong>
+                    </th>
+                    <th width="34%">
+                        <strong>操作</strong>
+                    </th>
+                </tr>
+            </thead>
+            <tbody>
+                <tr class="text-c" bgcolor='#FFFFFF' height='26' onMouseMove="javascript:this.bgColor='#FCFDEE';"
+                    onMouseOut="javascript:this.bgColor='#FFFFFF';">
+                    <td>
+                        {notempty name="activepath"}<i class="Hui-iconfont Hui-iconfont-arrow1-top"></i>{/notempty}
+                        <a href="/sys/file_manager/explorer?activepath={$activeurl}">上级目录</a>
+                    </td>
+                    <td>当前目录:
+                        <span style="color:#f00;"> ./storage{$activepath} </span>  
+                    </td>
+                    <td></td>
+                    <td></td>
+                </tr>
+                {foreach $dirs as $dir}
+                <tr class="text-c" style="height:26px; " onMouseMove="javascript:this.bgColor='#FCFDEE';"
+                    onMouseOut="javascript:this.bgColor='#FFFFFF';">
+                    <td style="text-align:left;">
+                        <img src=/static/images/icon/dir.png>
+                        <a href="/sys/file_manager/explorer?activepath={$activepath.'/'.$dir}">
+                            {$dir}
+                        </a>
+                    </td>
+                    <td></td>
+                    <td></td>
+                    <td>
+                        <a class="btn" onclick="del_dir(this, '{$activepath}/{$dir}')">删除</a>
+                    </td>
+                </tr>
+                {/foreach}
+                {foreach $files as $file}
+                <tr class="text-c" bgcolor='#FFFFFF' height='26' onMouseMove="javascript:this.bgColor='#FCFDEE';"
+                    onMouseOut="javascript:this.bgColor='#FFFFFF';">
+                    <td style="text-align:left;">
+                        <img src="/static/images/icon/{$file['extension']}.png">
+                        <a href="/storage{$activepath}/{$file['filename']}" target="_blank">
+                            {$file['filename']}
+                        </a>
+                    </td>
+                    <td align='center'> {$file['size']} </td>
+                    <td align='center'> {$file['time']|date="Y-m-d H:i:s"} </td>
+                    <td>
+                        <a href="/storage{$activepath.'/'.$file['filename']}" class="btn radius btn-primary"
+                            target="_blank">查看/下载</a>&nbsp;
+                        <a class="btn radius btn-danger"
+                            onclick="del_file(this,'{$activepath}/{$file.filename}')">删除</a>&nbsp;
+                        <!-- <a href='' class="btn" >移动</a> -->
+                    </td>
+                </tr>
+                {/foreach}
+            </tbody>
+        </table>
+    </div>
+</article>
+
+<!--请在下方写此页面业务相关的脚本-->
+<script type="text/javascript">
+    /*删除图片*/
+    function del_dir(obj, dir) {
+        layer.confirm('确认要删除吗?', function (index) {
+            $.post('deldir', {
+                'dir': dir
+            }, function (res) {
+                if (res.code == 0) {
+                    $(obj).parents('tr').remove();
+                    topalert({
+                        type: 0,
+                        content: res.msg,
+                        speed: 1000
+                    });
+                } else {
+                    topalert({
+                        type: 2,
+                        content: res.msg,
+                        speed: 2000
+                    });
+                }
+                layer.close(layer.index);
+            }, 'json');
+        });
+    }
+
+    /*删除图片*/
+    function del_file(obj, filename) {
+        layer.confirm('确认要删除吗?', function (index) {
+            $.post('delfile', {
+                'filename': filename
+            }, function (res) {
+                if (res.code == 0) {
+                    $(obj).parents('tr').remove();
+                    topalert({
+                        type: 0,
+                        content: res.msg,
+                        speed: 1000
+                    });
+                } else {
+                    topalert({
+                        type: 2,
+                        content: res.msg,
+                        speed: 2000
+                    });
+                }
+                layer.close(layer.index);
+            }, 'json');
+        });
+    }
+
+    //通过点击图片来触发文件上传按钮
+    function uploadFile(params) {
+        $("#upload_file").click();
+    }
+
+    // 自动上传处理
+    function fileChange() {
+        let uploadFile = $("#upload_file").get(0).files;
+        // console.log(uploadFile);
+        if (uploadFile == undefined || uploadFile == null) {
+            layer.msg("请选择文件", { icon: 5, time: 1000 });
+            return false;
+        }
+
+        if (uploadFile.length > 20) {
+            layer.msg("最多20个文件", { icon: 5, time: 1000 });
+            return false;
+        }
+
+        let formData = new FormData();
+
+        formData.append('activepath', $('#activepath').val());
+
+        for (let i = 0; i < uploadFile.length; i++) {
+            formData.append('upload_file[]', uploadFile[i]);
+        }
+
+        $.ajax({
+            url: '{:url("file_manager/uploadFile")}',
+            type: 'post',
+            dataType: 'json',
+            data: formData,
+            processData: false,
+            contentType: false,
+            xhr: function () {
+                var xhr = new XMLHttpRequest();
+                //使用XMLHttpRequest.upload监听上传过程,注册progress事件,打印回调函数中的event事件
+                xhr.upload.addEventListener('progress', function (e) {
+                    // console.log(e);
+                    //loaded代表上传了多少
+                    //total代表总数为多少
+                    var progressRate = (e.loaded / e.total) * 100 + '%';
+
+                    //通过设置进度条的宽度达到效果
+                    $('.progress > div').css('width', progressRate);
+                })
+
+                return xhr;
+            },
+            success: function (res) {
+                console.log(res);
+                if (res.code == 0) {
+                    layer.msg(res.msg, {
+                        icon: 1,
+                        time: 1000
+                    });
+                    window.location.reload();
+                } else {
+                    layer.msg(res.msg, {
+                        icon: 5,
+                        time: 1000
+                    });
+                    return false;
+                }
+            }
+        });
+    }
+</script>
+<!--请在上方写此页面业务相关的脚本-->

+ 107 - 33
view/sys/file_manager/index.html

@@ -1,28 +1,31 @@
 <style>
-.progress {
-    width: 600px;
-    height: 10px;
-    border: 1px solid #ccc;
-    border-radius: 10px;
-    margin: 10px 0px;
-    overflow: hidden;
-}
+    .progress {
+        width: 600px;
+        height: 10px;
+        border: 1px solid #ccc;
+        border-radius: 10px;
+        margin: 10px 0px;
+        overflow: hidden;
+        display: -webkit-inline-box;
+    }
 
-/* 初始状态设置进度条宽度为0px */
-.progress>div {
-    width: 0px;
-    height: 100%;
-    background-color: yellowgreen;
-    transition: all .3s ease;
-}
+    /* 初始状态设置进度条宽度为0px */
+    .progress>div {
+        width: 0px;
+        height: 100%;
+        background-color: yellowgreen;
+        transition: all .3s ease;
+    }
 </style>
+
 <article class="cl pd-10">
     <div class="cl pd-5 bg-1 bk-gray mt-20">
         <span class="l">
             <a class="btn radius btn-secondary"><i class="Hui-iconfont Hui-iconfont-jifen"></i>数据库模式</a>
             <a class="btn radius btn-default" href="{:url('explorer')}"><i class="Hui-iconfont Hui-iconfont-pages"></i> 目录模式 </a>
+            <a class="btn btn-danger radius" onclick="del_all();"><i class="Hui-iconfont Hui-iconfont-del2"></i>批量删除</a>
             <a class="btn btn-primary radius" onclick="uploadFile();"><i class="Hui-iconfont Hui-iconfont-add"></i>上传附件</a>
-            <input type="file" id="upload_file" hidden multiple onchange ="fileChange()">
+            <input type="file" id="upload_file" hidden multiple onchange="fileChange()">
             <div class="progress">
                 <div></div>
             </div>
@@ -38,8 +41,8 @@
                         <input type="checkbox" name="allcheck" value="">
                     </th>
                     <th width="60px;">ID</th>
-                    <th width="120px;">文件title</th>
-                    <th style="min-width: 260px;">文件</th>
+                    <th>文件title</th>
+                    <th style="min-width: 260px;">文件路径</th>
                     <th>文件类型</th>
                     <th>文件大小</th>
                     <th>增加者</th>
@@ -56,13 +59,17 @@
                     <td>{$val.fileid}</td>
                     <td class="text-l">{$val.title}</td>
                     <td class="text-l">
-                        <a href="{$val.filepath}" title="{$val.filepath}" target="_blank">{$val.filename}</a>
+                        <a href="{$val.filepath}" title="{$val.filepath}" target="_blank">{$val.filepath}</a>
                     </td>
                     <td>{$val.fileextension}</td>
                     <td>{$val.filesize|format_bytes}</td>
                     <td>{$val.username}</td>
-                    <td>{$val.filetime|date="Y-m-d"}</td>
-                    <td><a class="btn btn-danger radius" title="删除" onClick="del(this,'{$val.fileid}')"><i class="Hui-iconfont Hui-iconfont-del2"></i></a></td>
+                    <td>{$val.filetime|date="Y-m-d H:i:s"}</td>
+                    <td class="td-manager">
+                        <a class="btn btn-secondary radius" title="编辑title" onClick="editTitle('{$val.fileid}','{$val.title}')"><i
+                            class="Hui-iconfont Hui-iconfont-edit"></i></a>
+                        <a class="btn btn-danger radius" title="删除" onClick="del(this,'{$val.fileid}')"><i
+                            class="Hui-iconfont Hui-iconfont-del2"></i></a></td>
                 </tr>
                 {/foreach}
             </tbody>
@@ -78,15 +85,24 @@
 
     // 上传处理
     function fileChange() {
-        let data = $("#upload_file").get(0).files;
-        console.log(data);
-        if (data == undefined || data == null) {
-            layer.msg("请选择视频文件", { icon: 5, time: 1000 });
+        let uploadFile = $("#upload_file").get(0).files;
+        // console.log(uploadFile);
+        if (uploadFile == undefined || uploadFile == null) {
+            layer.msg("请选择文件", { icon: 5, time: 1000 });
+            return false;
+        }
+
+        if (uploadFile.length > 20) {
+            layer.msg("最多20个文件", { icon: 5, time: 1000 });
             return false;
         }
 
         let formData = new FormData();
-        formData.append("upload_file", data);
+
+        for (let i = 0; i < uploadFile.length; i++) {
+            formData.append('upload_file[]', uploadFile[i]);
+        }
+
         $.ajax({
             url: '{:url("file_manager/uploadFile")}',
             type: 'post',
@@ -98,7 +114,7 @@
                 var xhr = new XMLHttpRequest();
                 //使用XMLHttpRequest.upload监听上传过程,注册progress事件,打印回调函数中的event事件
                 xhr.upload.addEventListener('progress', function (e) {
-                    console.log(e);
+                    // console.log(e);
                     //loaded代表上传了多少
                     //total代表总数为多少
                     var progressRate = (e.loaded / e.total) * 100 + '%';
@@ -111,11 +127,11 @@
             },
             success: function (res) {
                 console.log(res);
-                if (res.code == 1) {
-                    layer.msg(data.msg, {
-                            icon: 5,
-                            time: 1000
-                        });
+                if (res.code == 0) {
+                    layer.msg(res.msg, {
+                        icon: 1,
+                        time: 1000
+                    });
                     window.location.reload();
                 } else {
                     layer.msg(res.msg, {
@@ -128,4 +144,62 @@
         });
     }
 
-</script>
+    function editTitle(id, title) {
+        if (id==0) {
+            layer.msg('id不可为空', {icon: 5,time: 1000});
+        }
+
+        var content  = '<div  class="cl" style="padding:20px;">';
+            content += '<label class="form-label col-sm-4">';
+            content += '<span class="c-red">*</span>文件title:</label>';
+            content += '<div class="formControls col-sm-6">';
+            content += '<input type="text" class="input-text" name="filetile" id="filetile">';
+            content += '</div><div class="col-3"></div></div></div>';
+
+        layer.open({
+            type: 1,
+            area: ['500px', '200px'],
+            title: '修改文件title',
+            content: '\<\div style="padding:20px;">\<\span class="c-red">*\<\/span>文件title:\<\input type="text" class="input-text" name="filetitle" value="'+title+'" id="filetitle">\<\/div>',
+            btn: ['确定', '取消'],
+            yes: function(index, layero){
+                let filetitle = document.querySelector('input[name="filetitle"]').value;
+                $.ajax({
+                    url: '{:url("file_manager/updateFileTitle")}',
+                    type: 'post',
+                    dataType: 'json',
+                    contentType: 'application/json',
+                    data: JSON.stringify({
+                        id: id,
+                        filetitle: filetitle
+                    }),
+                    success: function (res) {
+                        if (res.code == 0) {
+                            layer.msg(res.msg, {
+                                icon: 1,
+                                time: 1000
+                            });
+                            window.location.reload();
+                        } else {
+                            layer.msg(res.msg, {
+                                icon: 5,
+                                time: 1000
+                            });
+                        }
+                        layer.close(index);
+                    }
+                });
+            }
+        });
+        
+        // layer.open({
+        //     type: 2,
+        //     area: ['700px', '500px'],
+        //     fix: false, //不固定
+        //     maxmin: true,
+        //     shade: 0.4,
+        //     title: '添加标题图',
+        //     content: 'test'
+        // });
+    }
+</script>

+ 450 - 0
view/sys/file_manager/uploadimg copy.html

@@ -0,0 +1,450 @@
+<!-- <div class="cl pd-5 bg-1 bk-gray">
+        <a href="{:url('/file_manager/selectpicture')}" class="btn btn-default radius sethumb">
+            <i class="Hui-iconfont">&#xe600;</i> 站内选择 </a>&nbsp;&nbsp;
+        <a href="javascript:void(0);" class="btn btn-primary radius sethumb">
+            <i class="Hui-iconfont">&#xe600;</i> 本地上传 </a>&nbsp;&nbsp;
+        <a href="{:url('/file_manager/onlinepicture')}" class="btn btn-default radius sethumb">
+            <i class="Hui-iconfont">&#xe600;</i> 网络图片 </a>&nbsp;&nbsp;
+    </div> -->
+<!-- 本地上传 -->
+<style>
+    #online {
+        width: 100%;
+        height: 224px;
+        padding: 10px 0 0 0;
+    }
+
+    #online #imageList {
+        width: 100%;
+        height: 100%;
+        overflow-x: hidden;
+        overflow-y: auto;
+        position: relative;
+        margin-left: 20px;
+    }
+
+    #online ul {
+        display: block;
+        list-style: none;
+        margin: 0;
+        padding: 0;
+    }
+
+    #online li {
+        float: left;
+        display: block;
+        list-style: none;
+        padding: 0;
+        width: 113px;
+        height: 113px;
+        margin: 0 0 9px 9px;
+        background-color: #eee;
+        overflow: hidden;
+        cursor: pointer;
+        position: relative;
+    }
+
+    #online li img {
+        cursor: pointer;
+    }
+
+    #online li .icon {
+        cursor: pointer;
+        width: 113px;
+        height: 113px;
+        position: absolute;
+        top: 0;
+        left: 0;
+        z-index: 2;
+        border: 0;
+        background-repeat: no-repeat;
+    }
+
+    #online li .icon:hover {
+        width: 107px;
+        height: 107px;
+        border: 3px solid #1094fa;
+    }
+
+    #online li.selected .icon {
+        background-image: url(/static/images/success.png);
+        background-image: url(images/success.gif)\9;
+        background-position: 75px 75px;
+    }
+
+    #online li.clearFloat {
+        float: none;
+        clear: both;
+        display: block;
+        width: 0;
+        height: 0;
+        margin: 0;
+        padding: 0;
+    }
+</style>
+
+<div id="tab-img" class="HuiTab">
+    <div class="tabBar clearfix">
+        <span>本地上传</span>
+        <span>网络文件上传</span>
+        <a onclick="onlinepicture(1)"><span>服务器图片选择</span></a>
+    </div>
+    <div class="tabCon">
+        <div class="step1 active" style="margin-left:30px;">
+            <form id="form-uploadimg" method="post" action="" enctype="multipart/form-data">
+                <div class="row cl" style="margin-top:20px;">
+                    <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>图片要求: </label>
+                    <div class="formControls col-xs-8 col-sm-8">
+                        格式 jpg,png,gif,jpeg,webp; 大小不超过4M.
+                    </div>
+                    <div class="col-3"> </div>
+                </div>
+                <div class="row cl" style="margin-top:20px;">
+                    <label class="form-label col-xs-2 col-sm-2">
+                        <span class="c-red">*</span>本地上传:</label>
+                    <div class="formControls col-xs-4 col-sm-4">
+                        <input type="file" class="input-text" name="upload_file" id="upload_file">
+                    </div>
+                    <div class="col-3"> </div>
+                </div>
+                <div class="row cl" style="margin-top:20px;">
+                    <input type="hidden" name="img_id" value={$img_id}>
+                    <div class="formControls col-xs-12 col-sm-8">
+                        <div class="skin-minimal">
+                            <div class="check-box">
+                                <input type="checkbox" name="overwrite" value="{$overwrite}" {$overwrite ? 'checked'
+                                    : "" }>
+                                <label for="overwrite">覆盖原图</label>
+                            </div>
+                            <div class="check-box">
+                                <input type="checkbox" name="water" value="{$water}" {$water ? 'checked' : "" }>
+                                <label for="water">水印</label>
+                            </div>
+                            <div class="check-box">
+                                <input type="checkbox" name="thumb" value="{$thumb}" {$thumb ? 'checked' : "" }>
+                                <label for="thumb-1">缩略图</label>
+                                <input type="text" class="input-text" name="width" value={$width}
+                                    style="width: 80px;">缩略图宽度
+                                <input type="text" class="input-text" name="height" value={$height}
+                                    style="width: 80px;">缩略图高度
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                <div class="row cl" style="margin-top:30px;margin-left:30px;">
+                    <div class="col-xs-6 col-sm-5 col-xs-offset-2 col-sm-offset-2">
+                        <input class="btn btn-primary radius" type="button" value="&nbsp;确&nbsp;定&nbsp;"
+                            onCLick="uploadImg()">
+                        <input class="btn btn-default radius" type="button" value="&nbsp;取&nbsp;消&nbsp;"
+                            onClick="layer_close();">
+                    </div>
+                </div>
+            </form>
+        </div>
+        <!-- 本地上传end -->
+    </div>
+    <div class="tabCon">
+        <form id="form-uploadurlimg" method="post" action="" enctype="multipart/form-data">
+            <div class="row cl" style="margin-top:20px;">
+                <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>图片要求: </label>
+                <div class="formControls col-xs-8 col-sm-8">
+                    格式 jpg,png,gif,jpeg,webp; 大小不超过4M.
+                </div>
+                <div class="col-3"> </div>
+            </div>
+            <div class="row cl" style="margin-top:20px;">
+                <label class="form-label col-xs-2 col-sm-2">
+                    <span class="c-red">*</span>图片地址:</label>
+                <div class="formControls col-xs-4 col-sm-4">
+                    <input type="text" class="input-text" name="url_file" id="url_file">
+                </div>
+                <div class="col-3"> </div>
+            </div>
+            <div class="row cl" style="margin-top:20px;">
+                <input type="hidden" name="img_id" value={$img_id}>
+                <div class="formControls col-xs-12 col-sm-8">
+                    <div class="skin-minimal">
+                        <div class="check-box">
+                            <input type="checkbox" name="overwrite" value="{$overwrite}" {$overwrite ? 'checked' : "" }>
+                            <label for="overwrite">覆盖原图</label>
+                        </div>
+                        <div class="check-box">
+                            <input type="checkbox" name="water" value="{$water}" {$water ? 'checked' : "" }>
+                            <label for="water">水印</label>
+                        </div>
+                        <div class="check-box">
+                            <input type="checkbox" name="thumb" value="{$thumb}" {$thumb ? 'checked' : "" }>
+                            <label for="thumb-1">缩略图</label>
+                            <input type="text" class="input-text" name="width" value={$width} style="width: 80px;">缩略图宽度
+                            <input type="text" class="input-text" name="height" value={$height}
+                                style="width: 80px;">缩略图高度
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="row cl" style="margin-top:30px;margin-left:30px;">
+                <div class="col-xs-6 col-sm-5 col-xs-offset-2 col-sm-offset-2">
+                    <input class="btn btn-primary radius" type="button" value="&nbsp;确&nbsp;定&nbsp;"
+                        onCLick="uploadUrlImg()">
+                    <input class="btn btn-default radius" type="button" value="&nbsp;取&nbsp;消&nbsp;"
+                        onClick="layer_close();">
+                </div>
+            </div>
+        </form>
+    </div>
+    <!-- 在线图片 -->
+    <div class="tabCon">
+        <form id="form-uploadonlineimg" method="post" action="" enctype="multipart/form-data">
+            <div class="row cl" style="margin-top:20px;" id="online">
+                <div id="imageList">
+                    <ul class="list">
+                        <!-- <li>
+                            <img width="170" height="113" src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg?noCache=1634567323"
+                             _src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg">
+                            <span class="icon"></span>
+                        </li>
+                         -->
+                        <li class="clearFloat"></li>
+                    </ul>
+                </div>
+            </div>
+            <div class="row cl" style="margin-top:20px;">
+                <label class="form-label col-xs-2 col-sm-2">
+                    <span class="c-red">*</span>图片地址:</label>
+                <div class="formControls col-xs-8 col-sm-8">
+                    <input type="text" class="input-text" name="online_file" id="online_file">
+                </div>
+                <div class="col-3"> </div>
+            </div>
+            <div class="row cl" style="margin-top:20px;">
+                <input type="hidden" name="img_id" value={$img_id}>
+                <div class="formControls col-xs-12 col-sm-8">
+                    <div class="skin-minimal">
+                        <div class="check-box">
+                            <input type="checkbox" name="thumb" value="{$thumb}" {$thumb ? 'checked' : "" }>
+                            <label for="thumb-1">缩略图</label>
+                            <input type="text" class="input-text" name="width" value={$width} style="width: 80px;">缩略图宽度
+                            <input type="text" class="input-text" name="height" value={$height}
+                                style="width: 80px;">缩略图高度
+                            <input type="checkbox" name="overwrite" value="{$overwrite}" {$overwrite ? 'checked' : "" }>
+                            <label for="overwrite">覆盖原图</label>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="row cl" style="margin-top:30px;margin-left:30px;">
+                <div class="col-xs-6 col-sm-5 col-xs-offset-2 col-sm-offset-2">
+                    <input class="btn btn-primary radius" type="button" value="&nbsp;确&nbsp;定&nbsp;"
+                        onCLick="uploadOnlineImg()">
+                    <input class="btn btn-default radius" type="button" value="&nbsp;取&nbsp;消&nbsp;"
+                        onClick="layer_close();">
+                </div>
+            </div>
+        </form>
+    </div>
+</div>
+
+<!--请在下方写此页面业务相关的脚本-->
+<script type="text/javascript">
+    jQuery.Huitab = function (tabBar, tabCon, class_name, tabEvent, i) {
+        var $tab_menu = $(tabBar);
+        // 初始化操作
+        $tab_menu.removeClass(class_name);
+        $(tabBar).eq(i).addClass(class_name);
+        $(tabCon).hide();
+        $(tabCon).eq(i).show();
+
+        $tab_menu.bind(tabEvent, function () {
+            $tab_menu.removeClass(class_name);
+            $(this).addClass(class_name);
+            var index = $tab_menu.index(this);
+            $(tabCon).hide();
+            $(tabCon).eq(index).show()
+        })
+    }
+
+    $(function () {
+        $.Huitab("#tab-img .tabBar span", "#tab-img .tabCon", "current", "click", "0");
+        $(document).on("click", "#online li", function(){
+            $("#online li").removeClass('selected');
+
+            $(this).addClass('selected');
+
+            img = $(this).children('img').attr('_src');
+
+            $("#online_file").val(img);
+        })
+    });
+
+    function onlinepicture(page) {
+        var data = { "page": page };
+        $.ajax({
+            url: '{:url("file_manager/onlineimg")}',
+            type: 'GET',
+            async: true,
+            cache: false,
+            data: 'page=' + page,
+            processData: false,
+            contentType: false,
+            dataType: "json",
+            success: function (res) {
+                if (res.code == 0) {
+                    html_str = "";
+                    res.list.forEach(element => {
+                        html_str += '<li><img width="170" height="113" src="' + element.url + '?noCache=' + element.mtime + '"';
+                        html_str += '_src="' + element.url + '">';
+                        html_str += '<span class="icon"></span></li>';
+                    });
+                    $('ul.list').prepend(html_str);
+                }
+            }
+        });
+    }
+
+    //step1本地上传图片
+    function uploadImg() {
+        if ($("#upload_file").val() == '') {
+            layer.msg("请选择要上传的文件", {
+                icon: 6,
+                time: 1000
+            });
+            return false;
+        } else {
+            var formData = new FormData($("#form-uploadimg")[0]);
+            $.ajax({
+                url: '{:url("file_manager/uploadimg")}',
+                type: 'POST',
+                async: true,
+                cache: false,
+                data: formData,
+                processData: false,
+                contentType: false,
+                dataType: "json",
+                beforeSend: function () {
+                    // loadIndex = layer.load();
+                },
+                success: function (res) {
+                    if (res.code == 0) {
+                        // layer.close(loadIndex);
+                        console.log(res);
+                        var img = res.picture_url + res.picname;
+                        window.parent.$("#" + res.img_id).val(img);
+
+                        if (res.thumbname) {
+                            img = res.picture_url + res.thumbname;
+                            window.parent.$("#thumb").val(img);
+                        }
+
+                        window.parent.$("#view-" + res.img_id).attr('src', img);
+                        layer_close();
+                    } else {
+                        // layer.close(loadIndex);
+                        layer.msg(res.msg, {
+                            icon: 5,
+                            time: 1000
+                        });
+                        return false;
+                    }
+                }
+            });
+        }
+    }
+
+    // 网络图片
+    function uploadUrlImg() {
+        if ($("#url_file").val() == '') {
+            layer.msg("文件地址不可以为空", {
+                icon: 6,
+                time: 1000
+            });
+            return false;
+        } else {
+            var formData = new FormData($("#form-uploadurlimg")[0]);
+            $.ajax({
+                url: '{:url("file_manager/uploadurlimg")}',
+                type: 'POST',
+                async: true,
+                cache: false,
+                data: formData,
+                processData: false,
+                contentType: false,
+                dataType: "json",
+                beforeSend: function () {
+                    // loadIndex = layer.load();
+                },
+                success: function (res) {
+                    if (res.code == 0) {
+                        console.log(res);
+                        // layer.close(loadIndex);
+                        var img = res.picture_url + res.picname;
+                        window.parent.$("#" + res.img_id).val(img);
+
+                        if (res.thumbname) {
+                            img = res.picture_url + res.thumbname;
+                            window.parent.$("#thumb").val(img);
+                        }
+
+                        window.parent.$("#view-" + res.img_id).attr('src', img);
+                        layer_close();
+                    } else {
+                        // layer.close(loadIndex);
+                        layer.msg(res.msg, {
+                            icon: 5,
+                            time: 1000
+                        });
+                        return false;
+                    }
+                }
+            });
+        }
+    }
+
+    function uploadOnlineImg() {
+        if ($("#online_file").val() == '') {
+            layer.msg("文件地址不可以为空", {
+                icon: 6,
+                time: 1000
+            });
+            return false;
+        } else {
+            var formData = new FormData($("#form-uploadonlineimg")[0]);
+            $.ajax({
+                url: '{:url("file_manager/uploadonlineimg")}',
+                type: 'POST',
+                async: true,
+                cache: false,
+                data: formData,
+                processData: false,
+                contentType: false,
+                dataType: "json",
+                beforeSend: function () {
+                    // loadIndex = layer.load();
+                },
+                success: function (res) {
+                    if (res.code == 0) {
+                        // console.log(res);
+                        // layer.close(loadIndex);
+                        var img = res.picname;
+                        window.parent.$("#" + res.img_id).val(img);
+
+                        if (res.thumbname) {
+                            img = res.thumbname;
+                            window.parent.$("#thumb").val(img);
+                        }
+
+                        window.parent.$("#view-" + res.img_id).attr('src', img);
+                        layer_close();
+                    } else {
+                        // layer.close(loadIndex);
+                        layer.msg(res.msg, {
+                            icon: 5,
+                            time: 1000
+                        });
+                        return false;
+                    }
+                }
+            });
+        }
+    }
+</script>
+<!--请在上方写此页面业务相关的脚本-->

+ 2 - 94
view/sys/file_manager/uploadimg.html

@@ -144,103 +144,11 @@
         <!-- 本地上传end -->
     </div>
     <div class="tabCon">
-        <form id="form-uploadurlimg" method="post" action="" enctype="multipart/form-data">
-            <div class="row cl" style="margin-top:20px;">
-                <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>图片要求: </label>
-                <div class="formControls col-xs-8 col-sm-8">
-                    格式 jpg,png,gif,jpeg,webp; 大小不超过4M.
-                </div>
-                <div class="col-3"> </div>
-            </div>
-            <div class="row cl" style="margin-top:20px;">
-                <label class="form-label col-xs-2 col-sm-2">
-                    <span class="c-red">*</span>图片地址:</label>
-                <div class="formControls col-xs-4 col-sm-4">
-                    <input type="text" class="input-text" name="url_file" id="url_file">
-                </div>
-                <div class="col-3"> </div>
-            </div>
-            <div class="row cl" style="margin-top:20px;">
-                <input type="hidden" name="img_id" value={$img_id}>
-                <div class="formControls col-xs-12 col-sm-8">
-                    <div class="skin-minimal">
-                        <div class="check-box">
-                            <input type="checkbox" name="overwrite" value="{$overwrite}" {$overwrite ? 'checked' : "" }>
-                            <label for="overwrite">覆盖原图</label>
-                        </div>
-                        <div class="check-box">
-                            <input type="checkbox" name="water" value="{$water}" {$water ? 'checked' : "" }>
-                            <label for="water">水印</label>
-                        </div>
-                        <div class="check-box">
-                            <input type="checkbox" name="thumb" value="{$thumb}" {$thumb ? 'checked' : "" }>
-                            <label for="thumb-1">缩略图</label>
-                            <input type="text" class="input-text" name="width" value={$width} style="width: 80px;">缩略图宽度
-                            <input type="text" class="input-text" name="height" value={$height}
-                                style="width: 80px;">缩略图高度
-                        </div>
-                    </div>
-                </div>
-            </div>
-            <div class="row cl" style="margin-top:30px;margin-left:30px;">
-                <div class="col-xs-6 col-sm-5 col-xs-offset-2 col-sm-offset-2">
-                    <input class="btn btn-primary radius" type="button" value="&nbsp;确&nbsp;定&nbsp;"
-                        onCLick="uploadUrlImg()">
-                    <input class="btn btn-default radius" type="button" value="&nbsp;取&nbsp;消&nbsp;"
-                        onClick="layer_close();">
-                </div>
-            </div>
-        </form>
+
     </div>
     <!-- 在线图片 -->
     <div class="tabCon">
-        <form id="form-uploadonlineimg" method="post" action="" enctype="multipart/form-data">
-            <div class="row cl" style="margin-top:20px;" id="online">
-                <div id="imageList">
-                    <ul class="list">
-                        <!-- <li>
-                            <img width="170" height="113" src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg?noCache=1634567323"
-                             _src="/storage/20220223/d5cc488e71c58bb072debe45ed06c6ad.jpg">
-                            <span class="icon"></span>
-                        </li>
-                         -->
-                        <li class="clearFloat"></li>
-                    </ul>
-                </div>
-            </div>
-            <div class="row cl" style="margin-top:20px;">
-                <label class="form-label col-xs-2 col-sm-2">
-                    <span class="c-red">*</span>图片地址:</label>
-                <div class="formControls col-xs-8 col-sm-8">
-                    <input type="text" class="input-text" name="online_file" id="online_file">
-                </div>
-                <div class="col-3"> </div>
-            </div>
-            <div class="row cl" style="margin-top:20px;">
-                <input type="hidden" name="img_id" value={$img_id}>
-                <div class="formControls col-xs-12 col-sm-8">
-                    <div class="skin-minimal">
-                        <div class="check-box">
-                            <input type="checkbox" name="thumb" value="{$thumb}" {$thumb ? 'checked' : "" }>
-                            <label for="thumb-1">缩略图</label>
-                            <input type="text" class="input-text" name="width" value={$width} style="width: 80px;">缩略图宽度
-                            <input type="text" class="input-text" name="height" value={$height}
-                                style="width: 80px;">缩略图高度
-                            <input type="checkbox" name="overwrite" value="{$overwrite}" {$overwrite ? 'checked' : "" }>
-                            <label for="overwrite">覆盖原图</label>
-                        </div>
-                    </div>
-                </div>
-            </div>
-            <div class="row cl" style="margin-top:30px;margin-left:30px;">
-                <div class="col-xs-6 col-sm-5 col-xs-offset-2 col-sm-offset-2">
-                    <input class="btn btn-primary radius" type="button" value="&nbsp;确&nbsp;定&nbsp;"
-                        onCLick="uploadOnlineImg()">
-                    <input class="btn btn-default radius" type="button" value="&nbsp;取&nbsp;消&nbsp;"
-                        onClick="layer_close();">
-                </div>
-            </div>
-        </form>
+
     </div>
 </div>
 

+ 1 - 2
view/sys/public/header.html

@@ -30,8 +30,7 @@
                                 class="Hui-iconfont">&#xe6d5;</i></a>
                         <ul class="dropDown-menu menu radius box-shadow">
                             <li>
-                                <img src="{:session('adminuser.avatar') ?: '/static/images/user-64x64.png'}"
-                                    class="img-circle">
+                                <img src="{:session('adminuser.avatar') ?: '/static/images/user-64x64.png'}" style="width: 200px;" class="img-circle">
                                 <a href="javascript:void(0);">上次登录时间:{:session('adminuser.perTime')}</a>
                                 <a href="javascript:void(0);">上次登录IP:{:session('adminuser.perIp')}</a>
                             </li>