|
@@ -9,7 +9,11 @@
|
|
|
:pulling-text="'下拉加载更多...'"
|
|
|
:loosing-text="'释放即可加载...'"
|
|
|
>
|
|
|
- <div v-for="item in messages" :key="item.sentTime">
|
|
|
+ <div
|
|
|
+ v-for="item in messages"
|
|
|
+ :key="item.sentTime"
|
|
|
+ @contextmenu.prevent="onContextmenu(item, $event)"
|
|
|
+ >
|
|
|
<message-item
|
|
|
:message="item"
|
|
|
:conversation="conversation"
|
|
@@ -21,10 +25,18 @@
|
|
|
/>
|
|
|
</div>
|
|
|
</van-pull-refresh>
|
|
|
+
|
|
|
+ <Contextmenu
|
|
|
+ :dropdown="dropdown"
|
|
|
+ :dropdownList="dropdownList"
|
|
|
+ ref="contextmenuRef"
|
|
|
+ @currentContextmenuClick="onCurrentContextmenuClick"
|
|
|
+ />
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import Contextmenu from "./contextmenu.vue";
|
|
|
import {
|
|
|
ConversationType,
|
|
|
getTextMessageDraft,
|
|
@@ -49,10 +61,21 @@ import "@vant/touch-emulator"; // 引入模块后自动生效
|
|
|
export default {
|
|
|
name: "message-list",
|
|
|
components: {
|
|
|
- MessageItem
|
|
|
+ MessageItem,
|
|
|
+ Contextmenu
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ dropdown: { x: "", y: "" },
|
|
|
+ dropdownList: [
|
|
|
+ { contextMenuClickId: 0, txt: "复制", hid: false },
|
|
|
+ { contextMenuClickId: 1, txt: "撤回", hid: false },
|
|
|
+ {
|
|
|
+ contextMenuClickId: 2,
|
|
|
+ txt: "删除",
|
|
|
+ hid: false
|
|
|
+ }
|
|
|
+ ],
|
|
|
isConnect: false, // 是否连接
|
|
|
hasMore: true, // 是否有更多消息
|
|
|
className: "",
|
|
@@ -93,6 +116,97 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ onContextmenu(item, e) {
|
|
|
+ // contextMenuClickId
|
|
|
+ console.log(item, "item");
|
|
|
+ // 文本类型才有复制
|
|
|
+ if (MessageType.TextMessage === item.messageType) {
|
|
|
+ this.dropdownList[0].hid = false;
|
|
|
+ } else {
|
|
|
+ this.dropdownList[0].hid = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.messageDirection === MessageDirection.SEND) {
|
|
|
+ this.dropdownList[1].hid = false;
|
|
|
+ } else {
|
|
|
+ this.dropdownList[1].hid = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ const { clientX, clientY } = e;
|
|
|
+ this.dropdown.x = clientX;
|
|
|
+ this.dropdown.y = clientY;
|
|
|
+ this.$refs.contextmenuRef.openContextmenu(item);
|
|
|
+ },
|
|
|
+ handleCopy(obj) {
|
|
|
+ let item;
|
|
|
+ switch (obj.messageType) {
|
|
|
+ case MessageType.TEXT:
|
|
|
+ item = {
|
|
|
+ ["text/plain"]: new Blob([obj.content.content], {
|
|
|
+ type: "text/plain"
|
|
|
+ })
|
|
|
+ };
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ item = null;
|
|
|
+ }
|
|
|
+ if (!item) {
|
|
|
+ throw new Error("No data copied");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (navigator.clipboard) {
|
|
|
+ const clipboardObj = navigator.clipboard;
|
|
|
+ clipboardObj.write([new ClipboardItem(item)]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let copyInput = document.createElement("input");
|
|
|
+ copyInput.setAttribute("id", "COPY_INPUT");
|
|
|
+ copyInput.style.position = "fixed";
|
|
|
+ copyInput.style.left = "-100%";
|
|
|
+ copyInput.style.top = "0";
|
|
|
+ copyInput.style.zIndex = "-100";
|
|
|
+ copyInput.style.opacity = "0";
|
|
|
+ document.body.appendChild(copyInput);
|
|
|
+ copyInput.value = obj.content.content;
|
|
|
+ copyInput.focus();
|
|
|
+ copyInput.select();
|
|
|
+ // document.execCommand 可能会被废弃
|
|
|
+ if (document.execCommand("copy")) {
|
|
|
+ document.execCommand("copy");
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error("Failed to copy: ", e);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleRecall(item) {
|
|
|
+ if (!item || item.messageDirection !== MessageDirection.SEND) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ core.recallMessage(item);
|
|
|
+ },
|
|
|
+ handleDelete(item) {
|
|
|
+ console.log(item);
|
|
|
+ if (!item) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ core.deleteMessage(item);
|
|
|
+ },
|
|
|
+ async onCurrentContextmenuClick(item) {
|
|
|
+ console.log(item, "item");
|
|
|
+ switch (item.contextMenuClickId) {
|
|
|
+ case 0:
|
|
|
+ this.handleCopy(item);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ // this.handleNotificationStatusChange(item);
|
|
|
+ this.handleRecall(item);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ // this.handleDelete(item);
|
|
|
+ this.handleDelete(item);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ },
|
|
|
getMessageStyleClass(message) {
|
|
|
const styleMap = {
|
|
|
[MessageType.IMAGE]: "image-message-item",
|
|
@@ -152,11 +266,11 @@ export default {
|
|
|
},
|
|
|
handleFail() {
|
|
|
const conversation = {
|
|
|
- conversationType: this.message.conversationType,
|
|
|
- targetId: this.message.targetId,
|
|
|
- channelId: this.message.channelId
|
|
|
+ conversationType: obj.conversationType,
|
|
|
+ targetId: obj.targetId,
|
|
|
+ channelId: obj.channelId
|
|
|
};
|
|
|
- core.resendMessage(conversation, this.message);
|
|
|
+ core.resendMessage(conversation, obj);
|
|
|
},
|
|
|
onRefresh() {
|
|
|
// 清空列表数据
|
|
@@ -175,8 +289,8 @@ export default {
|
|
|
return;
|
|
|
}
|
|
|
let lastestTime = Date.now();
|
|
|
- if (this.messages.length) {
|
|
|
- lastestTime = this.messages[0].sentTime;
|
|
|
+ if (objs.length) {
|
|
|
+ lastestTime = objs[0].sentTime;
|
|
|
}
|
|
|
// 先显示正在加载,然后开始请求数据,保证显示效果
|
|
|
|
|
@@ -279,7 +393,7 @@ export default {
|
|
|
this.isLoading = false;
|
|
|
this.messages = messages.list;
|
|
|
this.hasMore = messages.hasMore;
|
|
|
- console.log(this.messages);
|
|
|
+ console.log(this.messages, "getMessages");
|
|
|
if (this.messages.length) {
|
|
|
this.scrollToBottom();
|
|
|
// if (!this.bscroll) {
|
|
@@ -309,7 +423,7 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- console.log(this.messages);
|
|
|
+ // console.log(this.messages);
|
|
|
});
|
|
|
},
|
|
|
scrollToBottom(time = 200, scrollY = 0) {
|
|
@@ -317,7 +431,7 @@ export default {
|
|
|
setTimeout(() => {
|
|
|
const pullRefresh = this.$refs.pullRefresh;
|
|
|
const scrollY = scrollY || pullRefresh.offsetHeight;
|
|
|
- console.log(scrollY, "scrollY");
|
|
|
+ // console.log(scrollY, "scrollY");
|
|
|
document.querySelector("#el-main").scrollTo(0, scrollY);
|
|
|
}, time);
|
|
|
});
|
|
@@ -343,7 +457,7 @@ export default {
|
|
|
const refreshData = () => {
|
|
|
const messages = [...this.messages, ...newMessages];
|
|
|
this.messages = messages;
|
|
|
- console.log(this.messages, "this.messages");
|
|
|
+ // console.log(this.messages, "this.messages");
|
|
|
|
|
|
this.scrollToBottom(100);
|
|
|
// if (!this.bscroll) {
|