mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-07 16:16:37 +08:00
裁剪
swagger 移除 merchant swagger 改造首页内容为通用后台管理系统定位 - 修改首页标题从 'LINUX DO Credit' 改为 'Modern Platform' - 更新副标题为 '为二次开发而生' - 更新首页描述为通用平台的特点 - 更新首页特性标签为 '开箱即用、高度可扩展、工业级基建' - 修改展示卡片为技术栈和二次开发相关 - 更新开发者示例代码为通用的注册和 API Key 获取示例 - 更新页脚品牌名为 'Modern Platform' - 调整页脚导航链接为通用平台相关内容 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> 去除遗留 裁剪 移除 /api/v1/user/pay-key 相关代码 - 删除后端 UpdatePayKey 处理器函数和 UpdatePayKeyRequest 结构体 - 删除 User 模型中的 PayKey 字段 - 删除 User.VerifyPayKey 方法 - 删除 EncryptPayKeyFailed 错误常量 - 删除 /api/v1/user/pay-key PUT 路由 - 删除 OAuth 返回中的 IsPayKey 字段 - 删除前端 UserService.updatePayKey 方法 - 删除前端所有支付密钥 UI 和逻辑 - 更新相关的导出和注释 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> 去除遗留 api 修正 系统配置 前端裁剪 后端裁剪 init
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import type { DisputeWithOrder, DisputeStatus } from "@/lib/services"
|
||||
import { useUser } from "@/contexts/user-context"
|
||||
import { toast } from "sonner"
|
||||
|
||||
const DISPUTE_PAGE_SIZE = 20
|
||||
|
||||
/**
|
||||
* 争议数据获取 Hook
|
||||
* 用于获取争议数据
|
||||
*
|
||||
* @param fetchFn 获取争议数据的函数
|
||||
* @returns 争议数据
|
||||
*/
|
||||
interface UseDisputeDataProps {
|
||||
fetchFn: (params: { page: number; page_size: number; status: DisputeStatus }) => Promise<{ total: number; disputes: DisputeWithOrder[] }>
|
||||
}
|
||||
|
||||
export const useDisputeData = ({ fetchFn }: UseDisputeDataProps) => {
|
||||
const { user } = useUser()
|
||||
const [disputes, setDisputes] = React.useState<{ count: number; list: DisputeWithOrder[] }>({ count: 0, list: [] })
|
||||
const [loading, setLoading] = React.useState<boolean>(true)
|
||||
const fetchFnRef = React.useRef(fetchFn)
|
||||
|
||||
React.useEffect(() => {
|
||||
fetchFnRef.current = fetchFn
|
||||
}, [fetchFn])
|
||||
|
||||
const fetchData = React.useCallback(async () => {
|
||||
if (!user) return
|
||||
|
||||
try {
|
||||
setLoading(true)
|
||||
const result = await fetchFnRef.current({
|
||||
page: 1,
|
||||
page_size: DISPUTE_PAGE_SIZE,
|
||||
status: 'disputing'
|
||||
}).catch(() => ({ total: 0, disputes: [] }))
|
||||
|
||||
setDisputes({
|
||||
count: result.total,
|
||||
list: result.disputes
|
||||
})
|
||||
} catch (err) {
|
||||
toast.error('获取争议数据失败', {
|
||||
description: err instanceof Error ? err.message : '获取争议数据失败'
|
||||
})
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [user])
|
||||
|
||||
React.useEffect(() => {
|
||||
fetchData()
|
||||
}, [fetchData])
|
||||
|
||||
const handleRefresh = React.useCallback(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const result = await fetchFnRef.current({
|
||||
page: 1,
|
||||
page_size: DISPUTE_PAGE_SIZE,
|
||||
status: 'disputing'
|
||||
})
|
||||
setDisputes({
|
||||
count: result.total,
|
||||
list: result.disputes
|
||||
})
|
||||
} catch (err) {
|
||||
toast.error('刷新争议数据失败', {
|
||||
description: err instanceof Error ? err.message : '刷新争议数据失败'
|
||||
})
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return { disputes, loading, handleRefresh, refetchData: fetchData }
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { LeaderboardService } from "@/lib/services/leaderboard";
|
||||
import type {
|
||||
LeaderboardListResponse,
|
||||
LeaderboardListRequest,
|
||||
LeaderboardEntry,
|
||||
UserRankResponse,
|
||||
} from "@/lib/services/leaderboard";
|
||||
|
||||
export const useLeaderboard = () => {
|
||||
const [data, setData] = React.useState<LeaderboardListResponse | null>(null);
|
||||
const [allItems, setAllItems] = React.useState<LeaderboardEntry[]>([]);
|
||||
const [myRank, setMyRank] = React.useState<UserRankResponse | null>(null);
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
const [loadingMore, setLoadingMore] = React.useState(false);
|
||||
const [myRankLoading, setMyRankLoading] = React.useState(true);
|
||||
const [error, setError] = React.useState<Error | null>(null);
|
||||
|
||||
const currentPageRef = React.useRef(1);
|
||||
|
||||
const fetchData = React.useCallback(
|
||||
async (
|
||||
queryParams: LeaderboardListRequest,
|
||||
append = false,
|
||||
ignore?: { current: boolean },
|
||||
) => {
|
||||
if (append) {
|
||||
setLoadingMore(true);
|
||||
} else {
|
||||
setLoading(true);
|
||||
setAllItems([]);
|
||||
currentPageRef.current = 1;
|
||||
}
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const response = await LeaderboardService.getList(queryParams);
|
||||
|
||||
if (ignore?.current) return;
|
||||
|
||||
setData(response);
|
||||
if (append) {
|
||||
setAllItems((prev) => [...prev, ...response.items]);
|
||||
} else {
|
||||
setAllItems(response.items);
|
||||
}
|
||||
currentPageRef.current = response.page;
|
||||
} catch (err) {
|
||||
if (ignore?.current) return;
|
||||
if (err instanceof Error) {
|
||||
setError(err);
|
||||
}
|
||||
} finally {
|
||||
if (!ignore?.current) {
|
||||
setLoading(false);
|
||||
setLoadingMore(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const fetchMyRank = React.useCallback(
|
||||
async (ignore?: { current: boolean }) => {
|
||||
setMyRankLoading(true);
|
||||
try {
|
||||
const response = await LeaderboardService.getMyRank();
|
||||
if (!ignore?.current) {
|
||||
setMyRank(response);
|
||||
}
|
||||
} catch {
|
||||
if (!ignore?.current) {
|
||||
setMyRank(null);
|
||||
}
|
||||
} finally {
|
||||
if (!ignore?.current) {
|
||||
setMyRankLoading(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
const ignore = { current: false };
|
||||
fetchData({ page: 1, page_size: 50 }, false, ignore);
|
||||
fetchMyRank(ignore);
|
||||
return () => {
|
||||
ignore.current = true;
|
||||
};
|
||||
}, [fetchData, fetchMyRank]);
|
||||
|
||||
const loadNextPage = React.useCallback(() => {
|
||||
if (
|
||||
data &&
|
||||
currentPageRef.current * data.page_size < data.total &&
|
||||
!loadingMore
|
||||
) {
|
||||
const nextPage = currentPageRef.current + 1;
|
||||
fetchData({ page: nextPage, page_size: data.page_size }, true);
|
||||
}
|
||||
}, [data, loadingMore, fetchData]);
|
||||
|
||||
const refresh = React.useCallback(() => {
|
||||
fetchData({ page: 1, page_size: 50 }, false);
|
||||
fetchMyRank();
|
||||
}, [fetchData, fetchMyRank]);
|
||||
|
||||
const hasMore = data
|
||||
? currentPageRef.current * data.page_size < data.total
|
||||
: false;
|
||||
|
||||
return {
|
||||
data,
|
||||
items: allItems,
|
||||
myRank,
|
||||
loading,
|
||||
loadingMore,
|
||||
myRankLoading,
|
||||
error,
|
||||
hasMore,
|
||||
loadNextPage,
|
||||
refresh,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user