refactor: kb & station & terminal
This commit is contained in:
@@ -35,6 +35,18 @@ class TerminalResource extends Resource
|
||||
return auth()->user()?->can('terminal.view') ?? false;
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
$query = parent::getEloquentQuery();
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user && $user->hasStationRestriction()) {
|
||||
$query->whereIn('station_id', $user->getAccessibleStationIds());
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
@@ -77,11 +89,13 @@ class TerminalResource extends Resource
|
||||
'regex' => 'MAC地址格式不正确,应为 AA:BB:CC:DD:EE:FF',
|
||||
]),
|
||||
|
||||
Forms\Components\TextInput::make('station_id')
|
||||
->label('线站ID')
|
||||
->maxLength(50)
|
||||
->placeholder('例如: BL02U1')
|
||||
->helperText('关联的光束线/线站标识'),
|
||||
Forms\Components\Select::make('station_id')
|
||||
->label('所属线站')
|
||||
->relationship('station', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->placeholder('未绑定')
|
||||
->helperText('终端所属的线站'),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
@@ -131,44 +145,6 @@ class TerminalResource extends Resource
|
||||
->columns(2)
|
||||
->description('配置终端的语音唤醒能力'),
|
||||
|
||||
Forms\Components\Section::make('指引关联')
|
||||
->schema([
|
||||
Forms\Components\Repeater::make('guideAssociations')
|
||||
->label('关联指引')
|
||||
->relationship('guides')
|
||||
->schema([
|
||||
Forms\Components\Select::make('id')
|
||||
->label('指引')
|
||||
->options(\App\Models\Guide::where('status', 'published')->pluck('name', 'id'))
|
||||
->required()
|
||||
->searchable()
|
||||
->distinct()
|
||||
->disableOptionsWhenSelectedInSiblingRepeaterItems()
|
||||
->helperText('选择要关联的指引'),
|
||||
|
||||
Forms\Components\TextInput::make('priority')
|
||||
->label('优先级')
|
||||
->numeric()
|
||||
->default(0)
|
||||
->required()
|
||||
->minValue(0)
|
||||
->helperText('数字越小优先级越高,0为最高优先级'),
|
||||
])
|
||||
->columns(2)
|
||||
->reorderable()
|
||||
->reorderableWithButtons()
|
||||
->addActionLabel('添加指引')
|
||||
->reorderableWithDragAndDrop(false)
|
||||
->itemLabel(
|
||||
fn(array $state): ?string =>
|
||||
\App\Models\Guide::find($state['id'])?->name ?? '未选择'
|
||||
)
|
||||
->collapsed()
|
||||
->collapsible()
|
||||
->helperText('可以关联多个指引,并设置优先级。拖动或使用按钮调整顺序。'),
|
||||
])
|
||||
->description('配置终端可以访问的操作指引及其优先级'),
|
||||
|
||||
Forms\Components\Section::make('AI提示词配置')
|
||||
->schema([
|
||||
Forms\Components\Grid::make(3)
|
||||
@@ -177,21 +153,18 @@ class TerminalResource extends Resource
|
||||
->label('提示词模板')
|
||||
->language('markdown')
|
||||
->fontSize('14px')
|
||||
->helperText('编辑AI提示词模板,支持使用占位符 {station_id}, {user}, {time}(由HMI端替换)')
|
||||
->helperText('编辑AI提示词模板,可用占位符: {station_name} {terminal_code} {terminal_name} {user} {time}')
|
||||
->placeholderText('请输入AI提示词模板...')
|
||||
->disablePreview()
|
||||
->columnSpan(2),
|
||||
|
||||
Forms\Components\Grid::make(1)
|
||||
->schema([
|
||||
Forms\Components\Placeholder::make('variable_helper')
|
||||
->label('变量参考')
|
||||
->content(fn() => view('filament.components.prompt-variable-helper')),
|
||||
])
|
||||
Forms\Components\Placeholder::make('variable_helper')
|
||||
->label('可用占位符')
|
||||
->content('`{station_name}` 线站名称 · `{terminal_code}` 终端编码 · `{terminal_name}` 终端名称 · `{user}` 用户名称 · `{time}` 当前时间')
|
||||
->columnSpan(1),
|
||||
]),
|
||||
])
|
||||
->description('配置终端的AI提示词模板,占位符由HMI端替换')
|
||||
->description('配置终端的AI提示词模板')
|
||||
->collapsible(),
|
||||
|
||||
Forms\Components\Section::make('状态信息')
|
||||
@@ -243,8 +216,8 @@ class TerminalResource extends Resource
|
||||
->copyable()
|
||||
->placeholder('未设置'),
|
||||
|
||||
Tables\Columns\TextColumn::make('station_id')
|
||||
->label('线站ID')
|
||||
Tables\Columns\TextColumn::make('station.name')
|
||||
->label('所属线站')
|
||||
->sortable()
|
||||
->placeholder('未绑定'),
|
||||
|
||||
@@ -299,7 +272,7 @@ class TerminalResource extends Resource
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->groups([
|
||||
Tables\Grouping\Group::make('station_id')
|
||||
Tables\Grouping\Group::make('station.name')
|
||||
->label('按线站分组')
|
||||
->collapsible(),
|
||||
Tables\Grouping\Group::make('is_online')
|
||||
|
||||
Reference in New Issue
Block a user