feat: get expenditure and income

This commit is contained in:
KUN1007 2023-10-16 17:31:16 +08:00
parent f385fb233c
commit 9c4ce78f5e
8 changed files with 133 additions and 2 deletions

View file

@ -8,6 +8,10 @@
href="/src/assets/images/favicon.png" href="/src/assets/images/favicon.png"
/> />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="The CUTEST Visual Novel Forum!世界上最萌的 Galgame 论坛. Topic, Technique. NO ADs Forever. Free Forever"
/>
<title>KUNGalgame</title> <title>KUNGalgame</title>
</head> </head>
<body> <body>

26
src/api/balance/index.ts Normal file
View file

@ -0,0 +1,26 @@
import { fetchGet } from '@/utils/request'
import type * as Balance from './types/balance'
// 将对象转为请求参数的函数
import objectToQueryParams from '@/utils/objectToQueryParams'
// 获取 income
export async function getIncomeApi(
requestData: Balance.BalanceIncomeRequestData
): Promise<Balance.BalanceIncomeResponseData> {
const queryParams = objectToQueryParams(requestData)
const response = await fetchGet<Balance.BalanceIncomeResponseData>(
`/balance/income?${queryParams}`
)
return response
}
// 获取 expenditure
export async function getExpenditureApi(
requestData: Balance.BalanceExpenditureRequestData
): Promise<Balance.BalanceExpenditureResponseData> {
const queryParams = objectToQueryParams(requestData)
const response = await fetchGet<Balance.BalanceExpenditureResponseData>(
`/balance/expenditure?${queryParams}`
)
return response
}

View file

@ -0,0 +1,34 @@
type SortField = 'time' | 'amount'
type SortOrder = 'asc' | 'desc'
// 获取 income 请求数据
export interface BalanceIncomeRequestData {
page: number
limit: number
sortField: SortField
sortOrder: SortOrder
}
// 获取 expenditure 请求数据
export interface BalanceExpenditureRequestData {
page: number
limit: number
sortField: SortField
sortOrder: SortOrder
}
// income 响应数据
export type BalanceIncomeResponseData = KUNGalgameResponseData<{
iid: number
reason: string
time: number
amount: number
}>
// expenditure 响应数据
export type BalanceExpenditureResponseData = KUNGalgameResponseData<{
eid: number
reason: string
time: number
amount: number
}>

View file

@ -3,6 +3,7 @@
*/ */
// 暴露出所有 interface // 暴露出所有 interface
export * from './balance/types/balance'
export * from './edit/types/edit' export * from './edit/types/edit'
export * from './home/types/home' export * from './home/types/home'
export * from './user/types/user' export * from './user/types/user'
@ -11,6 +12,7 @@ export * from './topic/types'
export * from './update-log/types/updateLog' export * from './update-log/types/updateLog'
// 暴露出所有 api // 暴露出所有 api
export * from './balance'
export * from './edit' export * from './edit'
export * from './home' export * from './home'
export * from './user' export * from './user'

View file

@ -254,6 +254,8 @@ $navNumber: v-bind(navItemNum);
} }
} }
img { img {
height: 40px;
width: 40px;
cursor: pointer; cursor: pointer;
border-radius: 50%; border-radius: 50%;
height: 40px; height: 40px;

View file

@ -0,0 +1,62 @@
// 评论的临时数据,用于组件间传输
import { defineStore } from 'pinia'
import type {
BalanceIncomeRequestData,
BalanceExpenditureRequestData,
BalanceIncomeResponseData,
BalanceExpenditureResponseData,
} from '@/api'
import { getIncomeApi, getExpenditureApi } from '@/api'
interface BalanceStore {
income: BalanceIncomeRequestData
expenditure: BalanceExpenditureRequestData
}
export const useKUNGalgameBalanceStore = defineStore({
id: 'KUNGalgameBalance',
// 不持久
persist: false,
state: (): BalanceStore => ({
income: {
page: 0,
limit: 0,
sortField: 'time',
sortOrder: 'desc',
},
expenditure: {
page: 0,
limit: 0,
sortField: 'time',
sortOrder: 'desc',
},
}),
getters: {},
actions: {
// 获取 income
async getIncome(): Promise<BalanceIncomeResponseData> {
// 这里的默认值用于初始化
const requestData: BalanceIncomeRequestData = {
page: this.income.page,
limit: this.income.limit,
sortField: this.income.sortField,
sortOrder: this.income.sortOrder,
}
return await getIncomeApi(requestData)
},
// 获取 expenditure
async getExpenditure(): Promise<BalanceExpenditureResponseData> {
// 这里的默认值用于初始化
const requestData: BalanceExpenditureRequestData = {
page: this.income.page,
limit: this.income.limit,
sortField: this.income.sortField,
sortOrder: this.income.sortOrder,
}
return await getExpenditureApi(requestData)
},
},
})

View file

@ -1,6 +1,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { FSLog } from '../log' import { FSLog } from '../log'
defineProps(['isIncome']) defineProps<{
isIncome?: boolean
}>()
</script> </script>
<template> <template>

View file

@ -61,7 +61,6 @@ const mpWidth = computed(() => {
width: 140px; width: 140px;
height: 140px; height: 140px;
border-radius: 50%; border-radius: 50%;
box-shadow: 0px 0px 2px 4px var(--kungalgame-trans-red-2);
&:hover { &:hover {
animation: spin 1s; animation: spin 1s;
} }