diff --git a/backend/api.go b/backend/api.go
index c7dc55e..68b4ef5 100644
--- a/backend/api.go
+++ b/backend/api.go
@@ -384,6 +384,7 @@ func APIHandler(w http.ResponseWriter, r *http.Request) {
}
if h, ok := apimap[r.URL.Path]; ok {
+ global.UserDB.VisitAPI()
h.handle(w, r)
return
}
diff --git a/backend/file.go b/backend/file.go
index 1465215..23edd97 100644
--- a/backend/file.go
+++ b/backend/file.go
@@ -13,6 +13,13 @@ 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 c3b0f65..08e1cb6 100644
--- a/backend/global/user.go
+++ b/backend/global/user.go
@@ -60,8 +60,9 @@ const (
type MessageType uint8
const (
- UserTableUser = "user"
- UserTableMessage = "msg"
+ UserTableUser = "user"
+ UserTableMessage = "msg"
+ UserTableMonthlyAPIVisit = "visit"
)
var (
@@ -97,6 +98,10 @@ func init() {
if err != nil {
panic(err)
}
+ err = UserDB.db.Create(UserTableMonthlyAPIVisit, &MonthlyAPIVisit{})
+ if err != nil {
+ panic(err)
+ }
if isinit { // 添加初始账户
UserDB.AddUser(&User{
Role: RoleSuper,
@@ -720,3 +725,50 @@ func (u *UserDatabase) DelMessageByID(id int) (err error) {
u.mu.Unlock()
return
}
+
+// MonthlyAPIVisit counts the api visit history
+type MonthlyAPIVisit struct {
+ YM uint32 // YM is yyyymm
+ Count uint32 // visit count this mounth
+}
+
+// VisitAPI increases count of this mounth by 1
+func (u *UserDatabase) VisitAPI() {
+ now := time.Now()
+ ym := uint32(now.Year())*100 + uint32(now.Month())
+ var v MonthlyAPIVisit
+ u.mu.Lock()
+ defer u.mu.Unlock()
+ _ = u.db.Find(UserTableMonthlyAPIVisit, &v, "WHERE YM="+strconv.FormatUint(uint64(ym), 10))
+ v.YM = ym
+ v.Count++
+ err := u.db.Insert(UserTableMonthlyAPIVisit, &v)
+ if err != nil {
+ logrus.Warnln("[global.user] insert visit error:", err)
+ }
+}
+
+// GetAnnualAPIVisitCount get the latest 12 mounths' count
+func (u *UserDatabase) GetAnnualAPIVisitCount() (cnts [12]uint32) {
+ var v MonthlyAPIVisit
+ var yms [12]uint32
+ now := time.Now()
+ y100 := uint32(now.Year()) * 100
+ py100 := uint32(now.Year()-1) * 100
+ nm := int(now.Month())
+ for i := 0; i < nm; i++ {
+ yms[i] = y100 + uint32(i+1)
+ }
+ for i := nm; i < 12; i++ {
+ yms[i] = py100 + uint32(i+1)
+ }
+ u.mu.RLock()
+ defer u.mu.RUnlock()
+ i := 0
+ for _, ym := range yms {
+ _ = u.db.Find(UserTableMonthlyAPIVisit, &v, "WHERE YM="+strconv.FormatUint(uint64(ym), 10))
+ cnts[i] = v.Count
+ i++
+ }
+ return
+}
diff --git a/backend/upload.go b/backend/upload.go
index b124759..7482b11 100644
--- a/backend/upload.go
+++ b/backend/upload.go
@@ -33,6 +33,7 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
writeresult(w, codeError, nil, errInvalidToken.Error(), typeError)
return
}
+ global.UserDB.VisitAPI()
ff, h, err := r.FormFile("avatar")
if err == nil {
defer ff.Close()
diff --git a/frontend/vben/src/views/dashboard/analysis/components/GrowCard.vue b/frontend/vben/src/views/dashboard/analysis/components/GrowCard.vue
deleted file mode 100644
index 6d5ede4..0000000
--- a/frontend/vben/src/views/dashboard/analysis/components/GrowCard.vue
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
diff --git a/frontend/vben/src/views/dashboard/analysis/components/SalesProductPie.vue b/frontend/vben/src/views/dashboard/analysis/components/SalesProductPie.vue
deleted file mode 100644
index 5e90f17..0000000
--- a/frontend/vben/src/views/dashboard/analysis/components/SalesProductPie.vue
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
-
-
-
diff --git a/frontend/vben/src/views/dashboard/analysis/components/SiteAnalysis.vue b/frontend/vben/src/views/dashboard/analysis/components/SiteAnalysis.vue
index 4ba132c..4edc1f1 100644
--- a/frontend/vben/src/views/dashboard/analysis/components/SiteAnalysis.vue
+++ b/frontend/vben/src/views/dashboard/analysis/components/SiteAnalysis.vue
@@ -1,38 +1,17 @@
-
-
-
-
-
-
+
diff --git a/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysis.vue b/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysis.vue
deleted file mode 100644
index a238e13..0000000
--- a/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysis.vue
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
-
diff --git a/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysisBar.vue b/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysisBar.vue
index ef9f2b8..44854b4 100644
--- a/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysisBar.vue
+++ b/frontend/vben/src/views/dashboard/analysis/components/VisitAnalysisBar.vue
@@ -1,15 +1,19 @@
-
diff --git a/frontend/vben/src/views/dashboard/analysis/components/VisitSource.vue b/frontend/vben/src/views/dashboard/analysis/components/VisitSource.vue
deleted file mode 100644
index 65bb84f..0000000
--- a/frontend/vben/src/views/dashboard/analysis/components/VisitSource.vue
+++ /dev/null
@@ -1,81 +0,0 @@
-
-
-
-
-
-
diff --git a/frontend/vben/src/views/dashboard/analysis/components/props.ts b/frontend/vben/src/views/dashboard/analysis/components/props.ts
deleted file mode 100644
index a91a779..0000000
--- a/frontend/vben/src/views/dashboard/analysis/components/props.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { PropType } from 'vue'
-
-export interface BasicProps {
- width: string
- height: string
-}
-export const basicProps = {
- width: {
- type: String as PropType,
- default: '100%',
- },
- height: {
- type: String as PropType,
- default: '280px',
- },
-}
diff --git a/frontend/vben/src/views/dashboard/analysis/data.ts b/frontend/vben/src/views/dashboard/analysis/data.ts
deleted file mode 100644
index 9667391..0000000
--- a/frontend/vben/src/views/dashboard/analysis/data.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-export interface GrowCardItem {
- icon: string
- title: string
- value: number
- total: number
- color: string
- action: string
-}
diff --git a/frontend/vben/src/views/dashboard/analysis/index.vue b/frontend/vben/src/views/dashboard/analysis/index.vue
index a2eecf8..77e0ca5 100644
--- a/frontend/vben/src/views/dashboard/analysis/index.vue
+++ b/frontend/vben/src/views/dashboard/analysis/index.vue
@@ -1,21 +1,11 @@