处理搜索不同条件、不同类型跳转对应聊天记录

This commit is contained in:
wangyifeng 2025-03-17 19:54:43 +08:00
parent a6810d4f12
commit 026e4fa3e6
8 changed files with 189 additions and 37 deletions

View File

@ -45,3 +45,12 @@ export const ServeTalkDate = (data) => {
data, data,
}) })
} }
//获取会话Id
export const ServeGetSessionId = (data) => {
return request({
url: '/api/v1/talk/session/getId',
method: 'POST',
data,
})
}

View File

@ -21,9 +21,20 @@
<script setup> <script setup>
import { defineProps, defineEmits, reactive, watch } from 'vue' import { defineProps, defineEmits, reactive, watch } from 'vue'
const props = defineProps({ const props = defineProps({
searchText: String, searchText: {
first_talk_record_infos: Object, type: String,
disabled: Boolean, default: ''
},
first_talk_record_infos: {
type: Object,
default(){
return {}
}
},
disabled: {
type: Boolean,
default: false
},
}) })
const state = reactive({ const state = reactive({
searchText: '', // searchText: '', //

View File

@ -804,7 +804,7 @@ const onEditorChange = () => {
// emit('editor-event', emitCall('input_event', text)) // emit('editor-event', emitCall('input_event', text))
// 5 // 5
const now = new Date().getTime() const now = new Date().getTime()
Object.keys(state.value.revokedMessages).forEach((msgId) => { Object.keys(state.value.revokedMessages || {}).forEach((msgId) => {
if (now - state.value.revokedMessages[msgId].revokeTime > 5 * 60 * 1000) { if (now - state.value.revokedMessages[msgId].revokeTime > 5 * 60 * 1000) {
delete state.value.revokedMessages[msgId] delete state.value.revokedMessages[msgId]
} }

View File

@ -99,11 +99,26 @@ import { beautifyTime } from '@/utils/datetime'
const { t } = useI18n() const { t } = useI18n()
const props = defineProps({ const props = defineProps({
searchItem: Object | Number, searchItem: Object | Number,
searchResultKey: String, searchResultKey: {
searchText: String, // type: String,
searchRecordDetail: Boolean, // default: '',
pointerIconSrc: String, // },
conditionType: Number, // searchText: {
type: String,
default: '',
}, //
searchRecordDetail: {
type: Boolean,
default: false,
}, //
pointerIconSrc: {
type: String,
default: '',
}, //
conditionType: {
type: Number,
default: 0,
}, //
}) })
// - // -
const keyMapping = { const keyMapping = {
@ -193,10 +208,8 @@ const imgText = computed(() => {
}) })
// -groupType // -groupType
const groupTypeMapping = { const groupTypeMapping = {
0: { 0: {},
}, 1: {},
1: {
},
2: { 2: {
result_type: t('index.mine.department'), result_type: t('index.mine.department'),
result_type_color: '#377EC6', result_type_color: '#377EC6',

View File

@ -139,14 +139,37 @@ const state = reactive({
}) })
const props = defineProps({ const props = defineProps({
searchResultPageSize: Number, // searchResultPageSize: {
listLimit: Boolean, // type: Number,
apiParams: String, // default: 0,
}, //
listLimit: {
type: Boolean,
default: false,
}, //
apiParams: {
type: String,
default: '',
}, //
apiRequest: Function, // apiRequest: Function, //
searchText: String, // searchText: {
isPagination: Boolean, // type: String,
searchRecordDetail: Boolean, // default: '',
first_talk_record_infos: Object, // }, //
isPagination: {
type: Boolean,
default: false,
}, //
searchRecordDetail: {
type: Boolean,
default: false,
}, //
first_talk_record_infos: {
type: Object,
default() {
return {}
},
}, //
}) })
const { t } = useI18n() const { t } = useI18n()
@ -366,6 +389,9 @@ const getHasMoreResult = (searchResultKey) => {
} }
break break
case 'general_infos': case 'general_infos':
// if (state?.searchResult['general_infos']?.length >= 3) {
// has_more_result = t('has_more') + t('chat.type.record')
// }
break break
default: default:
} }
@ -379,12 +405,40 @@ const toMoreResultPage = (searchResultKey) => {
// //
const clickSearchItem = (searchResultKey, searchItem) => { const clickSearchItem = (searchResultKey, searchItem) => {
console.log(searchResultKey, searchItem)
let talk_type = searchItem.talk_type
let receiver_id = searchItem.receiver_id
if (searchResultKey === 'user_infos') {
talk_type = 1
receiver_id = searchItem.id
} else if (searchResultKey === 'combinedGroup') {
talk_type = searchItem.type || 2
receiver_id = searchItem.group_id || searchItem.id
} else if (searchResultKey === 'general_infos') {
if (searchItem.talk_type === 1) {
if (searchItem.user_id === state.uid) {
//
}
if (searchItem.receiver_id === state.uid) {
//
let temp_id = searchItem.receiver_id
let temp_name = searchItem.receiver_name
let temp_avatar = searchItem.receiver_avatar
searchItem.receiver_id = searchItem.user_id
searchItem.receiver_name = searchItem.user_name
searchItem.receiver_avatar = searchItem.user_avatar
searchItem.user_id = temp_id
searchItem.user_name = temp_name
searchItem.user_avatar = temp_avatar
}
}
}
emits( emits(
'clickSearchItem', 'clickSearchItem',
state.searchText, state.searchText,
searchResultKey, searchResultKey,
searchItem.talk_type, talk_type,
searchItem.receiver_id, receiver_id,
encodeURIComponent(JSON.stringify(searchItem)), encodeURIComponent(JSON.stringify(searchItem)),
) )
} }

View File

@ -13,7 +13,7 @@
</template> </template>
<script setup> <script setup>
import searchList from './components/searchList.vue' import searchList from './components/searchList.vue'
import { ServeSeachQueryAll } from '@/api/search/index' import { ServeSeachQueryAll, ServeGetSessionId } from '@/api/search/index'
import { onMounted } from 'vue' import { onMounted } from 'vue'
import { handleSetWebviewStyle } from '@/utils/common' import { handleSetWebviewStyle } from '@/utils/common'
@ -37,7 +37,7 @@ const toMoreResultPage = (searchResultKey, searchText) => {
} }
// //
const clickSearchItem = ( const clickSearchItem = async (
searchText, searchText,
searchResultKey, searchResultKey,
talk_type, talk_type,
@ -47,17 +47,25 @@ const clickSearchItem = (
console.log(searchResultKey) console.log(searchResultKey)
const result = JSON.parse(decodeURIComponent(res)) const result = JSON.parse(decodeURIComponent(res))
console.log(result) console.log(result)
console.log(talk_type, receiver_id)
const sessionId = await getSessionId(talk_type, receiver_id)
if (searchResultKey === 'user_infos') { if (searchResultKey === 'user_infos') {
dialogueStore.setDialogue({
name: result.nickname,
talk_type: 1,
receiver_id: receiver_id,
})
uni.navigateTo({
url: '/pages/dialog/index?sessionId=' + sessionId,
})
} else if (searchResultKey === 'combinedGroup') { } else if (searchResultKey === 'combinedGroup') {
dialogueStore.setDialogue({ dialogueStore.setDialogue({
name: result.name || result.group_name, name: result.name || result.group_name,
talk_type: result.type || 2, talk_type: result.type || 2,
receiver_id: result.id || result.group_id, receiver_id: result.group_id || result.id,
}) })
uni.navigateTo({ uni.navigateTo({
url: '/pages/dialog/index', url: '/pages/dialog/index?sessionId=' + sessionId
}) })
} else if (searchResultKey === 'general_infos') { } else if (searchResultKey === 'general_infos') {
uni.navigateTo({ uni.navigateTo({
@ -71,5 +79,25 @@ const clickSearchItem = (
}) })
} }
} }
//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(() => {})
})
}
</script> </script>
<style scoped lang="scss"></style> <style scoped lang="scss"></style>

View File

@ -21,6 +21,7 @@ import {
ServeQueryUser, ServeQueryUser,
ServeQueryGroup, ServeQueryGroup,
ServeTalkRecord, ServeTalkRecord,
ServeGetSessionId,
} from '@/api/search/index' } from '@/api/search/index'
import { reactive } from 'vue' import { reactive } from 'vue'
@ -30,9 +31,9 @@ const dialogueStore = useDialogueStore()
const state = reactive({ const state = reactive({
apiRequest: Function, apiRequest: Function,
apiParams: String, apiParams: '',
searchText: String, searchText: '',
searchResultKey: String, searchResultKey: '',
}) })
onLoad((options) => { onLoad((options) => {
@ -90,7 +91,7 @@ const lastIdChange = (last_id, last_group_id, last_member_id) => {
} }
// //
const clickSearchItem = ( const clickSearchItem = async (
searchText, searchText,
searchResultKey, searchResultKey,
talk_type, talk_type,
@ -100,21 +101,57 @@ const clickSearchItem = (
console.log(state.searchResultKey) console.log(state.searchResultKey)
const result = JSON.parse(decodeURIComponent(res)) const result = JSON.parse(decodeURIComponent(res))
console.log(result) console.log(result)
console.log(talk_type, receiver_id)
const sessionId = await getSessionId(talk_type, receiver_id)
if (state.searchResultKey === 'user_infos') { if (state.searchResultKey === 'user_infos') {
dialogueStore.setDialogue({
name: result.nickname,
talk_type: 1,
receiver_id: receiver_id,
})
uni.navigateTo({
url: '/pages/dialog/index?sessionId=' + sessionId,
})
} else if (state.searchResultKey === 'combinedGroup') { } else if (state.searchResultKey === 'combinedGroup') {
dialogueStore.setDialogue({ dialogueStore.setDialogue({
name: result.name || result.group_name, name: result.name || result.group_name,
talk_type: result.type || 2, talk_type: result.type || 2,
receiver_id: result.id || result.group_id, receiver_id: result.group_id || result.id,
}) })
uni.navigateTo({ uni.navigateTo({
url: '/pages/dialog/index', url: '/pages/dialog/index?sessionId=' + sessionId,
}) })
} else if (state.searchResultKey === 'general_infos') { } else if (state.searchResultKey === 'general_infos') {
uni.navigateTo({ uni.navigateTo({
url: '/pages/search/moreResult/moreResultDetail?searchText=' + searchText, url:
'/pages/search/moreResult/moreResultDetail?searchText=' +
searchText +
'&talk_type=' +
talk_type +
'&receiver_id=' +
receiver_id,
}) })
} }
} }
//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(() => {})
})
}
</script> </script>
<style scoped lang="scss"></style> <style scoped lang="scss"></style>

View File

@ -27,8 +27,8 @@ const dialogueStore = useDialogueStore()
const userStore = useUserStore() const userStore = useUserStore()
const state = reactive({ const state = reactive({
apiParams: String, apiParams: '',
searchText: String, searchText: '',
uid: computed(() => userStore.uid), //id uid: computed(() => userStore.uid), //id
}) })