Files
nl-um-vue-ts/src/api/modules/search.ts
2025-12-14 12:19:47 +08:00

59 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 }
})
}