@@ -10,23 +10,36 @@ import type { Ref, PropType, VNode } from "vue"
1010import { ElOption , ElSelect , ElTag } from "element-plus"
1111import { ref , h , defineComponent } from "vue"
1212import statService , { HostSet } from "@service/stat-service"
13+ import siteService from "@service/site-service"
1314import { t } from "@app/locale"
1415import SelectFilterItem from "@app/components/common/select-filter-item"
1516import { labelOfHostInfo } from "../util"
1617
17- async function handleRemoteSearch ( queryStr : string , trendDomainOptions : Ref < timer . site . SiteKey [ ] > , searching : Ref < boolean > ) {
18+ const calcUniqueKey = ( { host, virtual, merged } : timer . site . SiteInfo ) => `${ host } ${ virtual ? 1 : 0 } ${ merged ? 1 : 0 } `
19+
20+ async function handleRemoteSearch ( queryStr : string , trendDomainOptions : Ref < timer . site . SiteInfo [ ] > , searching : Ref < boolean > ) {
1821 if ( ! queryStr ) {
1922 trendDomainOptions . value = [ ]
2023 return
2124 }
2225 searching . value = true
23- const domains : HostSet = await statService . listHosts ( queryStr )
24- const options : timer . site . SiteKey [ ] = [ ]
25- const { origin, merged, virtual } = domains
26- origin . forEach ( host => options . push ( { host } ) )
27- merged . forEach ( host => options . push ( { host, merged : true } ) )
28- virtual . forEach ( host => options . push ( { host, virtual : true } ) )
29- trendDomainOptions . value = options
26+
27+ const options : Record < string , timer . site . SiteInfo > = { }
28+ const sites = await siteService . selectAll ( { fuzzyQuery : queryStr } )
29+ const hosts : HostSet = await statService . listHosts ( queryStr )
30+
31+ sites . forEach ( site => options [ calcUniqueKey ( site ) ] = site )
32+
33+ const { origin, merged, virtual } = hosts
34+ const originSiteInfo : timer . site . SiteInfo [ ] = [ ]
35+ origin . forEach ( host => originSiteInfo . push ( { host } ) )
36+ merged . forEach ( host => originSiteInfo . push ( { host, merged : true } ) )
37+ virtual . forEach ( host => originSiteInfo . push ( { host, virtual : true } ) )
38+ originSiteInfo . forEach ( o => {
39+ const key = calcUniqueKey ( o )
40+ ! options [ key ] && ( options [ key ] = o )
41+ } )
42+ trendDomainOptions . value = Object . values ( options )
3043 searching . value = false
3144}
3245
@@ -55,16 +68,21 @@ function hostInfoOfKey(key: string): timer.site.SiteKey {
5568
5669const MERGED_TAG_TXT = t ( msg => msg . analysis . common . merged )
5770const VIRTUAL_TAG_TXT = t ( msg => msg . analysis . common . virtual )
58- function renderHostLabel ( hostInfo : timer . site . SiteKey ) : VNode [ ] {
71+
72+ const renderOptionTag = ( tagLabel : string ) => h ( 'span' ,
73+ { style : { float : "right" , height : "34px" } } ,
74+ h ( ElTag , { size : 'small' } , ( ) => tagLabel )
75+ )
76+
77+ function renderHostLabel ( { host, merged, virtual, alias } : timer . site . SiteInfo ) : VNode [ ] {
5978 const result = [
60- h ( 'span' , { } , hostInfo . host )
79+ h ( 'span' , { } , host )
6180 ]
62- hostInfo . merged && result . push (
63- h ( ElTag , { size : 'small' } , ( ) => MERGED_TAG_TXT )
64- )
65- hostInfo . virtual && result . push (
66- h ( ElTag , { size : 'small' } , ( ) => VIRTUAL_TAG_TXT )
81+ alias && result . push (
82+ h ( ElTag , { size : 'small' , type : 'info' } , ( ) => alias )
6783 )
84+ merged && result . push ( renderOptionTag ( MERGED_TAG_TXT ) )
85+ virtual && result . push ( renderOptionTag ( VIRTUAL_TAG_TXT ) )
6886 return result
6987}
7088
@@ -113,10 +131,10 @@ const _default = defineComponent({
113131 handleSiteChange ( )
114132 }
115133 } , ( ) => ( trendDomainOptions . value || [ ] ) ?. map (
116- hostInfo => h ( ElOption , {
117- value : keyOfHostInfo ( hostInfo ) ,
118- label : labelOfHostInfo ( hostInfo ) ,
119- } , ( ) => renderHostLabel ( hostInfo ) )
134+ siteInfo => h ( ElOption , {
135+ value : keyOfHostInfo ( siteInfo ) ,
136+ label : labelOfHostInfo ( siteInfo ) ,
137+ } , ( ) => renderHostLabel ( siteInfo ) )
120138 ) ) ,
121139 h ( SelectFilterItem , {
122140 historyName : 'timeFormat' ,
0 commit comments