22 * 个性磁铁小部件
33 */
44
5- import { isLaunchInsideApp , showActionSheet , showNotification , showPreviewOptions } from '@app/lib/help'
5+ import {
6+ isLaunchInsideApp ,
7+ setTransparentBackground ,
8+ showActionSheet ,
9+ showModal ,
10+ showNotification ,
11+ showPreviewOptions ,
12+ useStorage ,
13+ } from '@app/lib/help'
614import { Col } from '@app/lib/components'
715import { WstackProps } from '@app/types/widget'
816import { FC } from 'react'
917
10- // 文字颜色
11- const textColor = '#ffffff'
18+ const { setStorage, getStorage} = useStorage ( 'luancher-xiaoming' )
19+
20+ /**文字颜色*/
21+ const textColor = getStorage < string > ( 'textColor' ) || '#ffffff'
22+
23+ /**所有格子统一颜色*/
24+ const gridColor : string | null = getStorage < string > ( 'gridColor' )
25+
26+ /**背景颜色或背景图链接*/
27+ const boxBg = getStorage < string > ( 'boxBg' ) || '#ffffff'
28+
29+ /**透明背景*/
30+ const transparentBg : Image | string = getStorage < Image > ( 'transparentBg' ) || '#ffffff'
1231
1332// 好看的颜色
1433const colors = {
@@ -49,9 +68,9 @@ const Grid: FC<GridProps> = ({...props}) => {
4968 const bgRandom = Math . floor ( Math . random ( ) * bgColors . length )
5069 const bgColor = bgColors [ bgRandom ]
5170 return (
52- < wstack background = { background || bgColor } href = { href } borderColor = "#00000088" borderWidth = { 1 } >
71+ < wstack background = { gridColor || background || bgColor } href = { href } borderColor = "#00000088" borderWidth = { 1 } >
5372 < Col
54- background = { / ^ \# [ \d ] + $ / . test ( String ( background ) ) ? '#00000000' : '#00000033 ' }
73+ background = { / ^ \# [ \d \w ] + $ / . test ( String ( background ) ) || gridColor ? '#00000000' : '#00000055 ' }
5574 alignItems = "center"
5675 justifyContent = "center"
5776 >
@@ -95,6 +114,7 @@ class Launcher {
95114 padding = { [ 0 , 0 , 0 , 0 ] }
96115 updateDate = { new Date ( Date . now ( ) + updateInterval ) }
97116 href = { size === 'small' ? this . config [ 0 ] . href : '' }
117+ background = { boxBg . match ( '透明背景' ) ? transparentBg : boxBg }
98118 >
99119 { size === 'small' && this . renderSmall ( ) }
100120 { size === 'medium' && this . renderMedium ( ) }
@@ -176,10 +196,44 @@ class Launcher {
176196 async showMenu ( ) {
177197 const selectIndex = await showActionSheet ( {
178198 title : '菜单' ,
179- itemList : [ '预览组件' ] ,
199+ itemList : [ '设置全局背景和颜色' , '设置透明背景' , ' 预览组件'] ,
180200 } )
181201 switch ( selectIndex ) {
182202 case 0 :
203+ const { texts, cancel} = await showModal ( {
204+ title : '设置全局背景和颜色' ,
205+ content :
206+ '此处不能修改单个格子的风格,只能统一覆盖,如果为空,则还原默认,只有在设置格子半透明下(如#00000055)才能看到背景' ,
207+ inputItems : [
208+ {
209+ text : getStorage < string > ( 'boxBg' ) || '' ,
210+ placeholder : '这里填全局背景,可以是颜色、图片链接' ,
211+ } ,
212+ {
213+ text : getStorage < string > ( 'gridColor' ) || '' ,
214+ placeholder : '这里填所有格子颜色' ,
215+ } ,
216+ {
217+ text : getStorage < string > ( 'textColor' ) || '' ,
218+ placeholder : '这里填文字颜色' ,
219+ } ,
220+ ] ,
221+ } )
222+ if ( cancel ) return
223+ setStorage ( 'boxBg' , texts [ 0 ] )
224+ setStorage ( 'gridColor' , texts [ 1 ] )
225+ setStorage ( 'textColor' , texts [ 2 ] )
226+ await showNotification ( { title : '设置完成' , sound : 'default' } )
227+ break
228+ case 1 :
229+ const img : Image | null = ( await setTransparentBackground ( ) ) || null
230+ if ( img ) {
231+ setStorage ( 'transparentBg' , img )
232+ setStorage ( 'boxBg' , '透明背景' )
233+ await showNotification ( { title : '设置透明背景成功' , sound : 'default' } )
234+ }
235+ break
236+ case 2 :
183237 await showPreviewOptions ( this . render . bind ( this ) )
184238 break
185239 }
@@ -191,13 +245,13 @@ const luancherConfig: GridProps[] = [
191245 href : 'weixin://scanqrcode' ,
192246 background : colors . green ,
193247 iconName : 'barcode.viewfinder' ,
194- text : '扫一扫 ' ,
248+ text : '微信扫一扫 ' ,
195249 } ,
196250 {
197251 href : 'alipayqr://platformapi/startapp?saId=10000007' ,
198252 background : colors . blue ,
199253 iconName : 'barcode.viewfinder' ,
200- text : '扫一扫 ' ,
254+ text : '支付宝 ' ,
201255 } ,
202256 {
203257 href : 'weixin://' ,
@@ -224,7 +278,7 @@ const luancherConfig: GridProps[] = [
224278 text : 'QQ' ,
225279 } ,
226280 {
227- href : 'weibo ://' ,
281+ href : 'sinaweibo ://' ,
228282 background : colors . red ,
229283 iconName : 'eye' ,
230284 text : '微博' ,
@@ -237,7 +291,8 @@ const luancherConfig: GridProps[] = [
237291 } ,
238292 {
239293 href : 'zhihu://' ,
240- background : colors . blue ,
294+ //background: colors.blue,
295+ background : `https://bing.ioliu.cn/v1/rand?w=600&h=200×tamp=${ Date . now ( ) } ` ,
241296 iconName : 'questionmark' ,
242297 text : '知乎' ,
243298 } ,
0 commit comments