diff --git a/forms/hero.form.yao b/forms/hero.form.yao index 3347e8b..e0a6a45 100644 --- a/forms/hero.form.yao +++ b/forms/hero.form.yao @@ -160,7 +160,9 @@ "columns": [ { "name": "AutoComplete", "width": 24 }, { "name": "AutoComplete Remote", "width": 24 }, - { "name": "AutoComplete Option with Icon", "width": 24 } + { "name": "AutoComplete Option with Icon", "width": 24 }, + { "name": "AutoComplete Query Params", "width": 24 }, + { "name": "AutoComplete Query DSL", "width": 24 } ] }, { @@ -169,7 +171,9 @@ "weight": "medium", "color": "danger", "columns": [ - { "name": "Select Option with Icon", "width": 24 } + { "name": "Select Option with Icon", "width": 24 }, + { "name": "Select Query Params", "width": 24 }, + { "name": "Select Query DSL", "width": 24 } ] }, { @@ -413,6 +417,67 @@ } }, + "Select Query Params": { + "bind": "identity", + "edit": { + "type": "Select", + "props": { + "query": { + // Specify the field name of the label, value, and icon + "labelField": "name", // required. the field name of the label + "valueField": "type", // required. the field name of the value + "iconField": "icon", // optional. the field name of the icon + + // Query parameters + "from": "roles", // Model name + // [[ $KEYWORDS ]] is the search keyword + // [[ $SELECTED ]] is the selected value, the type could be a number, string or an array + "wheres": [ + { "column": "name", "value": "[[ $KEYWORDS ]]", "op": "match" }, // if the search is enabled, the query will be executed when the user types in the search box + { + "method": "orwhere", + "type": "name", + "value": "[[ $KEYWORDS ]]" + } // suggest showing the selected value, if the selected value is not in the search result, it will be added to the search result + ], + "limit": 20, // the number of records returned, default is 100. if it's 0, use the default value + + // Format search results + "labelFormat": "%name-%type", // optional. the format of the label, field name should be add prefix '%' + "valueFormat": "%type", // required. the field name of the value should be add prefix '%' + "iconFormat": "%icon" // optional. the field name of the icon should be add prefix '%' + } + } + } + }, + + "Select Query DSL": { + "bind": "identity", + "edit": { + "type": "Select", + "props": { + "query": { + // Query DSL + "engine": "default", // The query engine name, if you want to use queryDSL, this field is required + "select": ["name as label", "type as value", "icon"], // required. must have label, value and icon fields. icon is optional + "from": "roles", // required. table name or model name. if it's a model name, should use '$' prefix. eg: '$roles' + // [[ $KEYWORDS ]] is the search keyword + // [[ $SELECTED ]] is the selected value, the type could be a number, string or an array + "wheres": [ + { "field": "name", "match": "[[ $KEYWORDS ]]" }, // if the search is enabled, the query will be executed when the user types in the search box + { "or": true, ":type": "[[ $SELECTED ]" } // suggest showing the selected value, if the selected value is not in the search result, it will be added to the search result + ], + "limit": 20, // the number of records returned, default is 100. if it's 0, use the default value + + // Format search results + "labelFormat": "%name-%type", // optional. the format of the label, field name should be add prefix '%' + "valueFormat": "%type", // required. the field name of the value should be add prefix '%' + "iconFormat": "%icon" // optional. the field name of the icon should be add prefix '%' + } + } + } + }, + "AutoComplete Option with Icon": { "bind": "identity", "edit": { @@ -439,6 +504,63 @@ } }, + "AutoComplete Query Params": { + "bind": "identity", + "edit": { + "type": "AutoComplete", + "props": { + "query": { + "labelField": "name", // required. the field name of the label + "valueField": "type", // required. the field name of the value + "iconField": "icon", // optional. the field name of the icon + "from": "roles", // Model name + "wheres": [ + // [[ $KEYWORDS ]] is the search keyword + // [[ $SELECTED ]] is the selected value, the type could be a number, string or an array + { "column": "name", "value": "[[ $KEYWORDS ]]", "op": "match" }, // if the search is enabled, the query will be executed when the user types in the search box + { + "method": "orwhere", + "type": "name", + "value": "[[ $KEYWORDS ]]" + } // suggest showing the selected value, if the selected value is not in the search result, it will be added to the search result + ], + "limit": 20, // the number of records returned, default is 100. if it's 0, use the default value + + // Format search results + "labelFormat": "%name-%type", // optional. the format of the label, field name should be add prefix '%' + "valueFormat": "%type", // required. the field name of the value should be add prefix '%' + "iconFormat": "%icon" // optional. the field name of the icon should be add prefix '%' + } + } + } + }, + + "AutoComplete Query DSL": { + "bind": "identity", + "edit": { + "type": "AutoComplete", + "props": { + "query": { + "engine": "default", // The query engine name, if you want to use queryDSL, this field is required + "select": ["name as label", "type as value", "icon"], // required. must have label,value and icon fields, icon is optional + "from": "roles", // required. table name or model name. if it's a model name, should use '$' prefix. eg: '$roles' + "wheres": [ + // [[ $KEYWORDS ]] is the search keyword + // [[ $SELECTED ]] is the selected value, the type could be a number, string or an array + { "field": "name", "match": "[[ $KEYWORDS ]]" }, // if the search is enabled, the query will be executed when the user types in the search box + { "or": true, ":type": "[[ $SELECTED ]" } // suggest showing the selected value, if the selected value is not in the search result, it will be added to the search result + ], + "limit": 20, // the number of records returned, default is 100. if it's 0, use the default value + + // Format search results + "labelFormat": "%name-%type", // optional. the format of the label, field name should be add prefix '%' + "valueFormat": "%type", // required. the field name of the value should be add prefix '%' + "iconFormat": "%icon" // optional. the field name of the icon should be add prefix '%' + } + } + } + }, + "Form Builder": { "hideLabel": true, "bind": "form_dsl", @@ -593,6 +715,7 @@ } } }, + "AutoComplete Remote": { "bind": "identity", "edit": { diff --git a/forms/role.form.yao b/forms/role.form.yao index 4b373a9..e3bb053 100644 --- a/forms/role.form.yao +++ b/forms/role.form.yao @@ -69,14 +69,9 @@ "sections": [ { "columns": [ - { - "name": "角色名称", - "width": 24 - }, - { - "name": "角色类型", - "width": 24 - } + { "name": "角色名称", "width": 24 }, + { "name": "角色类型", "width": 24 }, + { "name": "图标", "width": 24 } ] } ] diff --git a/models/role.mod.yao b/models/role.mod.yao index 318fdf8..8d5313a 100644 --- a/models/role.mod.yao +++ b/models/role.mod.yao @@ -19,6 +19,14 @@ "length": 20, "index": true, "nullable": true + }, + { + "name": "icon", + "label": "图标", + "comment": "图标", + "type": "string", + "length": 200, + "nullable": true } ], "relations": {}, diff --git a/scripts/init.ts b/scripts/init.ts index 15a4655..cf32e5c 100644 --- a/scripts/init.ts +++ b/scripts/init.ts @@ -70,12 +70,12 @@ function setData() { Process( "models.role.Insert", - ["name", "type"], + ["name", "type", "icon"], [ - ["法师", "mage"], - ["战士", "fighter"], - ["坦克", "tank"], - ["辅助", "support"], + ["法师", "mage", "icon-shield"], + ["战士", "fighter", "material-favorite"], + ["坦克", "tank", "icon-pocket"], + ["辅助", "support", ""], ] ); } diff --git a/tables/role.tab.json b/tables/role.tab.json index 46bf346..c4de4a0 100644 --- a/tables/role.tab.json +++ b/tables/role.tab.json @@ -1,134 +1,142 @@ { - "name": "Role List", - "action": { - "bind": { - "model": "role", - "option": { - "withs": { - "role": {} - } - } - }, - "search": {}, - "find": {}, - "get": {}, - "save": {}, - "delete": {} - }, - "layout": { - "primary": "id", - "header": {}, - "filter": { - "columns": [ - { - "name": "角色名称", - "width": 4 - } - ], - "actions": [ - { - "title": "添加角色", - "icon": "icon-plus", - "width": 3, - "action": { - "Common.openModal": { - "width": 640, - "Form": { - "type": "edit", - "model": "role" - } - } - } - } - ] - }, - "table": { - "columns": [ - { - "name": "角色名称" - }, - { - "name": "角色类型" - } - ], - "operation": { - "fold": false, - "width": 60, - "actions": [ - { - "title": "查看", - "icon": "icon-eye", - "action": { - "Common.openModal": { - "width": 640, - "Form": { - "type": "view", - "model": "role" - } - } - } - }, - { - "title": "编辑", - "icon": "icon-edit-2", - "action": { - "Common.openModal": { - "Form": { - "type": "edit", - "model": "role" - } - } - } - }, - { - "title": "删除", - "icon": "icon-trash-2", - "action": { - "Table.delete": {} - }, - "style": "danger", - "confirm": { - "title": "提示", - "desc": "确认删除,删除后数据无法恢复?" - } - } - ] - } + "name": "Role List", + "action": { + "bind": { + "model": "role", + "option": { + "withs": { + "role": {} + } + } + }, + "search": {}, + "find": {}, + "get": {}, + "save": {}, + "delete": {} + }, + "layout": { + "primary": "id", + "header": {}, + "filter": { + "columns": [ + { + "name": "角色名称", + "width": 4 + } + ], + "actions": [ + { + "title": "添加角色", + "icon": "icon-plus", + "width": 3, + "action": { + "Common.openModal": { + "width": 640, + "Form": { + "type": "edit", + "model": "role" + } } - }, - "fields": { - "filter": { - "角色名称": { - "bind": "where.name.like", - "edit": { - "type": "Input", - "props": {} - } - } + } + } + ] + }, + "table": { + "columns": [ + { "name": "角色名称" }, + { "name": "角色类型" }, + { "name": "角色图标" } + ], + "operation": { + "fold": false, + "width": 60, + "actions": [ + { + "title": "查看", + "icon": "icon-eye", + "action": { + "Common.openModal": { + "width": 640, + "Form": { + "type": "view", + "model": "role" + } + } + } + }, + { + "title": "编辑", + "icon": "icon-edit-2", + "action": { + "Common.openModal": { + "Form": { + "type": "edit", + "model": "role" + } + } + } + }, + { + "title": "删除", + "icon": "icon-trash-2", + "action": { + "Table.delete": {} }, - "table": { - "角色名称": { - "bind": "name", - "view": { - "type": "Text", - "props": {} - }, - "edit": { - "type": "Input", - "props": {} - } - }, - "角色类型": { - "bind": "type", - "view": { - "type": "Text", - "props": {} - }, - "edit": { - "type": "Input", - "props": {} - } - } + "style": "danger", + "confirm": { + "title": "提示", + "desc": "确认删除,删除后数据无法恢复?" } + } + ] + } + } + }, + "fields": { + "filter": { + "角色名称": { + "bind": "where.name.like", + "edit": { + "type": "Input", + "props": {} + } + } + }, + "table": { + "角色名称": { + "bind": "name", + "view": { + "type": "Text", + "props": {} + }, + "edit": { + "type": "Input", + "props": {} + } + }, + "角色类型": { + "bind": "type", + "view": { + "type": "Text", + "props": {} + }, + "edit": { + "type": "Input", + "props": {} + } + }, + "角色图标": { + "bind": "icon", + "view": { + "type": "Text", + "props": {} + }, + "edit": { + "type": "Input", + "props": {} + } } -} \ No newline at end of file + } + } +}