diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index e1e806a70..5064fe1c4 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -2,8 +2,10 @@ namespace App\Http\Controllers\Api; +use App\Models\AbstractModel; use App\Models\File; use App\Models\FileContent; +use App\Models\FileLink; use App\Models\ProjectTask; use App\Models\ProjectTaskFile; use App\Models\User; @@ -781,6 +783,77 @@ class DialogController extends AbstractController } } + /** + * @api {get} api/dialog/msg/sendfileid 15. 通过文件ID发送文件 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName msg__sendfileid + * + * @apiParam {Number} file_id 消息ID + * @apiParam {Array} dialogids 转发给的对话ID + * @apiParam {Array} userids 转发给的成员ID + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function msg__sendfileid() + { + $user = User::auth(); + // + $file_id = intval(Request::input("file_id")); + $dialogids = Request::input('dialogids'); + $userids = Request::input('userids'); + // + if (empty($dialogids) && empty($userids)) { + return Base::retError("请选择转发对话或成员"); + } + // + $file = File::permissionFind($file_id); + $fileLink = $file->getShareLink($user->userid); + $fileMsg = "~{$file->getNameAndExt()}"; + // + $sender = $user->userid; + return AbstractModel::transaction(function() use ($sender, $fileMsg, $userids, $dialogids) { + $msgs = []; + $already = []; + if ($dialogids) { + if (!is_array($dialogids)) { + $dialogids = [$dialogids]; + } + foreach ($dialogids as $dialogid) { + $res = WebSocketDialogMsg::sendMsg(null, $dialogid, 'text', ['text' => $fileMsg], $sender); + if (Base::isSuccess($res)) { + $msgs[] = $res['data']; + $already[] = $dialogid; + } + } + } + if ($userids) { + if (!is_array($userids)) { + $userids = [$userids]; + } + foreach ($userids as $userid) { + if (!User::whereUserid($userid)->exists()) { + continue; + } + $dialog = WebSocketDialog::checkUserDialog($sender, $userid); + if ($dialog && !in_array($dialog->id, $already)) { + $res = WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $fileMsg], $sender); + if (Base::isSuccess($res)) { + $msgs[] = $res['data']; + } + } + } + } + return Base::retSuccess('发送成功', [ + 'msgs' => $msgs + ]); + }); + } + /** * @api {get} api/dialog/msg/readlist 16. 获取消息阅读情况 * diff --git a/resources/assets/js/pages/manage/file.vue b/resources/assets/js/pages/manage/file.vue index 517c5f3ce..3c6810f6c 100644 --- a/resources/assets/js/pages/manage/file.vue +++ b/resources/assets/js/pages/manage/file.vue @@ -185,6 +185,7 @@ {{$L('共享')}} {{$L('退出共享')}} + {{$L('发送')}} {{$L('链接')}} {{$L('下载')}} @@ -314,6 +315,18 @@ + + + + + {{$L('取消')}} + {{$L('发送文件')}} + + + import('./components/FilePreview'); const FileContent = () => import('./components/FileContent'); export default { - components: {PreviewImage, FilePreview, DrawerOverlay, UserInput, FileContent}, + components: {DialogSelect, PreviewImage, FilePreview, DrawerOverlay, UserInput, FileContent}, directives: {longpress}, data() { return { @@ -453,6 +467,13 @@ export default { shareList: [], shareLoad: 0, + sendShow: false, + sendLoad: false, + sendData: { + dialogids: [], + userids: [], + }, + linkShow: false, linkData: {}, linkLoad: 0, @@ -1142,6 +1163,15 @@ export default { this.shearIds = $A.cloneJSON(this.selectIds); break; + case 'send': + this.sendData = { + dialogids: [], + userids: [], + file_id: item.id + }; + this.sendShow = true; + break; + case 'share': this.shareInfo = { id: item.id, @@ -1204,6 +1234,27 @@ export default { } }, + onSendFile() { + if ($A.arrayLength(this.sendData.dialogids) === 0 && $A.arrayLength(this.sendData.userids) === 0) { + $A.messageWarning("请选择转发对话或成员"); + return + } + this.sendLoad = true; + this.$store.dispatch("call", { + url: 'dialog/msg/sendfileid', + data: this.sendData + }).then(({data, msg}) => { + this.sendShow = false; + this.$store.dispatch("saveDialogMsg", data.msgs); + this.$store.dispatch("updateDialogLastMsg", data.msgs); + $A.messageSuccess(msg); + }).catch(({msg}) => { + $A.modalError(msg); + }).finally(_ => { + this.sendLoad = false; + }); + }, + linkGet(refresh) { this.linkLoad++; this.$store.dispatch("call", {