admin workflow

main
panliang 2024-04-19 17:03:37 +08:00
parent 3039ffe27e
commit 98c979ac6b
5 changed files with 86 additions and 28 deletions

View File

@ -32,16 +32,40 @@ class AgreementController extends AdminController
...$this->baseHeaderToolBar(),
])
->bulkActions([])
->filter($this->baseFilter()->body([
amis()->GroupControl()->mode('horizontal')->body([
amisMake()->TextControl()
->name('name')
->label(__('agreement.name'))
->columnRatio(3)
->clearable(),
amisMake()->TextControl()->name('employee_search')
->label(__('agreement.employee_id'))
->placeholder(__('employee.name').'/'.__('employee.phone'))
->columnRatio(3)
->clearable(),
amisMake()->DateRangeControl()
->name('date_range')
->label(__('agreement.created_at'))
->columnRatio(3)
->clearable(),
]),
]))
->columns([
amisMake()->TableColumn()->name('id')->label(__('agreement.id')),
amisMake()->TableColumn()->name('name')->label(__('agreement.name')),
amisMake()->TableColumn()->name('employee.name')->label(__('agreement.employee_id')),
amisMake()->TableColumn()->name('created_at')->label(__('agreement.created_at')),
amisMake()->TableColumn()->name('workflow.check_status')->label(__('workflow_log.check_status'))->set('type', 'mapping')->map(CheckStatus::options()),
amisMake()->TableColumn()->name('created_at')->label(__('agreement.created_at')),
amisMake()->Operation()->label(__('admin.actions'))->buttons([
$this->rowShowTypeButton('drawer', 'xl')->visible($user->can('admin.agreement.view')),
$this->rowEditTypeButton('drawer', 'xl')->visible($user->can('admin.agreement.update')),
$this->rowDeleteButton()->visible($user->can('admin.agreement.delete')),
$this->rowShowTypeButton('drawer', 'xl')
->visible($user->can('admin.agreement.view')),
$this->rowEditTypeButton('drawer', 'xl')
->visible($user->can('admin.agreement.update'))
->visibleOn('${OR(workflow.check_status == '.CheckStatus::None->value.', workflow.check_status == '.CheckStatus::Cancel->value.', workflow.check_status == '.CheckStatus::Fail->value.')}'),
$this->rowDeleteButton()
->visible($user->can('admin.agreement.delete'))
->visibleOn('${OR(workflow.check_status == '.CheckStatus::None->value.', workflow.check_status == '.CheckStatus::Cancel->value.', workflow.check_status == '.CheckStatus::Fail->value.')}'),
$this->applyAction(),
$this->cancelAction(),
amisMake()->AjaxAction()

View File

@ -56,29 +56,54 @@ class WorkflowController extends AdminController
return $this->baseList($crud);
}
public function create()
{
$this->isCreate = true;
$form = amis()->Card()
->className('base-form')
->header(['title' => __('admin.create')])
->toolbar([$this->backButton()])
->body($this->form(false)->api($this->getStorePath()));
$page = $this->basePage()->id('workflow-form-page')->body($form);
return $this->response()->success($page);
}
public function edit($id)
{
$this->isEdit = true;
if ($this->actionOfGetData()) {
return $this->response()->success($this->service->getEditData($id));
}
$form = amis()->Card()
->className('base-form')
->header(['title' => __('admin.edit')])
->toolbar([$this->backButton()])
->body(
$this->form(true)->api($this->getUpdatePath())->initApi($this->getEditGetDataPath())
);
$page = $this->basePage()->id('workflow-form-page')->body($form);
return $this->response()->success($page);
}
public function form($edit): Form
{
return $this->baseForm()->title('')->body([
amisMake()->TextControl()->name('key')->label(__('workflow.key'))->required(),
amisMake()->TextControl()->name('name')->label(__('workflow.name'))->required(),
amisMake()->ArrayControl()->name('config')->label(__('workflow.config'))->items(amisMake()->ComboControl()->items([
amisMake()->TableControl()->name('config')->label(__('workflow.config'))->showIndex()->addable()->removable()->needConfirm(false)->draggable()->columns([
amisMake()->SelectControl()->options(CheckType::options())->name('type')->label(__('workflow.type')),
amisMake()->SelectControl()
->options($this->getJobOptions())
->labelField('name')
->valueField('key')
->name('job')
// ->visibleOn('${config.type == '.CheckType::Job->value.'}')
->label(CheckType::Job->text()),
amisMake()->SelectControl()
->options($this->getEmployeeOptions())
->labelField('name')
->valueField('id')
->searchable()
->name('user')
// ->visibleOn('${config.type == '.CheckType::User->value.'}')
->label(CheckType::User->text()),
])),
->source(admin_url('api/workflow/value-options?type=${type}'))
->name('value')
->label(__('workflow.value')),
]),
]);
}
@ -93,6 +118,17 @@ class WorkflowController extends AdminController
return $this->baseDetail()->title('')->body($detail);
}
public function getValueOptions(Request $request)
{
$type = $request->input('type');
$options = match($type) {
CheckType::Job->value => $this->getJobOptions(),
CheckType::User->value => $this->getEmployeeOptions(),
default => []
};
return $this->response()->success($options);
}
public function apply(Request $request)
{
$model = WorkflowCheck::findOrFail($request->input('id'));
@ -202,7 +238,7 @@ class WorkflowController extends AdminController
public function getJobOptions()
{
if (! $this->jobOptions) {
$this->jobOptions = Keyword::where('parent_key', 'job')->get();
$this->jobOptions = Keyword::where('parent_key', 'job')->select(['key as value', 'name as label'])->get();
}
return $this->jobOptions;
@ -211,7 +247,7 @@ class WorkflowController extends AdminController
public function getEmployeeOptions()
{
if (! $this->employeeOptions) {
$this->employeeOptions = Employee::enable()->get();
$this->employeeOptions = Employee::enable()->select(['id as value', 'name as label'])->get();
}
return $this->employeeOptions;

View File

@ -224,12 +224,8 @@ class WorkFlowService extends BaseService
CheckType::User->value => CheckType::User->text(),
};
$item['subTitle'] = match ($item['type']) {
CheckType::Job->value => Keyword::where('key', $item['job'])->value('name'),
CheckType::User->value => Employee::where('id', $item['user'])->value('name'),
};
$item['value'] = match ($item['type']) {
CheckType::Job->value => $item['job'],
CheckType::User->value => $item['user'],
CheckType::Job->value => Keyword::where('key', $item['value'])->value('name'),
CheckType::User->value => Employee::where('id', $item['value'])->value('name'),
};
$item['sort'] = $key + 1;
}

View File

@ -228,6 +228,7 @@ Route::group([
$router->get('employee-sign-logs', [SignLogController::class, 'shareList']);
$router->get('keywords/tree-list', [KeywordController::class, 'getTreeList'])->name('api.keywords.tree-list');
$router->get('workflow/value-options', [WorkflowController::class, 'getValueOptions']);
$router->post('workflow/apply', [WorkflowController::class, 'apply']);
$router->post('workflow/cancel', [WorkflowController::class, 'cancel']);
$router->post('workflow/success', [WorkflowController::class, 'success']);

View File

@ -12,6 +12,7 @@ class Workflow extends Model
protected $fillable = ['key', 'name', 'config'];
protected $casts = [
// [{type, value, sort, title, subTitle}]
'config' => 'array',
];
}