+ Load API

This commit is contained in:
Max 2021-11-27 20:32:57 +08:00
parent d57333fcf4
commit 362e788157
3 changed files with 59 additions and 8 deletions

View file

@ -17,6 +17,7 @@ import (
"github.com/yaoapp/xiang/query"
"github.com/yaoapp/xiang/share"
"github.com/yaoapp/xiang/table"
"github.com/yaoapp/xiang/workflow"
)
// Load 根据配置加载 API, FLow, Model, Plugin
@ -28,14 +29,15 @@ func Load(cfg config.Config) {
LoadEngine(cfg.Path)
query.Load(cfg) // 加载数据分析引擎
share.Load(cfg) // 加载共享库 lib
model.Load(cfg) // 加载数据模型 model
api.Load(cfg) // 加载业务接口 API
flow.Load(cfg) // 加载业务逻辑 Flow
plugin.Load(cfg) // 加载业务插件 plugin
table.Load(cfg) // 加载数据表格 table
chart.Load(cfg) // 加载分析图表 chart
page.Load(cfg) // 加载页面 page
share.Load(cfg) // 加载共享库 lib
model.Load(cfg) // 加载数据模型 model
flow.Load(cfg) // 加载业务逻辑 Flow
plugin.Load(cfg) // 加载业务插件 plugin
table.Load(cfg) // 加载数据表格 table
chart.Load(cfg) // 加载分析图表 chart
page.Load(cfg) // 加载页面 page
workflow.Load(cfg) // 加载工作流 workflow
api.Load(cfg) // 加载业务接口 API
// 加密密钥函数
gou.LoadCrypt(fmt.Sprintf(`{"key":"%s"}`, cfg.Database.AESKey), "AES")

View file

@ -12,6 +12,7 @@ import (
"github.com/yaoapp/xiang/page"
"github.com/yaoapp/xiang/share"
"github.com/yaoapp/xiang/table"
"github.com/yaoapp/xiang/workflow"
)
// Watch 监听应用目录文件变更
@ -24,6 +25,7 @@ func Watch(cfg config.Config) {
WatchTable(cfg.RootTable, "")
WatchChart(cfg.RootChart, "")
WatchPage(cfg.RootPage, "")
WatchWorkFlow(cfg.RootWorkFlow, "")
// 看板大屏
WatchPage(filepath.Join(cfg.Root, "/kanban"), "")
@ -325,3 +327,46 @@ func WatchPage(root string, prefix string) {
}
})
}
// WatchWorkFlow 监听工作流更新
func WatchWorkFlow(root string, prefix string) {
if share.DirNotExists(root) {
return
}
root = share.DirAbs(root)
go share.Watch(root, func(op string, filename string) {
if !strings.HasSuffix(filename, ".json") {
return
}
if op == "write" || op == "create" {
name := prefix + share.SpecName(root, filename)
content := share.ReadFile(filename)
_, err := workflow.LoadWorkFlow(content, name) // Relaod
if err != nil {
return
}
api, has := gou.APIs["xiang.workflow."+name]
if has {
api.Reload() // 重载API
}
log.Printf("WorkFlow %s 已重新加载完毕", name)
} else if op == "remove" || op == "rename" {
name := prefix + share.SpecName(root, filename)
if _, has := workflow.WorkFlows[name]; has {
delete(workflow.WorkFlows, name)
log.Printf("WorkFlow %s 已经移除", name)
}
}
// 重启服务器
if op == "write" || op == "create" || op == "remove" || op == "rename" {
Stop(func() {
log.Printf("服务器重启完毕")
go Start()
})
}
})
}

View file

@ -3,6 +3,10 @@
"version": "1.0.0",
"description": "指派商务负责人",
"apis": {
"/confirm": {
"label": "确认",
"process": "xiang.assign.confirm"
},
"/save": {
"label": "保存",
"process": "xiang.assign.save"