YAO abstracts common function modules into widgets, describes differences through YAO DSL, and quickly replicates various functions. During development, if you develop a similar function module, you need to copy and paste the existing functions and replace the differences in batches.
YAO has a built-in set of Widgets covering most of the common functions of application development.
Widget supports customization. When the service starts, the application engine parses it into a set of API interfaces and a set of handlers according to the widget logic. This article describes how to use JavaScript scripts to add widgets.
Built-in Widget | Function |
---|---|
model | Data Structure Modeling |
flow | Data logic arrangement |
api | RESTFul API |
table | table CURD |
chart | data chart |
login | User login |
register | User registration |
task | Concurrent tasks |
schedule | Scheduled tasks |
socket | Socket |
websocket | WebSocket |
Related tutorials: [Use YAO Widget to build a cloud table] (../Tutorial/Use YAO Widget To Create A Cloud Table)
Design the DSL structure according to the business logic features. In this example, the differences between different tables are table fields, searchers, and table names.
Example:
{"name": "TEST","decription": "A TEST DYFORM","columns": [{"title": "First Name","name": "name","type": "input","search": true,"props": {"placeholder": "Please input your first name"}},{"title": "Amount","name": "amount","type": "input","search": true,"props": {"placeholder": "Please input amount"}},{"title": "Description","name": "desc","type": "textArea","props": {"placeholder": "Please input Description"}}]}
Take dyform as an example to create a widget:
cd /your/project/rootmkdir -p widgets/dyform# create widget filetouch widgets/dyform/widget.json # Widget basic informationtouch widgets/dyform/compile.js # dyform DSL compilertouch widgets/dyform/process.js # dyform handlertouch widgets/dyform/export.js # dyform exports built-in widget definitions
Tip: YAO custom widgets are placed in the widgets directory, which needs to be created manually.
Use an editor to open dyform/widget.json and fill in the basic information of the dyform widget
{"label": "Dynamic Form","description": "A form widget. users can design forms online","version": "0.1.0","root": "dyforms","extension": ".form.json","modules": ["Models", "Tables"]}
Field Description:
Configuration Items | Description |
---|---|
label | Widget name, displayed in the visual editor. |
description | Widget introduction, displayed in the visual editor. |
version | version number |
root | DSL file save path (relative to the project root directory) |
extension | DSL file extension |
modules | Modules that need to be exported. According to the DSL description in export.js, the converted YAO built-in widgets. Such as model, table, etc. These widgets are equivalent to DSL files saved in the project directory. |
Write dyform/process.js script, implement Model, Table process, convert custom DSL into YAO data model widget and table widget.
Write the Export function, declare the process to be exported, View source
function Export() {return { Model: "Model", Table: "Table" };}
Implement Model & Table process logic
process | Description | Source link |
---|---|---|
Model | Convert dyform DSL to model DSL, which is equivalent to manually writing a xxx.mod.json DSL file in the models folder | View source |
Table | Convert dyform DSL to table DSL, which is equivalent to manually writing a xxx..json DSL file in the tables folder | View source |
Tip: It is recommended to use the yao run command to debug the process, refer to the source code comment documentation.
Write dyform/export.js script, implement Models, Tables functions, export as YAO model & table widgets.
Export function | Description | Source code link |
---|---|---|
Models | Call the Model process to export the Yao model widget, the data structure is {MODEL_NAME:String: Model_DSL:Object} | View source code |
Tables | Call the Table process, export it as Yao table widget, the data structure is: {TABLE_NAME:String: Table_DSL:Object} | View source code |
In the dyforms folder, add the xxx.form.json file and write the dyform DSL description file to quickly create a set of form management modules, form APIs, form processes and model processes.
Use the yao migrate command to create the data table structure, the yao start command to start the service, and log in to the management interface to use the table management function. Routing address: http://127.0.0.1:5099/xiang/table/dyform.xxx
YAO abstracts common function modules into widgets, describes differences through YAO DSL, and quickly replicates various functions. During development, if you develop a similar function module, you need to copy and paste the existing functions and replace the differences in batches.
YAO has a built-in set of Widgets covering most of the common functions of application development.
Widget supports customization. When the service starts, the application engine parses it into a set of API interfaces and a set of handlers according to the widget logic. This article describes how to use JavaScript scripts to add widgets.
Built-in Widget | Function |
---|---|
model | Data Structure Modeling |
flow | Data logic arrangement |
api | RESTFul API |
table | table CURD |
chart | data chart |
login | User login |
register | User registration |
task | Concurrent tasks |
schedule | Scheduled tasks |
socket | Socket |
websocket | WebSocket |
Related tutorials: [Use YAO Widget to build a cloud table] (../Tutorial/Use YAO Widget To Create A Cloud Table)
Design the DSL structure according to the business logic features. In this example, the differences between different tables are table fields, searchers, and table names.
Example:
{"name": "TEST","decription": "A TEST DYFORM","columns": [{"title": "First Name","name": "name","type": "input","search": true,"props": {"placeholder": "Please input your first name"}},{"title": "Amount","name": "amount","type": "input","search": true,"props": {"placeholder": "Please input amount"}},{"title": "Description","name": "desc","type": "textArea","props": {"placeholder": "Please input Description"}}]}
Take dyform as an example to create a widget:
cd /your/project/rootmkdir -p widgets/dyform# create widget filetouch widgets/dyform/widget.json # Widget basic informationtouch widgets/dyform/compile.js # dyform DSL compilertouch widgets/dyform/process.js # dyform handlertouch widgets/dyform/export.js # dyform exports built-in widget definitions
Tip: YAO custom widgets are placed in the widgets directory, which needs to be created manually.
Use an editor to open dyform/widget.json and fill in the basic information of the dyform widget
{"label": "Dynamic Form","description": "A form widget. users can design forms online","version": "0.1.0","root": "dyforms","extension": ".form.json","modules": ["Models", "Tables"]}
Field Description:
Configuration Items | Description |
---|---|
label | Widget name, displayed in the visual editor. |
description | Widget introduction, displayed in the visual editor. |
version | version number |
root | DSL file save path (relative to the project root directory) |
extension | DSL file extension |
modules | Modules that need to be exported. According to the DSL description in export.js, the converted YAO built-in widgets. Such as model, table, etc. These widgets are equivalent to DSL files saved in the project directory. |
Write dyform/process.js script, implement Model, Table process, convert custom DSL into YAO data model widget and table widget.
Write the Export function, declare the process to be exported, View source
function Export() {return { Model: "Model", Table: "Table" };}
Implement Model & Table process logic
process | Description | Source link |
---|---|---|
Model | Convert dyform DSL to model DSL, which is equivalent to manually writing a xxx.mod.json DSL file in the models folder | View source |
Table | Convert dyform DSL to table DSL, which is equivalent to manually writing a xxx..json DSL file in the tables folder | View source |
Tip: It is recommended to use the yao run command to debug the process, refer to the source code comment documentation.
Write dyform/export.js script, implement Models, Tables functions, export as YAO model & table widgets.
Export function | Description | Source code link |
---|---|---|
Models | Call the Model process to export the Yao model widget, the data structure is {MODEL_NAME:String: Model_DSL:Object} | View source code |
Tables | Call the Table process, export it as Yao table widget, the data structure is: {TABLE_NAME:String: Table_DSL:Object} | View source code |
In the dyforms folder, add the xxx.form.json file and write the dyform DSL description file to quickly create a set of form management modules, form APIs, form processes and model processes.
Use the yao migrate command to create the data table structure, the yao start command to start the service, and log in to the management interface to use the table management function. Routing address: http://127.0.0.1:5099/xiang/table/dyform.xxx