1
0
mirror of https://github.com/fumiama/paper-manager.git synced 2026-06-08 09:34:42 +08:00

finish dashboard/anaylsis

This commit is contained in:
源文雨
2023-03-21 23:30:52 +08:00
parent 6269a9544f
commit f2a26a6067
5 changed files with 26 additions and 7 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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
}

View File

@@ -5,6 +5,11 @@ enum Api {
GetMessageList = '/getMessageList',
AcceptMessage = '/acceptMessage',
DeleteMessage = '/delMessage',
GetAnnualVisits = '/getAnnualVisits',
}
export const getAnnualVisits = () => {
return defHttp.get<number[]>({ url: Api.GetAnnualVisits })
}
export const getMessageList = () => {

View File

@@ -4,6 +4,7 @@
<script lang="ts" setup>
import { onMounted, ref, Ref } from 'vue'
import { useECharts } from '/@/hooks/web/useECharts'
import { getAnnualVisits } from '/@/api/dashboard'
defineProps({
width: {
@@ -18,6 +19,10 @@
const chartRef = ref<HTMLDivElement | null>(null)
const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>)
const visitsRef = ref([...new Array(12)])
getAnnualVisits().then((visits) => {
visitsRef.value = visits
})
onMounted(() => {
setOptions({
tooltip: {
@@ -40,7 +45,7 @@
},
series: [
{
data: [3000, 2000, 3333, 5000, 3200, 4200, 3200, 2100, 3000, 5100, 6000, 3200, 4800],
data: visitsRef as any,
type: 'bar',
barMaxWidth: 80,
},