refactor(super_manage/index): uoj_form_v2

This commit is contained in:
Baoshuo Ren 2023-01-16 21:40:11 +08:00
parent e4585f90ba
commit e28f8d97b4
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -83,13 +83,11 @@ if ($cur_tab == 'index') {
"order by level desc, important_blogs.blog_id desc", "order by level desc, important_blogs.blog_id desc",
]); ]);
$add_announcement_form = new UOJBs4Form('add_announcement'); $add_announcement_form = new UOJForm('add_announcement');
$add_announcement_form->addInput( $add_announcement_form->addInput('blog_id', [
'blog_id', 'div_class' => 'col-auto',
'text', 'label' => '博客 ID',
'博客 ID', 'validator_php' => function ($id, &$vdata) {
'',
function ($id, &$vdata) {
if (!validateUInt($id)) { if (!validateUInt($id)) {
return '博客 ID 无效'; return '博客 ID 无效';
} }
@ -102,14 +100,12 @@ if ($cur_tab == 'index') {
return ''; return '';
}, },
null ]);
); $add_announcement_form->addInput('blog_level', [
$add_announcement_form->addInput( 'div_class' => 'col-auto',
'blog_level', 'label' => '置顶级别',
'text', 'default_value' => '0',
'置顶级别', 'validator_php' => function ($x, &$vdata) {
'0',
function ($x, &$vdata) {
if (!validateUInt($x)) { if (!validateUInt($x)) {
return '数字不合法'; return '数字不合法';
} }
@ -122,8 +118,7 @@ if ($cur_tab == 'index') {
return ''; return '';
}, },
null ]);
);
$add_announcement_form->handle = function (&$vdata) { $add_announcement_form->handle = function (&$vdata) {
$blog_id = $vdata['blog_id']; $blog_id = $vdata['blog_id'];
$blog_level = $vdata['level']; $blog_level = $vdata['level'];
@ -152,8 +147,9 @@ if ($cur_tab == 'index') {
]); ]);
} }
}; };
$add_announcement_form->submit_button_config['align'] = 'compressed'; $add_announcement_form->config['form']['class'] = 'row gy-2 gx-3 align-items-end';
$add_announcement_form->submit_button_config['text'] = '提交'; $add_announcement_form->config['submit_container']['class'] = 'col-auto';
$add_announcement_form->config['submit_button']['text'] = '提交';
$add_announcement_form->succ_href = '/super_manage/index#announcements'; $add_announcement_form->succ_href = '/super_manage/index#announcements';
$add_announcement_form->runAtServer(); $add_announcement_form->runAtServer();
@ -183,13 +179,11 @@ if ($cur_tab == 'index') {
"order by end_time asc", "order by end_time asc",
]); ]);
$add_countdown_form = new UOJBs4Form('add_countdown'); $add_countdown_form = new UOJForm('add_countdown');
$add_countdown_form->addInput( $add_countdown_form->addInput('countdown_title', [
'countdown_title', 'div_class' => 'col-auto',
'text', 'label' => '标题',
'标题', 'validator_php' => function ($title, &$vdata) {
'',
function ($title, &$vdata) {
if ($title == '') { if ($title == '') {
return '标题不能为空'; return '标题不能为空';
} }
@ -198,14 +192,12 @@ if ($cur_tab == 'index') {
return ''; return '';
}, },
null ]);
); $add_countdown_form->addInput('countdown_end_time', [
$add_countdown_form->addInput( 'div_class' => 'col-auto',
'countdown_end_time', 'label' => '结束时间',
'text', 'default_value' => UOJTime::$time_now_str,
'结束时间', 'validator_php' => function ($end_time, &$vdata) {
date("Y-m-d H:i:s"),
function ($end_time, &$vdata) {
try { try {
$vdata['end_time'] = new DateTime($end_time); $vdata['end_time'] = new DateTime($end_time);
} catch (Exception $e) { } catch (Exception $e) {
@ -214,8 +206,7 @@ if ($cur_tab == 'index') {
return ''; return '';
}, },
null ]);
);
$add_countdown_form->handle = function (&$vdata) { $add_countdown_form->handle = function (&$vdata) {
DB::insert([ DB::insert([
"insert into countdowns", "insert into countdowns",
@ -224,8 +215,9 @@ if ($cur_tab == 'index') {
DB::tuple([$vdata['title'], $vdata['end_time']->format('Y-m-d H:i:s')]), DB::tuple([$vdata['title'], $vdata['end_time']->format('Y-m-d H:i:s')]),
]); ]);
}; };
$add_countdown_form->submit_button_config['align'] = 'compressed'; $add_countdown_form->config['form']['class'] = 'row gy-2 gx-3 align-items-end';
$add_countdown_form->submit_button_config['text'] = '添加'; $add_countdown_form->config['submit_container']['class'] = 'col-auto';
$add_countdown_form->config['submit_button']['text'] = '添加';
$add_countdown_form->succ_href = '/super_manage/index#countdowns'; $add_countdown_form->succ_href = '/super_manage/index#countdowns';
$add_countdown_form->runAtServer(); $add_countdown_form->runAtServer();
@ -255,13 +247,11 @@ if ($cur_tab == 'index') {
"order by level desc, id asc", "order by level desc, id asc",
]); ]);
$add_link_form = new UOJBs4Form('add_link'); $add_link_form = new UOJForm('add_link');
$add_link_form->addInput( $add_link_form->addInput('link_title', [
'link_title', 'div_class' => 'col-auto',
'text', 'label' => '标题',
'标题', 'validator_php' => function ($title, &$vdata) {
'',
function ($title, &$vdata) {
if ($title == '') { if ($title == '') {
return '标题不能为空'; return '标题不能为空';
} }
@ -270,14 +260,11 @@ if ($cur_tab == 'index') {
return ''; return '';
}, },
null ]);
); $add_link_form->addInput('link_url', [
$add_link_form->addInput( 'div_class' => 'col-auto',
'link_url', 'label' => '链接',
'text', 'validator_php' => function ($url, &$vdata) {
'链接',
'',
function ($url, &$vdata) {
if (!validateURL($url)) { if (!validateURL($url)) {
return '链接不合法'; return '链接不合法';
} }
@ -286,14 +273,12 @@ if ($cur_tab == 'index') {
return ''; return '';
}, },
null ]);
); $add_link_form->addInput('link_level', [
$add_link_form->addInput( 'div_class' => 'col-auto',
'link_level', 'label' => '权重',
'text', 'default_value' => '10',
'权重', 'validator_php' => function ($level, &$vdata) {
'10',
function ($level, &$vdata) {
if (!validateUInt($level)) { if (!validateUInt($level)) {
return '数字不合法'; return '数字不合法';
} }
@ -302,8 +287,7 @@ if ($cur_tab == 'index') {
return ''; return '';
}, },
null ]);
);
$add_link_form->handle = function (&$vdata) { $add_link_form->handle = function (&$vdata) {
DB::insert([ DB::insert([
"insert into friend_links", "insert into friend_links",
@ -312,8 +296,9 @@ if ($cur_tab == 'index') {
DB::tuple([$vdata['title'], $vdata['url'], $vdata['level']]), DB::tuple([$vdata['title'], $vdata['url'], $vdata['level']]),
]); ]);
}; };
$add_link_form->submit_button_config['align'] = 'compressed'; $add_link_form->config['form']['class'] = 'row gy-2 gx-3 align-items-end';
$add_link_form->submit_button_config['text'] = '添加'; $add_link_form->config['submit_container']['class'] = 'col-auto';
$add_link_form->config['submit_button']['text'] = '添加';
$add_link_form->succ_href = '/super_manage/index#links'; $add_link_form->succ_href = '/super_manage/index#links';
$add_link_form->runAtServer(); $add_link_form->runAtServer();
} elseif ($cur_tab == 'users') { } elseif ($cur_tab == 'users') {