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

init
xialiang 4 years ago
parent 63d989da3b
commit 60f324eb8f

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

Loading…
Cancel
Save