-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathHeader.vue
More file actions
844 lines (756 loc) · 21.1 KB
/
Header.vue
File metadata and controls
844 lines (756 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
<template>
<a-layout-header class="header">
<!-- 左侧控制按钮 -->
<div class="header-left">
<!-- 聚合搜索页面模式 -->
<template v-if="isSearchAggregationPage">
<a-button shape="circle" @click="goBackFromSearch">
<template #icon>
<icon-left/>
</template>
</a-button>
<span class="search-page-title">聚合搜索</span>
</template>
<!-- 普通页面模式 -->
<template v-else>
<a-button shape="circle" @click="goBack">
<template #icon>
<icon-left/>
</template>
</a-button>
<a-button shape="circle" @click="goForward">
<template #icon>
<icon-right/>
</template>
</a-button>
<a-button shape="circle" @click="refreshPage">
<template #icon>
<icon-refresh/>
</template>
</a-button>
</template>
</div>
<!-- 中间搜索框 -->
<div class="header-center" :class="{ 'search-page-mode': isSearchAggregationPage }" v-if="searchAggregationEnabled">
<div class="search-container">
<a-input-search
v-model="searchValue"
placeholder="搜索内容..."
enter-button="搜索"
allow-clear
@search="onSearch"
@keyup.enter="onSearch(searchValue)"
@click="handleSearchClick"
@input="handleSearchInput"
@clear="handleSearchClear"
/>
<a-button
class="search-settings-btn"
shape="circle"
@click="openSearchSettings"
:title="'搜索设置'"
>
<template #icon>
<icon-settings/>
</template>
</a-button>
<a-button
v-if="hasSearchResults"
class="close-search-btn"
shape="circle"
@click="closeSearchResults"
:title="'关闭搜索结果'"
>
<template #icon>
<icon-close/>
</template>
</a-button>
</div>
</div>
<!-- 右侧控制按钮 -->
<div class="header-right">
<a-button shape="circle" @click="minimize">
<template #icon>
<icon-shrink/>
</template>
</a-button>
<a-button shape="circle" @click="maximize">
<template #icon>
<icon-expand/>
</template>
</a-button>
<a-button shape="circle" @click="showCloseConfirm">
<template #icon>
<icon-close/>
</template>
</a-button>
</div>
<!-- 全屏居中确认弹窗 -->
<div v-if="showConfirmModal" class="confirm-modal-overlay" @click="hideCloseConfirm">
<div class="confirm-modal" @click.stop>
<div class="modal-header">
<icon-exclamation-circle-fill class="warning-icon" />
<h3 class="modal-title">确认关闭</h3>
</div>
<div class="modal-content">
<p class="modal-message">你确认要关闭当前应用吗?</p>
<p class="modal-submessage">关闭后将退出应用程序</p>
</div>
<div class="modal-footer">
<a-button class="cancel-btn" @click="hideCloseConfirm">
取消
</a-button>
<a-button type="primary" status="warning" class="clear-cache-btn" @click="clearSessionStorage">
仅清缓存
</a-button>
<a-button type="primary" status="danger" class="confirm-btn" @click="confirmClose">
确认关闭
</a-button>
</div>
</div>
</div>
<!-- 搜索设置弹窗 -->
<SearchSettingsModal
v-model:visible="showSearchSettings"
@confirm="onSearchSettingsConfirm"
/>
</a-layout-header>
</template>
<script>
import {defineComponent, ref, computed, watch} from 'vue';
import {useRoute, useRouter} from 'vue-router';
import {Message} from '@arco-design/web-vue';
import SearchSettingsModal from './SearchSettingsModal.vue';
export default defineComponent({
components: {
SearchSettingsModal
},
setup() {
const route = useRoute();
const router = useRouter();
const showConfirmModal = ref(false);
const searchValue = ref('');
// 检测是否在聚合搜索页面
const isSearchAggregationPage = computed(() => {
return route.name === 'SearchAggregation';
});
// 检测是否有搜索结果(当在搜索页面且有搜索关键词或保存的搜索状态时)
const hasSearchResults = computed(() => {
// 依赖forceUpdate来触发重新计算
forceUpdate.value;
if (!isSearchAggregationPage.value) {
return false;
}
// 检查URL参数
if (route.query.keyword) {
return true;
}
// 检查是否有保存的搜索状态
try {
const savedState = localStorage.getItem('pageState_searchAggregation');
if (savedState) {
const state = JSON.parse(savedState);
return state.hasSearched && state.searchKeyword;
}
} catch (error) {
console.error('检查搜索状态失败:', error);
}
return false;
});
// 从localStorage获取聚搜功能状态
const getSearchAggregationStatus = () => {
try {
const appSettings = localStorage.getItem('appSettings');
if (appSettings) {
const settings = JSON.parse(appSettings);
return settings.searchAggregation || false;
}
} catch (error) {
console.error('获取聚搜状态失败:', error);
}
return false;
};
// 响应式的聚搜状态
const searchAggregationEnabled = ref(getSearchAggregationStatus());
// 用于强制更新hasSearchResults计算属性的响应式变量
const forceUpdate = ref(0);
// 监听localStorage变化
const updateSearchAggregationStatus = () => {
searchAggregationEnabled.value = getSearchAggregationStatus();
// 强制更新hasSearchResults计算属性
forceUpdate.value++;
};
// 监听storage事件
window.addEventListener('storage', updateSearchAggregationStatus);
// 定期检查状态变化(用于同一页面内的状态更新)
const checkInterval = setInterval(updateSearchAggregationStatus, 1000);
// 监听路由变化,同步搜索关键词
watch(() => route.query.keyword, (keyword) => {
if (keyword && isSearchAggregationPage.value) {
searchValue.value = keyword;
}
}, { immediate: true });
// 监听路由变化,清空搜索框(当离开搜索页面时)
watch(() => route.name, (routeName) => {
if (routeName !== 'SearchAggregation') {
searchValue.value = '';
}
});
return {
showConfirmModal,
searchAggregationEnabled,
searchValue,
showSearchSettings: ref(false),
isSearchAggregationPage,
hasSearchResults,
router
};
},
methods: {
goBack() {
Message.info("前进按钮");
// 执行前进逻辑
},
goBackFromSearch() {
// 从聚合搜索页面返回到上一页
// 检查是否有历史记录可以返回
if (window.history.length > 1) {
this.$router.back();
} else {
// 如果没有历史记录,返回到首页
this.$router.push({ name: 'Home' });
}
},
goForward() {
Message.info("后退按钮");
// 执行后退逻辑
},
refreshPage() {
Message.info("刷新页面");
// 刷新页面逻辑
window.location.reload();
},
onSearch(value) {
console.log('🔍 [Header] onSearch被触发:', { value, isSearchPage: this.isSearchAggregationPage });
if (!value || !value.trim()) {
Message.warning('请输入搜索内容');
return;
}
const keyword = value.trim();
console.log('🔍 [Header] 准备执行搜索:', { keyword, currentRoute: this.$route.name });
if (this.isSearchAggregationPage) {
// 如果已经在搜索页面,直接更新查询参数
console.log('🔍 [Header] 在搜索页面,更新查询参数');
// 添加时间戳参数强制触发路由变化,确保即使相同关键词也能重新搜索
this.$router.push({
name: 'SearchAggregation',
query: {
keyword,
_t: Date.now() // 时间戳参数强制路由更新
}
});
} else {
// 如果不在搜索页面,跳转到聚合搜索页面并执行搜索
console.log('🔍 [Header] 不在搜索页面,跳转到搜索页面');
this.$router.push({
name: 'SearchAggregation',
query: { keyword }
});
}
},
handleSearchClick() {
// 点击搜索框时的处理
if (!this.isSearchAggregationPage) {
// 如果不在搜索页面,跳转到搜索页面
this.$router.push({ name: 'SearchAggregation' });
}
},
handleSearchInput(value) {
// 搜索输入时的处理:在聚合搜索页写入草稿以生成建议
if (this.isSearchAggregationPage) {
const query = { ...this.$route.query, keywordDraft: value };
this.$router.push({ name: 'SearchAggregation', query });
}
},
handleSearchClear() {
// 清除输入内容,同时清空聚搜页的草稿
if (this.isSearchAggregationPage) {
const query = { ...this.$route.query };
delete query.keywordDraft;
this.$router.push({ name: 'SearchAggregation', query });
}
},
openSearchSettings() {
// 打开搜索设置弹窗
this.showSearchSettings = true;
},
onSearchSettingsConfirm(settings) {
// 处理搜索设置确认
const selectedCount = settings.selectedSources ? settings.selectedSources.length : 0;
Message.success(`已选择 ${selectedCount} 个搜索源`);
this.showSearchSettings = false;
// 触发自定义事件通知搜索源变更
window.dispatchEvent(new CustomEvent('searchSettingsChanged', {
detail: settings
}));
},
closeSearchResults() {
// 关闭搜索结果,回到搜索页面的初始状态
this.searchValue = '';
// 清除保存的页面状态
try {
localStorage.removeItem('pageState_searchAggregation');
console.log('🔄 [状态清理] 已清除聚合搜索页面保存的状态');
} catch (error) {
console.error('清除页面状态失败:', error);
}
this.$router.push({ name: 'SearchAggregation' });
},
minimize() {
Message.info("最小化窗口");
// 最小化窗口的逻辑,可以通过调用系统接口来实现
this.exitFullScreen()
},
maximize() {
Message.info("最大化窗口");
// 最大化窗口的逻辑
this.enterFullScreen()
},
showCloseConfirm() {
this.showConfirmModal = true;
},
hideCloseConfirm() {
this.showConfirmModal = false;
},
clearSessionStorage() {
try {
// 清除当前页面的sessionStorage
sessionStorage.clear();
this.showConfirmModal = false;
Message.success("缓存已清除");
} catch (error) {
console.error('清除缓存失败:', error);
Message.error("清除缓存失败");
}
},
confirmClose() {
this.showConfirmModal = false;
Message.info("正在关闭应用...");
// 尝试多种关闭方式
try {
// 方式1: 尝试关闭当前窗口
if (window.opener) {
window.close();
} else {
// 方式2: 如果是主窗口,尝试使用about:blank方式
window.open('about:blank', '_self');
window.close();
}
// 方式3: 如果上述方式都失败,提供备用方案
setTimeout(() => {
// 检查窗口是否已关闭
if (!window.closed) {
Message.warning("无法自动关闭窗口,请手动关闭浏览器标签页");
// 可以考虑跳转到一个关闭页面
window.location.href = 'about:blank';
}
}, 500);
} catch (error) {
console.error('关闭窗口失败:', error);
Message.error("关闭失败,请手动关闭浏览器标签页");
}
},
enterFullScreen() {
let element = document.documentElement;
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) { /* Firefox */
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) { /* IE/Edge */
element.msRequestFullscreen();
}
},
exitFullScreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) { /* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE/Edge */
document.msExitFullscreen();
}
},
}
});
</script>
<style scoped>
.header {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 64px;
padding: 0;
background: var(--color-bg-3);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
border-bottom: 1px solid var(--color-border-2);
border: none;
}
.header-left {
display: flex;
align-items: center;
padding-left: 20px;
min-width: 200px;
gap: 8px;
}
.search-page-title {
font-size: 16px;
font-weight: 600;
color: var(--color-text-1);
margin-left: 12px;
white-space: nowrap;
user-select: none;
display: flex;
align-items: center;
}
.header-center {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
max-width: 600px;
margin: 0 20px;
}
.header-right {
display: flex;
align-items: center;
padding-right: 20px;
min-width: 200px;
justify-content: flex-end;
gap: 8px;
}
.header-left :deep(.arco-btn),
.header-right :deep(.arco-btn) {
width: 32px;
height: 32px;
border-radius: 6px;
border: 1px solid var(--color-border-2);
background: var(--color-bg-2);
color: var(--color-text-1);
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
}
.header-left :deep(.arco-btn:hover),
.header-right :deep(.arco-btn:hover) {
background: var(--color-fill-3);
border-color: var(--color-border-3);
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.header-left :deep(.arco-btn:active),
.header-right :deep(.arco-btn:active) {
transform: translateY(0);
background: var(--color-fill-4);
}
/* 特殊样式:关闭按钮 */
.header-right :deep(.arco-btn:last-child) {
background: #ff4757;
border-color: #ff3742;
color: white;
}
.header-right :deep(.arco-btn:last-child:hover) {
background: #ff3742;
border-color: #ff2f3a;
box-shadow: 0 2px 8px rgba(255, 71, 87, 0.3);
}
/* 搜索容器样式 */
.search-container {
display: flex;
align-items: center;
gap: 0;
width: 100%;
max-width: 450px;
border: 1px solid var(--color-border-2);
border-radius: 8px;
background: var(--color-bg-1);
padding: 4px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
transition: all 0.2s ease;
}
.search-container:hover {
border-color: var(--color-border-3);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
/* 搜索框样式 */
.search-container :deep(.arco-input-search) {
flex: 1;
border-radius: 4px;
background: transparent;
border: none;
box-shadow: none;
transition: all 0.2s ease;
cursor: pointer;
}
.search-container :deep(.arco-input-search:hover) {
background: transparent;
border: none;
box-shadow: none;
}
/* 聚合搜索页面时的搜索框样式 */
.header-center.search-page-mode .search-container :deep(.arco-input-search) {
border-radius: 10px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.header-center.search-page-mode .search-container :deep(.arco-input-search .arco-input-wrapper) {
border: 2px solid var(--color-border-2);
transition: all 0.2s ease;
}
.header-center.search-page-mode .search-container :deep(.arco-input-search .arco-input-wrapper:focus-within) {
border-color: var(--color-primary-6);
box-shadow: 0 0 0 3px rgba(var(--primary-6), 0.1);
}
/* 搜索设置按钮样式 */
.search-settings-btn {
width: 32px !important;
height: 32px !important;
border-radius: 4px !important;
border: none !important;
background: transparent !important;
color: var(--color-text-2) !important;
transition: all 0.2s ease !important;
flex-shrink: 0;
margin-left: 4px;
}
.search-settings-btn:hover {
background: var(--color-fill-2) !important;
border: none !important;
color: var(--color-text-1) !important;
transform: none;
box-shadow: none !important;
}
.search-settings-btn:active {
transform: none !important;
background: var(--color-fill-3) !important;
}
/* 关闭搜索按钮样式 */
.close-search-btn {
width: 32px !important;
height: 32px !important;
border-radius: 4px !important;
border: none !important;
background: transparent !important;
color: var(--color-text-2) !important;
transition: all 0.2s ease !important;
flex-shrink: 0;
margin-left: 4px;
}
.close-search-btn:hover {
background: var(--color-danger-light-1) !important;
border: none !important;
color: var(--color-danger-6) !important;
transform: none;
box-shadow: none !important;
}
.close-search-btn:active {
transform: none !important;
background: var(--color-danger-light-2) !important;
}
.search-container:focus-within {
border-color: var(--color-primary-6);
box-shadow: 0 0 0 2px var(--color-primary-1);
}
.search-container :deep(.arco-input-search:focus-within) {
border: none;
box-shadow: none;
}
.search-container :deep(.arco-input-wrapper) {
border-radius: 8px;
background: transparent;
border: none;
}
.search-container :deep(.arco-input) {
background: transparent;
border: none;
color: var(--color-text-1);
font-size: 14px;
}
.search-container :deep(.arco-input::placeholder) {
color: var(--color-text-3);
}
.search-container :deep(.arco-input-search-btn) {
border-radius: 0 8px 8px 0;
background: var(--color-primary-6);
border: none;
color: white;
transition: background-color 0.2s ease;
}
.search-container :deep(.arco-input-search-btn:hover) {
background: var(--color-primary-7);
}
/* 全屏居中确认弹窗样式 */
.confirm-modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(4px);
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
animation: fadeIn 0.3s ease-out;
}
.confirm-modal {
background: var(--color-bg-1);
border-radius: 12px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
min-width: 400px;
max-width: 500px;
padding: 0;
animation: slideIn 0.3s ease-out;
border: 1px solid var(--color-border-2);
}
.modal-header {
display: flex;
align-items: center;
padding: 24px 24px 16px;
border-bottom: 1px solid var(--color-border-2);
}
.warning-icon {
font-size: 24px;
color: #ff6b35;
margin-right: 12px;
}
.modal-title {
margin: 0;
font-size: 18px;
font-weight: 600;
color: var(--color-text-1);
}
.modal-content {
padding: 20px 24px;
}
.modal-message {
margin: 0 0 8px 0;
font-size: 16px;
color: var(--color-text-1);
line-height: 1.5;
}
.modal-submessage {
margin: 0;
font-size: 14px;
color: var(--color-text-3);
line-height: 1.4;
}
.modal-footer {
display: flex;
justify-content: flex-end;
gap: 12px;
padding: 16px 24px 24px;
border-top: 1px solid var(--color-border-2);
}
.cancel-btn {
min-width: 80px;
height: 36px;
border-radius: 6px;
font-weight: 500;
}
.clear-cache-btn {
min-width: 90px;
height: 36px;
border-radius: 6px;
font-weight: 500;
}
.confirm-btn {
min-width: 100px;
height: 36px;
border-radius: 6px;
font-weight: 500;
}
/* 动画效果 */
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-20px) scale(0.95);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
/* 响应式设计 */
@media (max-width: 768px) {
.header-left,
.header-right {
min-width: 120px;
}
.header-center {
margin: 0 10px;
}
.search-container {
max-width: 280px;
}
.confirm-modal {
min-width: 320px;
max-width: 90vw;
margin: 20px;
}
}
@media (max-width: 480px) {
.header-left,
.header-right {
min-width: 80px;
gap: 4px;
}
.header-left {
padding-left: 10px;
}
.header-right {
padding-right: 10px;
}
.header-center {
margin: 0 5px;
}
.search-container {
max-width: 220px;
}
.header-left :deep(.arco-btn),
.header-right :deep(.arco-btn) {
width: 28px;
height: 28px;
}
.confirm-modal {
min-width: 280px;
margin: 16px;
}
.modal-header,
.modal-content,
.modal-footer {
padding-left: 20px;
padding-right: 20px;
}
.modal-footer {
flex-direction: column;
gap: 8px;
}
.cancel-btn,
.confirm-btn {
width: 100%;
}
}
</style>