2024-12-30 09:03:40 +00:00
|
|
|
|
<template>
|
|
|
|
|
<div class="outer-layer search-page">
|
|
|
|
|
<div class="root">
|
2024-12-31 09:01:18 +00:00
|
|
|
|
<searchList
|
|
|
|
|
:searchResultPageSize="10"
|
|
|
|
|
:listLimit="false"
|
|
|
|
|
:apiRequest="state.apiRequest"
|
|
|
|
|
:apiParams="state.apiParams"
|
|
|
|
|
:searchText="state.searchText"
|
|
|
|
|
:isPagination="true"
|
|
|
|
|
@lastIdChange="lastIdChange"
|
|
|
|
|
@clickSearchItem="clickSearchItem"
|
|
|
|
|
></searchList>
|
2024-12-30 09:03:40 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup>
|
|
|
|
|
import searchList from '../components/searchList.vue'
|
|
|
|
|
import { onLoad } from '@dcloudio/uni-app'
|
2024-12-31 03:04:11 +00:00
|
|
|
|
import {
|
|
|
|
|
ServeQueryUser,
|
|
|
|
|
ServeQueryGroup,
|
|
|
|
|
ServeTalkRecord,
|
2025-03-17 11:54:43 +00:00
|
|
|
|
ServeGetSessionId,
|
2024-12-31 03:04:11 +00:00
|
|
|
|
} from '@/api/search/index'
|
2024-12-31 09:01:18 +00:00
|
|
|
|
import { reactive } from 'vue'
|
2024-12-31 03:04:11 +00:00
|
|
|
|
|
2025-03-29 09:15:19 +00:00
|
|
|
|
import { useDialogueStore, useTalkStore } from '@/store'
|
|
|
|
|
import { ServeCreateTalkList } from '@/api/chat/index.js'
|
|
|
|
|
import { formatTalkItem } from '@/utils/talk'
|
2025-03-15 08:44:40 +00:00
|
|
|
|
|
|
|
|
|
const dialogueStore = useDialogueStore()
|
|
|
|
|
|
2024-12-30 09:03:40 +00:00
|
|
|
|
const state = reactive({
|
2024-12-31 09:01:18 +00:00
|
|
|
|
apiRequest: Function,
|
2025-03-17 11:54:43 +00:00
|
|
|
|
apiParams: '',
|
|
|
|
|
searchText: '',
|
|
|
|
|
searchResultKey: '',
|
2024-12-30 09:03:40 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onLoad((options) => {
|
|
|
|
|
console.log(options)
|
|
|
|
|
if (options.searchResultKey) {
|
2025-01-02 08:01:36 +00:00
|
|
|
|
state.searchResultKey = options.searchResultKey
|
2024-12-31 09:01:18 +00:00
|
|
|
|
if (options.searchResultKey === 'user_infos') {
|
|
|
|
|
state.apiParams = encodeURIComponent(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
last_id: 0, //最后一条用户id
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
state.apiRequest = ServeQueryUser
|
|
|
|
|
} else if (options.searchResultKey === 'combinedGroup') {
|
|
|
|
|
state.apiParams = encodeURIComponent(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
last_group_id: 0, //最后一条群id
|
|
|
|
|
last_member_id: 0, //最后一条用户id
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
state.apiRequest = ServeQueryGroup
|
|
|
|
|
} else if (options.searchResultKey === 'general_infos') {
|
|
|
|
|
state.apiParams = encodeURIComponent(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
talk_type: 0, //1私聊2群聊
|
|
|
|
|
receiver_id: 0, //查详情的时候需传入
|
|
|
|
|
last_group_id: 0, //最后一条群id
|
|
|
|
|
last_member_id: 0, //最后一条用户id
|
2025-03-24 08:37:29 +00:00
|
|
|
|
last_receiver_user_name: '', //最后一条用户名
|
|
|
|
|
last_receiver_group_name: '', //最后一条群名
|
2024-12-31 09:01:18 +00:00
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
state.apiRequest = ServeTalkRecord
|
|
|
|
|
}
|
2024-12-30 09:03:40 +00:00
|
|
|
|
}
|
|
|
|
|
if (options.searchText) {
|
|
|
|
|
state.searchText = options.searchText
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-12-31 09:01:18 +00:00
|
|
|
|
//分页查询时,最后一条id变化
|
2025-03-29 09:15:19 +00:00
|
|
|
|
const lastIdChange = (
|
|
|
|
|
last_id,
|
|
|
|
|
last_group_id,
|
|
|
|
|
last_member_id,
|
|
|
|
|
last_receiver_user_name,
|
|
|
|
|
last_receiver_group_name,
|
|
|
|
|
) => {
|
2024-12-31 09:01:18 +00:00
|
|
|
|
let idChanges = {
|
|
|
|
|
last_id,
|
|
|
|
|
last_group_id,
|
|
|
|
|
last_member_id,
|
2025-03-24 08:37:29 +00:00
|
|
|
|
last_receiver_user_name,
|
|
|
|
|
last_receiver_group_name,
|
2024-12-30 09:03:40 +00:00
|
|
|
|
}
|
2024-12-31 09:01:18 +00:00
|
|
|
|
state.apiParams = encodeURIComponent(
|
|
|
|
|
JSON.stringify(
|
|
|
|
|
Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
JSON.parse(decodeURIComponent(state.apiParams)),
|
|
|
|
|
idChanges,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
2024-12-30 09:03:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-31 09:01:18 +00:00
|
|
|
|
//点击了搜索结果项
|
2025-03-17 11:54:43 +00:00
|
|
|
|
const clickSearchItem = async (
|
2025-03-15 08:44:40 +00:00
|
|
|
|
searchText,
|
|
|
|
|
searchResultKey,
|
|
|
|
|
talk_type,
|
|
|
|
|
receiver_id,
|
|
|
|
|
res,
|
|
|
|
|
) => {
|
|
|
|
|
console.log(state.searchResultKey)
|
|
|
|
|
const result = JSON.parse(decodeURIComponent(res))
|
|
|
|
|
console.log(result)
|
2025-03-17 11:54:43 +00:00
|
|
|
|
console.log(talk_type, receiver_id)
|
|
|
|
|
const sessionId = await getSessionId(talk_type, receiver_id)
|
2025-03-15 08:44:40 +00:00
|
|
|
|
if (state.searchResultKey === 'user_infos') {
|
2025-03-29 09:15:19 +00:00
|
|
|
|
if (useTalkStore().findTalkIndex(`${talk_type}_${receiver_id}`) === -1) {
|
|
|
|
|
ServeCreateTalkList({
|
|
|
|
|
talk_type,
|
|
|
|
|
receiver_id,
|
|
|
|
|
erp_user_id: result.erp_user_id,
|
|
|
|
|
}).then(async ({ code, data }) => {
|
|
|
|
|
if (code == 200) {
|
|
|
|
|
let item = formatTalkItem(data)
|
|
|
|
|
useTalkStore().addItem(item)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-03-17 11:54:43 +00:00
|
|
|
|
dialogueStore.setDialogue({
|
|
|
|
|
name: result.nickname,
|
|
|
|
|
talk_type: 1,
|
|
|
|
|
receiver_id: receiver_id,
|
|
|
|
|
})
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url: '/pages/dialog/index?sessionId=' + sessionId,
|
|
|
|
|
})
|
2025-03-15 08:44:40 +00:00
|
|
|
|
} else if (state.searchResultKey === 'combinedGroup') {
|
|
|
|
|
dialogueStore.setDialogue({
|
|
|
|
|
name: result.name || result.group_name,
|
|
|
|
|
talk_type: result.type || 2,
|
2025-03-17 11:54:43 +00:00
|
|
|
|
receiver_id: result.group_id || result.id,
|
2025-03-15 08:44:40 +00:00
|
|
|
|
})
|
|
|
|
|
uni.navigateTo({
|
2025-03-17 11:54:43 +00:00
|
|
|
|
url: '/pages/dialog/index?sessionId=' + sessionId,
|
2025-03-15 08:44:40 +00:00
|
|
|
|
})
|
|
|
|
|
} else if (state.searchResultKey === 'general_infos') {
|
2025-01-02 08:01:36 +00:00
|
|
|
|
uni.navigateTo({
|
2025-03-17 11:54:43 +00:00
|
|
|
|
url:
|
|
|
|
|
'/pages/search/moreResult/moreResultDetail?searchText=' +
|
|
|
|
|
searchText +
|
|
|
|
|
'&talk_type=' +
|
|
|
|
|
talk_type +
|
|
|
|
|
'&receiver_id=' +
|
|
|
|
|
receiver_id,
|
2025-01-02 08:01:36 +00:00
|
|
|
|
})
|
|
|
|
|
}
|
2024-12-30 09:03:40 +00:00
|
|
|
|
}
|
2025-03-17 11:54:43 +00:00
|
|
|
|
|
|
|
|
|
//获取会话Id
|
|
|
|
|
const getSessionId = (talk_type, receiver_id) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let params = {
|
|
|
|
|
talkType: talk_type,
|
|
|
|
|
receiverId: receiver_id,
|
|
|
|
|
}
|
|
|
|
|
const resp = ServeGetSessionId(params)
|
|
|
|
|
console.log(resp)
|
|
|
|
|
resp.then(({ code, data }) => {
|
|
|
|
|
console.log(data)
|
|
|
|
|
if (code == 200) {
|
|
|
|
|
resolve(data?.sessionId)
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
resp.catch(() => {})
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-12-30 09:03:40 +00:00
|
|
|
|
</script>
|
2024-12-31 09:01:18 +00:00
|
|
|
|
<style scoped lang="scss"></style>
|