evoxwht 2 лет назад
Родитель
Сommit
cfb98d0ce9

+ 6 - 1
crmeb/app/adminapi/controller/v1/system/SystemFile.php

@@ -69,7 +69,12 @@ class SystemFile extends AuthController
     //打开目录
     public function opendir()
     {
-        return app('json')->success($this->services->opendir());
+        [$dir, $fileDir, $superior] = $this->request->getMore([
+            ['dir', ''],
+            ['filedir', ''],
+            ['superior', ''],
+        ], true);
+        return app('json')->success($this->services->opendir($dir, $fileDir, $superior));
     }
 
     //文件备注

+ 30 - 16
crmeb/app/services/system/log/SystemFileServices.php

@@ -233,29 +233,25 @@ class SystemFileServices extends BaseServices
     }
 
     //打开目录
-    public function opendir()
+    public function opendir($dir, $fileDir, $superior)
     {
         $markList = app()->make(SystemFileInfoServices::class)->getColumn([], 'mark', 'full_path');
         $fileAll = array('dir' => [], 'file' => []);
         //根目录
-        $rootdir = $this->formatPath(app()->getRootPath());
-        //当前目录
-        $request_dir = app('request')->param('dir');
+        $rootDir = $this->formatPath(app()->getRootPath());
         //防止查看站点以外的目录
-        if (strpos($request_dir, $rootdir) === false) {
-            $request_dir = $rootdir;
+        if (strpos($dir, $rootDir) === false || $dir == '') {
+            $dir = $rootDir;
         }
         //判断是否是返回上级
-        if (app('request')->param('superior') && !empty($request_dir)) {
-            if (strpos(dirname($request_dir), $rootdir) !== false) {
-                $dir = dirname($request_dir);
+        if ($superior) {
+            if (strpos(dirname($dir), $rootDir) !== false) {
+                $dir = dirname($dir);
             } else {
-                $dir = $rootdir;
+                $dir = $rootDir;
             }
-
         } else {
-            $dir = !empty($request_dir) ? $request_dir : $rootdir;
-            $dir = rtrim($dir, DS) . DS . app('request')->param('filedir');
+            $dir = $dir . '/' . $fileDir;
         }
         $list = scandir($dir);
         foreach ($list as $key => $v) {
@@ -272,12 +268,12 @@ class SystemFileServices extends BaseServices
         $uname = php_uname('s');
         if (strstr($uname, 'Windows') !== false) {
             $dir = ltrim($dir, '\\');
-            $rootdir = str_replace('\\', '\\\\', $rootdir);
+            $rootDir = str_replace('\\', '\\\\', $rootDir);
         }
         $list = array_merge($fileAll['dir'], $fileAll['file']);
         $navList = [];
         foreach ($list as $key => $value) {
-            $list[$key]['real_path'] = str_replace($rootdir, '', $value['pathname']);
+            $list[$key]['real_path'] = str_replace($rootDir, '', $value['pathname']);
             $list[$key]['mtime'] = date('Y-m-d H:i:s', $value['mtime']);
 
             $navList[$key]['title'] = $value['filename'];
@@ -288,8 +284,26 @@ class SystemFileServices extends BaseServices
             $navList[$key]['pathname'] = $value['pathname'];
             $navList[$key]['contextmenu'] = true;
             $list[$key]['mark'] = $markList[str_replace(root_path(), '/', $value['pathname'])] ?? '';
+            $count = app()->make(SystemFileInfoServices::class)->count(['full_path' => $list[$key]['real_path']]);
+            if (!$count) app()->make(SystemFileInfoServices::class)->save([
+                'name' => $value['filename'],
+                'path' => str_replace('/' . $value['filename'], '', $list[$key]['real_path']),
+                'full_path' => $list[$key]['real_path'],
+                'type' => $value['type'],
+                'create_time' => date('Y-m-d H:i:s', $value['ctime']),
+                'update_time' => date('Y-m-d H:i:s', time()),
+            ]);
+        }
+        $routeList = [['key' => '根目录', 'route' => '']];
+        $pathArray = explode('/', str_replace($rootDir, '', $dir));
+        $str = '';
+        foreach ($pathArray as $item) {
+            if ($item) {
+                $str = $str . '/' . $item;
+                $routeList[] = ['key' => $item, 'route' => $rootDir . $str];
+            }
         }
-        return compact('dir', 'list', 'navList');
+        return compact('dir', 'list', 'navList', 'routeList');
     }
 
     //读取文件

+ 3 - 3
template/admin/src/pages/system/maintain/systemFile/opendir.vue

@@ -346,7 +346,7 @@ export default {
     open(row) {
       // this.rows = row;
       this.formItem = {
-        dir: row.path ? row.path + '/' : row.path,
+        dir: row.path,
         superior: 0,
         filedir: row.filename,
         fileToken: this.fileToken,
@@ -356,8 +356,8 @@ export default {
     jumpRoute(item) {
       console.log
       let data = {
-        path: item.route ? item.route : '',
-        filename: item.route ? item.key : '',
+        path: item.route,
+        filename: '',
       };
       this.open(data);
     },