diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index 47d57cbd..bc479566 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; +use App\Models\AbstractModel; use App\Models\File; use App\Models\FileContent; use App\Models\FileUser; @@ -345,7 +346,7 @@ class FileController extends AbstractController if ($status === 2) { $parse = parse_url($url); $from = 'http://10.22.22.6' . $parse['path'] . '?' . $parse['query']; - $path = 'uploads/office/' . $file->id . '/' . $user->userid . '-' . $key; + $path = 'uploads/office/' . date("Ym") . '/' . $file->id . '/' . $user->userid . '-' . $key; $save = public_path($path); Base::makeDir(dirname($save)); $res = Ihttp::download($from, $save); @@ -369,6 +370,88 @@ class FileController extends AbstractController return ['error' => 0]; } + /** + * 保存文件内容(上传文件) + * + * @apiParam {Number} [pid] 父级ID + * @apiParam {String} [files] 文件名 + */ + public function content__upload() + { + $user = User::auth(); + // + $pid = intval(Request::input('pid')); + // + $userid = $user->userid; + if ($pid > 0) { + if (File::wherePid($pid)->count() >= 300) { + return Base::retError('每个文件夹里最多只能创建300个文件或文件夹'); + } + $row = File::allowFind($pid, '主文件不存在'); + $userid = $row->userid; + } else { + if (File::whereUserid($user->userid)->wherePid(0)->count() >= 300) { + return Base::retError('每个文件夹里最多只能创建300个文件或文件夹'); + } + } + // + $path = 'uploads/office/' . date("Ym") . '/u' . $user->userid . '/'; + $data = Base::upload([ + "file" => Request::file('files'), + "type" => 'office', + "path" => $path, + ]); + if (Base::isError($data)) { + return $data; + } + $data = $data['data']; + // + $type = ""; + switch ($data['ext']) { + case 'doc': + case 'docx': + $type = "word"; + break; + case 'xls': + case 'xlsx': + $type = "excel"; + break; + case 'ppt': + case 'pptx': + $type = "ppt"; + break; + } + $file = File::createInstance([ + 'pid' => $pid, + 'name' => Base::rightDelete($data['name'], '.' . $data['ext']), + 'type' => $type, + 'userid' => $userid, + 'created_id' => $user->userid, + ]); + // 开始创建 + return AbstractModel::transaction(function () use ($user, $data, $file) { + $file->save(); + // + $content = FileContent::createInstance([ + 'fid' => $file->id, + 'content' => [ + 'from' => '', + 'url' => $data['path'] + ], + 'text' => '', + 'size' => $data['size'] * 1024, + 'userid' => $user->userid, + ]); + $content->save(); + // + $file->size = $content->size; + $file->save(); + // + $data = File::find($file->id); + return Base::retSuccess($data['name'] . ' 上传成功', $data); + }); + } + /** * 获取共享信息 * diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 7d18f870..8729d40a 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -38,5 +38,8 @@ class VerifyCsrfToken extends Middleware // 保存文件内容(office) 'api/file/content/office/', + + // 保存文件内容(上传) + 'api/file/content/upload/', ]; } diff --git a/app/Models/FileContent.php b/app/Models/FileContent.php index 81f60c32..badb6f8b 100644 --- a/app/Models/FileContent.php +++ b/app/Models/FileContent.php @@ -60,7 +60,7 @@ class FileContent extends AbstractModel switch ($type) { case 'document': $content = [ - "type" => "text", + "type" => "md", "content" => "", ]; break; diff --git a/app/Module/Base.php b/app/Module/Base.php index a442bd77..c5bc04d9 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2229,6 +2229,9 @@ class Base case 'file': $type = ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz']; break; + case 'office': + $type = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx']; + break; case 'firmware': $type = ['img', 'tar', 'bin']; break; diff --git a/public/images/file/upload.svg b/public/images/file/upload.svg new file mode 100644 index 00000000..14a8ffb9 --- /dev/null +++ b/public/images/file/upload.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/assets/js/pages/manage/components/FileContent.vue b/resources/assets/js/pages/manage/components/FileContent.vue index a5318ecc..95b8b9d6 100644 --- a/resources/assets/js/pages/manage/components/FileContent.vue +++ b/resources/assets/js/pages/manage/components/FileContent.vue @@ -24,8 +24,8 @@
- +
diff --git a/resources/assets/js/pages/manage/file.vue b/resources/assets/js/pages/manage/file.vue index 9c42b32f..4e1748c2 100644 --- a/resources/assets/js/pages/manage/file.vue +++ b/resources/assets/js/pages/manage/file.vue @@ -17,8 +17,13 @@ @command="addFile"> - -
{{$L('新建' + type.name)}}
+ +
{{$L(type.label)}}
@@ -105,6 +110,24 @@
+ + diff --git a/resources/assets/sass/pages/page-file.scss b/resources/assets/sass/pages/page-file.scss index 60e51a19..8f274f17 100644 --- a/resources/assets/sass/pages/page-file.scss +++ b/resources/assets/sass/pages/page-file.scss @@ -255,6 +255,9 @@ background-size: contain; margin-right: 8px; } + &.upload:before { + background-image: url("../images/file/upload.svg"); + } &.folder:before { background-image: url("../images/file/folder.svg"); } @@ -389,6 +392,9 @@ &.shear { opacity: 0.38; } + &.upload .file-icon { + background-image: url("../images/file/upload.svg"); + } &.folder .file-icon { background-image: url("../images/file/folder.svg"); } @@ -439,6 +445,9 @@ background-size: contain; margin-right: 8px; } + &.upload:before { + background-image: url("../images/file/upload.svg"); + } &.folder:before { background-image: url("../images/file/folder.svg"); } diff --git a/resources/assets/statics/public/images/file/upload.svg b/resources/assets/statics/public/images/file/upload.svg new file mode 100644 index 00000000..14a8ffb9 --- /dev/null +++ b/resources/assets/statics/public/images/file/upload.svg @@ -0,0 +1 @@ + \ No newline at end of file