Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mangenotwork committed Nov 9, 2023
1 parent bc6cd9f commit 2037497
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 12 deletions.
30 changes: 27 additions & 3 deletions master/dao/request_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dao
import (
"encoding/json"
"github.com/boltdb/bolt"
"github.com/mangenotwork/common/log"
"github.com/mangenotwork/common/utils"
"sort"
"time"
"website-monitor/master/entity"
Expand All @@ -18,6 +20,7 @@ type RequestToolEr interface {
DelGlobalHeader(key string) error
SetRequestNowList(data *entity.RequestNowList) error
GetRequestNowList() ([]*entity.RequestNowList, error)
DelRequestNowList(id string) error
}

func NewRequestTool() RequestToolEr {
Expand All @@ -43,6 +46,10 @@ func (r *requestToolDao) Add(data *entity.RequestTool) error {
func (r *requestToolDao) GetAtID(id string) (*entity.RequestTool, error) {
data := &entity.RequestTool{}
err := DB.Get(RequestTable, id, &data)
if err == ISNULL { // 空数据忽略
err = nil
data.Method = "GET"
}
return data, err
}

Expand Down Expand Up @@ -79,11 +86,18 @@ func (r *requestToolDao) SetRequestNowList(data *entity.RequestNowList) error {
return DB.Set(RequestNowListTable, data.Id, data)
}

func (r *requestToolDao) initRequestNowList() (*entity.RequestNowList, error) {
data := &entity.RequestNowList{
Id: utils.IDStr(),
Name: "新建请求",
Method: "GET",
}
err := DB.Set(RequestNowListTable, data.Id, data)
return data, err
}

func (r *requestToolDao) GetRequestNowList() ([]*entity.RequestNowList, error) {
conn := GetDBConn()
defer func() {
_ = conn.Close()
}()
list := make([]*entity.RequestNowList, 0)
err := conn.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(RequestNowListTable))
Expand All @@ -101,6 +115,11 @@ func (r *requestToolDao) GetRequestNowList() ([]*entity.RequestNowList, error) {
}
return nil
})
_ = conn.Close()
if len(list) < 1 {
data, _ := r.initRequestNowList()
list = append(list, data)
}
sort.Slice(list, func(i, j int) bool {
if list[i].Time > list[j].Time {
return true
Expand All @@ -111,6 +130,11 @@ func (r *requestToolDao) GetRequestNowList() ([]*entity.RequestNowList, error) {
return list, err
}

func (r *requestToolDao) DelRequestNowList(id string) error {
log.Info("id = ", id)
return DB.Delete(RequestNowListTable, id)
}

func (r *requestToolDao) SetGlobalHeader(list []*entity.RequesterGlobalHeader) error {
var err error
for _, v := range list {
Expand Down
12 changes: 12 additions & 0 deletions master/handler/website_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,17 @@ func RequesterCreateTab(c *ginHelper.GinCtx) {
return
}

func RequesterCloseTab(c *ginHelper.GinCtx) {
hostId := c.Param("reqId")
err := dao.NewRequestTool().DelRequestNowList(hostId)
if err != nil {
c.APIOutPutError(nil, err.Error())
return
}
c.APIOutPut("成功", "成功")
return
}

type RequesterExecuteParam struct {
ReqId string `json:"reqId"` // 请求id 确认当前窗口
Name string `json:"name"` // api name
Expand Down Expand Up @@ -764,6 +775,7 @@ func RequesterHistoryList(c *ginHelper.GinCtx) {
func RequesterHistoryDelete(c *ginHelper.GinCtx) {
reqId := c.Param("reqId")
err := dao.NewRequestTool().HistoryDelete(reqId)
err = dao.NewRequestTool().DelRequestNowList(reqId)
if err != nil {
c.APIOutPutError(nil, err.Error())
return
Expand Down
1 change: 1 addition & 0 deletions master/routers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func API() {

// requester
api.GET("/requester/create/tab", ginHelper.Handle(handler.RequesterCreateTab)) // 创建一个新请求标签页
api.GET("/requester/close/tab/:reqId", ginHelper.Handle(handler.RequesterCloseTab)) // 删除一个标签页
api.POST("/requester/execute", ginHelper.Handle(handler.RequesterExecute)) // TODO 请求调试执行
api.GET("/requester/data/:reqId", ginHelper.Handle(handler.RequesterGetData)) // 获取指定请求数据
api.GET("/requester/list", ginHelper.Handle(handler.RequesterList)) // 请求调试列表
Expand Down
41 changes: 40 additions & 1 deletion master/static/js/requester.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const app = createApp({
len: 0,
},
createTabApi: "/api/requester/create/tab",
getNowApi: function (id) {return "/api/requester/data/"+id; },
getNowApi: function (id) { return "/api/requester/data/"+id; },
closeTabApi: function (id) { return "/api/requester/close/tab/"+id; },
deleteHistoryApi: function (id) { return "/api/requester/history/delete/"+id; },
}
},
created:function(){
Expand Down Expand Up @@ -67,11 +69,40 @@ const app = createApp({
}
});
},
openTab: function (id) {
let t = this;
t.param.reqId = id;

for (item in t.nowReqList.list) {
if (t.nowReqList.list[item].id === id ) {
t.nowReqList.list[item].isNow = true;
} else {
t.nowReqList.list[item].isNow = false;
}
}
t.getNow();
},
closeTab: function (id) {
let t = this;
common.AjaxGet(t.closeTabApi(id), function (data){
if (data.code === 0) {
for (item in t.nowReqList.list) {
if (t.nowReqList.list[item].id === id ) {
t.nowReqList.list.splice(item, 1);
}
}
if (t.nowReqList.list.length === 0) {
t.getNowReqList();
}
}
});
},
createTab: function () {
let t = this;
common.AjaxGet(t.createTabApi, function (data){
if (data.code === 0) {
t.getNowReqList()
$('.gdtiao').scrollLeft(0);
}
});
},
Expand All @@ -95,6 +126,14 @@ const app = createApp({
}
});
},
deleteHistory: function (id) {
let t = this;
common.AjaxGet(this.deleteHistoryApi(id), function (data){
if (data.code === 0) {
t.getHistory();
}
});
},
closeSet: function () {
console.log("closeSet");
$("#setHeaderTable").hide();
Expand Down
13 changes: 5 additions & 8 deletions master/views/page/requester.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<div style="height: 240px;overflow: auto;">
<ul style="font-size: 9px;">
<template v-for="item in history.list">
<li><a class="" href="#">[{{ item.method }}] {{ item.name }}</a> <span style="float: right;margin-right: 4px;">{[ SVG "trash-fill" 12 12 ]}</span></li>
<li><a class="" href="#">[{{ item.method }}] {{ item.name }}</a> <span @click="deleteHistory(item.id)" style="float: right;margin-right: 4px;cursor: pointer;">{[ SVG "trash-fill" 12 12 ]}</span></li>
</template>
</ul>
</div>
Expand Down Expand Up @@ -67,20 +67,17 @@
</div>
<div class="col-10" style="padding: 12px;padding-top: 2px;">
<div style="margin-bottom: 8px;">
<ul class="nav nav-tabs" style="width: 100%;height:54px;flex-direction: row;flex-wrap: nowrap;overflow-x: scroll;font-size: 11px;">

<ul class="nav nav-tabs gdtiao" style="width: 100%;height:54px;flex-direction: row;flex-wrap: nowrap;overflow-x: scroll;font-size: 11px;">
<template v-for="item in nowReqList.list">
<li class="nav-item">
<template v-if="item.isNow == true">
<a class="nav-link active" aria-current="page" href="#" style="width: 200px;">[GET] {{ item.name }} <span style="float: right;">{[ SVG "x-square-fill" 16 16 ]}</span></a>
<a class="nav-link active" aria-current="page" href="#" style="width: 200px;">[GET] {{ item.name }} <span @click="closeTab(item.id)" style="float: right;cursor: pointer;">{[ SVG "x-square-fill" 16 16 ]}</span></a>
</template>
<template v-else>
<a class="nav-link" href="#" style="width: 200px;">[GET] {{ item.name }} <span style="float: right;">{[ SVG "x-square-fill" 16 16 ]}</span></a>
<a class="nav-link" @click="openTab(item.id)" style="width: 200px;">[GET] {{ item.name }} <span @click="closeTab(item.id)" style="float: right;cursor: pointer;">{[ SVG "x-square-fill" 16 16 ]}</span></a>
</template>
</li>
</template>


</ul>
</div>
<div class="row">
Expand All @@ -89,7 +86,7 @@
</div>
<div class="col-8">
<div class="btn-group btn-group-sm" role="group" style="font-size: 11px;">
<a type="button" class="btn btn-outline-dark btn-sm" @click="">{[ SVG "lightning" 14 14 ]} 新建请求</a>
<a type="button" class="btn btn-outline-dark btn-sm" @click="createTab()">{[ SVG "lightning" 14 14 ]} 新建请求</a>
<a type="button" class="btn btn-outline-dark btn-sm" @click="openGlobalParamModal()">{[ SVG "text-left" 14 14 ]} 全局参数</a>
<a type="button" class="btn btn-outline-dark btn-sm" @click="openCookieManageModal()">{[ SVG "window" 14 14 ]} Cookie管理</a>
<a type="button" class="btn btn-outline-dark btn-sm" @click="openApiNoteModal()">{[ SVG "pass" 14 14 ]} 接口说明</a>
Expand Down

0 comments on commit 2037497

Please sign in to comment.