Files
im/pages/conversation/conversationList/index.vue
T

238 lines
5.5 KiB
Vue
Raw Normal View History

2025-11-07 09:56:20 +08:00
<template>
<view class="conversation_container">
<chat-header ref="chatHeaderRef" />
2026-01-11 15:48:41 +08:00
<uni-swipe-action ref="swipe_action">
2026-01-15 22:50:35 +08:00
<template v-for="item in storeConversationList" >
2026-01-11 15:48:41 +08:00
<uni-swipe-action-item
2026-01-15 22:50:35 +08:00
v-if="item.sendID !='system1'"
2026-01-11 15:48:41 +08:00
:right-options="swipe_actions"
@click="actionClick($event,item)"
:key="item.conversationID" >
<conversation-item @longtapEvent="showExtendMenu(item)" :source="item"/>
</uni-swipe-action-item>
2026-01-15 22:50:35 +08:00
</template>
2026-01-11 15:48:41 +08:00
</uni-swipe-action>
2025-11-07 09:56:20 +08:00
<view class="loading_wrap" v-if="storeProgress > 0 && storeProgress < 100">
<u-loading-icon :vertical="true" :text="storeProgress + '%'"></u-loading-icon>
</view>
</view>
</template>
<script>
2025-12-05 16:10:52 +08:00
import {mapGetters} from "vuex";
import IMSDK from "openim-uniapp-polyfill";
2025-11-07 09:56:20 +08:00
import ChatHeader from "./components/ChatHeader.vue";
import ConversationItem from "./components/ConversationItem.vue";
2025-12-11 22:33:43 +08:00
import {getConversationContent,formatConversionTime,prepareConversationState,} from "@/util/imCommon";
2025-11-07 09:56:20 +08:00
export default {
components: {
ChatHeader,
ConversationItem,
},
data() {
return {
scrollTop: 0,
old: {
scrollTop: 0,
},
2025-12-05 16:10:52 +08:00
swipe_actions: [
{
text: '取消',
style: {
backgroundColor: '#1184ed'
}
},
{
text: '隐藏',
style: {
backgroundColor: '#fa9d3a'
}
},
{
text: '删除',
style: {
backgroundColor: '#f85050'
}
}
],
2025-11-07 09:56:20 +08:00
refreshing: false,
};
},
computed: {
2026-01-15 22:50:35 +08:00
...mapGetters([
"storeConversationList",
"storeIsSyncing",
"storeProgress",
'storeCurrentUserID'
]),
2025-11-07 09:56:20 +08:00
},
onReady() {
2025-12-05 16:10:52 +08:00
// #ifdef APP
2025-11-07 09:56:20 +08:00
this.$nextTick(() => plus.navigator.closeSplashscreen());
2025-12-05 16:10:52 +08:00
// #endif
2025-11-07 09:56:20 +08:00
},
onLoad() {
2025-12-05 16:10:52 +08:00
//console.log(this.storeConversationList);
2026-01-11 13:51:16 +08:00
this.freshing = false;
if(process.env.NODE_ENV == 'development'){
// setTimeout(()=>{
// // uni.switchTab({
// // url:"/pages/user/index/index"
// // })
// // uni.navigateTo({
// // url:"/pages/user/vip/vip"
// // });
// //prepareConversationState(this.storeConversationList[1]);
// },1000)
}
2025-11-07 09:56:20 +08:00
},
methods: {
2025-12-05 16:10:52 +08:00
test(){
console.log(11);
},
showExtendMenu(item){
const _this = this;
2026-01-15 22:50:35 +08:00
const menu = [item.recvMsgOpt===0 ? '免打扰':'关闭免打扰',item.isPrivateChat? '关闭阅后即焚':'开启阅后即焚','隐藏',item.isPinned ? '取消置顶':'置顶','删除'];
2025-12-05 16:10:52 +08:00
uni.showActionSheet({
itemList:menu,
success(e) {
switch(menu[e.tapIndex]){
case '免打扰':
2026-01-15 22:50:35 +08:00
_this.setConversation({
conversationID: item.conversationID,
2025-12-05 16:10:52 +08:00
recvMsgOpt: 2
})
break;
case '关闭免打扰':
2026-01-15 22:50:35 +08:00
_this.setConversation({
conversationID: item.conversationID,
2025-12-05 16:10:52 +08:00
recvMsgOpt: 0
})
break;
case '开启阅后即焚':
2026-01-15 22:50:35 +08:00
_this.setConversation({
conversationID: item.conversationID,
2025-12-05 16:10:52 +08:00
isPrivateChat: true,
burnDuration:60
})
break;
case '关闭阅后即焚':
2026-01-15 22:50:35 +08:00
_this.setConversation({
conversationID: item.conversationID,
2025-12-05 16:10:52 +08:00
isPrivateChat: false
})
break;
case '隐藏':
IMSDK.asyncApi('hideConversation', IMSDK.uuid(), item.conversationID)
break;
case '置顶':
2026-01-15 22:50:35 +08:00
_this.setConversation({
conversationID: item.conversationID,
isPinned: true
});
2025-12-05 16:10:52 +08:00
break;
case '取消置顶':
2026-01-15 22:50:35 +08:00
_this.setConversation({
conversationID: item.conversationID,
isPinned: false
})
2025-12-05 16:10:52 +08:00
break;
case '删除':
_this.deleteConversation(item.conversationID);
break;
}
}
});
},
actionClick(e,item){
const _this = this;
this.$refs.swipe_action.closeAll();
switch(e.index){
case 0:
break;
case 1:
IMSDK.asyncApi('hideConversation', IMSDK.uuid(), item.conversationID)
break;
case 2:
_this.deleteConversation(item.conversationID);
break;
}
},
deleteConversation(conversationID){
IMSDK.asyncApi(IMSDK.IMMethods.DeleteConversationAndDeleteAllMsg, IMSDK.uuid(), conversationID).then(res=>{
console.log('删除成功');
}).catch(e=>{
})
},
2026-01-15 22:50:35 +08:00
async setConversation(data){
await IMSDK.asyncApi('setConversation', IMSDK.uuid(), data);
2025-12-05 16:10:52 +08:00
},
2025-11-07 09:56:20 +08:00
onRefresh() {
2026-01-11 13:51:16 +08:00
if (this.refreshing) return;
console.log('onRefresh');
this.refreshing = true;
2025-11-07 09:56:20 +08:00
this.queryList(true);
},
scrolltolower() {
this.queryList();
},
async queryList(isFirstPage = false) {
2025-12-05 16:10:52 +08:00
await this.$store.dispatch("conversation/getConversationList",isFirstPage);
2026-01-11 15:48:41 +08:00
uni.stopPullDownRefresh();
2026-01-11 13:51:16 +08:00
this.refreshing = false;
2025-11-07 09:56:20 +08:00
},
closeAllSwipe() {
this.$refs.swipeWrapperRef.closeAll();
},
},
2026-01-11 15:48:41 +08:00
onReachBottom() {
this.scrolltolower();
},
onPullDownRefresh() {
this.queryList(true);
},
onPageScroll(res) {
this.old.scrollTop = res.scrollTop;
}
2025-11-07 09:56:20 +08:00
};
</script>
<style lang="scss" scoped>
.conversation_container {
@include colBox(false);
height: 100vh;
}
.conversation_search {
padding: 0 44rpx 24rpx;
}
.z-paging-content {
flex: 1;
}
.swipe_wrapper {
@include colBox(false);
flex: 1;
width: 100%;
overflow-y: auto;
}
.loading_wrap {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
::v-deep.u-swipe-action-item__right__button__wrapper__text {
-webkit-line-clamp: 2 !important;
max-width: 32px;
}
</style>