schema([ // Tabs::make("")->tabs([ Tab::make('基本資訊')->schema([ TextInput::make('keyword')->label("關聯字詞"), Translate::make()->schema(fn (string $locale) => [ TextInput::make('title') ->label("標題") ->columnSpan(1), ])->locales(["zh_TW", "en"]) ->columnSpanFull()->columns(3), ]), Tab::make('Banner 設定')->schema([ FileUpload::make('banner_pc')->label("Banner (PC)") ->disk("public") // ->helperText('建議寬高限制為:1280*720px,檔案大小限制為1M以下')->maxSize('1024') ->directory("esg"), FileUpload::make('banner_mobile')->label("Banner (Mobile)") ->disk("public") // ->helperText('建議寬高限制為:600*896px,檔案大小限制為1M以下')->maxSize('1024') ->directory("esg"), Translate::make()->schema(fn (string $locale) => [ TextInput::make('banner_alt') ->label("Banner 圖片註釋"), Textarea::make("description")->rows(5)->columnSpanFull()->label("短文"), ])->locales(["zh_TW", "en"]) ->columnSpanFull(), ]), Tab::make("段落設計")->schema([ //1: 純文字 2:區塊文字 3:表格 4:影片 or 圖片 5:左右圖文 Repeater::make("paragraphs")->schema([ TextInput::make('item_key') ->default(fn () => Str::random()) ->hidden() ->afterStateHydrated(function (TextInput $component, $state) { if (empty($state)) { $component->state(Str::random()); } }), Radio::make("type")->options([ 1 => "純文字", 2 => "區塊文字", 3 => "表格", 4 => "圖片", ])->label("")->default(1)->Live(), Group::make()->schema([ Translate::make()->schema(fn (string $locale) => [ RichEditor::make('content.text_content') ->fileAttachmentsDirectory('attachments') ->fileAttachmentsVisibility('private') ->disableToolbarButtons(['attachFiles']), ]) ->locales(["zh_TW", "en"]) ->id(fn ($get) => "para_text_" . $get('item_key')), ])->visible(fn (Get $get):bool => $get("type") == 1), Group::make()->schema([ Section::make('區塊文字設定')->schema([ // // 佈局設定 // Radio::make('layout_type')->label('佈局方式')->options([ // 'vertical' => '垂直排列', // 'horizontal' => '水平排列', // 'grid' => '網格排列', // ])->default('vertical')->Live(), // 文字區塊重複器 Repeater::make("content.text_blocks")->schema([ TextInput::make('block_item_key') ->default(fn () => Str::random()) ->hidden() ->afterStateHydrated(function (TextInput $component, $state) { if (empty($state)) { $component->state(Str::random()); } }), // 多語系內容 Translate::make()->schema(fn (string $locale) => [ // TextInput::make('block_title') // ->label("區塊標題") // ->maxLength(200) // ->visible(fn (Get $get) => in_array($get('block_type'), ['title', 'subtitle', 'highlight'])), RichEditor::make('block_content') ->disableToolbarButtons(['attachFiles']) ->required(), ]) ->locales(["zh_TW", "en"]) ->id(fn ($get) => "text_block_" . $get('block_item_key')), ]) ->label("") ->addActionLabel('增加區塊') ->orderColumn('order') ->reorderableWithButtons() ->cloneable() ->minItems(1) ->maxItems(20) ->defaultItems(1), ]), ])->visible(fn (Get $get):bool => $get('type') == 2), Group::make()->schema([ Section::make('表格設定')->schema([ Radio::make('content.is_card') ->label('手機板卡片顯示') ->options([ 1 => '是', // 改為數字鍵值 0 => '否' ]) ->default(2) ->inline(), // 表格基本資訊 // Translate::make()->schema(fn (string $locale) => [ // TextInput::make('content.table_title') // ->label("表格標題") // ->maxLength(200), // Textarea::make('content.table_description') // ->label("表格說明") // ->rows(3) // ->maxLength(500), // ])->locales(["zh_TW", "en"]) // ->id(fn ($get) => "table_info_" . $get('item_key')), // 表格資料 Placeholder::make('table_builder_info') ->content('請先設定表格欄數,然後填入表格資料'), Grid::make(3)->schema([ Radio::make('content.column_count') ->label('欄數') ->options([ 2 => '2欄', // 改為數字鍵值 3 => '3欄', 4 => '4欄' ]) ->default(2) ->inline() ->live() ->reactive(), // ✅ 添加 reactive() // Radio::make('content.is_card') // ->label('是否卡片呈現') // ->options([ // 1 => '是', // 改為數字鍵值 // 0 => '否', // ]) // ->default(1) // ->inline() // ->required() ]), Translate::make()->schema(fn (string $locale) => [ Grid::make(2) // 改用 Grid 來支援動態 columns ->schema([ TextInput::make('content.head1')->label('標題第1欄')->required(), Radio::make('content.head_align1') ->label('對齊') ->options([ 1 => '置左', // 改為數字鍵值 2 => '置中', 3 => '置右' ]) ->default(1), TextInput::make('content.head2')->label('標題第2欄')->required(), Radio::make('content.head_align2') ->label('對齊') ->options([ 1 => '置左', // 改為數字鍵值 2 => '置中', 3 => '置右' ]) ->default(1), TextInput::make('content.head3')->label('標題第3欄') ->visible(fn (Get $get) => intval($get('content.column_count')) >= 3)->columnSpan(1), Radio::make('content.head_align3') ->label('對齊') ->options([ 1 => '置左', // 改為數字鍵值 2 => '置中', 3 => '置右' ]) ->default(1) ->visible(fn (Get $get) => intval($get('content.column_count')) >= 3)->columnSpan(1), TextInput::make('content.head4')->label('標題第4欄') ->visible(fn (Get $get) => intval($get('content.column_count')) >= 4)->columnSpan(1), Radio::make('content.head_align4') ->label('對齊') ->options([ 1 => '置左', // 改為數字鍵值 2 => '置中', 3 => '置右' ]) ->default(1) ->visible(fn (Get $get) => intval($get('content.column_count')) >= 4)->columnSpan(1), ]) ->reactive() // 加入響應式 ])->locales(["zh_TW", "en"]), Repeater::make('content.simple_table_rows') ->label('表格資料') ->schema([ TextInput::make('simple_table_rows_key') ->default(fn () => Str::random()) ->hidden() ->afterStateHydrated(function (TextInput $component, $state) { if (empty($state)) { $component->state(Str::random()); } }), Translate::make()->schema(fn (string $locale) => [ Grid::make(1) // 改用 Grid 來支援動態 columns ->schema([ Radio::make('align1') ->label('對齊') ->options([ 1 => '置左', // 改為數字鍵值 2 => '置中', 3 => '置右' ]) ->default(1), RichEditor::make('col1') ->label('第1欄') ->disableToolbarButtons(['attachFiles']), // TextInput::make('col2')->label('第2欄')->required(), Radio::make('align2') ->label('對齊') ->options([ 1 => '置左', // 改為數字鍵值 2 => '置中', 3 => '置右' ]) ->default(1), RichEditor::make('col2') ->label('第2欄') ->disableToolbarButtons(['attachFiles']), Radio::make('align3') ->label('對齊') ->options([ 1 => '置左', // 改為數字鍵值 2 => '置中', 3 => '置右' ]) ->default(1) ->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 3), RichEditor::make('col3') ->label('第3欄') ->disableToolbarButtons(['attachFiles']) ->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 3), Radio::make('align4') ->label('對齊') ->options([ 1 => '置左', // 改為數字鍵值 2 => '置中', 3 => '置右' ]) ->default(1) ->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 4), RichEditor::make('col4') ->label('第4欄') ->disableToolbarButtons(['attachFiles']) ->visible(fn (Get $get) => intval($get('../../../content.column_count')) >= 4), ]) ->reactive() // 加入響應式 ])->locales(["zh_TW", "en"]), ]) ->id(fn ($get) => "simple_table_" . $get('simple_table_key')) ->addActionLabel('新增列') ->reorderableWithButtons() ->minItems(1) ]), ])->visible(fn (Get $get):bool => $get('type') == 3), Group::make()->schema([ Section::make('')->schema([ Repeater::make("content.multiple_images")->schema([ TextInput::make('para_img_item_key') ->default(fn () => Str::random()) ->hidden() ->afterStateHydrated(function (TextInput $component, $state) { if (empty($state)) { $component->state(Str::random()); } }), Translate::make()->schema(fn (string $locale) => [ TextInput::make('image_alt')->label("圖片註文"), ])->locales(["zh_TW", "en"]) ->id(fn ($get) => "para_img_mul_" . $get('para_img_item_key')), FileUpload::make('image_url')->label("")->disk("public") // ->helperText('建議寬高限制為:1080*675px,檔案大小限制為1M以下')->maxSize('1024') ->directory("esg/paragraphPhoto") ->maxFiles(10), ]) ->addActionLabel('新增') ->label("") ->orderColumn('order') ]) ])->visible(fn (Get $get):bool => $get("type") == 4), ]) ->relationship("paragraphs") ->addActionLabel('新增段落') ->collapsible() ->reorderableWithButtons() ->orderColumn('order') ->cloneable() ])->columnSpanFull(), ]) ->columnSpanFull() ]); } public static function table(Table $table): Table { return $table ->columns([ // TextColumn::make("title")->label("標題"), ]) ->filters([ // ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListEsg::route('/'), 'create' => Pages\CreateEsg::route('/create'), 'edit' => Pages\EditEsg::route('/{record}/edit'), ]; } }