diff --git a/route/route.go b/route/route.go index c950d4d..ad71a50 100644 --- a/route/route.go +++ b/route/route.go @@ -37,5 +37,5 @@ func Init() { gpPlug.Any("/edit", core.GinHandler(server.PlugEdit)) gpPlug.Any("/del", core.GinHandler(server.PlugDel)) gpPlug.Any("/runs", core.GinHandler(server.PlugRuns)) - //gpPlug.Any("/log", core.GinHandler(server.PlugLog)) + gpPlug.Any("/log", core.GinHandler(server.PlugLog)) } diff --git a/route/server/plugin.go b/route/server/plugin.go index 63c7ed8..24c6d0a 100644 --- a/route/server/plugin.go +++ b/route/server/plugin.go @@ -9,7 +9,6 @@ import ( "gokins/models" "gokins/service/dbService" "io/ioutil" - "strconv" "time" ) @@ -83,29 +82,35 @@ func PlugRuns(c *gin.Context, req *ruisUtil.Map) { res.Set("list", ls) res.Set("tid", mr.Tid) res.Set("end", mr.State >= 2) - plugLog(req.GetString("pid"), mr, res) c.JSON(200, res) } -func plugLog(pids string, mr *model.TModelRun, ret *ruisUtil.Map) { - pid, err := strconv.ParseInt(pids, 10, 64) +func PlugLog(c *gin.Context, req *ruisUtil.Map) { + tid, err := req.GetInt("tid") + if err != nil || tid <= 0 { + c.String(500, "param err") + return + } + pid, err := req.GetInt("pid") if err != nil || pid <= 0 { + c.String(500, "param err") + return + } + mr := dbService.GetModelRun(int(tid)) + if mr == nil { + c.String(404, "not found") return } rn := dbService.FindPluginRun(mr.Tid, mr.Id, int(pid)) if rn == nil { return } - res := ruisUtil.NewMap() - res.Set("id", rn.Id) - res.Set("up", true) - res.Set("text", "") - if rn.State >= 2 { - res.Set("up", false) - } + ret := ruisUtil.NewMap() + ret.Set("id", rn.Id) + ret.Set("text", "") logpth := fmt.Sprintf("%s/data/logs/%d/%d.log", comm.Dir, rn.Mid, rn.Id) outs, err := ioutil.ReadFile(logpth) if err == nil { - res.Set("text", string(outs)) + ret.Set("text", string(outs)) } - ret.Set("log", res) + c.JSON(200, ret) } diff --git a/uis/vue-admin/src/views/ruis/PlugRunList.vue b/uis/vue-admin/src/views/ruis/PlugRunList.vue index f42314d..4231f24 100644 --- a/uis/vue-admin/src/views/ruis/PlugRunList.vue +++ b/uis/vue-admin/src/views/ruis/PlugRunList.vue @@ -64,7 +64,7 @@ data() { return { tid:'', - running=false, + running:false, loading: false, listdata: [], @@ -98,7 +98,7 @@ //获取列表 getList() { if(!this.running)return; - this.$post('/plug/runs',{id:this.tid,pid:this.selid,first:this.running}).then((res) => { + this.$post('/plug/runs',{id:this.tid,pid:this.selid,first:this.loading}).then((res) => { console.log(res); this.loading = false; this.getInfo(res.data.tid); @@ -107,9 +107,7 @@ this.running=false; } this.getList(); - if(res.data.log&&res.data.log.id){ - this.logs[res.data.log.id]=res.data.log; - } + this.getLog(); }).catch(err=>{ this.loading = false; this.$message({ @@ -133,6 +131,13 @@ this.selid=e.Id; this.$forceUpdate(); console.log('showLog:',this.mpdata[idx]); + if(!this.running)this.getLog(); + },getLog(ls){ + if(this.selid==''||this.selid<=0)return; + this.$post('/plug/log',{tid:this.tid,pid:this.selid}).then(res=>{ + this.logs[this.selid]=res.data; + this.$forceUpdate(); + }) } } }