From 06815b4b8c1691b6e67500bc6e0e3c3860b5ede4 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 9 Mar 2023 13:26:20 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=96=87=E4=BB=B6=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=98=BE=E7=A4=BA=E6=96=87=E4=BB=B6=E8=8F=9C?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/FileController.php | 45 +++++++++++------ .../pages/manage/components/DialogWrapper.vue | 50 ++++++++++++++++++- resources/assets/js/pages/manage/file.vue | 10 ++-- resources/assets/js/store/actions.js | 11 ++-- resources/assets/js/store/state.js | 1 + 5 files changed, 93 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index ef6879241..287b4dc68 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -164,6 +164,7 @@ class FileController extends AbstractController * @apiGroup file * @apiName search * + * @apiParam {String} [link] 通过分享地址搜索(如:https://t.hitosea.com/single/file/ODcwOCwzOSxpa0JBS2lmVQ==) * @apiParam {String} [key] 关键词 * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) @@ -174,28 +175,42 @@ class FileController extends AbstractController { $user = User::auth(); // + $link = trim(Request::input('link')); $key = trim(Request::input('key')); + $id = 0; + $take = 50; + if (preg_match("/\/single\/file\/(.*?)$/i", $link, $match)) { + $id = intval(FileLink::whereCode($match[1])->value('file_id')); + $take = 1; + } // 搜索自己的 $builder = File::whereUserid($user->userid); + if ($id) { + $builder->where("id", $id); + } if ($key) { $builder->where("name", "like", "%{$key}%"); } - $array = $builder->take(50)->get()->toArray(); + $array = $builder->take($take)->get()->toArray(); // 搜索共享的 - $take = 50 - count($array); - if ($take > 0 && $key) { - $list = File::where("name", "like", "%{$key}%") - ->whereIn('pshare', function ($queryA) use ($user) { - $queryA->select('files.id') - ->from('files') - ->join('file_users', 'files.id', '=', 'file_users.file_id') - ->where('files.userid', '!=', $user->userid) - ->where(function ($queryB) use ($user) { - $queryB->whereIn('file_users.userid', [0, $user->userid]); - }); - }) - ->take($take) - ->get(); + $take = $take - count($array); + if ($take > 0 && ($id || $key)) { + $builder = File::whereIn('pshare', function ($queryA) use ($user) { + $queryA->select('files.id') + ->from('files') + ->join('file_users', 'files.id', '=', 'file_users.file_id') + ->where('files.userid', '!=', $user->userid) + ->where(function ($queryB) use ($user) { + $queryB->whereIn('file_users.userid', [0, $user->userid]); + }); + }); + if ($id) { + $builder->where("id", $id); + } + if ($key) { + $builder->where("name", "like", "%{$key}%"); + } + $list = $builder->take($take)->get(); if ($list->isNotEmpty()) { foreach ($list as $file) { $temp = $file->toArray(); diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index a4a655354..e28f90ad5 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -643,7 +643,8 @@ export default { 'wsOpenNum', 'touchBackInProgress', 'dialogIns', - 'cacheUserBasic' + 'cacheUserBasic', + 'fileLinks' ]), ...mapGetters(['isLoad']), @@ -2006,6 +2007,9 @@ export default { value: $A.rightDelete(event.target.currentSrc, '_thumb.jpg'), }) } else if (event.target.nodeName === 'A') { + if (event.target.classList.contains("mention") && event.target.classList.contains("file")) { + this.findOperateFile(this.operateItem.id, event.target.href) + } this.operateCopys.push({ type: 'link', icon: '', @@ -2147,7 +2151,10 @@ export default { url: value, token: false }) + break; + case 'filepos': + this.goForward({name: 'manage-file', params: value}); break; case 'link': @@ -2552,6 +2559,47 @@ export default { }) }, + findOperateFile(msgId, link) { + const file = this.fileLinks.find(item => item.link === link) + if (file) { + this.addFileMenu(msgId, file) + return + } + this.$store.dispatch("searchFiles", { + link + }).then(({data}) => { + if (data.length === 1) { + const file = { + link, + id: data[0].id, + pid: data[0].pid, + } + this.fileLinks.push(file) + this.addFileMenu(msgId, file) + } + }).catch(_ => {}) + }, + + addFileMenu(msgId, data) { + if (this.operateItem.id != msgId) { + return + } + if (this.operateCopys.findIndex(item => item.type === 'filepos') !== -1) { + return + } + const index = Math.max(0, this.operateCopys.findIndex(item => item.type === 'link') - 1) + this.operateCopys.splice(index, 0, { + type: 'filepos', + icon: '', + label: '显示文件', + value: { + folderId: data.pid, + fileId: null, + shakeId: data.id + }, + }) + }, + getBase64Image(url) { return new Promise(resolve => { let canvas = document.createElement('CANVAS'), diff --git a/resources/assets/js/pages/manage/file.vue b/resources/assets/js/pages/manage/file.vue index 7f60df30d..823e5246f 100644 --- a/resources/assets/js/pages/manage/file.vue +++ b/resources/assets/js/pages/manage/file.vue @@ -927,6 +927,7 @@ export default { this.$store.dispatch("getFiles", this.pid).then(async () => { this.loadIng--; this.openFileJudge() + this.shakeFile(this.$route.params.shakeId); await $A.IDBSet("fileFolderId", this.pid) }).catch(({msg}) => { this.loadIng--; @@ -997,9 +998,9 @@ export default { }) }, - browseFolder(id) { + browseFolder(id, shakeId = null) { if (id > 0) { - this.goForward({name: 'manage-file', params: {folderId: id, fileId: null}}); + this.goForward({name: 'manage-file', params: {folderId: id, fileId: null, shakeId}}); } else { this.searchKey = ''; this.goForward({name: 'manage-file'}); @@ -1152,7 +1153,7 @@ export default { case 'upperFolder': this.searchKey = ''; - this.browseFolder(item.pid) + this.browseFolder(item.pid, item.id) break; case 'select': @@ -1624,6 +1625,9 @@ export default { }, shakeFile(fileId) { + if (!fileId) { + return + } this.$nextTick(_ => { const dom = $A(this.$el).find(`[data-id="${fileId}"]`) if (dom.length > 0) { diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 535f81d23..1f19c7a33 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -747,16 +747,17 @@ export default { * 搜索文件 * @param state * @param dispatch - * @param key + * @param data * @returns {Promise} */ - searchFiles({state, dispatch}, key) { + searchFiles({state, dispatch}, data) { + if (!$A.isJson(data)) { + data = {key: data} + } return new Promise(function (resolve, reject) { dispatch("call", { url: 'file/search', - data: { - key, - }, + data, }).then((result) => { dispatch("saveFile", result.data); resolve(result) diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index b539ce976..e1e886533 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -88,6 +88,7 @@ export default { // 文件 fileLists: [], + fileLinks: [], // 项目任务 projectId: 0,