#tips :在学习本教程之前,默认您已经搭建好开发环境
GitHub: https://github.com/YaoApp/demo-lms
Infra 一键部署: https://letsinfra.com/openapp/demo-lms
yao init
此时的目录结构为:├─apis├─data├─db├─flows├─libs├─logs├─models├─scripts├─tables├─ui└─yao└─icons
.env
文件:# 数据库配置YAO_DB_AESKEY="KBPdcRn44LzykphsVM\*y"YAO_DB_DRIVER=mysqlYAO_DB_PRIMARY="root:123456@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local" # 主库连接YAO_DB_SECONDARY="root:123456@tcp(127.0.0.1.100:3306)/test?charset=utf8mb4&parseTime=True&loc=Local" # 主库连接
数据库字段含义:YAO_DB_PRIMARY=用户名:密码@tcp(数据库ip:端口)/数据库名??charset=utf8mb4&parseTime=True&loc=Local
配置修改完成后执行 yao migrate
看看是否报错,要是没有报错说明连接成功!
models/category.mod.yao
文件,写入以下内容:models/book.mod.yao
模型文件,并且关联模型分类category
:yao migrate
命令迁移数据表,出现以下结果,并且可以在数据库中看到对应数据表:Update schema model: category (category)Update schema model: xiang.user (xiang_user)Update schema model: xiang.menu (xiang_menu)Update schema model: xiang.workflow (xiang_workflow)Update schema model: book (book)✨DONE✨
/flows/menu.flow.yao
:yao run flows.menu
出现以下结果,并且可以在数据库中看到对应数据表:Run: flows.menu--------------------------------------flows.menu Response--------------------------------------"done"--------------------------------------✨DONE✨
/app.json
文件中的内容"admin": "/table/book"
,把登录后第一个显示的菜单改为书籍列表:{"name": "Yao","short": "Yao","description": "Another yao app","option": {"nav_user": "xiang.user","nav_menu": "xiang.menu","hide_user": false,"hide_menu": false,"login": {"entry": {"admin": "/table/book"}}}}
tables/book.tab.yao
代码如下:yao start
可以看到项目已经开始运行:WebSocket(0)---------------------------------Yao development---------------------------------Root /mnt/shared/testFrontend http://127.0.0.1:5099/Dashboard http://127.0.0.1:5099/xiang/login/adminAPI http://127.0.0.1:5099/apiListening 127.0.0.1:5099Watching: /mnt/shared/test/modelsWatching: /mnt/shared/test/scriptsWatching: /mnt/shared/test/apisWatching: /mnt/shared/test/libs✨LISTENING✨Watching: /mnt/shared/test/flowsWatching: /mnt/shared/test/tables
打开浏览器访问:http://127.0.0.1:5099/xiang/login/admin
输入默认账号 xiang@iqka.com
和密码A123456p+
登录到后台可以看到书籍列表效果图:
tables/category.tab.yao
代码:在命令行使用 ctrl+C
停止 Yao 的服务,然后执行 yao start
重启服务,打开浏览器刷新一下页面,点击分类菜单:
apis/select.http.json
:{"name": "下拉搜索","version": "1.0.0","description": "下拉搜索","guard": "bearer-jwt","group": "select","paths": [{"path": "/category","method": "GET","process": "flows.category","in": [],"out": {"status": 200,"type": "application/json"}}]}
flows/category.flow.yao
文件:{"label": "类目树","version": "1.0.0","description": "类目树","nodes": [{"name": "类目","engine": "xiang","query": {"select": ["id", "name", "name as label", "id as value", "parent_id"],"wheres": [{ ":deleted_at": "删除", "=": null }],"from": "category","limit": 1000}},{"name": "类目树","process": "xiang.helper.ArrayTree","args": ["{{$res.类目}}", { "parent": "parent_id" }]}],"output": "{{$res.类目树}}"}
tables/book.tab.yao
的 columns 分类组件,并且调整一下表单和添加页面的布局:#tips :在学习本教程之前,默认您已经搭建好开发环境
GitHub: https://github.com/YaoApp/demo-lms
Infra 一键部署: https://letsinfra.com/openapp/demo-lms
yao init
此时的目录结构为:├─apis├─data├─db├─flows├─libs├─logs├─models├─scripts├─tables├─ui└─yao└─icons
.env
文件:# 数据库配置YAO_DB_AESKEY="KBPdcRn44LzykphsVM\*y"YAO_DB_DRIVER=mysqlYAO_DB_PRIMARY="root:123456@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local" # 主库连接YAO_DB_SECONDARY="root:123456@tcp(127.0.0.1.100:3306)/test?charset=utf8mb4&parseTime=True&loc=Local" # 主库连接
数据库字段含义:YAO_DB_PRIMARY=用户名:密码@tcp(数据库ip:端口)/数据库名??charset=utf8mb4&parseTime=True&loc=Local
配置修改完成后执行 yao migrate
看看是否报错,要是没有报错说明连接成功!
models/category.mod.yao
文件,写入以下内容:models/book.mod.yao
模型文件,并且关联模型分类category
:yao migrate
命令迁移数据表,出现以下结果,并且可以在数据库中看到对应数据表:Update schema model: category (category)Update schema model: xiang.user (xiang_user)Update schema model: xiang.menu (xiang_menu)Update schema model: xiang.workflow (xiang_workflow)Update schema model: book (book)✨DONE✨
/flows/menu.flow.yao
:yao run flows.menu
出现以下结果,并且可以在数据库中看到对应数据表:Run: flows.menu--------------------------------------flows.menu Response--------------------------------------"done"--------------------------------------✨DONE✨
/app.json
文件中的内容"admin": "/table/book"
,把登录后第一个显示的菜单改为书籍列表:{"name": "Yao","short": "Yao","description": "Another yao app","option": {"nav_user": "xiang.user","nav_menu": "xiang.menu","hide_user": false,"hide_menu": false,"login": {"entry": {"admin": "/table/book"}}}}
tables/book.tab.yao
代码如下:yao start
可以看到项目已经开始运行:WebSocket(0)---------------------------------Yao development---------------------------------Root /mnt/shared/testFrontend http://127.0.0.1:5099/Dashboard http://127.0.0.1:5099/xiang/login/adminAPI http://127.0.0.1:5099/apiListening 127.0.0.1:5099Watching: /mnt/shared/test/modelsWatching: /mnt/shared/test/scriptsWatching: /mnt/shared/test/apisWatching: /mnt/shared/test/libs✨LISTENING✨Watching: /mnt/shared/test/flowsWatching: /mnt/shared/test/tables
打开浏览器访问:http://127.0.0.1:5099/xiang/login/admin
输入默认账号 xiang@iqka.com
和密码A123456p+
登录到后台可以看到书籍列表效果图:
tables/category.tab.yao
代码:在命令行使用 ctrl+C
停止 Yao 的服务,然后执行 yao start
重启服务,打开浏览器刷新一下页面,点击分类菜单:
apis/select.http.json
:{"name": "下拉搜索","version": "1.0.0","description": "下拉搜索","guard": "bearer-jwt","group": "select","paths": [{"path": "/category","method": "GET","process": "flows.category","in": [],"out": {"status": 200,"type": "application/json"}}]}
flows/category.flow.yao
文件:{"label": "类目树","version": "1.0.0","description": "类目树","nodes": [{"name": "类目","engine": "xiang","query": {"select": ["id", "name", "name as label", "id as value", "parent_id"],"wheres": [{ ":deleted_at": "删除", "=": null }],"from": "category","limit": 1000}},{"name": "类目树","process": "xiang.helper.ArrayTree","args": ["{{$res.类目}}", { "parent": "parent_id" }]}],"output": "{{$res.类目树}}"}
tables/book.tab.yao
的 columns 分类组件,并且调整一下表单和添加页面的布局: