Commit 3347be3d by Sixong.Zhu

style

parent eca55214
<template> <template>
<div class="msg-detail file-message d-flex" @dblclick="openFile"> <div class="msg-detail file-message d-flex" @dblclick="openFile">
<div class="file-message-info"> <div
class="file-message-info"
:class="{ 'd-flex align-items-center': !messageBody.msg.size }"
>
<div <div
class="text-nowrap text-truncate file-message-name" class="file-message-name"
:title="messageBody.msg.name" :title="messageBody.msg.name"
:class="{ 'text-truncate': messageBody.msg.size }"
> >
{{ messageBody.msg.name }} {{ messageBody.msg.name }}
</div> </div>
<div class="text-hint"> <div class="text-hint" v-if="messageBody.msg.size">
{{ format(messageBody.msg.size) }} {{ format(messageBody.msg.size) }}
</div> </div>
</div> </div>
......
...@@ -108,443 +108,447 @@ ...@@ -108,443 +108,447 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Inject, Prop, Vue } from "vue-property-decorator"; import { Component, Inject, Prop, Vue } from "vue-property-decorator";
import * as dto from "../model"; import * as dto from "../model";
import chat from "./../xim"; import chat from "./../xim";
import { import {
isAudio, isAudio,
isImage, isImage,
isVideo, isVideo,
MAX_FILE_SIZE, MAX_FILE_SIZE,
MAX_IMAGE_SIZE, MAX_IMAGE_SIZE,
} from "./message-item/file-controller"; } from "./message-item/file-controller";
import WhoReadList from "./who-read-list.vue"; import WhoReadList from "./who-read-list.vue";
import avatar from "@/customer-service/components/avatar.vue"; import avatar from "@/customer-service/components/avatar.vue";
import { chatStore, ChatStore } from "@/customer-service/store/model"; import { chatStore, ChatStore } from "@/customer-service/store/model";
import ximInstance from "../xim/xim"; import ximInstance from "../xim/xim";
import { dbController } from "../database"; import { dbController } from "../database";
import ImageMessage from "./message-item/image-message.vue"; import ImageMessage from "./message-item/image-message.vue";
import FileMessage from "./message-item/file-message.vue"; import FileMessage from "./message-item/file-message.vue";
import AudioMessage from "./message-item/audio-message.vue"; import AudioMessage from "./message-item/audio-message.vue";
import VideoMessage from "./message-item/video-message.vue"; import VideoMessage from "./message-item/video-message.vue";
import TextMessage from "./message-item/text-message.vue"; import TextMessage from "./message-item/text-message.vue";
import WithdrawMessage from "./message-item/withdraw-message.vue"; import WithdrawMessage from "./message-item/withdraw-message.vue";
import xim from "./../xim"; import xim from "./../xim";
const twoMinutes = 2 * 60 * 1000; const twoMinutes = 2 * 60 * 1000;
const messageMapping = new Map<dto.MessageType, string>([ const messageMapping = new Map<dto.MessageType, string>([
[dto.MessageType.Image, "image-message"], [dto.MessageType.Image, "image-message"],
[dto.MessageType.File, "file-message"], [dto.MessageType.File, "file-message"],
[dto.MessageType.Video, "video-message"], [dto.MessageType.Video, "video-message"],
[dto.MessageType.Voice, "audio-message"], [dto.MessageType.Voice, "audio-message"],
[dto.MessageType.Text, "text-message"], [dto.MessageType.Text, "text-message"],
[dto.MessageType.Withdraw, "withdraw-message"], [dto.MessageType.Withdraw, "withdraw-message"],
[dto.MessageType.GeneralOrderMsg, "text-message"], [dto.MessageType.GeneralOrderMsg, "text-message"],
]); ]);
@Component({ @Component({
components: { components: {
WhoReadList, WhoReadList,
avatar, avatar,
ImageMessage, ImageMessage,
FileMessage, FileMessage,
AudioMessage, AudioMessage,
VideoMessage, VideoMessage,
TextMessage, TextMessage,
WithdrawMessage, WithdrawMessage,
}, },
}) })
export default class Message extends Vue { export default class Message extends Vue {
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_USER_UID) @chatStore.State(ChatStore.STATE_CHAT_CURRENT_USER_UID)
private readonly chatMyId!: ChatStore.STATE_CHAT_CURRENT_USER_UID; private readonly chatMyId!: ChatStore.STATE_CHAT_CURRENT_USER_UID;
@chatStore.Getter(ChatStore.GETTER_CURRENT_CHAT_PRESENT_MEMBERS) @chatStore.Getter(ChatStore.GETTER_CURRENT_CHAT_PRESENT_MEMBERS)
private readonly chatMembers!: ChatStore.GETTER_CURRENT_CHAT_PRESENT_MEMBERS; private readonly chatMembers!: ChatStore.GETTER_CURRENT_CHAT_PRESENT_MEMBERS;
@chatStore.State(ChatStore.STATE_CHAT_SOURCE) @chatStore.State(ChatStore.STATE_CHAT_SOURCE)
private readonly chatSource!: ChatStore.STATE_CHAT_SOURCE; private readonly chatSource!: ChatStore.STATE_CHAT_SOURCE;
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_ID) @chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_ID)
private readonly chatId!: ChatStore.STATE_CHAT_CURRENT_CHAT_ID; private readonly chatId!: ChatStore.STATE_CHAT_CURRENT_CHAT_ID;
@chatStore.Mutation(ChatStore.MUTATION_WITHDRAW) @chatStore.Mutation(ChatStore.MUTATION_WITHDRAW)
private readonly executeWithDraw!: ChatStore.MUTATION_WITHDRAW; private readonly executeWithDraw!: ChatStore.MUTATION_WITHDRAW;
@chatStore.Action(ChatStore.ACTION_SET_HANDLED) @chatStore.Action(ChatStore.ACTION_SET_HANDLED)
private readonly setHandled!: ChatStore.ACTION_SET_HANDLED; private readonly setHandled!: ChatStore.ACTION_SET_HANDLED;
@Prop({ type: Object, default: () => Object.create(null) }) @Prop({ type: Object, default: () => Object.create(null) })
private readonly data!: dto.Message; private readonly data!: dto.Message;
@Prop() @Prop()
private readonly isSendingMessage!: boolean; private readonly isSendingMessage!: boolean;
@Prop() @Prop()
private readonly failed!: boolean; private readonly failed!: boolean;
@Prop({ default: "circle" }) @Prop({ default: "circle" })
private readonly shape!: string; private readonly shape!: string;
@Inject({ default: false }) readonly showReadSummary!: boolean; @Inject({ default: false }) readonly showReadSummary!: boolean;
private readonly backend = chat.isBackend(); private readonly backend = chat.isBackend();
private messageComponent = ""; private messageComponent = "";
private readListVisibility = false; private readListVisibility = false;
private org = ""; private org = "";
private readerListOffset = false; private readerListOffset = false;
private defaultMessageHandledStatus = dto.MessageHandled.Default; private defaultMessageHandledStatus = dto.MessageHandled.Default;
private showHostAvatar: boolean = false; private showHostAvatar: boolean = false;
private get canWithdraw() { private get canWithdraw() {
if (this.backend && this.data) { if (this.backend && this.data) {
return new Date().valueOf() - this.data.ts * 1000 < twoMinutes; return new Date().valueOf() - this.data.ts * 1000 < twoMinutes;
}
return false;
} }
return false;
}
private get isWithdrawMessage() {
return this.data.type === dto.MessageType.Withdraw;
}
private get isAllRead() { private get isWithdrawMessage() {
return this.data.read_count >= this.data.total_read_count; return this.data.type === dto.MessageType.Withdraw;
} }
private get messageBody(): { eid?: string; oid?: string; msg: any } { private get isAllRead() {
if (this.data) { return this.data.read_count >= this.data.total_read_count;
try {
return { ...this.data, msg: JSON.parse(this.data.msg) };
} catch {
return {
...this.data,
msg: JSON.parse(this.data.msg.replace(/\n/g, "\\n")),
};
}
} }
return { msg: { text: "" } }; private get messageBody(): { eid?: string; oid?: string; msg: any } {
} if (this.data) {
try {
return { ...this.data, msg: JSON.parse(this.data.msg) };
} catch {
return {
...this.data,
msg: JSON.parse(this.data.msg.replace(/\n/g, "\\n")),
};
}
}
private get handled() { return { msg: { text: "" } };
if (this.data) {
return this.defaultMessageHandledStatus || this.data.handled;
} }
return dto.MessageHandled.Default;
}
private get isMyMessage() { private get handled() {
if (this.isSendingMessage) { if (this.data) {
return true; return this.defaultMessageHandledStatus || this.data.handled;
}
return dto.MessageHandled.Default;
} }
const senderEid = this.messageBody.eid; private get isMyMessage() {
return senderEid!.toString() === this.chatMyId!.toString(); if (this.isSendingMessage) {
} return true;
created() {
this.messageComponent = messageMapping.get(this.messageType) as string;
}
private get userName() {
if (this.chatMembers) {
const t = this.chatMembers.find((i) => i.eid === this.data.eid);
if (t) {
return t.name;
} }
const senderEid = this.messageBody.eid;
return senderEid!.toString() === this.chatMyId!.toString();
} }
return "";
}
private get avatar() { created() {
const avatar = chat.getUserMapping(); this.messageComponent = messageMapping.get(this.messageType) as string;
}
if (this.isSendingMessage) { private get userName() {
if (Object.getOwnPropertyNames(avatar).length > 0) { if (this.chatMembers) {
this.showHostAvatar = true; const t = this.chatMembers.find((i) => i.eid === this.data.eid);
} else { if (t) {
this.showHostAvatar = false; return t.name;
}
if (avatar && this.chatMyId) {
const user = avatar[this.chatMyId];
if (user && user.avatar) {
return user.avatar;
} }
} }
return "";
} }
if (avatar && this.data) { private get avatar() {
if (Object.getOwnPropertyNames(avatar).length > 0) { const avatar = chat.getUserMapping();
this.showHostAvatar = true;
} else { if (this.isSendingMessage) {
this.showHostAvatar = false; if (Object.getOwnPropertyNames(avatar).length > 0) {
this.showHostAvatar = true;
} else {
this.showHostAvatar = false;
}
if (avatar && this.chatMyId) {
const user = avatar[this.chatMyId];
if (user && user.avatar) {
return user.avatar;
}
}
} }
const value = avatar[this.data.eid];
if (value && value.avatar) { if (avatar && this.data) {
return value.avatar; if (Object.getOwnPropertyNames(avatar).length > 0) {
this.showHostAvatar = true;
} else {
this.showHostAvatar = false;
}
const value = avatar[this.data.eid];
if (value && value.avatar) {
return value.avatar;
}
} }
}
return ""; return "";
} }
private get messageType() { private get messageType() {
const type = this.data?.type; const type = this.data?.type;
if (type === "file") { if (type === "file") {
const name = this.messageBody?.msg.name; const name = this.messageBody?.msg.name;
if (name) { if (name) {
const size = this.messageBody?.msg.size; const size = this.messageBody?.msg.size;
if (size) { if (size) {
const outImageSize = size > MAX_IMAGE_SIZE; const outImageSize = size > MAX_IMAGE_SIZE;
if (!outImageSize && isImage(name)) { if (!outImageSize && isImage(name)) {
return dto.MessageType.Image; return dto.MessageType.Image;
}
const outSize = size > MAX_FILE_SIZE;
if (!outSize) {
if (isAudio(name)) {
return dto.MessageType.Voice;
} }
if (isVideo(name)) { const outSize = size > MAX_FILE_SIZE;
return dto.MessageType.Video; if (!outSize) {
if (isAudio(name)) {
return dto.MessageType.Voice;
}
if (isVideo(name)) {
return dto.MessageType.Video;
}
} }
} }
} }
} }
return type;
} }
return type;
}
private get isTextMessage() { private get isTextMessage() {
return this.messageType === dto.MessageType.Text; return this.messageType === dto.MessageType.Text;
} }
private get matchKeywords() { private get matchKeywords() {
if (this.isTextMessage && !this.isMyMessage) { if (this.isTextMessage && !this.isMyMessage) {
const m = this.messageBody.msg as { text: string }; const m = this.messageBody.msg as { text: string };
if (m && m.text) { if (m && m.text) {
const keywords = xim.getMatchedTextKeywords(); const keywords = xim.getMatchedTextKeywords();
return keywords.find((i) => m.text.includes(i)); return keywords.find((i) => m.text.includes(i));
}
} }
return false;
} }
return false;
}
private isCustomer() { private isCustomer() {
return !this.showReadSummary; return !this.showReadSummary;
}
private openFile(url: string) {
if (this.isSendingMessage) {
return;
} }
if (this.failed) {
return; private openFile(url: string) {
if (this.isSendingMessage) {
return;
}
if (this.failed) {
return;
}
const copy = { ...this.messageBody.msg };
copy.url = url;
this.$emit("open", { type: this.messageType, msg: copy });
} }
const copy = { ...this.messageBody.msg };
copy.url = url;
this.$emit("open", { type: this.messageType, msg: copy });
}
private withdraw() { private withdraw() {
ximInstance.withdraw(this.chatId!, this.data.id).finally(() => { ximInstance.withdraw(this.chatId!, this.data.id).finally(() => {
dbController dbController
.removeMessage(this.chatId!, this.data.id) .removeMessage(this.chatId!, this.data.id)
.finally(() => { .finally(() => {
this.executeWithDraw(this.data.id); this.executeWithDraw(this.data.id);
this.$emit("withdraw", this.data.id); this.$emit("withdraw", this.data.id);
}); });
}); });
} }
private openReaderList(e: MouseEvent) { private openReaderList(e: MouseEvent) {
this.readerListOffset = e.x < 450; this.readerListOffset = e.x < 450;
this.readListVisibility = true; this.readListVisibility = true;
} }
private executeHandled() { private executeHandled() {
this.setHandled({ this.setHandled({
id: this.data.id, id: this.data.id,
value: (this.defaultMessageHandledStatus = value: (this.defaultMessageHandledStatus =
dto.MessageHandled.Handled), dto.MessageHandled.Handled),
}); });
this.closeKeywordPopover(); this.closeKeywordPopover();
} }
private ignoredKeyword() { private ignoredKeyword() {
this.setHandled({ this.setHandled({
id: this.data.id, id: this.data.id,
value: (this.defaultMessageHandledStatus = value: (this.defaultMessageHandledStatus =
dto.MessageHandled.Ignored), dto.MessageHandled.Ignored),
}); });
this.closeKeywordPopover(); this.closeKeywordPopover();
} }
private closeKeywordPopover() { private closeKeywordPopover() {
document.body.click(); document.body.click();
}
} }
}
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.message-con { .message-con {
padding-bottom: 20px; padding-bottom: 20px;
margin-right: 15px; margin-right: 15px;
position: relative; position: relative;
&.my-message { &.my-message {
.msg-detail { .msg-detail {
background-color: #dbf2ff; background-color: #dbf2ff;
border-radius: 8px 0 8px 8px; border-radius: 8px 0 8px 8px;
} }
.msg-read { .msg-read {
display: inline-block; display: inline-block;
color: #bfe1ff; color: #bfe1ff;
margin-right: 15px; margin-right: 15px;
user-select: none; user-select: none;
flex: none; flex: none;
margin-top: auto; margin-top: auto;
} }
.download-icon {
margin-right: 15px;
margin-left: 0;
margin-top: 0;
}
.withdraw {
color: #999;
position: absolute;
bottom: 0;
right: 0;
font-size: 12px;
display: none;
cursor: pointer;
}
&:hover {
.withdraw {
display: inline-block;
}
}
.download-icon { /deep/ .file-message-info {
margin-right: 15px; text-align: initial;
margin-left: 0; }
margin-top: 0;
} }
.withdraw { &.offset-bottom {
color: #999; margin-bottom: 30px;
position: absolute;
bottom: 0;
right: 0;
font-size: 12px;
display: none;
cursor: pointer;
} }
&:hover { > i {
.withdraw { height: 16px;
display: inline-block; font-size: 16px;
} margin-right: 10px;
} }
} }
&.offset-bottom { .msg-name {
margin-bottom: 30px; font-size: 14px;
color: #888;
text-align: right;
margin-bottom: 3px;
min-height: 16px;
&.algin-left {
text-align: left;
}
} }
> i { .msg-content {
height: 16px; text-align: right;
font-size: 16px; &.algin-left {
margin-right: 10px; text-align: left;
} }
}
.msg-name {
font-size: 14px;
color: #888;
text-align: right;
margin-bottom: 3px;
min-height: 16px;
&.algin-left {
text-align: left;
} }
}
.msg-content { .msg-detail {
text-align: right; margin-top: 10px;
&.algin-left { font-size: 14px;
text-align: left; line-height: 20px;
} background: #f5f6fa;
} border-radius: 0px 8px 8px;
padding: 10px;
.msg-detail { word-break: break-word;
margin-top: 10px; /deep/ img {
font-size: 14px; max-width: 300px;
line-height: 20px; }
background: #f5f6fa;
border-radius: 0px 8px 8px;
padding: 10px;
word-break: break-word;
/deep/ img {
max-width: 300px;
} }
}
.download-icon { .download-icon {
cursor: pointer; cursor: pointer;
text-decoration: none; text-decoration: none;
margin-left: 15px; margin-left: 15px;
margin-top: 42px; margin-top: 42px;
i { i {
color: #fff; color: #fff;
font-size: 14px; font-size: 14px;
}
} }
}
.no-selection {
.no-selection { user-select: none;
user-select: none;
}
.pointer {
cursor: pointer;
}
.all {
color: #4389f8;
}
.match-keyword {
background-color: #fff3e0;
border-radius: 13px;
padding: 3px 8px;
color: #e87005;
position: absolute;
bottom: -10px;
left: 0;
cursor: pointer;
font-size: 12px;
&.handled {
color: #59ba7b;
background-color: #f0f0f0;
cursor: default;
} }
&.ignored { .pointer {
color: #999; cursor: pointer;
background-color: #f0f0f0;
cursor: default;
} }
i { .all {
margin-right: 5px; color: #4389f8;
} }
}
.keyword-action { .match-keyword {
list-style: none; background-color: #fff3e0;
border-radius: 13px;
padding: 3px 8px;
color: #e87005;
position: absolute;
bottom: -10px;
left: 0;
cursor: pointer;
font-size: 12px;
&.handled {
color: #59ba7b;
background-color: #f0f0f0;
cursor: default;
}
&.ignored {
color: #999;
background-color: #f0f0f0;
cursor: default;
}
i {
margin-right: 5px;
}
}
li { .keyword-action {
list-style: none; list-style: none;
padding: 8px 10px;
color: #077aec;
cursor: pointer;
&:hover { li {
background-color: #f5f6fa; list-style: none;
padding: 8px 10px;
color: #077aec;
cursor: pointer;
&:hover {
background-color: #f5f6fa;
}
} }
} }
}
</style> </style>
<style lang="less"> <style lang="less">
.match-keyword-popover { .match-keyword-popover {
padding: 0; padding: 0;
} }
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment