2024-12-30 09:03:40 +00:00
|
|
|
<template>
|
|
|
|
<div class="outer-layer search-page">
|
|
|
|
<div class="root">
|
2024-12-31 03:04:11 +00:00
|
|
|
<ZPaging
|
|
|
|
ref="zPaging"
|
|
|
|
:show-scrollbar="false"
|
|
|
|
v-model="state.searchResultList"
|
|
|
|
@query="queryAllSearch"
|
|
|
|
:empty-view-img="'/src/static//image/search/search-no-data.png'"
|
|
|
|
:empty-view-text="$t('search.hint')"
|
|
|
|
:empty-view-img-style="{ width: '476rpx', height: '261rpx' }"
|
|
|
|
:empty-view-title-style="{
|
|
|
|
color: '#999999',
|
|
|
|
margin: '-20rpx 0 0',
|
|
|
|
'line-height': '40rpx',
|
|
|
|
'font-size': '28rpx',
|
|
|
|
'font-weight': 400,
|
|
|
|
}"
|
|
|
|
:default-page-no="1"
|
|
|
|
:default-page-size="state.searchResultPageSize"
|
2024-12-30 09:03:40 +00:00
|
|
|
>
|
2024-12-31 03:04:11 +00:00
|
|
|
<template #top>
|
|
|
|
<div class="searchRoot">
|
|
|
|
<tm-input
|
|
|
|
class="searchRoot_input"
|
|
|
|
placeholder="请输入…"
|
|
|
|
color="#F9F9FD"
|
|
|
|
:round="1"
|
|
|
|
prefix="tmicon-search"
|
|
|
|
prefixColor="#46299D"
|
|
|
|
v-model.lazy="state.searchText"
|
|
|
|
@input="inputSearchText"
|
|
|
|
></tm-input>
|
|
|
|
<span
|
|
|
|
class="searchRoot_cancelBtn text-[32rpx] font-medium"
|
|
|
|
@click="cancelSearch"
|
|
|
|
>
|
|
|
|
{{ $t('cancel') }}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<div
|
|
|
|
class="search-result"
|
|
|
|
:style="
|
|
|
|
!state.searchText
|
|
|
|
? 'align-items:center;justify-content:center;'
|
|
|
|
: ''
|
|
|
|
"
|
|
|
|
>
|
|
|
|
<searchList
|
|
|
|
:searchResult="state.searchResult"
|
|
|
|
:searchText="state.searchText"
|
|
|
|
:listLimit="false"
|
|
|
|
></searchList>
|
|
|
|
</div>
|
|
|
|
</ZPaging>
|
2024-12-30 09:03:40 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script setup>
|
2024-12-31 03:04:11 +00:00
|
|
|
import ZPaging from '@/uni_modules/z-paging/components/z-paging/z-paging.vue'
|
|
|
|
import useZPaging from '@/uni_modules/z-paging/components/z-paging/js/hooks/useZPaging.js'
|
2024-12-30 09:03:40 +00:00
|
|
|
import searchList from '../components/searchList.vue'
|
|
|
|
import { onLoad } from '@dcloudio/uni-app'
|
2024-12-31 03:04:11 +00:00
|
|
|
import {
|
|
|
|
ServeQueryUser,
|
|
|
|
ServeQueryGroup,
|
|
|
|
ServeTalkRecord,
|
|
|
|
} from '@/api/search/index'
|
2024-12-30 09:03:40 +00:00
|
|
|
import { ref, watch, computed, onMounted, onUnmounted, reactive } from 'vue'
|
|
|
|
import { useAuth } from '@/store/auth'
|
|
|
|
import { nextTick } from 'process'
|
2024-12-31 03:04:11 +00:00
|
|
|
|
|
|
|
const zPaging = ref()
|
|
|
|
useZPaging(zPaging)
|
|
|
|
|
2024-12-30 09:03:40 +00:00
|
|
|
const state = reactive({
|
|
|
|
searchText: '', //搜索内容
|
2024-12-31 03:04:11 +00:00
|
|
|
searchResultList: [], //搜索结果列表
|
2024-12-30 09:03:40 +00:00
|
|
|
searchResult: null, //搜索结果
|
|
|
|
searchResultPageSize: 10, //搜索结果每页数据量
|
|
|
|
searchResultKey: '',
|
|
|
|
})
|
|
|
|
|
|
|
|
onLoad((options) => {
|
|
|
|
console.log(options)
|
|
|
|
if (options.searchResultKey) {
|
|
|
|
state.searchResultKey = options.searchResultKey
|
|
|
|
}
|
|
|
|
if (options.searchText) {
|
|
|
|
state.searchText = options.searchText
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
//输入搜索文本
|
|
|
|
const inputSearchText = (e) => {
|
2024-12-31 03:04:11 +00:00
|
|
|
// console.log(e)
|
|
|
|
state.searchText = e
|
|
|
|
zPaging.value?.reload()
|
2024-12-30 09:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ES搜索聊天记录-指定用户、指定群、群与用户概览
|
2024-12-31 03:04:11 +00:00
|
|
|
const queryAllSearch = () => {
|
|
|
|
let params = {}
|
|
|
|
let resp = null
|
2024-12-30 09:03:40 +00:00
|
|
|
if (state.searchResultKey === 'user_infos') {
|
2024-12-31 03:04:11 +00:00
|
|
|
params = {
|
|
|
|
size: state.searchResultPageSize, //搜索结果每页数据量
|
|
|
|
key: state.searchText, //关键字
|
|
|
|
last_id: 0, //最后一条用户id
|
|
|
|
}
|
|
|
|
resp = ServeQueryUser(params)
|
2024-12-30 09:03:40 +00:00
|
|
|
} else if (state.searchResultKey === 'combinedGroup') {
|
2024-12-31 03:04:11 +00:00
|
|
|
params = {
|
|
|
|
size: state.searchResultPageSize, //搜索结果每页数据量
|
|
|
|
key: state.searchText, //关键字
|
|
|
|
last_group_id: 0, //最后一条群id
|
|
|
|
last_member_id: 0, //最后一条用户id
|
|
|
|
}
|
|
|
|
resp = ServeQueryGroup(params)
|
2024-12-30 09:03:40 +00:00
|
|
|
} else if (state.searchResultKey === 'general_infos') {
|
2024-12-31 03:04:11 +00:00
|
|
|
params = {
|
|
|
|
talk_type: 0, //1私聊2群聊
|
|
|
|
key: state.searchText, //关键字
|
|
|
|
size: state.searchResultPageSize, //搜索结果每页数据量
|
|
|
|
receiver_id: 0, //查详情的时候需传入
|
|
|
|
last_group_id: 0, //最后一条群id
|
|
|
|
last_member_id: 0, //最后一条用户id
|
|
|
|
}
|
|
|
|
resp = ServeTalkRecord(params)
|
2024-12-30 09:03:40 +00:00
|
|
|
}
|
|
|
|
resp.then(({ code, data }) => {
|
|
|
|
console.log(data)
|
|
|
|
if (code == 200) {
|
2024-12-31 03:04:11 +00:00
|
|
|
if ((data.user_infos || []).length > 0) {
|
|
|
|
;(data.user_infos || []).forEach((item) => {
|
|
|
|
item.group_type = 0
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if ((data.group_infos || []).length > 0) {
|
|
|
|
;(data.group_infos || []).forEach((item) => {
|
|
|
|
item.group_type = item.type
|
|
|
|
item.groupTempType = 'group_infos'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if ((data.group_member_infos || []).length > 0) {
|
|
|
|
;(data.group_member_infos || []).forEach((item) => {
|
|
|
|
item.groupTempType = 'group_member_infos'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
let tempGeneral_infos = Array.isArray(data.general_infos)
|
|
|
|
? [...data.general_infos]
|
|
|
|
: data.general_infos
|
|
|
|
delete data.general_infos
|
|
|
|
data.combinedGroup = (data.group_infos || []).concat(
|
|
|
|
data.group_member_infos || [],
|
|
|
|
)
|
|
|
|
data.general_infos = tempGeneral_infos
|
|
|
|
state.searchResult = data
|
|
|
|
let isEmpty = true
|
|
|
|
let dataKeys = Object.keys(data)
|
|
|
|
dataKeys.forEach((item) => {
|
|
|
|
if (Array.isArray(data[item]) && data[item].length > 0) {
|
|
|
|
console.log(data[item])
|
|
|
|
isEmpty = false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (isEmpty) {
|
|
|
|
zPaging.value?.complete([])
|
|
|
|
} else {
|
|
|
|
zPaging.value?.complete([data])
|
|
|
|
}
|
2024-12-30 09:03:40 +00:00
|
|
|
} else {
|
2024-12-31 03:04:11 +00:00
|
|
|
zPaging.value?.complete([])
|
2024-12-30 09:03:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-12-31 03:04:11 +00:00
|
|
|
resp.catch(() => {
|
|
|
|
zPaging.value?.complete([])
|
|
|
|
})
|
2024-12-30 09:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//点击取消搜索
|
|
|
|
const cancelSearch = () => {
|
|
|
|
uni.navigateBack({
|
|
|
|
delta: 1,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
|
|
uni-page-body,
|
|
|
|
page {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.outer-layer {
|
|
|
|
flex: 1;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.root {
|
|
|
|
flex: 1;
|
|
|
|
padding: 20rpx 32rpx;
|
|
|
|
min-height: 0;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.search-page {
|
|
|
|
.searchRoot {
|
2024-12-31 03:04:11 +00:00
|
|
|
padding: 20rpx 48rpx;
|
2024-12-30 09:03:40 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
|
|
.searchRoot_input {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.searchRoot_cancelBtn {
|
|
|
|
line-height: 44rpx;
|
|
|
|
color: $theme-primary;
|
|
|
|
margin: 0 0 0 20rpx;
|
|
|
|
flex-shrink: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.search-result {
|
|
|
|
width: 100%;
|
|
|
|
flex: 1;
|
2024-12-31 03:04:11 +00:00
|
|
|
padding: 0 32rpx;
|
2024-12-30 09:03:40 +00:00
|
|
|
min-height: 0;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: flex-start;
|
|
|
|
justify-content: flex-start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|