@@ -175,31 +175,17 @@ const topList: TopInfo[] = [
175175
176176const { setStorage, getStorage} = useStorage ( 'newsTop-xiaoming' )
177177
178+ /**默认背景颜色*/
179+ const defaultBgColor = Color . dynamic ( new Color ( '#ffffff' , 1 ) , new Color ( '#000000' , 1 ) )
180+
178181/**文字颜色*/
179- const textColor = getStorage < string > ( 'textColor' ) || '#000000'
182+ const textColor = getStorage < string > ( 'textColor' ) || Color . dynamic ( new Color ( '#000000' , 1 ) , new Color ( '#dddddd' , 1 ) )
180183
181184/**透明背景*/
182- const transparentBg : Image | string = getStorage < Image > ( 'transparentBg' ) || '#ffffff'
185+ const transparentBg : Image | Color = getStorage < Image > ( 'transparentBg' ) || defaultBgColor
183186
184187/**背景颜色或背景图链接*/
185- const boxBg = getStorage < string > ( 'boxBg' ) || '#ffffff'
186-
187- // 好看的颜色
188- const colors = {
189- red : '#e54d42' ,
190- orange : '#f37b1d' ,
191- yellow : '#fbbd08' ,
192- olive : '#8dc63f' ,
193- green : '#39b54a' ,
194- cyan : '#1cbbb4' ,
195- blue : '#0081ff' ,
196- purple : '#6739b6' ,
197- mauve : '#9c26b0' ,
198- pink : '#e03997' ,
199- brown : '#a5673f' ,
200- grey : '#8799a3' ,
201- black : '#000000' ,
202- }
188+ const boxBg = getStorage < string > ( 'boxBg' ) || defaultBgColor
203189
204190/**
205191 * 文章组件
@@ -208,10 +194,10 @@ const colors = {
208194 */
209195const Article : FC < { article : ArticleInfo ; sort : number } > = ( { article, sort} ) => {
210196 return (
211- < >
212- { sort > 1 && < wspacer length = { 8 } > </ wspacer > }
213- < wstack verticalAlign = "center" href = { article . href } >
214- < wtext font = { Font . heavySystemFont ( 14 ) } textColor = { textColor } >
197+ < wstack flexDirection = "column" href = { article . href } >
198+ { sort > 1 && < wspacer > </ wspacer > }
199+ < wstack verticalAlign = "center" >
200+ < wtext font = { Font . heavySystemFont ( 14 ) } textColor = { textColor } opacity = { 0.7 } >
215201 { sort }
216202 </ wtext >
217203 < wspacer length = { 8 } > </ wspacer >
@@ -223,7 +209,7 @@ const Article: FC<{article: ArticleInfo; sort: number}> = ({article, sort}) => {
223209 { article . hot }
224210 </ wtext >
225211 </ wstack >
226- </ >
212+ </ wstack >
227213 )
228214}
229215
@@ -252,15 +238,18 @@ class NewsTop {
252238 // 渲染尺寸
253239 const size = config . widgetFamily
254240
241+ const widgetBoxProps = size === 'small' ? { href : articleList [ 0 ] && articleList [ 0 ] . href } : { }
242+
255243 return (
256244 < wbox
257245 padding = { [ 0 , 0 , 0 , 0 ] }
258246 updateDate = { new Date ( Date . now ( ) + updateInterval ) }
259- background = { boxBg . match ( '透明背景' ) ? transparentBg : boxBg }
260- href = { size === 'small' ? articleList [ 0 ] && articleList [ 0 ] . href : '' }
247+ background = { typeof boxBg === 'string' && boxBg . match ( '透明背景' ) ? transparentBg : boxBg }
248+ { ... widgetBoxProps }
261249 >
262250 < wstack flexDirection = "column" padding = { [ 0 , 16 , 0 , 16 ] } >
263- < wspacer length = { 16 } > </ wspacer >
251+ < wspacer > </ wspacer >
252+ < wspacer > </ wspacer >
264253 { /* 标题和logo */ }
265254 < wstack verticalAlign = "center" >
266255 < wimage src = { logo } width = { 20 } height = { 20 } borderRadius = { 4 } > </ wimage >
@@ -269,7 +258,8 @@ class NewsTop {
269258 { title } 排行榜
270259 </ wtext >
271260 </ wstack >
272- < wspacer length = { 16 } > </ wspacer >
261+ < wspacer > </ wspacer >
262+ < wspacer > </ wspacer >
273263 { /* 内容 */ }
274264 { size === 'small' && this . renderSmall ( articleList ) }
275265 { size === 'medium' && this . renderMedium ( articleList ) }
@@ -294,7 +284,7 @@ class NewsTop {
294284 { article . hot }
295285 </ wtext >
296286 </ wstack >
297- < wspacer length = { 16 } > </ wspacer >
287+ < wspacer > </ wspacer >
298288 </ wstack >
299289 )
300290 }
@@ -303,37 +293,43 @@ class NewsTop {
303293 renderMedium ( articleList : ArticleInfo [ ] ) {
304294 const _articleList = articleList . slice ( 0 , 4 )
305295 return (
306- < wstack flexDirection = "column" >
307- { _articleList . map ( ( article , index ) => (
308- < Article article = { article } sort = { index + 1 } > </ Article >
309- ) ) }
296+ < >
297+ < wstack flexDirection = "column" >
298+ { _articleList . map ( ( article , index ) => (
299+ < Article article = { article } sort = { index + 1 } > </ Article >
300+ ) ) }
301+ </ wstack >
310302 < wspacer > </ wspacer >
311- </ wstack >
303+ < wspacer > </ wspacer >
304+ </ >
312305 )
313306 }
314307
315308 // 渲染大尺寸
316309 renderLarge ( articleList : ArticleInfo [ ] ) {
317- const _articleList = articleList . slice ( 0 , 12 )
310+ const _articleList = articleList . slice ( 0 , 10 )
318311 return (
319- < wstack flexDirection = "column" >
320- { _articleList . map ( ( article , index ) => (
321- < Article article = { article } sort = { index + 1 } > </ Article >
322- ) ) }
312+ < >
313+ < wstack flexDirection = "column" >
314+ { _articleList . map ( ( article , index ) => (
315+ < Article article = { article } sort = { index + 1 } > </ Article >
316+ ) ) }
317+ </ wstack >
323318 < wspacer > </ wspacer >
324- </ wstack >
319+ < wspacer > </ wspacer >
320+ </ >
325321 )
326322 }
327323
328324 // 显示菜单
329325 async showMenu ( ) {
330326 const selectIndex = await showActionSheet ( {
331327 title : '菜单' ,
332- itemList : [ '使用其他排行榜' , '设置颜色' , '设置透明背景' , '预览组件' ] ,
328+ itemList : [ '使用其他排行榜' , '设置颜色' , '设置透明背景' , '预览组件' , '优化体验' ] ,
333329 } )
334330 switch ( selectIndex ) {
335331 case 0 :
336- showModal ( {
332+ await showModal ( {
337333 title : '使用其他排行榜方法' ,
338334 content : `把小部件添加到桌面后,长按编辑小部件,在 Parameter 栏输入以下任一关键词即可:\n\n${ topList
339335 . map ( top => top . title )
@@ -371,6 +367,18 @@ class NewsTop {
371367 case 3 :
372368 await showPreviewOptions ( this . render . bind ( this ) )
373369 break
370+ case 4 :
371+ const { cancel : cancelLogin } = await showModal ( {
372+ title : '优化体验建议' ,
373+ content :
374+ '本组件数据来源于 tophub.today 这个网站,未登录状态获取的文章链接不是最终链接,有二次跳转,如果想获取真实链接,建议在此登录该网站。\n\n登录完成后,自行关闭网页' ,
375+ confirmText : '去登录' ,
376+ } )
377+ if ( cancelLogin ) return
378+ const loginUrl = 'https://tophub.today/login'
379+ const html = await new Request ( loginUrl ) . loadString ( )
380+ await WebView . loadHTML ( html , loginUrl , undefined , true )
381+ break
374382 }
375383 }
376384
0 commit comments