11import React , { useEffect , useRef , useState } from "react" ;
22import {
3+ Avatar ,
34 Button ,
45 Card ,
56 Divider ,
@@ -16,6 +17,7 @@ import {
1617 Tooltip ,
1718 Typography ,
1819} from "@arco-design/web-react" ;
20+ import { TbWorldWww } from "react-icons/tb" ;
1921import { ColumnProps } from "@arco-design/web-react/es/Table" ;
2022import { ComponentsProps } from "@arco-design/web-react/es/Table/interface" ;
2123import {
@@ -30,7 +32,7 @@ import {
3032} from "@App/app/repo/scripts" ;
3133import {
3234 IconClockCircle ,
33- IconCommon ,
35+ IconDesktop ,
3436 IconEdit ,
3537 IconLink ,
3638 IconMenu ,
@@ -88,9 +90,9 @@ import {
8890} from "@App/pages/store/features/script" ;
8991import { message , systemConfig } from "@App/pages/store/global" ;
9092import { ValueClient } from "@App/app/service/service_worker/client" ;
91- import { JSX } from "react/jsx-runtime " ;
93+ import { loadScriptFavicons } from "@App/pages/store/utils " ;
9294
93- type ListType = Script & { loading ?: boolean } ;
95+ type ListType = ScriptLoading ;
9496
9597function ScriptList ( ) {
9698 const [ userConfig , setUserConfig ] = useState < {
@@ -113,7 +115,12 @@ function ScriptList() {
113115 const [ dealColumns , setDealColumns ] = useState < ColumnProps [ ] > ( [ ] ) ;
114116
115117 useEffect ( ( ) => {
116- dispatch ( fetchScriptList ( ) ) ;
118+ dispatch ( fetchScriptList ( ) ) . then ( ( action ) => {
119+ if ( fetchScriptList . fulfilled . match ( action ) ) {
120+ // 在脚本列表加载完成后,加载favicon
121+ loadScriptFavicons ( action . payload ) ;
122+ }
123+ } ) ;
117124 } , [ dispatch ] ) ;
118125
119126 const columns : ColumnProps [ ] = [
@@ -250,7 +257,7 @@ function ScriptList() {
250257 title : t ( "apply_to_run_status" ) ,
251258 width : t ( "script_list_apply_to_run_status_width" ) ,
252259 className : "apply_to_run_status" ,
253- render ( col , item : Script ) {
260+ render ( col , item : ListType ) {
254261 const toLogger = ( ) => {
255262 navigate ( {
256263 pathname : "logger" ,
@@ -266,20 +273,44 @@ function ScriptList() {
266273 } ) ;
267274 } ;
268275 if ( item . type === SCRIPT_TYPE_NORMAL ) {
276+ // 处理站点icon
269277 return (
270- < Tooltip content = { t ( "foreground_page_script_tooltip" ) } >
271- < Tag
272- style = { {
273- cursor : "pointer" ,
274- } }
275- icon = { < IconCommon color = "" /> }
276- color = "cyan"
277- bordered
278- onClick = { toLogger }
279- >
280- { t ( "page_script" ) }
281- </ Tag >
282- </ Tooltip >
278+ < >
279+ < Avatar . Group size = { 20 } style = { { margin : 10 } } >
280+ { item . favorite &&
281+ // 排序并且只显示前5个
282+ // 排序将有icon的放在前面
283+ [ ...item . favorite ]
284+ . sort ( ( a , b ) => {
285+ if ( a . icon && ! b . icon ) return - 1 ;
286+ if ( ! a . icon && b . icon ) return 1 ;
287+ return a . match . localeCompare ( b . match ) ;
288+ } )
289+ . slice ( 0 , 5 )
290+ . map ( ( fav ) => (
291+ < Avatar
292+ key = { fav . match }
293+ shape = "square"
294+ style = { {
295+ backgroundColor : "unset" ,
296+ borderWidth : 1 ,
297+ } }
298+ className = { fav . website ? "cursor-pointer" : "cursor-default" }
299+ onClick = { ( ) => {
300+ if ( fav . website ) {
301+ window . open ( fav . website , "_blank" ) ;
302+ }
303+ } }
304+ >
305+ { fav . icon ? (
306+ < img title = { fav . match } src = { fav . icon } />
307+ ) : (
308+ < TbWorldWww title = { fav . match } color = "#aaa" size = { 24 } />
309+ ) }
310+ </ Avatar >
311+ ) ) }
312+ </ Avatar . Group >
313+ </ >
283314 ) ;
284315 }
285316 let tooltip = "" ;
0 commit comments