视频搜索

This commit is contained in:
lr 2025-02-23 15:23:44 +08:00
parent 1d2efd6397
commit 1e8c025c37
11 changed files with 478 additions and 493 deletions

View File

@ -301,9 +301,9 @@ const video = {
*/ */
hotVideos(param) { hotVideos(param) {
return util.request({ return util.request({
url: `/home/hotVideos`, url: `/video/search/getHot`,
// query: param.query, // query: param.query,
method: 'POST', method: 'GET',
}) })
}, },
@ -325,8 +325,8 @@ const video = {
*/ */
videoSearch(param) { videoSearch(param) {
return util.request({ return util.request({
url: `/home/videoSearch`, url: `/video/search/searchData`,
query: param.query, data: param.query,
method: 'POST', method: 'POST',
}) })
}, },

View File

@ -6,11 +6,9 @@ const config = {
// host: 'h5api', // host: 'h5api',
// #endif // #endif
// #ifndef H5 // #ifndef H5
host: 'http://91f.xyz:8080', // host: 'http://91f.xyz:8080',
<<<<<<< HEAD
// host: 'https://1a880cd5.r24.cpolar.top/', // host: 'https://1a880cd5.r24.cpolar.top/',
======= host: 'http://6mkwby.natappfree.cc',
>>>>>>> 409f137e8990b13381bdbe7efca7eec9a3cfc89e
// #endif // #endif
// 支付方式配置 // 支付方式配置
payType: { payType: {

View File

@ -110,8 +110,7 @@ function getList() {
uni.$emit('updateNum', {}) uni.$emit('updateNum', {})
uni.$chat.getConversationList().then(rs => { uni.$chat.getConversationList().then(rs => {
let res = rs.data.conversationList let res = rs.data.conversationList
console.log(res);
let arr = [] let arr = []
res.forEach(item => { res.forEach(item => {
let obj = {} let obj = {}

View File

@ -1,265 +1,296 @@
<script setup> <script setup>
/** /**
* 搜索 * 搜索
*/ */
import { import {
ref, ref,
reactive, reactive,
getCurrentInstance, getCurrentInstance,
computed, computed,
} from 'vue'; } from 'vue';
import { import {
onLoad, onLoad,
onReady, onReady,
onPullDownRefresh, onPullDownRefresh,
onReachBottom onReachBottom
} from '@dcloudio/uni-app' } from '@dcloudio/uni-app'
// //
import util from '@/common/js/util'; import util from '@/common/js/util';
// api // api
import api from '@/api/index.js' import api from '@/api/index.js'
// //
import statusBar from '@/components/header/statusBar.vue' import statusBar from '@/components/header/statusBar.vue'
import { set } from 'lodash';
const { const {
proxy proxy
} = getCurrentInstance() } = getCurrentInstance()
// //
const searchState = ref(false) const searchState = ref(false)
// //
const searchLog = reactive([]) const searchLog = reactive([])
//
const hotVideoList = reactive([])
//
const tabList = reactive([{
name: '视频',
getList: () => getVideoList(),
getMoreList: () => getMoreVideoList(),
refreshList: () => refreshVideoList()
},
{
name: '用户',
getList: () => getFriendList(),
getMoreList: () => getMoreFriendList(),
refreshList: () => refreshFriendList()
},
])
//
const tabIndex = ref(0)
//
const keyword = ref('')
//
const videoList = reactive({
data: [],
pageNum: 1,
pageSize: 10,
total: 0,
})
//
const userList = reactive({
data: [],
pageNum: 1,
pageSize: 10,
total: 0,
})
//
const userinfo = computed(() => {
let resuilt = uni.$store.state.userinfo
return resuilt
})
onLoad(() => {
//
getSearchLog()
//
getHotVideo()
})
onReachBottom(() => {
//
if (searchState.value) tabList[tabIndex.value].getMoreList()
})
onPullDownRefresh(() => {
if (!searchState.value) {
uni.stopPullDownRefresh()
return
}
//
tabList[tabIndex.value].refreshList()
})
//
function getSearchLog() {
// api.video.videoSearchLog().then(rs => {
// if (rs.code == 200) {
// searchLog.push(...rs.data)
// return
// }
// util.alert({
// content: rs.msg,
// showCancel: false,
// })
// })
let searchList = uni.getStorageSync('searchLog');
if (searchList) {
searchList = Array.from(new Set(searchList))
searchLog.push(...searchList)
}
}
//
function getHotVideo() {
// //
const hotVideoList = reactive([]) api.video.hotVideos().then(rs => {
// if (rs.code == 200) {
const tabList = reactive([{ hotVideoList.push(...rs.data)
name: '视频',
getList: () => getVideoList(),
getMoreList: () => getMoreVideoList(),
refreshList: () => refreshVideoList()
},
{
name: '用户',
getList: () => getFriendList(),
getMoreList: () => getMoreFriendList(),
refreshList: () => refreshFriendList()
},
])
//
const tabIndex = ref(0)
//
const keyword = ref('')
//
const videoList = reactive({
data: [],
pageNum: 1,
pageSize: 10,
total: 0,
})
//
const userList = reactive({
data: [],
pageNum: 1,
pageSize: 10,
total: 0,
})
onLoad(() => {
//
getSearchLog()
//
getHotVideo()
})
onReachBottom(() => {
//
if (searchState.value) tabList[tabIndex.value].getMoreList()
})
onPullDownRefresh(() => {
if (!searchState.value) {
uni.stopPullDownRefresh()
return return
} }
// util.alert({
tabList[tabIndex.value].refreshList() contuent: rs.msg,
showCancel: false,
})
}) })
}
// // tab
function getSearchLog() { function handleTabIndex(index) {
// if (tabIndex.value === index) return
api.video.videoSearchLog().then(rs => { tabIndex.value = index
if (rs.code == 200) { //
searchLog.push(...rs.data) tabList[tabIndex.value].refreshList()
return }
}
util.alert({ /**
content: rs.msg, * 查看用户主页
showCancel: false, * @param {Object} item
}) */
function handleUser(item) {
uni.navigateTo({
url: util.setUrl('/pages/index/videoHome', {
userId: item.userId
}) })
})
}
//
function handleSearch() {
if (!keyword.value) {
searchState.value = false
return
} else searchState.value = true
//
tabList[tabIndex.value].getList()
//
let searchList = uni.getStorageSync('searchLog');
searchList = searchList == '' ? [] : searchList;
searchList.push(keyword.value)
searchList = Array.from(new Set(searchList))
uni.setStorageSync("searchLog", searchList)
}
//
function refreshVideoList() {
videoList.pageNum = 1
videoList.total = 0
getVideoList()
}
//
function getMoreVideoList() {
if (videoList.data.length >= videoList.total) return
videoList.pageNum++
getVideoList()
}
//
function getVideoList() {
let obj = {
content: keyword.value,
type: +tabIndex.value + 1,
userId: userinfo.value.id,
} }
// api.video.videoSearch({ query: obj }).then(rs => {
function getHotVideo() { // console.log('videoSearch', rs)
// if (rs.code == 200) {
api.video.hotVideos().then(rs => { if (videoList.pageNum) videoList.data.length = 0
if (rs.code == 200) { //
hotVideoList.push(...rs.data) videoList.data.push(...rs.rows.map(item => {
return item.format_videoUrl = util.format_url(item.videoUrl, 'video')
} item.format_header = util.format_url(item.avatar, 'img')
util.alert({ item.format_imageUrl = util.format_url(item.coverUrl, 'img')
contuent: rs.msg, return item
showCancel: false, }))
}) //
videoList.total = rs.total
// console.log('videoList', videoList.data)
return
}
util.alert({
content: rs.msg,
showCancel: false,
}) })
} }).finally(() => {
uni.stopPullDownRefresh()
})
}
// tab //
function handleTabIndex(index) { function refreshFriendList() {
if (tabIndex.value === index) return userList.pageNum = 1
tabIndex.value = index userList.total = 0
// getFriendList()
tabList[tabIndex.value].refreshList() }
}
/** //
* 查看用户主页 function getMoreFriendList() {
* @param {Object} item if (userList.data.length >= userList.total) return
*/ userList.pageNum++
function handleUser(item) { getFriendList()
uni.navigateTo({ }
url: util.setUrl('/pages/index/videoHome', {
userId: item.userId //
}) function getFriendList() {
api.video.searchFriendByName({
path: [keyword.value],
query: {
pageNum: userList.pageNum,
pageSize: userList.pageSize,
}
}).then(rs => {
if (rs.code == 200) {
if (userList.pageNum) userList.data.length = 0
//
userList.data.push(...rs.rows.map(item => {
item.format_userPortrait = util.format_url(item.userPortrait, 'img')
return item
}))
//
userList.total = rs.total
return
}
util.alert({
content: rs.msg,
showCancel: false,
}) })
}).finally(() => {
uni.stopPullDownRefresh()
})
}
/**
* 点击当前元素搜索
* @param {Object} item 被点击的元素
* @param {String} key
*/
function handleItemSearch(item, key) {
if (key == 'search') {
keyword.value = item
} else if (key == 'title') {
keyword.value = item.topic
} }
// //
function handleSearch() { handleSearch()
if (!keyword.value) { }
searchState.value = false
return
} else searchState.value = true
// //
tabList[tabIndex.value].getList() function handleVideo(item) {
} uni.navigateTo({
url: util.setUrl('/pages/index/videoDetail', {
// videoId: item.id
function refreshVideoList() {
videoList.pageNum = 1
videoList.total = 0
getVideoList()
}
//
function getMoreVideoList() {
if (videoList.data.length >= videoList.total) return
videoList.pageNum++
getVideoList()
}
//
function getVideoList() {
api.video.videoSearch({
query: {
//
search: keyword.value,
pageNum: videoList.pageNum,
pageSize: videoList.pageSize,
}
}).then(rs => {
console.log('videoSearch', rs)
if (rs.code == 200) {
if (videoList.pageNum) videoList.data.length = 0
//
videoList.data.push(...rs.rows.map(item => {
item.format_videoUrl = util.format_url(item.videoUrl, 'video')
item.format_header = util.format_url(item.header, 'img')
item.format_imageUrl = util.format_url(item.imageUrl, 'img')
return item
}))
//
videoList.total = rs.total
console.log('videoList', videoList.data)
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
}).finally(() => {
uni.stopPullDownRefresh()
}) })
} })
}
// //
function refreshFriendList() { function deleteSearch() {
userList.pageNum = 1 util.alert({
userList.total = 0 content: '确认删除历史记录吗?',
getFriendList() }).then(rs => {
} uni.removeStorageSync('searchLog')
searchLog.value = []
// })
function getMoreFriendList() { }
if (userList.data.length >= userList.total) return
userList.pageNum++
getFriendList()
}
//
function getFriendList() {
api.video.searchFriendByName({
path: [keyword.value],
query: {
pageNum: userList.pageNum,
pageSize: userList.pageSize,
}
}).then(rs => {
console.log(rs)
if (rs.code == 200) {
if (userList.pageNum) userList.data.length = 0
//
userList.data.push(...rs.rows.map(item => {
item.format_userPortrait = util.format_url(item.userPortrait, 'img')
return item
}))
//
userList.total = rs.total
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
}).finally(() => {
uni.stopPullDownRefresh()
})
}
/**
* 点击当前元素搜索
* @param {Object} item 被点击的元素
* @param {String} key
*/
function handleItemSearch(item, key) {
keyword.value = item[key]
//
handleSearch()
}
//
function handleVideo(item) {
console.log('handleVideo', item)
//
uni.navigateTo({
url: util.setUrl('/pages/index/videoDetail', {
videoId: item.videoId
})
})
}
</script> </script>
<template> <template>
@ -292,10 +323,12 @@
<view class="searchList mtb30 mlr30"> <view class="searchList mtb30 mlr30">
<view class="rows"> <view class="rows">
<view class="title c333 f28 b">历史记录</view> <view class="title c333 f28 b">历史记录</view>
<uni-icons type="trash" size="24rpx" color="#999" @click="deleteSearch" />
</view> </view>
<view class="list mt20 c333 f24"> <view class="list mt20 c333 f24">
<view class="item dib mtb10 mlr10 ptb10 plr20 bar" v-for="(item,index) in searchLog" :key="index" @click="handleItemSearch(item,'search')">{{item.search}}</view> <view class="item dib mtb10 mlr10 ptb10 plr20 bar" v-for="(item, index) in searchLog" :key="index"
@click="handleItemSearch(item, 'search')">{{ item }}</view>
<view class="nomore mtb20" v-if="!searchLog[0]">暂无搜索记录</view> <view class="nomore mtb20" v-if="!searchLog[0]">暂无搜索记录</view>
</view> </view>
@ -308,7 +341,8 @@
</view> </view>
<view class="list mt20 c333 f24"> <view class="list mt20 c333 f24">
<view class="item dib mtb10 mlr10 ptb10 plr20 bar" v-for="(item,index) in 15" :key="index">电商</view> <view class="item dib mtb10 mlr10 ptb10 plr20 bar" v-for="(item, index) in 15" :key="index">电商
</view>
</view> </view>
</view> </view>
@ -316,19 +350,20 @@
<view class="hotList mtb30 mlr30 c333"> <view class="hotList mtb30 mlr30 c333">
<view class="title f28 b">热门搜索</view> <view class="title f28 b">热门搜索</view>
<view class="list"> <view class="list">
<view class="item df aic jcsb ptb20" v-for="(item,index) in hotVideoList" :key="index" @click="handleItemSearch(item,'title')"> <view class="item df aic jcsb ptb20" v-for="(item, index) in hotVideoList" :key="index"
<view class="rank c666 f32 b">{{index + 1}}</view> @click="handleItemSearch(item, 'title')">
<view class="rank c666 f32 b">{{ index + 1 }}</view>
<view class="content df aic f1 mlr15 f24"> <view class="content df aic f1 mlr15 f24">
<text>{{item.title}}</text> <text>{{ item.topic }}</text>
<template v-if="0"> <template v-if="index < 3">
<view class="label hot" v-if="index % 2 == 0"></view> <view class="label hot" v-if="index < 3"></view>
<view class="label new" v-if="index % 2 == 1"></view> <view class="label new" v-if="0"></view>
</template> </template>
<view class="f1"></view> <view class="f1"></view>
</view> </view>
<view class="number f22">热度{{item.play}}</view> <view v-if="0" class="number f22">热度{{ item.play }}</view>
<view class="change wh40" v-if="0"> <view class="change wh40" v-if="0">
<image src="/static/hotSearchUp.png" mode="aspectFit" v-if="1" /> <image src="/static/hotSearchUp.png" mode="aspectFit" v-if="1" />
<image src="/static/hotSearchDefault.png" mode="aspectFit" v-else-if="1" /> <image src="/static/hotSearchDefault.png" mode="aspectFit" v-else-if="1" />
@ -343,8 +378,9 @@
<template v-else> <template v-else>
<!-- tab --> <!-- tab -->
<view class="tabList df plr15"> <view class="tabList df plr15">
<view class="item df fdc aic plr20" v-for="(item,index) in tabList" :key="index" :class="{'active': index === tabIndex}" @click="handleTabIndex(index)"> <view class="item df fdc aic plr20" v-for="(item, index) in tabList" :key="index"
<view class="txt">{{item.name}}</view> :class="{ 'active': index === tabIndex }" @click="handleTabIndex(index)">
<view class="txt">{{ item.name }}</view>
<view class="line"></view> <view class="line"></view>
</view> </view>
</view> </view>
@ -353,7 +389,8 @@
<view class="listBox ptb15 plr15"> <view class="listBox ptb15 plr15">
<!-- 视频列表 --> <!-- 视频列表 -->
<view class="videoList" v-if="tabIndex === 0"> <view class="videoList" v-if="tabIndex === 0">
<view class="item oh mb25 plr30 c333 bfff br20" v-for="(item,index) in videoList.data" :key="index" @click="handleVideo(item)"> <view class="item oh mb25 plr30 c333 bfff br20" v-for="(item, index) in videoList.data" :key="index"
@click="handleVideo(item)">
<!-- 用户 --> <!-- 用户 -->
<view class="userinfo df aic mtb25"> <view class="userinfo df aic mtb25">
<view class="avatar" @click.stop="handleUser(item)"> <view class="avatar" @click.stop="handleUser(item)">
@ -361,13 +398,13 @@
</view> </view>
<view class="user ml15 f1"> <view class="user ml15 f1">
<view class="nickname f32">{{item.userName}}</view> <view class="nickname f32">{{ item.userNickname }}</view>
<view class="date mt10 c999 f24">{{item.createTime}}</view> <view class="date mt10 c999 f24">{{ item.createTime }}</view>
</view> </view>
</view> </view>
<!-- 简介 --> <!-- 简介 -->
<view class="desc mtb20 f28">{{item.title}}</view> <view class="desc mtb20 f28">{{ item.title }}</view>
<!-- 封面图 --> <!-- 封面图 -->
<view class="coverImg mtb20"> <view class="coverImg mtb20">
@ -378,21 +415,22 @@
<view class="menu df mtb20 c333 f28"> <view class="menu df mtb20 c333 f28">
<!-- 点赞数量 --> <!-- 点赞数量 -->
<view class="option f1 fmid"> <view class="option f1 fmid">
<image class="wh30" src="/static/indexLike.png" mode="aspectFit" v-if="item.isLike == 0" /> <image class="wh30" src="/static/indexLike.png" mode="aspectFit"
v-if="item.isLike == 1" />
<image class="wh30" src="/static/indexLike1.png" mode="aspectFit" v-else /> <image class="wh30" src="/static/indexLike1.png" mode="aspectFit" v-else />
<view class="number ml10">{{item.likes}}</view> <view class="number ml10">{{ item.likeCount }}</view>
</view> </view>
<!-- 评论数量 --> <!-- 评论数量 -->
<view class="option f1 fmid"> <view class="option f1 fmid">
<image class="wh30" src="/static/indexMsg.png" mode="aspectFit" /> <image class="wh30" src="/static/indexMsg.png" mode="aspectFit" />
<view class="number ml10">{{item.comment}}</view> <view class="number ml10">{{ item.reviewCount }}</view>
</view> </view>
<!-- 收藏数量 --> <!-- 收藏数量 -->
<view class="option f1 fmid"> <view class="option f1 fmid">
<image class="wh30" src="/static/indexCollect.png" mode="aspectFit" /> <image class="wh30" src="/static/indexCollect.png" mode="aspectFit" />
<view class="number ml10">{{item.collect}}</view> <view class="number ml10">{{ item.collectCount }}</view>
</view> </view>
<!-- 转发数量 --> <!-- 转发数量 -->
@ -419,18 +457,20 @@
</view> </view>
</view> </view>
</view> </view>
<view v-if="videoList.data.length == 0" class="mtb20 nomore">暂无更多</view>
</view> </view>
<!-- 用户列表 --> <!-- 用户列表 -->
<view class="userList" v-if="tabIndex === 1"> <view class="userList" v-if="tabIndex === 1">
<view class="item df aic mtb40 plr10" v-for="(item,index) in userList.data" :key="index" @click="handleUser(item)"> <view class="item df aic mtb40 plr10" v-for="(item, index) in userList.data" :key="index"
@click="handleUser(item)">
<view class="avatar fs0"> <view class="avatar fs0">
<image class="wh110 cir" :src="item.format_userPortrait" mode="aspectFill" /> <image class="wh110 cir" :src="item.format_userPortrait" mode="aspectFill" />
</view> </view>
<view class="user oh f1 mlr25"> <view class="user oh f1 mlr25">
<view class="nickname c333 f32">{{item.userNickname}}</view> <view class="nickname c333 f32">{{ item.userNickname }}</view>
<view class="fans c999 f24">粉丝{{item.userFans}}</view> <view class="fans c999 f24">粉丝{{ item.userFans }}</view>
</view> </view>
<view class="button fs0"> <view class="button fs0">
@ -446,114 +486,114 @@
</template> </template>
<style lang="scss"> <style lang="scss">
image { image {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
// //
.apex { .apex {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
right: 0; right: 0;
z-index: 1; z-index: 1;
background-color: #fff; background-color: #fff;
} }
// //
.search { .search {
height: 60rpx; height: 60rpx;
background-color: #f1f1f1;
}
//
.searchList {
//
.item {
background-color: #f1f1f1; background-color: #f1f1f1;
} }
}
// //
.searchList { .hotList {
// .item+.item {
.item { border-top: 1rpx solid #F6F6F6;
background-color: #f1f1f1;
}
} }
// .item:nth-child(1) .number {
.hotList { color: #FF0F2E;
.item+.item {
border-top: 1rpx solid #F6F6F6;
}
.item:nth-child(1) .number {
color: #FF0F2E;
}
.item:nth-child(2) .number {
color: #FF370F;
}
.item:nth-child(3) .number {
color: #FF630F;
}
//
.number {
color: #999999;
}
//
.label {
margin-left: 20rpx;
padding: 2rpx 10rpx;
font-size: 20rpx;
color: #fff;
border-radius: 50rpx 50rpx 50rpx 2rpx;
//
&.hot {
background-color: #FF0F2E;
}
//
&.new {
background-image: linear-gradient(123deg, #27EFE2 0%, #A45EFF 43%, #FF004F 99%);
}
}
} }
// .item:nth-child(2) .number {
.tabList { color: #FF370F;
}
.item:nth-child(3) .number {
color: #FF630F;
}
//
.number {
color: #999999;
}
//
.label {
margin-left: 20rpx;
padding: 2rpx 10rpx;
font-size: 20rpx;
color: #fff;
border-radius: 50rpx 50rpx 50rpx 2rpx;
//
&.hot {
background-color: #FF0F2E;
}
//
&.new {
background-image: linear-gradient(123deg, #27EFE2 0%, #A45EFF 43%, #FF004F 99%);
}
}
}
//
.tabList {
.item {
.line {
background-color: #333;
width: 0;
height: 10rpx;
border-radius: 100rpx;
}
//
&.active {
.txt {
font-weight: bold;
}
.item {
.line { .line {
background-color: #333; width: 30rpx;
width: 0;
height: 10rpx;
border-radius: 100rpx;
}
//
&.active {
.txt {
font-weight: bold;
}
.line {
width: 30rpx;
}
} }
} }
} }
}
// //
.listBox { .listBox {
min-height: 95vh; min-height: 95vh;
background-color: #f8f8f8; background-color: #f8f8f8;
.videoList { .videoList {
.coverImg { .coverImg {
height: 376rpx; height: 376rpx;
}
} }
} }
}
</style> </style>

View File

@ -3,11 +3,9 @@ import {
} from 'vite'; } from 'vite';
import uni from '@dcloudio/vite-plugin-uni'; import uni from '@dcloudio/vite-plugin-uni';
let target = 'http://91f.xyz:8080' // let target = 'http://91f.xyz:8080'
<<<<<<< HEAD
// let target = 'https://1a880cd5.r24.cpolar.top/' // let target = 'https://1a880cd5.r24.cpolar.top/'
======= let target = 'http://6mkwby.natappfree.cc'
>>>>>>> 409f137e8990b13381bdbe7efca7eec9a3cfc89e
export default defineConfig({ export default defineConfig({
plugins: [uni()], plugins: [uni()],

View File

@ -0,0 +1,9 @@
{
"version" : "1.0",
"configurations" : [
{
"playground" : "standard",
"type" : "uni-app:app-android"
}
]
}

View File

@ -6,7 +6,7 @@ const config = {
// #endif // #endif
// #ifndef H5 // #ifndef H5
// host: 'http://91f.xyz:8080', // host: 'http://91f.xyz:8080',
host: 'https://b433d23.r24.cpolar.top/', host: 'https://1a880cd5.r24.cpolar.top/',
// #endif // #endif
// 支付方式配置 // 支付方式配置
payType: { payType: {

View File

@ -1425,16 +1425,17 @@ const util = {
value: userinfo value: userinfo
}) })
uni.reLaunch({ setTimeout(() => {
url: '/pages/index/index' util.loginTencent(userinfo)
}) uni.reLaunch({
url: '/pages/index/index'
})
}, 500)
}, },
// 登录腾讯聊天 // 登录腾讯聊天
loginTencent(userinfo) { loginTencent(userinfo) {
api.login.getIMToken({}).then(rs => { api.login.getIMToken({}).then(rs => {
console.log(rs);
const imSig = rs.msg const imSig = rs.msg
uni.$chat.login({ uni.$chat.login({
@ -1444,22 +1445,6 @@ const util = {
console.log('im login success', rs) console.log('im login success', rs)
}) })
// // #ifdef APP
// // 音视频登录
// const loginParams = {
// SDKAppID: util.config.TChat.SDKAppID,
// userID: userinfo.id + '',
// userSig: imSig,
// }
// uni.$TUICallKit.login(loginParams, res => {
// if (res.code === 0) {
// console.log('[TUICallKit] login success.');
// } else {
// console.error('[TUICallKit] login failed, failed message = ', res.msg, params);
// }
// })
// // #endif
}) })
}, },

View File

@ -86,7 +86,7 @@ const videoContext = ref(null)
// //
const redPacket = reactive({}) const redPacket = reactive({})
onLoad(option => { onLoad(option => {
// //
let title = '' let title = ''
// //
@ -142,6 +142,10 @@ onUnload(() => {
videoContext.value.stop() videoContext.value.stop()
}) })
onUnmounted(() => {
removeListener()
})
// //
function addListener() { function addListener() {
let onMessageReceived = function (event) { let onMessageReceived = function (event) {
@ -160,7 +164,7 @@ function addListener() {
// //
function removeListener() { function removeListener() {
uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED); uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, () => { });
} }
// //

View File

@ -60,73 +60,66 @@ function addListener() {
// //
function removeListener() { function removeListener() {
uni.$chat.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED); uni.$chat.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED, () => { });
} }
// //
function getList() { function getList() {
api.news.getMessageList({ // sdk
query: { let isReady = uni.$chat.isReady();
userId: userinfo.serviceId, if (!isReady) {
} setTimeout(function () {
}).then(rs => { getList();
if (rs.code == 200) { }, 800);
chatList.push(...rs.data.map(item => { return
item.callbackData = JSON.parse(item.callbackJson) }
if (item.callbackData.callback_json.length) { uni.$chat.getConversationList().then(rs => {
let msgType = item.callbackData.callback_json[0].MsgType; let res = rs.data.conversationList
if (msgType == TencentCloudChat.TYPES.MSG_TEXT) { let arr = []
item.chatText = item.callbackData.callback_json[0].MsgContent.Text res.forEach(item => {
} else if (msgType == TencentCloudChat.TYPES.MSG_IMAGE) { let obj = {}
item.chatText = '[图片]' obj.type = item.type;
} else if (msgType == TencentCloudChat.TYPES.MSG_AUDIO) { obj.chatText = item.lastMessage.messageForShow;
item.chatText = '[语音]' obj.lastTime = handleDate(item.lastMessage.lastTime);
} else if (msgType == TencentCloudChat.TYPES.MSG_VIDEO) { obj.unreadCount = item.unreadCount;
item.chatText = '[视频]'
} else if (msgType == TencentCloudChat.TYPES.MSG_CUSTOM) { if (item.type == 'C2C') {
if (item.callbackData.callback_json[0].businessType == 'redPacket') { obj.avatar = item.userProfile.avatar;
item.chatText = `[红包] ${item.callbackData.blessing}` obj.name = item.userProfile.nick;
} obj.userID = item.userProfile.userID;
} }
} arr.push(obj)
return item
}))
return
}
util.alert({
content: rs.msg,
showCancel: false,
}) })
chatList.data = arr;
}) })
// api.news.getMessageList({
// query: {
// userId: userinfo.serviceId,
// }
// }).then(rs => {
// if (rs.code == 200) {
// chatList.push(...rs.data.map(item => {
// item.callbackData = JSON.parse(item.callbackJson)
// return item
// }))
// return
// }
// util.alert({
// content: rs.msg,
// showCancel: false,
// })
// })
} }
// /**
// *
// * @param {Number} item
// */
// function handleChat(item) {
// //
// }
// /**
// *
// * @param {String} url
// */
// function link(url) {
// uni.navigateTo({
// url,
// })
// }
// 退 // 退
function handleLogout() { function handleLogout() {
util.alert({ util.alert({
content: '确认退出登录吗?', content: '确认退出登录吗?',
}).then(rs => { }).then(rs => {
if (!rs.confirm) return if (!rs.confirm) return
util.logout(() => { util.logout(() => {
// #ifdef APP // #ifdef APP
plus.runtime.restart() plus.runtime.restart()
@ -135,22 +128,16 @@ function handleLogout() {
}) })
} }
/** /**
* 去聊天 * 去聊天
* @param {Object} item * @param {Object} item
*/ */
function handleChat(item) { function handleChat(item) {
console.log(111111111, item);
let param = { let param = {
type: 'C2C', type: 'C2C',
name: `${item.callbackData.from_name}`, name: `${item.callbackData.from_name}`,
msgId: `${item.callbackData.from_id}` msgId: `${item.callbackData.from_id}`
}; };
console.log(22222222, param);
util.toChat(param) util.toChat(param)
} }
@ -176,7 +163,7 @@ function delMsg(item) {
return return
} }
let conversationId = item.groupId == null ? `C2C${item.fromId}` : `GROUP${item.groupId}`; let conversationId = item.type == 'C2C' ? `C2C${item.userID}` : `GROUP${item.groupID}`;
uni.$chat.deleteConversation(conversationId).then(rs => { uni.$chat.deleteConversation(conversationId).then(rs => {
getList() getList()
@ -194,7 +181,7 @@ function setRead(item) {
return return
} }
let conversationId = item.groupId == null ? `C2C${item.fromId}` : `GROUP${item.groupId}`; let conversationId = item.type == 'C2C' ? `C2C${item.userID}` : `GROUP${item.groupID}`;
uni.$chat.setMessageRead({ uni.$chat.setMessageRead({
conversationID: conversationId, conversationID: conversationId,
}).then(rs => { }).then(rs => {
@ -228,60 +215,25 @@ function setRead(item) {
<view class="">商家订单管理</view> <view class="">商家订单管理</view>
<uni-icons type="right" /> <uni-icons type="right" />
</view> </view>
<!-- <view class="list">
<view class="item rows ptb20 plr20" v-for="(item, index) in chatList" :key="index"
@click="handleChat(item)">
<view class="avatar">
<image :src="item.avatar" class="wh80 cir" />
</view>
<view class="info f1 ml20">
<view class="rows">
<view class="name c333 f28">{{ item.name }}</view>
<view class="time c999 f22">2024.05.06 13:00</view>
</view>
<view class="rows">
<view class="content mt10 c666 f24">{{ item.lastMessage }}</view>
<view class="dot cfff f22">
<view class="content" v-if="item.dot">{{ item.dot }}</view>
</view>
</view>
</view>
</view>
</view> -->
<view class="firendBox pr"> <view class="firendBox pr">
<scroll-view scroll-y="true" class="scroll"> <scroll-view scroll-y="true" class="scroll">
<uni-swipe-action ref="swipeAction"> <uni-swipe-action ref="swipeAction">
<view class="list pb30"> <view class="list pb30">
<uni-swipe-action-item :right-options="rightOption" v-for="(item, index) in chatList" <uni-swipe-action-item :right-options="rightOption" v-for="(item, index) in chatList.data"
:key="index" @click="handleMenu($event, item)"> :key="index" @click="handleMenu($event, item)">
<view class="item rows ptb20 plr30" @click="handleChat(item)"> <view class="item rows ptb20 plr30" @click="handleChat(item)">
<view class="image wh90 pr"> <view class="image wh90 pr">
<template v-if="item.groupId == null"> <image class="cir wh90" :src="item.avatar" mode="aspectFill" />
<image class="cir wh90" :src="item.callbackJson.from_url" mode="aspectFill" />
</template>
<template v-else>
<image class="cir wh90" :src="item.groupChatDTO.groupFaceUrl"
mode="aspectFill" />
</template>
<view class="mark pa t0 r0 cfff f22 cir" v-if="item.unreadCount">{{ item.unreadCount <view class="mark pa t0 r0 cfff f22 cir" v-if="item.unreadCount">{{ item.unreadCount
}} }}
</view> </view>
</view> </view>
<view class="col f1 ml20"> <view class="col f1 ml20">
<view class="rows"> <view class="rows">
<template v-if="item.groupId == null"> <view class="name f1 thd c333 f32">{{ item.name }}</view>
<view class="name f1 thd c333 f32">{{ item.callbackJson.from_name }}</view>
</template>
<template v-else>
<view class="name f1 thd c333 f32">{{ item.groupChatDTO.name }}</view>
</template>
<view class="datetime c999 f22"> <view class="datetime c999 f22">
{{ util.formatTime('MM-dd HH:mm', item.createTime) }}</view> {{ util.formatTime('MM-dd HH:mm', item.lastTime) }}</view>
</view> </view>
<view class="desc thd mt10 c666 f24">{{ item.chatText }}</view> <view class="desc thd mt10 c666 f24">{{ item.chatText }}</view>
</view> </view>

View File

@ -4,7 +4,7 @@ import {
import uni from '@dcloudio/vite-plugin-uni'; import uni from '@dcloudio/vite-plugin-uni';
// let target = 'http://91f.xyz:8080' // let target = 'http://91f.xyz:8080'
let target = 'https://b433d23.r24.cpolar.top/' let target = 'https://1a880cd5.r24.cpolar.top/'
export default defineConfig({ export default defineConfig({
plugins: [uni()], plugins: [uni()],