Files
nl-um-vue-ts/src/api/modules/search.ts

59 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-12-14 12:19:47 +08:00
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 allcontactsgroupsmessages
* @param limit 20
*/
export function globalSearch(keyword: string, type: SearchType = 'all', limit: number = 20) {
return request.get<GlobalSearchResult>('/search', {
params: { keyword, type, limit }
})
}