11<script >
2+ import { ipcRenderer } from ' electron'
3+ import { SearchBar } from ' search-bar-vue2'
24import createMenus from ' @/view/router/menu'
35import zhCN from ' ant-design-vue/lib/locale-provider/zh_CN'
46import { colorTheme } from ' ./composables/theme'
57
68export default {
79 name: ' App' ,
810 components: {
11+ SearchBar,
912 },
1013 data () {
1114 return {
1215 locale: zhCN,
1316 info: {},
1417 menus: undefined ,
1518 config: undefined ,
19+ hideSearchBar: true ,
1620 }
1721 },
1822 computed: {
@@ -37,16 +41,48 @@ export default {
3741 this .$api .info .get ().then ((ret ) => {
3842 this .info = ret
3943 })
44+
45+ ipcRenderer .on (' search-bar' , (_ , message ) => {
46+ console .info (_, message)
47+ if (message .key === ' show-hide' ) {
48+ if (window .config .disableSearchBar ) {
49+ this .hideSearchBar = true
50+ return
51+ }
52+
53+ this .hideSearchBar = message .hideSearchBar != null ? message .hideSearchBar : ! this .hideSearchBar
54+
55+ // 显示后,获取输入框焦点
56+ if (! this .hideSearchBar ) {
57+ setTimeout (() => {
58+ try {
59+ this .$refs .searchBar .$el .querySelector (' input' ).focus ()
60+ } catch {
61+ }
62+ }, 100 )
63+ }
64+ } else {
65+ // 如果还未显示检索框,先显示出来
66+ if (this .hideSearchBar ) {
67+ this .hideSearchBar = false
68+ return
69+ }
70+
71+ if (message .key === ' next' && ! this .hideSearchBar ) {
72+ this .$refs .searchBar .next ()
73+ } else if (message .key === ' previous' && ! this .hideSearchBar ) {
74+ this .$refs .searchBar .previous ()
75+ }
76+ }
77+ })
4078 },
4179 methods: {
42- handleClick (e ) {
43- console .log (' click' , e)
44- },
4580 titleClick (item ) {
4681 console .log (' title click:' , item)
4782 },
4883 menuClick (item ) {
4984 console .log (' menu click:' , item)
85+ window .config .disableSearchBar = false
5086 this .$router .replace (item .path )
5187 },
5288 },
@@ -56,6 +92,12 @@ export default {
5692<template >
5793 <a-config-provider :locale =" locale" >
5894 <div class =" ds_layout" :class =" themeClass" >
95+ <SearchBar ref =" searchBar"
96+ :root =" '#document'"
97+ :highlightClass =" 'search-bar-highlight'"
98+ :selectedClass =" 'selected-highlight'"
99+ :hiden.sync =" hideSearchBar"
100+ />
59101 <a-layout >
60102 <a-layout-sider :theme =" theme" >
61103 <div class =" logo" />
@@ -82,7 +124,7 @@ export default {
82124 </a-layout-sider >
83125 <a-layout >
84126 <!-- <a-layout-header>Header</a-layout-header> -->
85- <a-layout-content >
127+ <a-layout-content id = " document " >
86128 <router-view />
87129 </a-layout-content >
88130 <a-layout-footer >
@@ -144,4 +186,11 @@ body {
144186 border : 0 ;
145187 }
146188}
189+ .search-bar-highlight {
190+ background-color : #ef0fff ;
191+
192+ & .selected-highlight {
193+ background-color : #38d878 ;
194+ }
195+ }
147196 </style >
0 commit comments