chat-app/src/pages/search/moreResult/moreResult.vue

244 lines
6.3 KiB
Vue
Raw Normal View History

<template>
<div class="outer-layer search-page">
<div class="root">
<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"
>
<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>
</div>
</div>
</template>
<script setup>
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'
import searchList from '../components/searchList.vue'
import { onLoad } from '@dcloudio/uni-app'
import {
ServeQueryUser,
ServeQueryGroup,
ServeTalkRecord,
} from '@/api/search/index'
import { ref, watch, computed, onMounted, onUnmounted, reactive } from 'vue'
import { useAuth } from '@/store/auth'
import { nextTick } from 'process'
const zPaging = ref()
useZPaging(zPaging)
const state = reactive({
searchText: '', //搜索内容
searchResultList: [], //搜索结果列表
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) => {
// console.log(e)
state.searchText = e
zPaging.value?.reload()
}
// ES搜索聊天记录-指定用户、指定群、群与用户概览
const queryAllSearch = () => {
let params = {}
let resp = null
if (state.searchResultKey === 'user_infos') {
params = {
size: state.searchResultPageSize, //搜索结果每页数据量
key: state.searchText, //关键字
last_id: 0, //最后一条用户id
}
resp = ServeQueryUser(params)
} else if (state.searchResultKey === 'combinedGroup') {
params = {
size: state.searchResultPageSize, //搜索结果每页数据量
key: state.searchText, //关键字
last_group_id: 0, //最后一条群id
last_member_id: 0, //最后一条用户id
}
resp = ServeQueryGroup(params)
} else if (state.searchResultKey === 'general_infos') {
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)
}
resp.then(({ code, data }) => {
console.log(data)
if (code == 200) {
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])
}
} else {
zPaging.value?.complete([])
}
})
resp.catch(() => {
zPaging.value?.complete([])
})
}
//点击取消搜索
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 {
padding: 20rpx 48rpx;
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;
padding: 0 32rpx;
min-height: 0;
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
}
}
</style>