个股论坛重做
This commit is contained in:
@@ -607,3 +607,77 @@ export const togglePinMessage = async (messageId: string, isPinned: boolean): Pr
|
||||
});
|
||||
if (!response.ok) throw new Error(isPinned ? '取消置顶失败' : '置顶失败');
|
||||
};
|
||||
|
||||
// ============================================================
|
||||
// 文件上传相关
|
||||
// ============================================================
|
||||
|
||||
export interface UploadedImage {
|
||||
url: string;
|
||||
filename: string;
|
||||
size: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*/
|
||||
export const uploadImage = async (file: File): Promise<UploadedImage> => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const response = await fetch(`${API_BASE}/api/community/upload/image`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.message || '上传图片失败');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.data;
|
||||
};
|
||||
|
||||
// ============================================================
|
||||
// 股票搜索相关
|
||||
// ============================================================
|
||||
|
||||
export interface StockSearchResult {
|
||||
stock_code: string;
|
||||
stock_name: string;
|
||||
full_name?: string;
|
||||
exchange?: string;
|
||||
isIndex?: boolean;
|
||||
security_type?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索股票
|
||||
*/
|
||||
export const searchStocks = async (
|
||||
query: string,
|
||||
limit: number = 10,
|
||||
type: 'all' | 'stock' | 'index' = 'stock'
|
||||
): Promise<StockSearchResult[]> => {
|
||||
if (!query.trim()) return [];
|
||||
|
||||
const params = new URLSearchParams({
|
||||
q: query,
|
||||
limit: String(limit),
|
||||
type,
|
||||
});
|
||||
|
||||
const response = await fetch(`${API_BASE}/api/stocks/search?${params}`, {
|
||||
credentials: 'include',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('搜索股票失败');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.results || [];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user