This commit is contained in:
2025-11-25 05:36:02 +08:00
parent 8e036cc171
commit b10e4b4336
65 changed files with 2672 additions and 2270 deletions
@@ -1,329 +1,301 @@
<template>
<view class="chat_header">
<view class="self_info">
<my-avatar
:src="storeSelfInfo.faceURL"
:desc="storeSelfInfo.nickname"
size="46"
/>
<view class="self_info_desc">
<view class="user_state">
<text class="nickname">{{ storeSelfInfo.nickname }}</text>
<view v-if="!storeReinstall">
<view class="tag" v-if="storeIsSyncing">
<img
class="loading"
style="height: 24rpx; width: 24rpx"
src="static/images/loading.png"
alt=""
/>
<text class="status">同步中</text>
</view>
<view class="tag" v-if="connectStart == 0">
<img
class="loading"
style="height: 24rpx; width: 24rpx"
src="static/images/loading.png"
alt=""
/>
<text class="status">连接中</text>
</view>
<view class="err-tag" v-if="connectStart == -1">
<img
style="height: 24rpx; width: 24rpx"
src="static/images/sync_error.png"
alt=""
/>
<text class="status">连接失败</text>
</view>
</view>
</view>
</view>
</view>
<view class="right_action">
<view class="call_icon"> </view>
<view @click="showMore" class="more_icon">
<image src="@/static/images/common_circle_add.png"></image>
</view>
<u-overlay
:show="moreMenuVisible"
@click="moreMenuVisible = false"
opacity="0"
>
<view
:style="{ top: popMenuPosition.top, right: popMenuPosition.right }"
class="more_menu"
>
<view
@click="clickMenu(item)"
v-for="item in moreMenus"
:key="item.idx"
class="menu_item"
>
<image :src="item.icon" mode=""></image>
<text>{{ item.title }}</text>
</view>
</view>
</u-overlay>
</view>
</view>
<view class="chat_header">
<view class="self_info">
<my-avatar :src="storeSelfInfo.faceURL" :desc="storeSelfInfo.nickname" size="46" />
<view class="self_info_desc">
<view class="user_state">
<text class="nickname">{{ storeSelfInfo.nickname }}</text>
<view v-if="!storeReinstall">
<view class="tag" v-if="storeIsSyncing">
<img class="loading" style="height: 24rpx; width: 24rpx" src="static/images/loading.png"
alt="" />
<text class="status">同步中</text>
</view>
<view class="tag" v-if="connectStart == 0">
<img class="loading" style="height: 24rpx; width: 24rpx" src="static/images/loading.png"
alt="" />
<text class="status">连接中</text>
</view>
<view class="err-tag" v-if="connectStart == -1">
<img style="height: 24rpx; width: 24rpx" src="static/images/sync_error.png" alt="" />
<text class="status">连接失败</text>
</view>
</view>
</view>
</view>
</view>
<view class="right_action">
<view class="call_icon"> </view>
<view @click="showMore" class="more_icon">
<image src="@/static/images/common_circle_add.png"></image>
</view>
<u-overlay :show="moreMenuVisible" @click="moreMenuVisible = false" opacity="0">
<view :style="{ top: popMenuPosition.top, right: popMenuPosition.right }" class="more_menu">
<view @click="clickMenu(item)" v-for="item in moreMenus" :key="item.idx" class="menu_item">
<image :src="item.icon" mode=""></image>
<text>{{ item.title }}</text>
</view>
</view>
</u-overlay>
</view>
</view>
</template>
<script>
import { mapGetters } from "vuex";
import MyAvatar from "@/components/MyAvatar/index.vue";
import IMSDK from "openim-uniapp-polyfill";
export default {
name: "ChatHeader",
components: {
MyAvatar,
},
props: {},
data() {
return {
connectStart: -2,
moreMenuVisible: false,
popMenuPosition: {
top: 0,
right: 0,
},
moreMenus: [
{
idx: 1,
title: "添加好友",
icon: require("static/images/more_add_friend.png"),
},
{
idx: 2,
title: "添加群聊",
icon: require("static/images/more_add_group.png"),
},
{
idx: 3,
title: "创建群聊",
icon: require("static/images/more_create_group.png"),
},
],
};
},
computed: {
...mapGetters(["storeSelfInfo", "storeIsSyncing", "storeReinstall"]),
},
mounted() {
this.subscribeAll();
},
beforeDestroy() {
this.unsubscribeAll();
},
methods: {
setStateStart() {
this.connectStart = 0;
},
setStateSuccess() {
this.connectStart = 1;
},
setStateError() {
this.connectStart = -1;
},
subscribeAll() {
IMSDK.subscribe(IMSDK.IMEvents.OnConnecting, this.setStateStart);
IMSDK.subscribe(IMSDK.IMEvents.OnConnectSuccess, this.setStateSuccess);
IMSDK.subscribe(IMSDK.IMEvents.OnConnectFailed, this.setStateError);
},
unsubscribeAll() {
IMSDK.unsubscribe(IMSDK.IMEvents.OnConnecting, this.setStateStart);
IMSDK.unsubscribe(IMSDK.IMEvents.OnConnectSuccess, this.setStateSuccess);
IMSDK.unsubscribe(IMSDK.IMEvents.OnConnectFailed, this.setStateError);
},
clickMenu({ idx }) {
switch (idx) {
case 1:
case 2:
uni.navigateTo({
url: `/pages/common/searchUserOrGroup/index?isSearchGroup=${
idx === 2
}`,
});
break;
case 3:
uni.navigateTo({
url: `/pages/common/createGroup/index`,
});
break;
default:
break;
}
},
async showMore() {
const { right, bottom } = await this.getEl(".more_icon");
this.popMenuPosition.right =
uni.getWindowInfo().windowWidth - right + "px";
this.popMenuPosition.top = bottom + "px";
this.moreMenuVisible = true;
},
getEl(el) {
return new Promise((resolve) => {
const query = uni.createSelectorQuery().in(this);
query
.select(el)
.boundingClientRect((data) => {
// 存在data,且存在宽和高,视为渲染完毕
resolve(data);
})
.exec();
});
},
},
};
import {
mapGetters
} from "vuex";
import MyAvatar from "@/components/MyAvatar/index.vue";
import IMSDK from "openim-uniapp-polyfill";
export default {
name: "ChatHeader",
components: {
MyAvatar,
},
props: {},
data() {
return {
connectStart: -2,
moreMenuVisible: false,
popMenuPosition: {
top: 0,
right: 0,
},
moreMenus: [{
idx: 1,
title: "添加好友",
icon: require("static/images/more_add_friend.png"),
},
{
idx: 2,
title: "添加群聊",
icon: require("static/images/more_add_group.png"),
},
{
idx: 3,
title: "创建群聊",
icon: require("static/images/more_create_group.png"),
},
],
};
},
computed: {
...mapGetters(["storeSelfInfo", "storeIsSyncing", "storeReinstall"]),
},
mounted() {
this.subscribeAll();
},
beforeDestroy() {
this.unsubscribeAll();
},
methods: {
setStateStart() {
this.connectStart = 0;
},
setStateSuccess() {
this.connectStart = 1;
},
setStateError() {
this.connectStart = -1;
},
subscribeAll() {
IMSDK.subscribe(IMSDK.IMEvents.OnConnecting, this.setStateStart);
IMSDK.subscribe(IMSDK.IMEvents.OnConnectSuccess, this.setStateSuccess);
IMSDK.subscribe(IMSDK.IMEvents.OnConnectFailed, this.setStateError);
},
unsubscribeAll() {
IMSDK.unsubscribe(IMSDK.IMEvents.OnConnecting, this.setStateStart);
IMSDK.unsubscribe(IMSDK.IMEvents.OnConnectSuccess, this.setStateSuccess);
IMSDK.unsubscribe(IMSDK.IMEvents.OnConnectFailed, this.setStateError);
},
clickMenu({idx}) {
switch (idx) {
case 1:
case 2:
uni.navigateTo({
url: `/pages/common/searchUserOrGroup/index?isSearchGroup=${idx === 2}`,
});
break;
case 3:
uni.navigateTo({
url: `/pages/common/createGroup/index`,
});
break;
default:
break;
}
},
async showMore() {
const {right,bottom} = await this.getEl(".more_icon");
this.popMenuPosition.right =
uni.getWindowInfo().windowWidth - right + "px";
this.popMenuPosition.top = bottom + "px";
this.moreMenuVisible = true;
},
getEl(el) {
return new Promise((resolve) => {
const query = uni.createSelectorQuery().in(this);
query
.select(el)
.boundingClientRect((data) => {
// 存在data,且存在宽和高,视为渲染完毕
resolve(data);
})
.exec();
});
},
},
};
</script>
<style lang="scss" scoped>
@keyframes loading {
0% {
transform: rotate(0deg);
}
@keyframes loading {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
100% {
transform: rotate(360deg);
}
}
.chat_header {
@include btwBox();
padding: 36rpx 44rpx;
margin-top: var(--status-bar-height);
.chat_header {
@include btwBox();
padding: 36rpx 44rpx;
margin-top: var(--status-bar-height);
.self_info {
@include btwBox();
.self_info {
@include btwBox();
&_desc {
@include colBox(true);
margin-left: 24rpx;
color: $uni-text-color;
&_desc {
@include colBox(true);
margin-left: 24rpx;
color: $uni-text-color;
.company {
@include nomalEllipsis();
font-size: 24rpx;
margin-bottom: 10rpx;
max-width: 300rpx;
}
.company {
@include nomalEllipsis();
font-size: 24rpx;
margin-bottom: 10rpx;
max-width: 300rpx;
}
.user_state {
@include vCenterBox();
.user_state {
@include vCenterBox();
.nickname {
@include nomalEllipsis();
font-size: 26rpx;
max-width: 240rpx;
}
.nickname {
@include nomalEllipsis();
font-size: 26rpx;
max-width: 240rpx;
}
.err-tag {
display: flex;
justify-content: center;
align-items: center;
width: 152rpx;
height: 44rpx;
background: #ffe1dd;
border-radius: 12rpx 12rpx 12rpx 12rpx;
margin-left: 8rpx;
.status {
font-size: 24rpx;
margin-left: 8rpx;
font-weight: 400;
color: #ff381f;
}
}
.err-tag {
display: flex;
justify-content: center;
align-items: center;
width: 152rpx;
height: 44rpx;
background: #ffe1dd;
border-radius: 12rpx 12rpx 12rpx 12rpx;
margin-left: 8rpx;
.tag {
display: flex;
justify-content: center;
align-items: center;
width: 152rpx;
height: 44rpx;
background: #f2f8ff;
border-radius: 12rpx 12rpx 12rpx 12rpx;
margin-left: 8rpx;
.status {
font-size: 24rpx;
margin-left: 8rpx;
font-weight: 400;
color: #ff381f;
}
}
.loading {
animation: loading 1.5s infinite;
}
.tag {
display: flex;
justify-content: center;
align-items: center;
width: 152rpx;
height: 44rpx;
background: #f2f8ff;
border-radius: 12rpx 12rpx 12rpx 12rpx;
margin-left: 8rpx;
.status {
font-size: 24rpx;
margin-left: 8rpx;
font-weight: 400;
color: #0089ff;
}
}
.loading {
animation: loading 1.5s infinite;
}
.online_state {
@include vCenterBox();
margin-left: 24rpx;
font-size: 24rpx;
.status {
font-size: 24rpx;
margin-left: 8rpx;
font-weight: 400;
color: #0089ff;
}
}
.dot {
background-color: #10cc64;
width: 12rpx;
height: 12rpx;
border-radius: 50%;
margin-right: 12rpx;
}
}
}
}
}
.online_state {
@include vCenterBox();
margin-left: 24rpx;
font-size: 24rpx;
.right_action {
display: flex;
position: relative;
.dot {
background-color: #10cc64;
width: 12rpx;
height: 12rpx;
border-radius: 50%;
margin-right: 12rpx;
}
}
}
}
}
.call_icon {
margin-right: 24rpx;
.right_action {
display: flex;
position: relative;
image {
width: 56rpx;
height: 56rpx;
}
}
.call_icon {
margin-right: 24rpx;
.more_icon {
image {
width: 56rpx;
height: 56rpx;
}
}
image {
width: 56rpx;
height: 56rpx;
}
}
.more_menu {
position: absolute;
// bottom: 0;
// left: 100%;
z-index: 999;
// transform: translate(-100%, 100%);
box-shadow: 0px 0px 6px 2px rgba(0, 0, 0, 0.16);
width: max-content;
border-radius: 12rpx;
background-color: #fff;
.more_icon {
image {
width: 56rpx;
height: 56rpx;
}
}
.menu_item {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 20rpx 24rpx;
font-size: 28rpx;
color: $uni-text-color;
border-bottom: 1px solid #f0f0f0;
.more_menu {
position: absolute;
// bottom: 0;
// left: 100%;
z-index: 999;
// transform: translate(-100%, 100%);
box-shadow: 0px 0px 6px 2px rgba(0, 0, 0, 0.16);
width: max-content;
border-radius: 12rpx;
background-color: #fff;
image {
width: 24px;
height: 24px;
margin-right: 24rpx;
}
.menu_item {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 20rpx 24rpx;
font-size: 28rpx;
color: $uni-text-color;
border-bottom: 1px solid #f0f0f0;
&:last-child {
border: none;
}
}
}
}
}
</style>
image {
width: 24px;
height: 24px;
margin-right: 24rpx;
}
&:last-child {
border: none;
}
}
}
}
}
</style>
@@ -1,34 +1,31 @@
<template>
<view @tap.prevent="clickConversationItem" class="conversation_item">
<view class="pinned" v-if="source.isPinned"></view>
<view @tap.prevent="clickConversationItem" :class="['conversation_item',source.isPinned?'pinned' : '']">
<view class="left_info">
<my-avatar :isGroup="isGroup" :isNotify="isNotify" :src="source.faceURL" :desc="source.showName"
size="46" />
<view class="details">
<text class="conversation_name">{{ source.showName }}</text>
<view class="title">
<text class="conversation_name">
{{ source.showName }}
</text>
<view class="right_desc">
<text class="send_time">{{ latestMessageTime }}</text>
<u-badge max="99" :value="source.unreadCount"></u-badge>
</view>
</view>
<view class="lastest_msg_wrap">
<text class="lastest_msg_content">{{ latestMessage }}</text>
</view>
</view>
</view>
<view class="right_desc">
<text class="send_time">{{ latestMessageTime }}</text>
<u-badge max="99" :value="source.unreadCount"></u-badge>
</view>
</view>
</template>
<script>
import {
SessionType,
} from "openim-uniapp-polyfill";
import {SessionType,} from "openim-uniapp-polyfill";
import MyAvatar from "@/components/MyAvatar/index.vue";
import UParse from "@/components/gaoyia-parse/parse.vue";
import {
getConversationContent,
formatConversionTime,
prepareConversationState,
} from "@/util/imCommon";
import {getConversationContent,formatConversionTime,prepareConversationState,} from "@/util/imCommon";
export default {
components: {
@@ -81,6 +78,9 @@
flex-direction: row;
padding: 12rpx 44rpx 20rpx;
position: relative;
&.pinned{
background-color: #ededed;
}
&_active {
background-color: #f3f3f3;
@@ -88,17 +88,41 @@
.left_info {
@include btwBox();
flex:1;
.details {
@include colBox(true);
flex:1;
margin-left: 24rpx;
height: 46px;
color: $uni-text-color;
border-bottom: 1px solid #eee;
padding-bottom:20rpx;
.title{
@include btwBox();
.conversation_name {
@include nomalEllipsis();
max-width: 40vw;
font-size: 32rpx;
font-weight: 500;
}
.conversation_name {
@include nomalEllipsis();
max-width: 40vw;
font-size: 28rpx;
.right_desc {
@include colBox(true);
align-items: flex-end;
width: max-content;
justify-content: space-between;
.send_time {
width: max-content;
font-size: 24rpx;
color: #999;
}
.u-badge {
width: fit-content;
}
}
}
.lastest_msg_wrap {
@@ -125,32 +149,5 @@
}
}
}
.right_desc {
@include colBox(true);
align-items: flex-end;
width: max-content;
justify-content: space-between;
height: 46px;
.send_time {
width: max-content;
font-size: 24rpx;
color: #999;
}
.u-badge {
width: fit-content;
}
}
.pinned {
position: absolute;
top: 0;
right: 24rpx;
width: 17rpx;
height: 17rpx;
background-image: linear-gradient(to bottom left, #314ffe 50%, white 50%);
}
}
</style>