Skip to content

Commit 262e5f2

Browse files
committed
Added a button to cancel the search; fixed some issues, I believe it is perfect
1 parent 4b709f1 commit 262e5f2

File tree

5 files changed

+67
-18
lines changed

5 files changed

+67
-18
lines changed

src/renderer/components/emptyStatus.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<div class="empty-text">
1010
{{ text }}
1111
</div>
12+
<slot />
1213
</div>
1314
</template>
1415

src/renderer/components/fileManager/fileFilters.vue

Whitespace-only changes.

src/renderer/components/fileManager/fileInfo.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
style="margin-top: 25px; padding-top: 20px;"
146146
>
147147
<div class="file-detail-name">
148-
配置项
148+
搜索配置项
149149
</div>
150150
<div style="display: flex; justify-content: center; margin-top: 20px;">
151151
<div
@@ -178,7 +178,7 @@
178178
<div
179179
v-if="searchValue"
180180
class="file-dirinfo-box"
181-
style="margin-top: 25px; padding-top: 20px;"
181+
style="margin-top: 10px; padding-top: 20px;"
182182
>
183183
<div class="file-detail-name">
184184
搜索结果
@@ -484,6 +484,9 @@ export default {
484484
(!this.file && !item.view ? ' control-button-disalbed' : '') +
485485
(this.file && item.icon === 'unselect-file'
486486
? ' control-button-warning'
487+
: '') +
488+
(this.searchValue && item.view === 'search'
489+
? ' control-button-modify'
487490
: '')
488491
)
489492
}
@@ -501,8 +504,11 @@ export default {
501504
watch: {
502505
// 计算目录及文件信息
503506
visibleList (fileList) {
504-
if (this.searchValue) this.filterCalculator(fileList)
505-
else this.filterCalculator(this.fileList)
507+
if (fileList.length > 0 && this.searchValue) { this.filterCalculator(fileList) }
508+
},
509+
510+
fileList (fileList) {
511+
if (fileList.length > 0) this.filterCalculator(fileList)
506512
},
507513
508514
// 监听搜索设置变动,变动则立即进行搜索
@@ -565,7 +571,8 @@ export default {
565571
566572
// 搜索处理
567573
handleSearch (handle) {
568-
const value = handle === 'clear' ? '' : this.$refs.fileSearchInput.value.trim()
574+
const value =
575+
handle === 'clear' ? '' : this.$refs.fileSearchInput.value.trim()
569576
this.$emit('searchFile', Object.assign({ value }, this.searchOptions))
570577
},
571578
@@ -904,7 +911,7 @@ export default {
904911
padding: 5px;
905912
font-size: 18px;
906913
height: 100%;
907-
transition: .2s ease;
914+
transition: 0.2s ease;
908915
color: #424242;
909916
cursor: pointer;
910917
}
@@ -914,6 +921,11 @@ export default {
914921
}
915922
916923
.file-search-input-button:active {
917-
filter: brightness(.8);
924+
filter: brightness(0.8);
925+
}
926+
927+
.control-button-modify {
928+
background-color: #FFECB3;
929+
color: #000000;
918930
}
919931
</style>

src/renderer/components/fileManager/fileListTopbar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</div>
4747
<file-dir-path-bar
4848
:dir="dir"
49-
@changeDir="handleChangeDir(targetDir)"
49+
@changeDir="(targetDir)=>handleChangeDir(targetDir)"
5050
/>
5151
</div>
5252
</template>

src/renderer/components/fileManager/fileManager.vue

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,18 @@
3939
/>
4040
<empty-status
4141
:show="listingDir === 2 && visibleFileList.length === 0"
42+
:text="searchValue ? '未搜索到任何结果哦' : '目录是空的哦'"
4243
@contextmenu.native="emptyShowContextMenu"
43-
/>
44+
>
45+
<div
46+
v-if="searchValue"
47+
class="handle-button"
48+
style="margin-top: 20px;"
49+
@click="$refs.fileInfo.handleSearch('clear')"
50+
>
51+
关闭搜索
52+
</div>
53+
</empty-status>
4454
</div>
4555
</vue-scroll>
4656
</div>
@@ -51,6 +61,7 @@
5161
/>
5262
</div>
5363
<file-info
64+
ref="fileInfo"
5465
:file="selectedFile"
5566
:file-list="fileList"
5667
:dir="currentDir"
@@ -187,11 +198,14 @@ export default {
187198
188199
// 文件列表变更
189200
fileList (fileList) {
190-
// 将文件内容区的最小高度设置为数据完全加载后的高度
191-
// 由于实际上列表数据是懒加载的,这样做可以使得滚动条的比例完整,让人一眼看不出来是懒加载
192-
this.$refs.fileListContent.style.minHeight = `${this.fileList.length *
193-
65}px`
194-
this.visibleFileList = this.fileList.slice(0, this.visibleCount)
201+
if (!this.searchValue) {
202+
// 将文件内容区的最小高度设置为数据完全加载后的高度
203+
// 由于实际上列表数据是懒加载的,这样做可以使得滚动条的比例完整,让人一眼看不出来是懒加载
204+
this.$refs.fileListContent.style.minHeight = `${this.fileList.length * 65}px`
205+
this.visibleFileList = this.fileList.slice(0, this.visibleCount)
206+
} else {
207+
this.handleSearchFile(Object.assign({ value: this.searchValue }, this.searchOptions))
208+
}
195209
},
196210
197211
// 当前文件内容区可视文件数量变更
@@ -202,7 +216,7 @@ export default {
202216
filters: {
203217
deep: true,
204218
handler: function (filters) {
205-
if (!this.visibleFileList.length) return
219+
if (!this.visibleFileList.length || Object.keys(filters).length === 0) return
206220
// 计算过滤掉的文件数量
207221
const filtedCount = Object.values(filters).reduce((acc, filter) => {
208222
if (filter.status === false) acc += filter.count
@@ -214,9 +228,8 @@ export default {
214228
this.filted = filtedCount
215229
}
216230
// 重新计算列表滚动高度
217-
this.$refs.fileListContent.style.minHeight = `${(this.fileList.length -
218-
filtedCount) *
219-
65}px`
231+
const length = this.searchValue ? this.visibleFileList.length : this.fileList.length
232+
this.$refs.fileListContent.style.minHeight = `${(length - filtedCount) * 65}px`
220233
}
221234
}
222235
},
@@ -416,15 +429,18 @@ export default {
416429
// 如果之前选择过的文件没有发生改变,将重建File对象,并保留之前的选择
417430
const handleHasSelectFiles = fileList => {
418431
let tempSelectedFile = null
432+
419433
const tempSelectedFiles = []
420434
const selectedFile = this.selectedFile
421435
const selectedFiles = this.selectedFiles
422436
437+
// 遍历文件列表并查找selectedFiles,如果找不到文件就将选择丢失
423438
this.fileList = fileList.map(fileInfo => {
424439
const file = new File(fileInfo)
425440
const selectedIdx = selectedFiles.findIndex(
426441
selectedFile => selectedFile.ino === file.ino
427442
)
443+
428444
if (selectedIdx !== -1) {
429445
file.selected = true
430446
tempSelectedFiles.push(file)
@@ -669,4 +685,24 @@ export default {
669685
background-color: #ffcdd2;
670686
color: #000000;
671687
}
688+
689+
.handle-button {
690+
cursor: pointer;
691+
white-space: nowrap;
692+
background-color: #E8EAF6;
693+
padding: 8px 18px;
694+
border-radius: 4px;
695+
transition: 0.2s ease;
696+
font-size: 14px;
697+
cursor: pointer;
698+
color: #000000;
699+
}
700+
701+
.handle-button:hover {
702+
filter: brightness(.9);
703+
}
704+
705+
.handle-button:active {
706+
filter: brightness(.8);
707+
}
672708
</style>

0 commit comments

Comments
 (0)