no message

This commit is contained in:
aipaw 2021-07-11 00:31:44 +08:00
parent 8f48d61cde
commit 7bf05c91a6
9 changed files with 244 additions and 16 deletions

View File

@ -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);
});
}
/**
* 获取共享信息
*

View File

@ -38,5 +38,8 @@ class VerifyCsrfToken extends Middleware
// 保存文件内容office
'api/file/content/office/',
// 保存文件内容(上传)
'api/file/content/upload/',
];
}

View File

@ -60,7 +60,7 @@ class FileContent extends AbstractModel
switch ($type) {
case 'document':
$content = [
"type" => "text",
"type" => "md",
"content" => "",
];
break;

View File

@ -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;

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1625931291710" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5154" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"></style></defs><path d="M209.60960101 98.14049639C187.14116856 98.70748393 169.06378546 116.81383719 168.49679793 139.31123981V880.87297556a39.37045459 39.37045459 0 0 0 12.34542899 28.80462145 40.39268755 40.39268755 0 0 0 28.76737408 12.36612197h603.27885982a39.31665284 39.31665284 0 0 0 28.76737408-12.36198337 40.71549797 40.71549797 0 0 0 12.34542901-28.80876005V331.51587048L620.90317569 98.14049639H209.60960101z" fill="#2171ff" p-id="5155"></path><path d="M854.00126391 331.51587048h-191.93148339c-22.48912543-0.53801736-40.59961731-18.65264783-41.16660483-41.17074341V98.14049639l233.09808822 233.37537409z" fill="#C4EAFF" p-id="5156"></path><path d="M384.41971674 536.88537197h71.97430626v116.68768702a14.12502485 14.12502485 0 0 0 13.74013553 13.7566899h82.22974477a14.12502485 14.12502485 0 0 0 13.74013552-13.7566899v-116.68768702h71.97016768a5.95957685 5.95957685 0 0 0 6.17478379-4.13859506c0.95187686-2.57420611 0.41385952-5.46294544-1.39470654-7.52396576L520.8567793 408.42752063a15.44523667 15.44523667 0 0 0-9.60567909-4.13859504 12.44475529 12.44475529 0 0 0-9.60981767 4.13859504L379.64791667 525.11520768a6.13339783 6.13339783 0 0 0-1.39470653 7.52396577c1.00153999 2.52454297 3.45572686 4.1758424 6.17064519 4.13859503v0.10760349z m298.20646532 178.49760389H339.87187977a13.73599692 13.73599692 0 0 0-12.61029907 6.60519767 13.77738286 13.77738286 0 0 0 0 14.25332131 13.73599692 13.73599692 0 0 0 12.61029905 6.60519767h342.75430231a13.75255131 13.75255131 0 0 0 12.87930775-13.73185833 13.75255131 13.75255131 0 0 0-12.87930775-13.73185832z" fill="#FFFFFF" p-id="5157"></path></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -24,8 +24,8 @@
</div>
<div v-if="file.type=='document' && contentDetail" class="header-hint">
<ButtonGroup size="small" shape="circle">
<Button :type="`${contentDetail.type!='md'?'primary':'default'}`" @click="$set(contentDetail, 'type', 'text')">{{$L('文本编辑器')}}</Button>
<Button :type="`${contentDetail.type=='md'?'primary':'default'}`" @click="$set(contentDetail, 'type', 'md')">{{$L('MD编辑器')}}</Button>
<Button :type="`${contentDetail.type!='md'?'primary':'default'}`" @click="$set(contentDetail, 'type', 'text')">{{$L('文本编辑器')}}</Button>
</ButtonGroup>
</div>
<div v-if="file.type=='mind'" class="header-hint">

View File

@ -17,8 +17,13 @@
@command="addFile">
<i class="taskfont">&#xe6f2;</i>
<EDropdownMenu slot="dropdown" class="page-file-dropdown-menu">
<EDropdownItem v-for="(type, key) in types" :key="key" :divided="!!type.divided" :command="type.value">
<div :class="['file-item ' + type.value]">{{$L('新建' + type.name)}}</div>
<EDropdownItem
v-for="(type, key) in types"
v-if="type.label"
:key="key"
:divided="!!type.divided"
:command="type.value">
<div :class="['file-item ' + type.value]">{{$L(type.label)}}</div>
</EDropdownItem>
</EDropdownMenu>
</EDropdown>
@ -105,6 +110,24 @@
</template>
</div>
<Upload
name="files"
ref="fileUpload"
v-show="false"
:action="actionUrl"
:headers="headers"
multiple
:format="uploadFormat"
:accept="uploadAccept"
:show-upload-list="false"
:max-size="maxSize"
:on-progress="handleProgress"
:on-success="handleSuccess"
:on-error="handleError"
:on-format-error="handleFormatError"
:on-exceeded-size="handleMaxSize"
:before-upload="handleBeforeUpload"/>
<!--项目设置-->
<Modal
v-model="shareShow"
@ -159,14 +182,53 @@ export default {
shearId: 0,
types: [
{value: 'folder', name: "目录"},
{value: 'document', name: "文本", divided: true},
{value: 'mind', name: "脑图"},
{value: 'sheet', name: "表格"},
{value: 'flow', name: "流程图"},
{value: 'word', name: " Word 文档", label: "Word", divided: true},
{value: 'excel', name: " Excel 工作表", label: "Excel"},
{value: 'ppt', name: " PPT 演示文稿", label: "PPT"},
{
"value": "folder",
"label": "新建目录",
"name": "目录",
},
{
"value": "upload",
"label": "上传文件",
"name": "上传",
},
{
"value": "document",
"label": "文本",
"name": "文本",
"divided": true
},
{
"value": "sheet",
"label": null,
"name": "表格",
},
{
"value": "flow",
"label": "流程图",
"name": "流程图",
},
{
"value": "mind",
"label": "思维导图",
"name": "导图",
},
{
"value": "word",
"label": "Word 文档",
"name": "Word",
"divided": true
},
{
"value": "excel",
"label": "Excel 工作表",
"name": "Excel",
},
{
"value": "ppt",
"label": "PPT 演示文稿",
"name": "PPT",
}
],
tableHeight: 500,
@ -181,6 +243,11 @@ export default {
editShowNum: 0,
editHeight: 0,
editInfo: {},
uploadIng: 0,
uploadFormat: ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'],
uploadAccept: ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx'].join(","),
maxSize: 204800
}
},
@ -195,7 +262,18 @@ export default {
},
computed: {
...mapState(['userId', 'userInfo', 'files']),
...mapState(['userId', 'userToken', 'userInfo', 'files']),
actionUrl() {
return this.$store.state.method.apiUrl('file/content/upload?pid=' + this.pid)
},
headers() {
return {
fd: this.$store.state.method.getStorageString("userWsFd"),
token: this.userToken,
}
},
shearFile() {
const {files, shearId} = this;
@ -388,7 +466,7 @@ export default {
render: (h, {row}) => {
let type = this.types.find(({value}) => value == row.type);
if (type) {
return h('AutoTip', type.label || type.name);
return h('AutoTip', type.name);
} else {
return h('div', '-')
}
@ -444,6 +522,10 @@ export default {
},
addFile(command) {
if (command == 'upload') {
this.$refs.fileUpload.handleClick();
return;
}
let id = $A.randomString(8);
this.files.push({
_edit: true,
@ -683,7 +765,53 @@ export default {
this.shareLoad--;
$A.modalError(msg)
})
},
/********************文件上传部分************************/
handleProgress() {
//
this.uploadIng++;
},
handleSuccess(res, file) {
//
this.uploadIng--;
if (res.ret === 1) {
this.$store.dispatch("saveFile", res.data);
} else {
$A.modalWarning({
title: '上传失败',
content: '文件 ' + file.name + ' 上传失败,' + res.msg
});
}
},
handleError() {
//
this.uploadIng--;
},
handleFormatError(file) {
//
$A.modalWarning({
title: '文件格式不正确',
content: '文件 ' + file.name + ' 格式不正确,仅支持上传:' + this.uploadFormat.join(',')
});
},
handleMaxSize(file) {
//
$A.modalWarning({
title: '超出文件大小限制',
content: '文件 ' + file.name + ' 太大,不能超过:' + $A.bytesToSize(this.maxSize * 1024) + '。'
});
},
handleBeforeUpload() {
//
return true;
},
}
}
</script>

