From 9c4ce78f5ec280d85cbd4468c3b0fa5a7300ddc0 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Mon, 16 Oct 2023 17:31:16 +0800 Subject: [PATCH] feat: get expenditure and income --- index.html | 4 ++ src/api/balance/index.ts | 26 +++++++++ src/api/balance/types/balance.ts | 34 +++++++++++ src/api/index.ts | 2 + src/components/top-bar/KUNGalgameTopBar.vue | 2 + src/store/modules/balance.ts | 62 +++++++++++++++++++++ src/views/balance/components/Log.vue | 4 +- src/views/kungalgamer/components/Header.vue | 1 - 8 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 src/api/balance/index.ts create mode 100644 src/api/balance/types/balance.ts create mode 100644 src/store/modules/balance.ts diff --git a/index.html b/index.html index 18bc1168..18421aa5 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,10 @@ href="/src/assets/images/favicon.png" /> + KUNGalgame diff --git a/src/api/balance/index.ts b/src/api/balance/index.ts new file mode 100644 index 00000000..4e7fd008 --- /dev/null +++ b/src/api/balance/index.ts @@ -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 { + const queryParams = objectToQueryParams(requestData) + const response = await fetchGet( + `/balance/income?${queryParams}` + ) + return response +} + +// 获取 expenditure +export async function getExpenditureApi( + requestData: Balance.BalanceExpenditureRequestData +): Promise { + const queryParams = objectToQueryParams(requestData) + const response = await fetchGet( + `/balance/expenditure?${queryParams}` + ) + return response +} diff --git a/src/api/balance/types/balance.ts b/src/api/balance/types/balance.ts new file mode 100644 index 00000000..f230463a --- /dev/null +++ b/src/api/balance/types/balance.ts @@ -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 +}> diff --git a/src/api/index.ts b/src/api/index.ts index a5e5f274..a52603bb 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -3,6 +3,7 @@ */ // 暴露出所有 interface +export * from './balance/types/balance' export * from './edit/types/edit' export * from './home/types/home' export * from './user/types/user' @@ -11,6 +12,7 @@ export * from './topic/types' export * from './update-log/types/updateLog' // 暴露出所有 api +export * from './balance' export * from './edit' export * from './home' export * from './user' diff --git a/src/components/top-bar/KUNGalgameTopBar.vue b/src/components/top-bar/KUNGalgameTopBar.vue index 585ab95c..9d562d89 100644 --- a/src/components/top-bar/KUNGalgameTopBar.vue +++ b/src/components/top-bar/KUNGalgameTopBar.vue @@ -254,6 +254,8 @@ $navNumber: v-bind(navItemNum); } } img { + height: 40px; + width: 40px; cursor: pointer; border-radius: 50%; height: 40px; diff --git a/src/store/modules/balance.ts b/src/store/modules/balance.ts new file mode 100644 index 00000000..33e84fcc --- /dev/null +++ b/src/store/modules/balance.ts @@ -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 { + // 这里的默认值用于初始化 + 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 { + // 这里的默认值用于初始化 + const requestData: BalanceExpenditureRequestData = { + page: this.income.page, + limit: this.income.limit, + sortField: this.income.sortField, + sortOrder: this.income.sortOrder, + } + return await getExpenditureApi(requestData) + }, + }, +}) diff --git a/src/views/balance/components/Log.vue b/src/views/balance/components/Log.vue index 25a79469..fc215c84 100644 --- a/src/views/balance/components/Log.vue +++ b/src/views/balance/components/Log.vue @@ -1,6 +1,8 @@