59 lines
1.2 KiB
TypeScript
59 lines
1.2 KiB
TypeScript
import request from '../request'
|
||
import type { User } from '@/types/api'
|
||
|
||
/**
|
||
* 搜索相关API
|
||
*/
|
||
|
||
// 联系人搜索结果
|
||
export interface ContactSearchResult {
|
||
user: User
|
||
remark_name: string
|
||
room_id: string
|
||
}
|
||
|
||
// 群聊搜索结果
|
||
export interface GroupSearchResult {
|
||
room_id: string
|
||
room_name: string
|
||
room_avatar: string
|
||
owner_id: string
|
||
member_count: number
|
||
}
|
||
|
||
// 消息搜索结果
|
||
export interface MessageSearchResult {
|
||
id: number
|
||
room_id: string
|
||
room_name: string
|
||
content: string
|
||
message_type: number
|
||
created_at: string
|
||
sender: User
|
||
is_group_chat: boolean
|
||
match_content: string
|
||
}
|
||
|
||
// 聚合搜索结果
|
||
export interface GlobalSearchResult {
|
||
contacts: ContactSearchResult[]
|
||
groups: GroupSearchResult[]
|
||
messages: MessageSearchResult[]
|
||
}
|
||
|
||
// 搜索类型
|
||
export type SearchType = 'all' | 'contacts' | 'groups' | 'messages'
|
||
|
||
/**
|
||
* 聚合搜索
|
||
* @param keyword 搜索关键词
|
||
* @param type 搜索类型:all(默认)、contacts、groups、messages
|
||
* @param limit 每类结果的最大数量,默认20
|
||
*/
|
||
export function globalSearch(keyword: string, type: SearchType = 'all', limit: number = 20) {
|
||
return request.get<GlobalSearchResult>('/search', {
|
||
params: { keyword, type, limit }
|
||
})
|
||
}
|
||
|