+ zin/searchform: implements search form component.

This commit is contained in:
陈涛
2023-03-05 22:18:04 +08:00
parent 16149f65e4
commit 2933eac6f0
6 changed files with 169 additions and 5 deletions
+143 -1
View File
@@ -216,6 +216,7 @@ if (\common::hasPriv('product', 'batchEdit'))
);
}
$others[] = array(
'id' => 'searchBtn',
'type' => 'button',
'icon' => 'search',
'text' => $lang->product->searchStory,
@@ -245,6 +246,102 @@ $btnGroup[] = array(
'url' => createLink('product', 'create')
);
/* Search Form options. */
$searchOptions = <<<OPTIONS
{
"formConfig": { "actions": "11", "method": "post" },
"fields": [
{ "label": "项目集名称", "name": "name", "control": "input", "operator": "include", "defaultValue": "1111", "placeholder": "请填写" },
{ "label": "状态", "name": "status", "control": "select", "operator": "!=", "defaultValue": "wait",
"values": {
"": "",
"wait": "未开始",
"doing": "进行中",
"suspended": "已挂起",
"closed": "已关闭"
}
},
{ "label": "项目集描述", "name": "desc", "control": "input", "defaultValue": "11", "placeholder": "请填写1" },
{ "label": "负责人", "name": "PM", "control": "select", "defaultValue": "", "placeholder": "请填写2" },
{ "label": "创建日期", "name": "openedDate", "control": "date", "defaultValue": "" },
{ "label": "计划开始", "name": "begin", "control": "date", "defaultValue": "" },
{ "label": "计划完成", "name": "end", "control": "date", "defaultValue": "" },
{ "label": "由谁创建", "name": "openedBy", "control": "select", "defaultValue": "" },
{ "label": "最后编辑日期", "name": "lastEditedDate", "control": "date", "defaultValue": "" },
{ "label": "实际开始", "name": "realBegan", "control": "date", "defaultValue": "" },
{ "label": "实际完成日期", "name": "realEnd", "control": "date", "defaultValue": "" },
{ "label": "关闭日期", "name": "closedDate", "control": "date", "defaultValue": "" }
],
"operators": [
{ "value": "=", "title": "=" },
{ "value": "!=", "title": "!=" },
{ "value": ">", "title": ">" },
{ "value": ">=", "title": ">=" },
{ "value": "<", "title": "<" },
{ "value": "<=", "title": "<=" },
{ "value": "include", "title": "包含" },
{ "value": "between", "title": "介于" },
{ "value": "notinclude", "title": "不包含" },
{ "value": "belong", "title": "从属于" }
],
"savedQuery": [
{ "id": "1", "title": "条件11", "account": "11",
"content": [
{ "fields": "status", "control": "select", "condition": "=", "value": "doing" },
{ "fields": "openedDate", "control": "date", "condition": "=", "value": "2022-11-15" },
{ "fields": "openedBy", "control": "input", "condition": "=", "value": "" },
{ "fields": "PM", "control": "select", "condition": "!=", "value": "" },
{ "fields": "openedDate", "control": "date", "condition": "include", "value": "" },
{ "fields": "begin", "control": "date", "condition": "=", "value": "" }
]
}
],
"andOr": [
{ "value": "and", "title": "并且" },
{ "value": "or", "title": "或者" }
],
"groupName": [
"第一组",
"第二组"
],
"savedQueryTitle": "已保存的查询条件",
"saveSearch": {
"text": "保存搜索条件",
"config": {
"data-toggle": "modal",
"href": "#saveModal",
"data-url": "/index.php?m=search&f=saveQuery&module=task&onMenuBar=yes"
}
}
}
OPTIONS;
$options = json_decode($searchOptions);
$jsSearch = <<<JSSEARCH
var el = document.getElementById('searchBtn');
if( el ) {
el.addEventListener('click', function(event){
var searchPanel = document.getElementById('searchPanel');
if(!searchPanel) return;
searchPanel.classList.toggle('hidden');
});
}
const ajaxForm = new AjaxForm('#saveForm', {
rules: {
name: {
required: true,
errMsg: '请输入登录名',
},
password: {
required: true,
errMsg: '请输入密码',
},
},
});
;
JSSEARCH;
page
(
set('title', $title),
@@ -291,6 +388,11 @@ page
set('others', $others),
set('btnGroup', $btnGroup)
),
panel
(
setId('searchPanel'),
to('body', searchform(set($options)))
),
dtable
(
set('width', '100%'),
@@ -299,5 +401,45 @@ page
set('footPager', $footer),
set('footToolbar', array('items' => array(array('size' => 'sm', 'text' => '编辑', 'btnType' => 'primary'))))
)
)
),
modal
(
setId('saveModal'),
form
(
setId('saveForm'),
div
(
setClass('flex flex-row justify-between'),
input
(
setId('title'),
set('name', 'title'),
setClass('form-control w-5/12'),
set('type', 'text'),
set('placeholder', '请输入保存条件名称')
),
checkbox
(
setId('common'),
set('name', 'common'),
setClass('w-3/12'),
'设为公共查询条件'
),
checkbox
(
setId('onMenuBar'),
set('name', 'onMenuBar'),
setClass('w-3/12'),
'显示在菜单栏'
),
btn(
setClass('w-1/12 primary'),
set('data-type', 'submit'),
'保存'
)
)
)
),
h::js($jsSearch)
);
+1
View File
@@ -54,3 +54,4 @@ function inputaddon() {return createWg('inputaddon', func_get_args());}
function inputgroup() {return createWg('inputgroup', func_get_args());}
function inputbtn() {return createWg('inputbtn', func_get_args());}
function toolbar() {return createWg('toolbar', func_get_args());}
function searchform() {return createWg('searchform', func_get_args());}
+2 -2
View File
@@ -61,8 +61,8 @@ class btn extends wg
if(!empty($size)) $classList[] = "size-$size";
$children = array();
if(!empty($icon)) $children[] = new icon($icon);
if(!empty($text)) $children[] = h::span($text, setClass('text'));
if(!empty($icon)) $children[] = new icon($icon);
if(!empty($text)) $children[] = h::span($text, setClass('text'));
$children[] = parent::build();
+6 -1
View File
@@ -18,8 +18,13 @@ class checkbox extends wg
{
return h::label
(
setClass('pl-2'),
set($this->props->skip(array_keys(static::getDefinedProps(), true))),
setClass('checkbox'),
h::checkbox(set($this->props->skip(array_keys(static::getDefinedProps()), true))),
h::checkbox
(
setId($this->prop('id'))
),
$this->prop('text')
);
}
+2 -1
View File
@@ -84,7 +84,8 @@ class modal extends wg
h::div
(
setClass('modal-body'),
!isset($this->blocks['body']) ? null : $this->blocks['body']
!isset($this->blocks['body']) ? null : $this->blocks['body'],
$this->children()
),
/* Footer. */
h::div
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace zin;
class searchform extends wg
{
protected static $defineProps = array
(
'js-render?:bool=true'
);
protected function build()
{
return zui::searchform(inherit($this));
}
}