From 699f10e8540ee1a3bfed3c2fbfe3097699c96f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Thu, 30 Nov 2023 17:31:50 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20=E5=AE=8C=E5=96=84=E9=A1=B5=E9=9D=A2(?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/friend.go | 56 +++++++++ app/group.go | 31 +++++ common/types/datetime.go | 2 +- main.go | 21 ++++ router/router.go | 7 ++ views/index.html | 236 ++++++++++++++++++++++++------------- views/static/css/index.css | 4 + views/static/js/index.js | 105 ++++++++++++++++- 8 files changed, 379 insertions(+), 83 deletions(-) create mode 100644 app/friend.go create mode 100644 app/group.go create mode 100644 views/static/css/index.css diff --git a/app/friend.go b/app/friend.go new file mode 100644 index 00000000..3b006873 --- /dev/null +++ b/app/friend.go @@ -0,0 +1,56 @@ +package app + +import ( + "github.com/gin-gonic/gin" + "log" + "net/http" +) + +// changeStatusParam +// @description: 修改状态用的参数集 +type changeStatusParam struct { + WxId string `json:"wxId" binding:"required"` + UserId string `json:"userId"` +} + +// ChangeEnableAiStatus +// @description: 修改是否开启AI +// @param ctx +func ChangeEnableAiStatus(ctx *gin.Context) { + var p changeStatusParam + if err := ctx.ShouldBindJSON(&p); err != nil { + ctx.String(http.StatusBadRequest, "参数错误") + return + } + log.Printf("待修改的微信Id:%s", p.WxId) + + ctx.String(http.StatusOK, "操作成功") +} + +// ChangeEnableGroupRankStatus +// @description: 修改是否开启水群排行榜 +// @param ctx +func ChangeEnableGroupRankStatus(ctx *gin.Context) { + var p changeStatusParam + if err := ctx.ShouldBindJSON(&p); err != nil { + ctx.String(http.StatusBadRequest, "参数错误") + return + } + log.Printf("待修改的群Id:%s", p.WxId) + + ctx.String(http.StatusOK, "操作成功") +} + +// ChangeSkipGroupRankStatus +// @description: 修改是否跳过水群排行榜 +// @param ctx +func ChangeSkipGroupRankStatus(ctx *gin.Context) { + var p changeStatusParam + if err := ctx.ShouldBindJSON(&p); err != nil { + ctx.String(http.StatusBadRequest, "参数错误") + return + } + log.Printf("待修改的群Id:%s -> %s", p.WxId, p.UserId) + + ctx.String(http.StatusOK, "操作成功") +} diff --git a/app/group.go b/app/group.go new file mode 100644 index 00000000..394443fa --- /dev/null +++ b/app/group.go @@ -0,0 +1,31 @@ +package app + +import ( + "github.com/gin-gonic/gin" + "go-wechat/client" + "go-wechat/entity" + "net/http" +) + +type getGroupUser struct { + GroupId string `json:"groupId" form:"groupId" binding:"required"` // 群Id +} + +// GetGroupUsers +// @description: 获取群成员列表 +// @param ctx +func GetGroupUsers(ctx *gin.Context) { + var p getGroupUser + if err := ctx.ShouldBind(&p); err != nil { + ctx.String(http.StatusBadRequest, "参数错误") + return + } + // 查询数据 + var users []entity.GroupUser + if err := client.MySQL.Where("group_id = ?", p.GroupId).Find(&users).Error; err != nil { + ctx.String(http.StatusInternalServerError, "查询数据失败") + return + } + // 暂时先就这样写着,跑通了再改 + ctx.JSON(http.StatusOK, users) +} diff --git a/common/types/datetime.go b/common/types/datetime.go index b6d99a89..7b5e8744 100644 --- a/common/types/datetime.go +++ b/common/types/datetime.go @@ -55,7 +55,7 @@ func (dt DateTime) Value() (dv driver.Value, err error) { // 用于 fmt.Println 和后续验证场景 func (dt DateTime) String() string { - return dt.Format(dateTimeFormat) + return dt.Format("2006-01-02 15:04:05") } // Format 格式化 diff --git a/main.go b/main.go index f4e4d638..5d73ec35 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,10 @@ import ( "go-wechat/tasks" "go-wechat/tcpserver" "go-wechat/utils" + "html/template" "log" + "net/http" + "strings" "time" ) @@ -30,14 +33,32 @@ func main() { // 启动HTTP服务 app := gin.Default() + + // 自定义模板引擎函数 + app.SetFuncMap(template.FuncMap{ + "checkSwap": func(flag bool) string { + if flag { + return "swap-active" + } + return "" + }, + }) + app.LoadHTMLGlob("views/*.html") app.Static("/assets", "./views/static") app.StaticFile("/favicon.ico", "./views/wechat.ico") // 404返回数据 app.NoRoute(func(ctx *gin.Context) { + if strings.HasPrefix(ctx.Request.URL.Path, "/api") { + ctx.String(404, "接口不存在") + return + } // 404直接跳转到首页 ctx.Redirect(302, "/index.html") }) + app.NoMethod(func(ctx *gin.Context) { + ctx.String(http.StatusMethodNotAllowed, "不支持的请求方式") + }) // 初始化路由 router.Init(app) if err := app.Run(":8080"); err != nil { diff --git a/router/router.go b/router/router.go index e60eefb2..8e554e90 100644 --- a/router/router.go +++ b/router/router.go @@ -18,4 +18,11 @@ func Init(g *gin.Engine) { g.GET("/test.html", func(ctx *gin.Context) { ctx.HTML(200, "test.html", nil) }) + + // 接口 + api := g.Group("/api") + api.PUT("/ai/status", app.ChangeEnableAiStatus) // 修改是否开启AI状态 + api.PUT("/grouprank/status", app.ChangeEnableGroupRankStatus) // 修改是否开启水群排行榜状态 + api.PUT("/grouprank/skip", app.ChangeSkipGroupRankStatus) // 修改是否跳过水群排行榜状态 + api.GET("/group/users", app.GetGroupUsers) // 获取群成员列表 } diff --git a/views/index.html b/views/index.html index fc54e98a..4e925d26 100644 --- a/views/index.html +++ b/views/index.html @@ -5,7 +5,11 @@ 水群助手 + + + + @@ -19,92 +23,162 @@ {{ end }} -
- -
- 好友列表 -
-
+
+ +
-
- - - - - - - - - - - - - - - {{ range .friends }} - - - - - - - - - - {{ end }} - -
微信Id微信号昵称最后活跃时间是否在通讯录是否启用AI是否启用水群排行榜
{{ .Wxid }}{{ .CustomAccount }}{{ .Nickname }} - {{ if eq .LastActiveTime.IsNil true }} - 无数据 - {{ else }} - {{ .LastActiveTime }} - {{ end }} - {{ .IsOk }}{{ .EnableAi }}{{ .EnableChatRank }}
-
+ + + + + + + + + + + + + + {{ range .friends }} + + + + + + + + + {{ end }} + +
微信Id微信号昵称最后活跃时间是否在通讯录是否启用AI
{{ .Wxid }}{{ .CustomAccount }}{{ .Nickname }} + {{ if eq .LastActiveTime.IsNil true }} + 无数据 + {{ else }} + {{ .LastActiveTime }} + {{ end }} + + {{ if eq .IsOk true }} +
+ 是 +
+ {{ else }} +
+ 否 +
+ {{ end }} +
+ +
-
-
- -
- 群列表 -
-
+ + +
-
- - - - - - - - - - - - - - {{ range .groups }} - - - - - - - - - {{ end }} - -
群Id昵称最后活跃时间是否在通讯录是否启用AI是否启用水群排行榜
{{ .Wxid }}{{ .Nickname }} - {{ if eq .LastActiveTime.IsNil true }} - 无数据 - {{ else }} - {{ .LastActiveTime }} - {{ end }} - {{ .IsOk }}{{ .EnableAi }}{{ .EnableChatRank }}
-
+ + + + + + + + + + + + + + + {{ range .groups }} + + + + + + + + + + {{ end }} + +
群Id昵称最后活跃时间是否在通讯录是否启用AI是否启用水群排行榜操作
{{ .Wxid }}{{ .Nickname }} + {{ if eq .LastActiveTime.IsNil true }} + 无数据 + {{ else }} + {{ .LastActiveTime }} + {{ end }} + + {{ if eq .IsOk true }} +
+ 是 +
+ {{ else }} +
+ 否 +
+ {{ end }} +
+ + + + + + + +
+ +
+ + + + \ No newline at end of file diff --git a/views/static/css/index.css b/views/static/css/index.css new file mode 100644 index 00000000..0e725a8c --- /dev/null +++ b/views/static/css/index.css @@ -0,0 +1,4 @@ +/* 隐藏滚动条 */ +::-webkit-scrollbar { + display: none; +} \ No newline at end of file diff --git a/views/static/js/index.js b/views/static/js/index.js index adaee6c2..5f22d42a 100644 --- a/views/static/js/index.js +++ b/views/static/js/index.js @@ -1 +1,104 @@ -console.log("打开首页") \ No newline at end of file +console.log("打开首页") + +// 改变AI开启状态 +function changeAiEnableStatus(wxId) { + console.log("修改AI开启状态: ", wxId) + + axios({ + method: 'put', + url: '/api/ai/status', + data: { + wxId: wxId + } + }).then(function (response) { + console.log(`返回结果: ${JSON.stringify(response)}`); + }).catch(function (error) { + console.log(`错误信息: ${error}`); + }) +} + +// 修改水群排行榜状态 +function changeGroupRankEnableStatus(wxId) { + console.log("修改水群排行榜开启状态: ", wxId) + axios({ + method: 'put', + url: '/api/grouprank/status', + data: { + wxId: wxId + } + }).then(function (response) { + console.log(`返回结果: ${JSON.stringify(response)}`); + }).catch(function (error) { + console.log(`错误信息: ${error}`); + }) +} + +// 修改群成员是否参与排行榜状态 +function changeUserGroupRankSkipStatus(groupId, userId) { + console.log("修改水群排行榜开启状态: ", groupId, userId) + axios({ + method: 'put', + url: '/api/grouprank/skip', + data: { + wxId: wxId, + userId: userId + } + }).then(function (response) { + console.log(`返回结果: ${JSON.stringify(response)}`); + }).catch(function (error) { + console.log(`错误信息: ${error}`); + }) +} + +// 获取群成员列表 +function getGroupUsers(groupId) { + // 打开模态框 + const modal = document.getElementById("groupUserModal"); + modal.showModal() + + axios.get('/api/group/users', { + params: { + groupId: groupId + } + }).then(function (response) { + console.log(`返回结果: ${JSON.stringify(response)}`); + // 渲染群成员列表 + const groupUsers = response.data + + // const groupUserList = document.getElementById("groupUsers") + + // 获取表格的tbody部分,以便稍后向其中添加行 + var tbody = document.getElementById("groupUsers"); + for (let i = 0; i < groupUsers.length; i++) { + const groupUser = groupUsers[i] + + var row = tbody.insertRow(i); // 插入新行 + + // 微信Id + var wxId = row.insertCell(0); + wxId.innerHTML = data[i].wxId; + + // 昵称 + var nickname = row.insertCell(1); + nickname.innerHTML = data[i].wxId; + + // 是否群成员 + var isMember = row.insertCell(2); + isMember.innerHTML = data[i].wxId; + + // 最后活跃时间 + var wxId = row.insertCell(3); + wxId.innerHTML = data[i].wxId; + + // 退群时间 + var wxId = row.insertCell(4); + wxId.innerHTML = data[i].wxId; + + // 是否跳过水群排行榜 + var wxId = row.insertCell(5); + wxId.innerHTML = data[i].wxId; + } + }).catch(function (error) { + console.log(`错误信息: ${error}`); + }) +} \ No newline at end of file