2
2
import random
3
3
import flet as ft
4
4
import flet .canvas as cv
5
+ import datetime
5
6
6
7
7
8
def hum_convert (value , bit = 2 ):
@@ -24,7 +25,7 @@ def hum_convert(value, bit=2):
24
25
value = value / size
25
26
26
27
27
- async def lottery_core (datashow ,page : ft .Page , lottery_list = {}):
28
+ async def lottery_core (datashow , page : ft .Page , lottery_list = {}):
28
29
# TODO: 不重复抽奖
29
30
def chance_prize (prize_list ):
30
31
"""
@@ -153,7 +154,7 @@ async def storage(
153
154
page .session .remove (key )
154
155
else :
155
156
raise LookupError ("Key not found in session storage" )
156
- print (f"[Log ]{ key } 值为: { page .session .get (key )} " )
157
+ print (f"[log-" , datetime . datetime . now (), " ]{key}值为: {page.session.get(key)}" )
157
158
elif type == "c" :
158
159
if mode == "r" :
159
160
if await page .client_storage .contains_key_async (key ):
@@ -277,8 +278,7 @@ def __init__(self, n=0.7):
277
278
),
278
279
col = 1.32 ,
279
280
alignment = ft .alignment .top_right ,
280
- margin = ft .margin .only (
281
- top = 12 * n , right = 19 * n ),
281
+ margin = ft .margin .only (top = 12 * n , right = 19 * n ),
282
282
height = 70 * n ,
283
283
),
284
284
],
@@ -291,16 +291,17 @@ def __init__(self, n=0.7):
291
291
)
292
292
]
293
293
294
- def on_data_change (self , data :str , page = ft .Page , n = 0.7 ):
294
+ def on_data_change (self , data : str , page = ft .Page , n = 0.7 ):
295
295
"""_summary_: 数据改变时调用
296
296
297
297
Args:
298
298
data (_type_): _description_
299
299
page (_type_, optional): _description_. Defaults to ft.Page.
300
300
n (float, optional): _description_. Defaults to 0.7.
301
301
"""
302
+ print (f"[log-{ datetime .datetime .now ()} ]获取到的缩放比例:{ n } " )
302
303
try :
303
- len (data )
304
+ print ( f"[log- { datetime . datetime . now () } ]当前Data字符串长度: { len (data ) } " )
304
305
except TypeError :
305
306
raise ValueError ("Data 数值过大!" )
306
307
else :
@@ -309,19 +310,50 @@ def on_data_change(self, data:str, page=ft.Page, n=0.7):
309
310
or page .platform == ft .PagePlatform .IOS
310
311
):
311
312
# 缩放倍数
312
- n *= 0.747
313
+ if len (data ) == 7 :
314
+ # 7位数
315
+ # SHIT 1GB
316
+ n *= 1.1
317
+ self .DATA = data
318
+ self .controls [0 ].controls [1 ].controls [1 ].content .spans [
319
+ 0
320
+ ].text = self .DATA
321
+ self .controls [0 ].controls [1 ].controls [1 ].margin = ft .margin .only (
322
+ top = (12 + (2 * (len (self .DATA ) - 7 ))) * n * 1.1 ,
323
+ right = (19 - (3 * (len (self .DATA ) - 7 ))) * n * 2 ,
324
+ )
325
+ self .controls [0 ].controls [1 ].controls [1 ].content .spans [
326
+ 0
327
+ ].style .size = ((35 - (2.5 * (len (self .DATA ) - 7 ))) * n * 0.92 )
328
+ page .update ()
329
+ else :
330
+ n *= 0.666
331
+ self .DATA = data
332
+ self .controls [0 ].controls [1 ].controls [1 ].content .spans [
333
+ 0
334
+ ].text = self .DATA
335
+ self .controls [0 ].controls [1 ].controls [1 ].margin = ft .margin .only (
336
+ top = (12 + (2 * (len (self .DATA ) - 7 ))) * n * 1.1 ,
337
+ right = (19 - (3 * (len (self .DATA ) - 7 ))) * n * 2 ,
338
+ )
339
+ self .controls [0 ].controls [1 ].controls [1 ].content .spans [
340
+ 0
341
+ ].style .size = ((35 - (2.5 * (len (self .DATA ) - 7 ))) * n * 0.92 )
342
+ page .update ()
313
343
else :
314
- n *= 1.2
315
- self .DATA = data
316
- self .controls [0 ].controls [1 ].controls [1 ].content .spans [0 ].text = self .DATA
317
- self .controls [0 ].controls [1 ].controls [1 ].margin = ft .margin .only (
318
- top = (12 + (2 * (len (self .DATA ) - 7 ))) * n * 1.1 ,
319
- right = (19 - (3 * (len (self .DATA ) - 7 ))) * n * 2 ,
320
- )
321
- self .controls [0 ].controls [1 ].controls [1 ].content .spans [0 ].style .size = (
322
- (35 - (2.5 * (len (self .DATA ) - 7 ))) * n * 0.92
323
- )
324
- page .update ()
344
+ n *= 1.1
345
+ self .DATA = data
346
+ self .controls [0 ].controls [1 ].controls [1 ].content .spans [
347
+ 0
348
+ ].text = self .DATA
349
+ self .controls [0 ].controls [1 ].controls [1 ].margin = ft .margin .only (
350
+ top = (12 + (2 * (len (self .DATA ) - 7 ))) * n * 1.1 ,
351
+ right = (19 - (3 * (len (self .DATA ) - 7 ))) * n * 2.2 ,
352
+ )
353
+ self .controls [0 ].controls [1 ].controls [1 ].content .spans [0 ].style .size = (
354
+ (35 - (2.5 * (len (self .DATA ) - 7 ))) * n * 0.92
355
+ )
356
+ page .update ()
325
357
326
358
327
359
class PhiLottery (ft .Stack ):
@@ -331,7 +363,7 @@ class PhiLottery(ft.Stack):
331
363
ft (_type_): _description_
332
364
"""
333
365
334
- nodata = False
366
+ nodata = False
335
367
336
368
def __init__ (self , n = 1 , page = ft .Page ):
337
369
if (
@@ -393,9 +425,7 @@ async def on_click(
393
425
datashow = PhiData (),
394
426
datakey = "data" ,
395
427
):
396
- async with (
397
- lock
398
- ): # 确保只有一个 on_click 在执行
428
+ async with lock : # 确保只有一个 on_click 在执行
399
429
n2 = n
400
430
if page and (
401
431
page .platform == ft .PagePlatform .ANDROID
@@ -425,7 +455,12 @@ async def on_click(
425
455
- datadelta ,
426
456
mode = "w" ,
427
457
)
428
- print ("[Log]当前Data:" , await storage (page = page , key = datakey , mode = "r" ))
458
+ print (
459
+ "[log-" ,
460
+ datetime .datetime .now (),
461
+ "]当前Data:" ,
462
+ await storage (page = page , key = datakey , mode = "r" ),
463
+ )
429
464
PhiData .on_data_change (
430
465
datashow ,
431
466
hum_convert (await storage (page = page , key = datakey , mode = "r" )),
@@ -437,8 +472,10 @@ async def on_click(
437
472
self .controls [1 ].offset = ft .transform .Offset (0 , 0 )
438
473
detailText .value = ""
439
474
# 对接抽奖函数
440
- result = await lottery_core (datashow = datashow ,page = page , lottery_list = lottery_list )
441
- print ("[Log]抽奖结果:" , result )
475
+ result = await lottery_core (
476
+ datashow = datashow , page = page , lottery_list = lottery_list
477
+ )
478
+ print ("[log-" , datetime .datetime .now (), "]抽奖结果:" , result )
442
479
text = str (result [0 ])
443
480
if result [1 ] == "White" :
444
481
detailText .color = ft .Colors .WHITE
@@ -452,7 +489,8 @@ async def on_click(
452
489
453
490
for i in range (1 , 24 ):
454
491
detail .scale = ft .transform .Scale (
455
- scale_x = 0.7 , scale_y = 0.7 / 23 * i )
492
+ scale_x = 0.7 , scale_y = 0.7 / 23 * i
493
+ )
456
494
page .update ()
457
495
await asyncio .sleep (0.016 )
458
496
# scale_x和scale_y无法使用动画,只能用这种方法
@@ -466,7 +504,7 @@ async def on_click(
466
504
elif await storage (page = page , key = "data" ) < datadelta :
467
505
self .nodata = True
468
506
self .controls [0 ].visible = not self .controls [0 ].visible # ?图
469
- print ("[Log ]余额不足" )
507
+ print ("[log-" , datetime . datetime . now (), " ]余额不足" )
470
508
# TODO: 前端日志输出失效,待修复
471
509
page .snack_bar = ft .SnackBar (ft .Text ("余额不足" ))
472
510
page .snack_bar .open = True
@@ -478,16 +516,150 @@ async def on_click(
478
516
self .controls [1 ].animate_opacity = 300
479
517
page .update ()
480
518
self .controls [1 ].opacity = 0
481
- offset_x = - 1 * \
482
- abs ((page .width // 4 / (350 * n2 ) - 1 )) * 0.05 - 0.25
519
+ offset_x = (
520
+ - 1 * abs ((page .width // 4 / (350 * n2 ) - 1 )) * 0.05 - 0.25
521
+ )
483
522
if offset_x >= - 0.15 :
484
523
offset_x -= 0.1
485
524
if offset_x < - 0.3 :
486
525
offset_x += 0.1
487
526
self .controls [1 ].offset = ft .transform .Offset (offset_x , 0 )
488
- print ("[Log]Offset:" , self .controls [1 ].offset .x )
527
+ print (
528
+ "[log-" ,
529
+ datetime .datetime .now (),
530
+ "]Offset:" ,
531
+ self .controls [1 ].offset .x ,
532
+ )
489
533
page .update ()
490
534
if multi :
491
535
await asyncio .sleep (0.1 )
492
536
else :
493
537
await asyncio .sleep (0.5 )
538
+
539
+
540
+ class PhiLotteryButton (ft .Stack ):
541
+ """_summary_: 抽奖按钮
542
+
543
+ Args:
544
+ ft (_type_): _description_
545
+ """
546
+
547
+ def __init__ (self , n = 1 ):
548
+ super ().__init__ ()
549
+ self .controls = [
550
+ ft .Container (
551
+ cv .Canvas (
552
+ [
553
+ cv .Path (
554
+ [
555
+ cv .Path .MoveTo (25.4551733 * n , 0 ),
556
+ cv .Path .LineTo (472 * n , 0 ),
557
+ cv .Path .LineTo (446.5448267 * n , 90 * n ),
558
+ cv .Path .LineTo (0 , 90 * n ),
559
+ cv .Path .Close (),
560
+ ],
561
+ paint = ft .Paint (
562
+ style = ft .PaintingStyle .STROKE ,
563
+ color = ft .Colors .WHITE ,
564
+ stroke_width = 2 ,
565
+ ),
566
+ ),
567
+ cv .Path (
568
+ [
569
+ cv .Path .MoveTo (25.4551733 * n , 0 ),
570
+ cv .Path .LineTo (472 * n , 0 ),
571
+ cv .Path .LineTo (446.5448267 * n , 90 * n ),
572
+ cv .Path .LineTo (0 , 90 * n ),
573
+ cv .Path .Close (),
574
+ ],
575
+ paint = ft .Paint (
576
+ style = ft .PaintingStyle .FILL ,
577
+ color = "#90000000" ,
578
+ ),
579
+ ),
580
+ ],
581
+ width = 472 * n ,
582
+ height = 90 * n ,
583
+ expand = True ,
584
+ ),
585
+ padding = 0 ,
586
+ ),
587
+ ft .Row (
588
+ controls = [
589
+ ft .Image (
590
+ "dataicon.png" ,
591
+ width = 70 * n ,
592
+ height = 70 * n ,
593
+ offset = ft .transform .Offset (0 , - 0.08 * n ),
594
+ ),
595
+ ft .Text (
596
+ "1024 KB " ,
597
+ color = ft .Colors .WHITE ,
598
+ size = 35 * n ,
599
+ # text_align=ft.TextAlign.CENTER,
600
+ ),
601
+ ],
602
+ expand = True ,
603
+ alignment = ft .MainAxisAlignment .SPACE_EVENLY ,
604
+ width = 472 * n ,
605
+ height = 90 * n ,
606
+ spacing = 0 ,
607
+ ),
608
+ ]
609
+
610
+
611
+ class PhiLotteryButtonM (ft .Stack ):
612
+ """_summary_: 抽奖按钮-连抽
613
+
614
+ Args:
615
+ ft (_type_): _description_
616
+ """
617
+
618
+ def __init__ (self , n = 1 ):
619
+ super ().__init__ ()
620
+ self .controls = [
621
+ ft .Container (
622
+ cv .Canvas (
623
+ [
624
+ cv .Path (
625
+ [
626
+ cv .Path .MoveTo (25.4551733 * n , 0 ),
627
+ cv .Path .LineTo (472 * n , 0 ),
628
+ cv .Path .LineTo (446.5448267 * n , 90 * n ),
629
+ cv .Path .LineTo (0 , 90 * n ),
630
+ cv .Path .Close (),
631
+ ],
632
+ paint = ft .Paint (
633
+ style = ft .PaintingStyle .FILL ,
634
+ color = "#EEAFB0B1" ,
635
+ ),
636
+ ),
637
+ ],
638
+ width = 472 * n ,
639
+ height = 90 * n ,
640
+ expand = True ,
641
+ ),
642
+ padding = 0 ,
643
+ ),
644
+ ft .Row (
645
+ controls = [
646
+ ft .Image (
647
+ "dataicon.png" ,
648
+ width = 70 * n ,
649
+ height = 70 * n ,
650
+ offset = ft .transform .Offset (0 , - 0.08 * n ),
651
+ ),
652
+ ft .Text (
653
+ "8 MB " ,
654
+ color = ft .Colors .BLACK ,
655
+ size = 35 * n ,
656
+ # text_align=ft.TextAlign.CENTER,
657
+ ),
658
+ ],
659
+ expand = True ,
660
+ alignment = ft .MainAxisAlignment .SPACE_EVENLY ,
661
+ width = 472 * n ,
662
+ height = 90 * n ,
663
+ spacing = 0 ,
664
+ ),
665
+ ]
0 commit comments