修改聊天调用逻辑。在会话列表读取已选id

init
xialiang 4 years ago
parent 63d989da3b
commit 60f324eb8f

@ -1,6 +1,6 @@
<template>
<li
:class="ind == nowIndex ? 'act' : ''"
:class="value.targetId == nowTargetId ? 'act' : 'a'"
class="conversation-content"
@click="setConversationIndex"
@mouseenter="mouseenter(true)"
@ -16,68 +16,91 @@
v-if="delConversationShow"
/>
<span style="float: left">
<a-badge :count="value.unreadMessageCount">
<a-avatar
v-if="value.type == 1"
icon="user"
class="conversation-avatar"
style="background-color: #2db7f5"
:src="avatar"
/>
<a-avatar
v-if="value.type == 3"
icon="team"
style="background-color: #f59a23"
:src="avatar"
/>
<a-avatar
v-if="value.type == 6"
icon="carry-out"
style="background-color: #f59a23"
/>
</a-badge>
<span v-if="show">
<a-badge :count="value.unreadMessageCount">
<a-avatar
v-if="value.type == 1"
icon="user"
class="conversation-avatar"
style="background-color: #2db7f5"
:src="conData.avatar"
/>
<a-avatar
v-if="value.type == 3"
icon="team"
style="background-color: #f59a23"
:src="conData.avatar"
/>
<a-avatar
v-if="value.type == 6"
icon="carry-out"
style="background-color: #f59a23"
/>
</a-badge>
</span>
</span>
<div class="conversation-name">
1<br /><span class="conversation-lastmassage">{{
value.latestMessage.content.content
}}</span>
<span v-if="show">
{{ value.type == 1 ? conData.person_name : conData.group_name }}</span
>
<br /><span class="conversation-lastmassage">
{{ value.latestMessage.content.content }}
</span>
</div>
</li>
</template>
<script>
import InterfaceConfig from "./../utils/interfaceConfig";
import { Avatar, Badge, Button } from "ant-design-vue";
export default {
name: "ConversationItem",
// props: {
// value: { },
// ind: { type: Number, default: 0 },
// nowIndex: { type: Number, default: 0 },
// targetId: { type: String, default: "" },
// type: {type:String,default:""},
// nowInfo:{},
// },
props: ["value", "ind", "nowIndex", "targetId", "type", "nowinfo"],
props: [
"value",
"ind",
"nowIndex",
"targetId",
"type",
"nowinfo",
"nowTargetId",
"user_info",
"target_info",
],
data() {
return {
target_name: "",
name: "",
show: false,
avatar: "",
data: {},
delConversationShow: false,
conData: {},
// user_info: "",
// target_info: "",
};
},
watch: {
data(e) {
this.getConversationItem();
conData(e) {
this.show = true;
// if (this.value.targetId == this.nowTargetId) {
// this.setLocalStorage();
// }
},
},
mounted() {
this.data = this.value;
this.getConversationItem();
console.log(this.value, "会话列表");
this.getUserAvatar();
// this.target_info = JSON.parse(localStorage.getItem("conversation_info"));
// this.user_info = JSON.parse(localStorage.getItem("user_info"));
// if (this.nowTargetId == this.user_info.id) {
// this.$emit("update:nowTargetId", this.target_info.targetId);
// }
this.$emit("update:nowTargetId", this.target_info.targetId);
// this.nowTargetId = this.target_info.targetId;
// console.log(this.nowTargetId, "nowTargetId111", this.target_info);
},
components: {
@ -85,124 +108,119 @@ export default {
ABadge: Badge,
AButton: Button,
},
methods: {
//
handelDel() {
console.log(this.data.type, this.data.targetId, "del");
confirm(this.data.type, this.data.targetId, "del").then(() => {
const conversation = this.RongIMClient.Conversation.get({
targetId: this.data.targetId,
type: this.data.type,
});
conversation.destory().then(() => console.log("删除会话成功"));
});
console.log(this.value.type, this.value.targetId, "del");
// confirm(this.value.type, this.value.targetId, "del").then(() => {
// const conversation = this.RongIMClient.Conversation.get({
// targetId: this.value.targetId,
// type: this.value.type,
// });
// conversation.destory().then(() => console.log(""));
// });
},
//
getUserAvatar() {
let url = "";
let params = {};
console.log(this.value.type, "this.value.type");
if (this.value.type == 1) {
url = "/dsSzxy/imRelate/GetPersonAvatar";
params = { userId: this.value.targetId };
} else {
url = "/dsSzxy/imRelate/GetGroupAvatar";
params = { groupId: this.value.targetId };
}
this.InterfaceConfig.callInterface(
[
{
url: url,
method: "get",
params: {
...params,
},
},
],
(res) => {
if (res && res[0]) {
// console.log(res[0].data, 11);
this.conData = res[0].data;
}
}
);
},
//
mouseenter(e) {
this.delConversationShow = e;
},
// mounted
getConversationItem() {
//indextargetID
if (this.ind == this.nowIndex) {
this.$emit("update:targetId", this.value.targetId);
this.$emit("update:type", this.value.type);
// console.log(this.value.targetId, 222444, this.nowTargetId, "222223");
if (this.value.targetId == this.nowTargetId) {
console.log(2222);
this.$emit("update:nowInfo", {
targetId: this.value.targetId,
type: this.value.type,
});
//
const conversation_info = {
person_name: this.name,
avatar: this.avatar,
targetId: this.value.targetId,
type: this.value.type,
};
localStorage.setItem(
"conversation_info",
JSON.stringify(conversation_info)
);
// this.setLocalStorage();
}
//
// if (!this.value.latestMessage.expansion) {
// if (this.value.type === 1) {
// this.getPersonAvatar(this.value.targetId);
// } else if (this.value.type === 3) {
// this.GetGroupAvatar(this.value.targetId);
// }
// }
},
//
setConversationIndex() {
//
// this.$emit("update:nowTargetId", this.value.targetId);
this.$bus.emit("getList", this.value.targetId, this.value.type);
this.$emit("update:nowIndex", this.ind);
// targetId
this.$emit("update:targetId", this.value.targetId);
//
this.$emit("update:type", this.value.type);
this.$emit("update:nowInfo", {
targetId: this.value.targetId,
type: this.value.type,
});
this.$emit("update:nowTargetId", this.value.targetId);
this.setLocalStorage();
console.log(this, "getList111", this.value.targetId, this.value.type);
},
//
setLocalStorage() {
let conversation_info = {};
//
if (this.value.type == 1) {
this.$bus.emit(
"setNowMessageInfo",
this.conData.person_name,
this.conData.avatar,
this.value.type,
this.value.targetId
);
//
getPersonAvatar(userId) {
this.InterfaceConfig.callInterface(
[
{
url: InterfaceConfig.GetPersonAvatar.url,
method: InterfaceConfig.GetPersonAvatar.method,
params: {
userId,
},
isTestLogin: InterfaceConfig.GetPersonAvatar.isTestLogin,
},
],
(result) => {
if (result && result[0]) {
this.data.latestMessage.expansion = {
group_name: "",
person_name: result[0].data.person_name,
avatar: result[0].data.avatar,
};
this.data.name = result[0].data.person_name;
this.name = result[0].data.person_name;
this.avatar = result[0].data.avatar;
conversation_info = {
user_id: this.user_info.id,
person_name: this.conData.person_name,
avatar: this.conData.avatar,
targetId: this.value.targetId,
type: this.value.type,
};
} else {
this.$bus.emit(
"setNowMessageInfo",
this.conData.group_name,
this.conData.avatar,
this.value.type,
this.value.targetId
);
if (this.ind == this.nowIndex) {
this.setConversationIndex();
}
}
}
);
},
//
GetGroupAvatar(groupId) {
this.InterfaceConfig.callInterface(
[
{
url: InterfaceConfig.GetGroupAvatar.url,
method: InterfaceConfig.GetGroupAvatar.method,
params: {
groupId,
},
isTestLogin: InterfaceConfig.GetGroupAvatar.isTestLogin,
},
],
(result) => {
if (result && result[0]) {
this.data.latestMessage.expansion = {
name: "",
group_name: result[0].data.group_name,
avatar: result[0].data.avatar,
};
this.name = result[0].data.group_name;
this.avatar = result[0].data.avatar;
if (this.ind == this.nowIndex) {
this.setConversationIndex();
}
}
}
conversation_info = {
user_id: this.user_info.id,
group_name: this.conData.group_name,
avatar: this.conData.avatar,
targetId: this.value.targetId,
type: this.value.type,
};
}
// console.log(this.value, "this.value", conversation_info);
localStorage.setItem(
"conversation_info",
JSON.stringify(conversation_info)
);
},
},

Loading…
Cancel
Save