diff --git a/backend/api.go b/backend/api.go index 68b4ef5..fc1ec94 100644 --- a/backend/api.go +++ b/backend/api.go @@ -375,6 +375,20 @@ func init() { } writeresult(w, codeSuccess, "成功", messageOk, typeSuccess) }} + + apimap["/api/getAnnualVisits"] = &apihandler{"GET", func(w http.ResponseWriter, r *http.Request) { + token := r.Header.Get("Authorization") + user := usertokens.Get(token) + if user == nil { + writeresult(w, codeError, nil, errInvalidToken.Error(), typeError) + return + } + if !user.IsSuper() { + writeresult(w, codeError, nil, errNoSetRolePermission.Error(), typeError) + return + } + writeresult(w, codeSuccess, global.UserDB.GetAnnualAPIVisitCount(), messageOk, typeSuccess) + }} } // APIHandler serves all backend /api call diff --git a/backend/file.go b/backend/file.go index 23edd97..d45f5d0 100644 --- a/backend/file.go +++ b/backend/file.go @@ -13,12 +13,6 @@ func FileHandler(w http.ResponseWriter, r *http.Request) { if !utils.IsMethod("GET", w, r) { return } - token := r.Header.Get("Authorization") - user := usertokens.Get(token) - if user == nil { - writeresult(w, codeError, nil, errInvalidToken.Error(), typeError) - return - } global.UserDB.VisitAPI() if r.URL.Path[0] != '/' { r.URL.Path = "/" + r.URL.Path diff --git a/backend/global/user.go b/backend/global/user.go index 08e1cb6..5bfaaa7 100644 --- a/backend/global/user.go +++ b/backend/global/user.go @@ -769,6 +769,7 @@ func (u *UserDatabase) GetAnnualAPIVisitCount() (cnts [12]uint32) { _ = u.db.Find(UserTableMonthlyAPIVisit, &v, "WHERE YM="+strconv.FormatUint(uint64(ym), 10)) cnts[i] = v.Count i++ + v.Count = 0 } return } diff --git a/frontend/vben/src/api/dashboard/index.ts b/frontend/vben/src/api/dashboard/index.ts index 7fbe13a..28cb204 100644 --- a/frontend/vben/src/api/dashboard/index.ts +++ b/frontend/vben/src/api/dashboard/index.ts @@ -5,6 +5,11 @@ enum Api { GetMessageList = '/getMessageList', AcceptMessage = '/acceptMessage', DeleteMessage = '/delMessage', + GetAnnualVisits = '/getAnnualVisits', +} + +export const getAnnualVisits = () => { + return defHttp.get({ url: Api.GetAnnualVisits }) } export const getMessageList = () => { diff --git a/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysisBar.vue b/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysisBar.vue index 44854b4..9d0926d 100644 --- a/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysisBar.vue +++ b/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysisBar.vue @@ -4,6 +4,7 @@