文件共享
This commit is contained in:
parent
e5ccdee472
commit
6991e01201
@ -113,10 +113,8 @@ class FileController extends AbstractController
|
||||
//
|
||||
if ($id > 0) {
|
||||
// 修改
|
||||
$file = File::whereUserid($user->userid)->whereId($id)->first();
|
||||
if (empty($file)) {
|
||||
return Base::retError('文件不存在或已被删除');
|
||||
}
|
||||
$file = File::allowFind($id);
|
||||
//
|
||||
$file->name = $name;
|
||||
$file->save();
|
||||
return Base::retSuccess('修改成功', $file);
|
||||
@ -132,20 +130,25 @@ class FileController extends AbstractController
|
||||
return Base::retError('类型错误');
|
||||
}
|
||||
//
|
||||
$userid = $user->userid;
|
||||
if ($pid > 0) {
|
||||
if (!File::whereUserid($user->userid)->whereId($pid)->exists()) {
|
||||
return Base::retError('参数错误');
|
||||
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个文件或文件夹');
|
||||
}
|
||||
}
|
||||
if (File::whereUserid($user->userid)->wherePid($pid)->count() >= 300) {
|
||||
return Base::retError('每个文件夹里最多只能创建300个文件或文件夹');
|
||||
}
|
||||
// 开始创建
|
||||
$file = File::createInstance([
|
||||
'pid' => $pid,
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
'userid' => $user->userid,
|
||||
'userid' => $userid,
|
||||
'created_id' => $user->userid,
|
||||
]);
|
||||
$file->save();
|
||||
//
|
||||
@ -165,10 +168,13 @@ class FileController extends AbstractController
|
||||
//
|
||||
$id = intval(Request::input('id'));
|
||||
//
|
||||
$row = File::whereUserid($user->userid)->whereId($id)->first();
|
||||
if (empty($row)) {
|
||||
return Base::retError('文件不存在或已被删除');
|
||||
$row = File::allowFind($id);
|
||||
//
|
||||
$userid = $user->userid;
|
||||
if ($row->pid > 0) {
|
||||
$userid = intval(File::whereId($row->pid)->value('userid'));
|
||||
}
|
||||
//
|
||||
if ($row->type == 'folder') {
|
||||
return Base::retError('不支持复制文件夹');
|
||||
}
|
||||
@ -180,7 +186,8 @@ class FileController extends AbstractController
|
||||
'pid' => $row->pid,
|
||||
'name' => $name,
|
||||
'type' => $row->type,
|
||||
'userid' => $user->userid,
|
||||
'userid' => $userid,
|
||||
'created_id' => $user->userid,
|
||||
]);
|
||||
$file->save();
|
||||
//
|
||||
@ -201,10 +208,13 @@ class FileController extends AbstractController
|
||||
$id = intval(Request::input('id'));
|
||||
$pid = intval(Request::input('pid'));
|
||||
//
|
||||
$file = File::whereUserid($user->userid)->whereId($id)->first();
|
||||
$file = File::whereId($id)->first();
|
||||
if (empty($file)) {
|
||||
return Base::retError('文件不存在或已被删除');
|
||||
}
|
||||
if ($file->userid != $user->userid) {
|
||||
return Base::retError('仅限所有者操作');
|
||||
}
|
||||
//
|
||||
if ($pid > 0) {
|
||||
if (!File::whereUserid($user->userid)->whereId($pid)->exists()) {
|
||||
@ -233,14 +243,9 @@ class FileController extends AbstractController
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$user = User::auth();
|
||||
//
|
||||
$id = intval(Request::input('id'));
|
||||
//
|
||||
$file = File::whereUserid($user->userid)->whereId($id)->first();
|
||||
if (empty($file)) {
|
||||
return Base::retError('文件不存在或已被删除');
|
||||
}
|
||||
$file = File::allowFind($id);
|
||||
$file->deleteFile();
|
||||
return Base::retSuccess('删除成功', $file);
|
||||
}
|
||||
@ -256,10 +261,7 @@ class FileController extends AbstractController
|
||||
//
|
||||
$id = intval(Request::input('id'));
|
||||
//
|
||||
$file = File::whereUserid($user->userid)->whereId($id)->first();
|
||||
if (empty($file)) {
|
||||
return Base::retError('文件不存在或已被删除');
|
||||
}
|
||||
$file = File::allowFind($id);
|
||||
//
|
||||
$content = FileContent::whereFid($file->id)->orderByDesc('id')->first();
|
||||
if (empty($content)) {
|
||||
@ -289,10 +291,7 @@ class FileController extends AbstractController
|
||||
$id = Base::getPostInt('id');
|
||||
$content = Base::getPostValue('content');
|
||||
//
|
||||
$file = File::whereUserid($user->userid)->whereId($id)->first();
|
||||
if (empty($file)) {
|
||||
return Base::retError('文件不存在或已被删除');
|
||||
}
|
||||
$file = File::allowFind($id);
|
||||
//
|
||||
$text = '';
|
||||
if ($file->type == 'document') {
|
||||
@ -346,7 +345,6 @@ class FileController extends AbstractController
|
||||
if (empty($file)) {
|
||||
return Base::retError('文件不存在或已被删除');
|
||||
}
|
||||
//
|
||||
if ($file->userid != $user->userid) {
|
||||
return Base::retError('仅限所有者操作');
|
||||
}
|
||||
@ -366,7 +364,7 @@ class FileController extends AbstractController
|
||||
* @apiParam {String} action 动作
|
||||
* - share: 设置共享
|
||||
* - unshare: 取消共享
|
||||
* @apiParam {Number} [share] 共享方式
|
||||
* @apiParam {Number} [share] 共享对象
|
||||
* - 1: 共享给所有人
|
||||
* - 2: 共享给指定成员
|
||||
* @apiParam {Array} [userids] 共享成员,格式: [userid1, userid2, userid3]
|
||||
@ -384,7 +382,6 @@ class FileController extends AbstractController
|
||||
if (empty($file)) {
|
||||
return Base::retError('文件不存在或已被删除');
|
||||
}
|
||||
//
|
||||
if ($file->userid != $user->userid) {
|
||||
return Base::retError('仅限所有者操作');
|
||||
}
|
||||
@ -400,7 +397,7 @@ class FileController extends AbstractController
|
||||
} else {
|
||||
// 设置共享
|
||||
if (!in_array($share, [1, 2])) {
|
||||
return Base::retError('请选择共享类型');
|
||||
return Base::retError('请选择共享对象');
|
||||
}
|
||||
$file->setShare($share);
|
||||
if ($share == 2) {
|
||||
|
@ -154,4 +154,20 @@ class File extends AbstractModel
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件并检测权限
|
||||
* @param $id
|
||||
* @param null $noExistTis
|
||||
* @return File
|
||||
*/
|
||||
public static function allowFind($id, $noExistTis = null)
|
||||
{
|
||||
$file = File::find($id);
|
||||
if (empty($file)) {
|
||||
throw new ApiException($noExistTis ?: '文件不存在或已被删除');
|
||||
}
|
||||
$file->chackAllow(User::userid());
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
<div class="file-head">
|
||||
<div class="file-nav">
|
||||
<h1>{{$L('文件')}}</h1>
|
||||
<div v-if="loadIng == 0" class="file-refresh" @click="getFileList"><i class="taskfont"></i></div>
|
||||
</div>
|
||||
<div :class="['file-search', searchKey ? 'has-value' : '']">
|
||||
<Input v-model="searchKey" suffix="ios-search" @on-change="onSearchChange" :placeholder="$L('搜索名称')"/>
|
||||
@ -70,18 +71,12 @@
|
||||
@command="dropFile(item, $event)">
|
||||
<Icon @click.stop="" type="ios-more" />
|
||||
<EDropdownMenu slot="dropdown">
|
||||
<template v-if="item.userid == userId">
|
||||
<EDropdownItem command="open">{{$L('打开')}}</EDropdownItem>
|
||||
<EDropdownItem command="rename" divided>{{$L('重命名')}}</EDropdownItem>
|
||||
<EDropdownItem command="copy" :disabled="item.type=='folder'">{{$L('复制')}}</EDropdownItem>
|
||||
<EDropdownItem command="shear">{{$L('剪切')}}</EDropdownItem>
|
||||
<EDropdownItem command="share" divided>{{$L('共享')}}</EDropdownItem>
|
||||
<EDropdownItem command="delete" divided style="color:red">{{$L('删除')}}</EDropdownItem>
|
||||
</template>
|
||||
<template v-else>
|
||||
<EDropdownItem command="open">{{$L('打开')}}</EDropdownItem>
|
||||
<EDropdownItem command="copy" :disabled="item.type=='folder'">{{$L('复制')}}</EDropdownItem>
|
||||
</template>
|
||||
<EDropdownItem command="open">{{$L('打开')}}</EDropdownItem>
|
||||
<EDropdownItem command="rename" divided>{{$L('重命名')}}</EDropdownItem>
|
||||
<EDropdownItem command="copy" :disabled="item.type=='folder'">{{$L('复制')}}</EDropdownItem>
|
||||
<EDropdownItem command="shear" :disabled="item.userid != userId">{{$L('剪切')}}</EDropdownItem>
|
||||
<EDropdownItem command="share" :disabled="item.userid != userId" divided>{{$L('共享')}}</EDropdownItem>
|
||||
<EDropdownItem command="delete" divided style="color:red">{{$L('删除')}}</EDropdownItem>
|
||||
</EDropdownMenu>
|
||||
</EDropdown>
|
||||
<div class="file-icon">
|
||||
@ -110,7 +105,7 @@
|
||||
:title="$L('共享设置')"
|
||||
:mask-closable="false">
|
||||
<Form ref="addProject" :model="shareInfo" label-width="auto" @submit.native.prevent>
|
||||
<FormItem prop="type" :label="$L('共享类型')">
|
||||
<FormItem prop="type" :label="$L('共享对象')">
|
||||
<RadioGroup v-model="shareInfo.share">
|
||||
<Radio :label="1">{{$L('所有人')}}</Radio>
|
||||
<Radio :label="2">{{$L('指定成员')}}</Radio>
|
||||
@ -229,14 +224,7 @@ export default {
|
||||
watch: {
|
||||
pid: {
|
||||
handler() {
|
||||
this.loadIng++;
|
||||
this.$store.dispatch("getFiles", this.pid).then(() => {
|
||||
this.loadIng--;
|
||||
this.$store.state.method.setStorage("fileOpenPid", this.pid)
|
||||
}).catch(({msg}) => {
|
||||
$A.modalError(msg);
|
||||
this.loadIng--;
|
||||
});
|
||||
this.getFileList();
|
||||
},
|
||||
immediate: true
|
||||
},
|
||||
@ -373,6 +361,17 @@ export default {
|
||||
]
|
||||
},
|
||||
|
||||
getFileList() {
|
||||
this.loadIng++;
|
||||
this.$store.dispatch("getFiles", this.pid).then(() => {
|
||||
this.loadIng--;
|
||||
this.$store.state.method.setStorage("fileOpenPid", this.pid)
|
||||
}).catch(({msg}) => {
|
||||
$A.modalError(msg);
|
||||
this.loadIng--;
|
||||
});
|
||||
},
|
||||
|
||||
addFile(command) {
|
||||
let id = $A.randomString(8);
|
||||
this.files.push({
|
||||
@ -595,7 +594,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
if (![1, 2].includes(this.shareInfo.share)) {
|
||||
$A.messageWarning("请选择共享类型")
|
||||
$A.messageWarning("请选择共享对象")
|
||||
return;
|
||||
}
|
||||
this.shareLoad++;
|
||||
|
26
resources/assets/sass/pages/page-file.scss
vendored
26
resources/assets/sass/pages/page-file.scss
vendored
@ -23,6 +23,19 @@
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.file-refresh {
|
||||
display: none;
|
||||
cursor: pointer;
|
||||
margin-left: 12px;
|
||||
> i {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
&:hover {
|
||||
.file-refresh {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
.file-search {
|
||||
flex-shrink: 0;
|
||||
@ -106,7 +119,7 @@
|
||||
}
|
||||
}
|
||||
.nav-load {
|
||||
margin-left: 4px;
|
||||
margin-left: 8px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
display: flex;
|
||||
@ -117,6 +130,9 @@
|
||||
height: 12px;
|
||||
}
|
||||
}
|
||||
.nav-refresh {
|
||||
margin-left: 8px;
|
||||
}
|
||||
.ivu-btn {
|
||||
font-size: 12px;
|
||||
margin-left: 12px;
|
||||
@ -332,8 +348,8 @@
|
||||
.taskfont {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
bottom: -1px;
|
||||
font-size: 16px;
|
||||
bottom: -2px;
|
||||
font-size: 18px;
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
@ -343,8 +359,8 @@
|
||||
&.folder .file-icon {
|
||||
background-image: url("../images/file/folder.svg");
|
||||
.taskfont {
|
||||
right: 7px;
|
||||
bottom: 3px;
|
||||
right: 6px;
|
||||
bottom: 2px;
|
||||
}
|
||||
}
|
||||
&.document .file-icon {
|
||||
|
Loading…
x
Reference in New Issue
Block a user