From 246b262a76bebb4f53fdec9b6d415f3b5bb26d28 Mon Sep 17 00:00:00 2001 From: jmal Date: Thu, 7 Aug 2025 11:07:02 +0800 Subject: [PATCH] fix: add null checks for refs before invoking methods to prevent potential errors --- src/components/ShowFile/mixins/fileList.js | 4 +++- src/components/ShowFile/mixins/searchFile.js | 2 +- src/components/ShowFile/mixins/shortcutKey.js | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/ShowFile/mixins/fileList.js b/src/components/ShowFile/mixins/fileList.js index f3cd8e2..ef14e20 100644 --- a/src/components/ShowFile/mixins/fileList.js +++ b/src/components/ShowFile/mixins/fileList.js @@ -313,7 +313,9 @@ export default { this.fileList.map((item, index) => { item.index = index }) - this.$refs.fileListTable.reloadData(this.fileList) + if (this.$refs.fileListTable) { + this.$refs.fileListTable.reloadData(this.fileList) + } setTimeout(() => { if (this.$refs.fileListTable) { this.$refs.fileListTable.reloadData(this.fileList) diff --git a/src/components/ShowFile/mixins/searchFile.js b/src/components/ShowFile/mixins/searchFile.js index 1dabe73..bf3945a 100644 --- a/src/components/ShowFile/mixins/searchFile.js +++ b/src/components/ShowFile/mixins/searchFile.js @@ -282,7 +282,7 @@ export default { item.searchOverall = false } this.debounceSearch(this.searchFileName, false) - this.$refs.searchOption.setFilterOption(item) + this.$refs.searchOption && this.$refs.searchOption.setFilterOption(item) this.$nextTick(() => { this._isSuggestionHandledBySelect = false }) diff --git a/src/components/ShowFile/mixins/shortcutKey.js b/src/components/ShowFile/mixins/shortcutKey.js index d6e2ea4..6b8c365 100644 --- a/src/components/ShowFile/mixins/shortcutKey.js +++ b/src/components/ShowFile/mixins/shortcutKey.js @@ -50,7 +50,7 @@ export default { event.stopPropagation() } // Del - if (keyCode === 8 && !this.inputting && this.selectRowData.length > 0 && !checkPreviewVisible) { + if (keyCode === 46 && !this.inputting && this.selectRowData.length > 0 && !checkPreviewVisible) { this.removeOperation() event.preventDefault() event.stopPropagation() @@ -91,7 +91,9 @@ export default { } // ctrl + P / cmd + P if (isCmd && keyCode === 80 && !checkPreviewVisible) { - this.$refs.searchInput.focus() + if (this.$refs.searchInput) { + this.$refs.searchInput.focus() + } event.preventDefault() event.stopPropagation() }