View File

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

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1625931291710" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5154" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"></style></defs><path d="M209.60960101 98.14049639C187.14116856 98.70748393 169.06378546 116.81383719 168.49679793 139.31123981V880.87297556a39.37045459 39.37045459 0 0 0 12.34542899 28.80462145 40.39268755 40.39268755 0 0 0 28.76737408 12.36612197h603.27885982a39.31665284 39.31665284 0 0 0 28.76737408-12.36198337 40.71549797 40.71549797 0 0 0 12.34542901-28.80876005V331.51587048L620.90317569 98.14049639H209.60960101z" fill="#2171ff" p-id="5155"></path><path d="M854.00126391 331.51587048h-191.93148339c-22.48912543-0.53801736-40.59961731-18.65264783-41.16660483-41.17074341V98.14049639l233.09808822 233.37537409z" fill="#C4EAFF" p-id="5156"></path><path d="M384.41971674 536.88537197h71.97430626v116.68768702a14.12502485 14.12502485 0 0 0 13.74013553 13.7566899h82.22974477a14.12502485 14.12502485 0 0 0 13.74013552-13.7566899v-116.68768702h71.97016768a5.95957685 5.95957685 0 0 0 6.17478379-4.13859506c0.95187686-2.57420611 0.41385952-5.46294544-1.39470654-7.52396576L520.8567793 408.42752063a15.44523667 15.44523667 0 0 0-9.60567909-4.13859504 12.44475529 12.44475529 0 0 0-9.60981767 4.13859504L379.64791667 525.11520768a6.13339783 6.13339783 0 0 0-1.39470653 7.52396577c1.00153999 2.52454297 3.45572686 4.1758424 6.17064519 4.13859503v0.10760349z m298.20646532 178.49760389H339.87187977a13.73599692 13.73599692 0 0 0-12.61029907 6.60519767 13.77738286 13.77738286 0 0 0 0 14.25332131 13.73599692 13.73599692 0 0 0 12.61029905 6.60519767h342.75430231a13.75255131 13.75255131 0 0 0 12.87930775-13.73185833 13.75255131 13.75255131 0 0 0-12.87930775-13.73185832z" fill="#FFFFFF" p-id="5157"></path></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB