mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-07 13:18:16 +00:00
perf: 文件共享成员支持分享链接
This commit is contained in:
parent
f403014ef6
commit
775fdec0b8
@ -853,10 +853,7 @@ class FileController extends AbstractController
|
|||||||
// 取消共享
|
// 取消共享
|
||||||
$action = "delete";
|
$action = "delete";
|
||||||
foreach ($userids as $userid) {
|
foreach ($userids as $userid) {
|
||||||
if (FileUser::where([
|
if (FileUser::deleteFileUser($file->id, $userid)) {
|
||||||
'file_id' => $file->id,
|
|
||||||
'userid' => $userid,
|
|
||||||
])->delete()) {
|
|
||||||
$array[] = $userid;
|
$array[] = $userid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -864,7 +861,7 @@ class FileController extends AbstractController
|
|||||||
// 设置共享
|
// 设置共享
|
||||||
$action = "update";
|
$action = "update";
|
||||||
if ($force === 0) {
|
if ($force === 0) {
|
||||||
if (File::where('pids', 'like', ",{$file->id},")->whereShare(1)->exists()) {
|
if (File::where("pids", "like", "%,{$file->id},%")->whereShare(1)->exists()) {
|
||||||
return Base::retError('此文件夹内已有共享文件夹', [], -3001);
|
return Base::retError('此文件夹内已有共享文件夹', [], -3001);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -913,16 +910,10 @@ class FileController extends AbstractController
|
|||||||
if ($file->userid == $user->userid) {
|
if ($file->userid == $user->userid) {
|
||||||
return Base::retError('不能退出自己共享的文件');
|
return Base::retError('不能退出自己共享的文件');
|
||||||
}
|
}
|
||||||
if (FileUser::where([
|
if (FileUser::whereFileId($file->id)->whereUserid(0)->exists()) {
|
||||||
'file_id' => $file->id,
|
|
||||||
'userid' => 0,
|
|
||||||
])->exists()) {
|
|
||||||
return Base::retError('无法退出共享所有人的文件或文件夹');
|
return Base::retError('无法退出共享所有人的文件或文件夹');
|
||||||
}
|
}
|
||||||
FileUser::where([
|
FileUser::deleteFileUser($file->id, $user->userid);
|
||||||
'file_id' => $file->id,
|
|
||||||
'userid' => $user->userid,
|
|
||||||
])->delete();
|
|
||||||
//
|
//
|
||||||
$file->updataShare();
|
$file->updataShare();
|
||||||
return Base::retSuccess("退出成功");
|
return Base::retSuccess("退出成功");
|
||||||
@ -947,20 +938,21 @@ class FileController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function link()
|
public function link()
|
||||||
{
|
{
|
||||||
User::auth();
|
$user = User::auth();
|
||||||
//
|
//
|
||||||
$id = intval(Request::input('id'));
|
$id = intval(Request::input('id'));
|
||||||
$refresh = Request::input('refresh', 'no');
|
$refresh = Request::input('refresh', 'no');
|
||||||
//
|
//
|
||||||
$file = File::permissionFind($id, 1000);
|
$file = File::permissionFind($id);
|
||||||
if ($file->type == 'folder') {
|
if ($file->type == 'folder') {
|
||||||
return Base::retError('文件夹暂不支持此功能');
|
return Base::retError('文件夹暂不支持此功能');
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
$fileLink = FileLink::whereFileId($file->id)->first();
|
$fileLink = FileLink::whereFileId($file->id)->whereUserid($user->userid)->first();
|
||||||
if (empty($fileLink)) {
|
if (empty($fileLink)) {
|
||||||
$fileLink = FileLink::createInstance([
|
$fileLink = FileLink::createInstance([
|
||||||
'file_id' => $file->id,
|
'file_id' => $file->id,
|
||||||
|
'userid' => $user->userid,
|
||||||
'code' => Base::generatePassword(64),
|
'code' => Base::generatePassword(64),
|
||||||
]);
|
]);
|
||||||
$fileLink->save();
|
$fileLink->save();
|
||||||
|
|||||||
@ -168,7 +168,7 @@ class File extends AbstractModel
|
|||||||
$this->share = $share;
|
$this->share = $share;
|
||||||
$this->save();
|
$this->save();
|
||||||
if ($share === 0) {
|
if ($share === 0) {
|
||||||
FileUser::whereFileId($this->id)->delete();
|
FileUser::deleteFileAll($this->id, $this->userid);
|
||||||
}
|
}
|
||||||
$list = self::wherePid($this->id)->get();
|
$list = self::wherePid($this->id)->get();
|
||||||
if ($list->isNotEmpty()) {
|
if ($list->isNotEmpty()) {
|
||||||
@ -224,8 +224,7 @@ class File extends AbstractModel
|
|||||||
AbstractModel::transaction(function () {
|
AbstractModel::transaction(function () {
|
||||||
$this->delete();
|
$this->delete();
|
||||||
$this->pushMsg('delete');
|
$this->pushMsg('delete');
|
||||||
FileLink::whereFileId($this->id)->delete();
|
FileUser::deleteFileAll($this->id);
|
||||||
FileUser::whereFileId($this->id)->delete();
|
|
||||||
FileContent::whereFid($this->id)->delete();
|
FileContent::whereFid($this->id)->delete();
|
||||||
$list = self::wherePid($this->id)->get();
|
$list = self::wherePid($this->id)->get();
|
||||||
if ($list->isNotEmpty()) {
|
if ($list->isNotEmpty()) {
|
||||||
|
|||||||
@ -25,4 +25,34 @@ namespace App\Models;
|
|||||||
*/
|
*/
|
||||||
class FileUser extends AbstractModel
|
class FileUser extends AbstractModel
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 删除所有共享成员(同时删除成员分享的链接)
|
||||||
|
* @param $file_id
|
||||||
|
* @param int $retain_link_userid 保留指定会员的链接
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function deleteFileAll($file_id, $retain_link_userid = 0)
|
||||||
|
{
|
||||||
|
return AbstractModel::transaction(function() use ($retain_link_userid, $file_id) {
|
||||||
|
if ($retain_link_userid > 0) {
|
||||||
|
FileLink::whereFileId($file_id)->where('userid', '!=', $retain_link_userid)->delete();
|
||||||
|
} else {
|
||||||
|
FileLink::whereFileId($file_id)->delete();
|
||||||
|
}
|
||||||
|
FileUser::whereFileId($file_id)->delete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 删除指定共享成员(同时删除成员分享的链接)
|
||||||
|
* @param $file_id
|
||||||
|
* @param $userid
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function deleteFileUser($file_id, $userid)
|
||||||
|
{
|
||||||
|
return AbstractModel::transaction(function() use ($userid, $file_id) {
|
||||||
|
FileLink::whereFileId($file_id)->whereUserid($userid)->delete();
|
||||||
|
return self::whereFileId($file_id)->whereUserid($userid)->delete();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddFileLinksUserid extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('file_links', function (Blueprint $table) {
|
||||||
|
if (!Schema::hasColumn('file_links', 'userid')) {
|
||||||
|
$table->integer('userid')->nullable()->default(0)->after('code')->comment('会员ID');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('file_links', function (Blueprint $table) {
|
||||||
|
$table->dropColumn("userid");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -146,6 +146,7 @@
|
|||||||
<template v-if="contextMenuItem.id">
|
<template v-if="contextMenuItem.id">
|
||||||
<DropdownItem @click.native="handleContextClick('open')">{{$L('打开')}}</DropdownItem>
|
<DropdownItem @click.native="handleContextClick('open')">{{$L('打开')}}</DropdownItem>
|
||||||
<DropdownItem @click.native="handleContextClick('select')">{{$L(selectIds.includes(contextMenuItem.id) ? '取消选择' : '选择')}}</DropdownItem>
|
<DropdownItem @click.native="handleContextClick('select')">{{$L(selectIds.includes(contextMenuItem.id) ? '取消选择' : '选择')}}</DropdownItem>
|
||||||
|
|
||||||
<Dropdown placement="right-start" transfer>
|
<Dropdown placement="right-start" transfer>
|
||||||
<DropdownItem divided>
|
<DropdownItem divided>
|
||||||
<div class="arrow-forward-item">{{$L('新建')}}<Icon type="ios-arrow-forward"></Icon></div>
|
<div class="arrow-forward-item">{{$L('新建')}}<Icon type="ios-arrow-forward"></Icon></div>
|
||||||
@ -161,17 +162,16 @@
|
|||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
|
||||||
<DropdownItem @click.native="handleContextClick('rename')" divided>{{$L('重命名')}}</DropdownItem>
|
<DropdownItem @click.native="handleContextClick('rename')" divided>{{$L('重命名')}}</DropdownItem>
|
||||||
<DropdownItem @click.native="handleContextClick('copy')" :disabled="contextMenuItem.type == 'folder'">{{$L('复制')}}</DropdownItem>
|
<DropdownItem @click.native="handleContextClick('copy')" :disabled="contextMenuItem.type == 'folder'">{{$L('复制')}}</DropdownItem>
|
||||||
<DropdownItem @click.native="handleContextClick('shear')" :disabled="contextMenuItem.userid != userId">{{$L('剪切')}}</DropdownItem>
|
<DropdownItem @click.native="handleContextClick('shear')" :disabled="contextMenuItem.userid != userId">{{$L('剪切')}}</DropdownItem>
|
||||||
<template v-if="contextMenuItem.userid == userId">
|
|
||||||
<DropdownItem @click.native="handleContextClick('share')" divided>{{$L('共享')}}</DropdownItem>
|
<DropdownItem v-if="contextMenuItem.userid == userId" @click.native="handleContextClick('share')" divided>{{$L('共享')}}</DropdownItem>
|
||||||
<DropdownItem @click.native="handleContextClick('link')" :disabled="contextMenuItem.type == 'folder'">{{$L('链接')}}</DropdownItem>
|
<DropdownItem v-else-if="contextMenuItem.share" @click.native="handleContextClick('outshare')" divided>{{$L('退出共享')}}</DropdownItem>
|
||||||
</template>
|
<DropdownItem @click.native="handleContextClick('link')" :divided="contextMenuItem.userid != userId && !contextMenuItem.share" :disabled="contextMenuItem.type == 'folder'">{{$L('链接')}}</DropdownItem>
|
||||||
<template v-else-if="contextMenuItem.share">
|
|
||||||
<DropdownItem @click.native="handleContextClick('outshare')" divided>{{$L('退出共享')}}</DropdownItem>
|
|
||||||
</template>
|
|
||||||
<DropdownItem @click.native="handleContextClick('download')" :disabled="contextMenuItem.ext == ''">{{$L('下载')}}</DropdownItem>
|
<DropdownItem @click.native="handleContextClick('download')" :disabled="contextMenuItem.ext == ''">{{$L('下载')}}</DropdownItem>
|
||||||
|
|
||||||
<DropdownItem @click.native="handleContextClick('delete')" divided style="color:red">{{$L('删除')}}</DropdownItem>
|
<DropdownItem @click.native="handleContextClick('delete')" divided style="color:red">{{$L('删除')}}</DropdownItem>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
@ -722,11 +722,6 @@ export default {
|
|||||||
size: 20
|
size: 20
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
if (row.permission == 0) {
|
|
||||||
iconArray.push(h('span', {
|
|
||||||
class: 'permission',
|
|
||||||
}, this.$L('只读')))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
iconArray.push(h('i', {
|
iconArray.push(h('i', {
|
||||||
class: 'taskfont',
|
class: 'taskfont',
|
||||||
@ -1304,7 +1299,7 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
upShare(item) {
|
upShare(item, force = false) {
|
||||||
if (item.loading === true) {
|
if (item.loading === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1316,6 +1311,7 @@ export default {
|
|||||||
id: this.shareInfo.id,
|
id: this.shareInfo.id,
|
||||||
userids: [item.userid],
|
userids: [item.userid],
|
||||||
permission: item.permission,
|
permission: item.permission,
|
||||||
|
force: force === true ? 1 : 0
|
||||||
},
|
},
|
||||||
}).then(({data, msg}) => {
|
}).then(({data, msg}) => {
|
||||||
item.loading = false;
|
item.loading = false;
|
||||||
@ -1330,15 +1326,18 @@ export default {
|
|||||||
}
|
}
|
||||||
}).catch(({ret, msg}) => {
|
}).catch(({ret, msg}) => {
|
||||||
item.loading = false;
|
item.loading = false;
|
||||||
item.permission = item._permission;
|
|
||||||
if (ret === -3001) {
|
if (ret === -3001) {
|
||||||
$A.modalConfirm({
|
$A.modalConfirm({
|
||||||
content: '此文件夹内已有共享文件夹,子文件的共享状态将被取消,是否继续?',
|
content: '此文件夹内已有共享文件夹,子文件的共享状态将被取消,是否继续?',
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
this.onShare(true)
|
this.upShare(item, true)
|
||||||
|
},
|
||||||
|
onCancel: () => {
|
||||||
|
item.permission = item._permission;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
item.permission = item._permission;
|
||||||
$A.modalError(msg, force === true ? 301 : 0)
|
$A.modalError(msg, force === true ? 301 : 0)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user