文件管理优化

This commit is contained in:
evoxwht 2023-04-25 16:41:42 +08:00
parent eb475ef4f6
commit cfb98d0ce9
3 changed files with 39 additions and 20 deletions

View File

@ -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));
}
//文件备注

View File

@ -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()),
]);
}
return compact('dir', 'list', 'navList');
$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', 'routeList');
}
//读取文件

View File

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