您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AppServiceProvider.php 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Providers;
  3. use App\Enums\PrimaryColor;
  4. use Closure;
  5. use Filament\Forms\Components\Field;
  6. use Filament\Forms\Components\Select;
  7. use Filament\Forms\Components\TextInput;
  8. use Filament\Forms\Get;
  9. use Filament\Notifications\Livewire\Notifications;
  10. use Filament\Support\Enums\Alignment;
  11. use Filament\Support\RawJs;
  12. use Filament\Tables\Actions\Action;
  13. use Filament\Tables\Columns\TextColumn;
  14. use Illuminate\Support\ServiceProvider;
  15. use Illuminate\Support\Str;
  16. class AppServiceProvider extends ServiceProvider
  17. {
  18. /**
  19. * Register any application services.
  20. */
  21. public function register(): void
  22. {
  23. //
  24. }
  25. /**
  26. * Bootstrap any application services.
  27. */
  28. public function boot(): void
  29. {
  30. Notifications::alignment(Alignment::Center);
  31. TextColumn::macro('currency', function (string|Closure|null $currency = null, bool|null $convert = null): static {
  32. $this->formatStateUsing(static function (TextColumn $column, $state) use ($currency, $convert): ?string {
  33. if (blank($state)) {
  34. return null;
  35. }
  36. $currency = $column->evaluate($currency);
  37. $convert = $column->evaluate($convert);
  38. return money($state, $currency, $convert);
  39. });
  40. return $this;
  41. });
  42. TextInput::macro('currency', function (string|Closure|null $currency = null): static {
  43. $this->extraAttributes(['wire:key' => Str::random()])
  44. ->prefix(static function (TextInput $component) use ($currency) {
  45. $currency = $component->evaluate($currency);
  46. return currency($currency)->getPrefix();
  47. })
  48. ->suffix(static function (TextInput $component) use ($currency) {
  49. $currency = $component->evaluate($currency);
  50. return currency($currency)->getSuffix();
  51. })
  52. ->mask(static function (TextInput $component) use ($currency) {
  53. $currency = $component->evaluate($currency);
  54. $decimal_mark = currency($currency)->getDecimalMark();
  55. $thousands_separator = currency($currency)->getThousandsSeparator();
  56. $precision = currency($currency)->getPrecision();
  57. $jsCode = "\$money(\$input, '" . $decimal_mark . "', '" . $thousands_separator . "', " . $precision . ");";
  58. return RawJs::make($jsCode);
  59. });
  60. return $this;
  61. });
  62. Select::macro('color', function (string|Closure|null $color = null): static {
  63. $this->options(
  64. collect(PrimaryColor::caseValues())
  65. ->mapWithKeys(static function ($color) {
  66. return [$color => Str::title($color)];
  67. })
  68. ->toArray()
  69. )
  70. ->extraAttributes(['wire:key' => Str::random()])
  71. ->prefix(static function (Select $component) use ($color) {
  72. $color = $component->evaluate($color);
  73. return '<span class="text-' . $color . '-500">●</span>';
  74. });
  75. return $this;
  76. });
  77. }
  78. }