Commit f2fd5722 by Sixong.Zhu

Merge branch 'master' into pre

parents 7abbf4ee f99c45d2
......@@ -13,10 +13,7 @@
>
{{ getCurrentInputingPeople }}正在输入
</div>
<messages
class="flex-fill"
@open-pay-message="openPayMessage"
/>
<messages class="flex-fill" @open-message="openMessage" />
<slot name="chat-right-panel"></slot>
</div>
<div
......@@ -31,7 +28,7 @@
class="chat-input flex-none h-100"
v-if="hasInput"
>
<message-input @error="onError" />
<message-input @error="onError" @sent="onMessageSent" />
</div>
</div>
</div>
......@@ -44,6 +41,7 @@
import messages from "@/customer-service/components/message-list.vue";
import { ChatStore, chatStore } from "@/customer-service/store/model";
import Chat from "@/customer-service/xim";
import { CustomerServiceEvent } from "../event";
@Component({ components: { MessageInput, messages } })
export default class ChatRoom extends Vue {
......@@ -70,6 +68,11 @@
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR)
private readonly chatError!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR;
@chatStore.Getter(ChatStore.GETTER_CURRENT_CURRENT_CHAT)
private readonly currentChat!: ChatStore.GETTER_CURRENT_CURRENT_CHAT;
private setting = 0;
private get hasInput() {
return this.isChatMember && this.chatError !== this.chatId;
}
......@@ -128,8 +131,23 @@
this.chatBox.clientHeight - this.refTop.clientHeight + "px");
}
private openPayMessage(id: number) {
this.$emit("open-pay-message", id);
private openMessage(o: any) {
CustomerServiceEvent.emit(this, o);
}
private onMessageSent() {
if (this.setting) {
clearTimeout(this.setting);
}
this.setting = setTimeout(
() =>
this.currentChat &&
Chat.setRead(
this.currentChat.model_name,
this.currentChat.obj_id
),
300
);
}
}
</script>
......
......@@ -34,6 +34,7 @@
import BaseMessage from "./index";
import Chat from "@/customer-service/xim";
import { ChatStore, chatStore } from "@/customer-service/store/model";
import { CustomerServiceEvent, MessageEvent } from "@/customer-service/event";
@Component({ components: {} })
export default class Index extends BaseMessage {
......@@ -112,7 +113,11 @@
private view() {
this.isChatMember &&
this.$emit("open-pay-message", this.payData.paymentId);
CustomerServiceEvent.open(
this,
MessageEvent.PayMessage,
+this.payData.paymentId
);
}
}
</script>
......
<template>
<div class="position-message" @click="openPosition">
<div class="d-flex justify-content-between align-items-center">
<span class="d-flex align-items-center">
<span class="title">{{ title }}</span>
<span
v-for="item in tags"
:key="item.title"
:style="{ 'background-color': item.color }"
class="tag"
>{{ item.title }}</span
>
</span>
<span class="salary">{{ salary }}</span>
</div>
<div class="summary">
<span v-for="item in summary" :key="item">{{ item }}</span>
</div>
<div class="msg-content" v-html="positionBody"></div>
<div class="msg-tail d-flex justify-content-between">
<span v-for="item in tail" :key="item" class="text-truncate">{{
item
}}</span>
</div>
</div>
</template>
<script lang="ts">
import { CustomerServiceEvent, MessageEvent } from "@/customer-service/event";
import { PositionMessage } from "@/customer-service/xim/models/chat";
import { Component } from "vue-property-decorator";
import BaseMessage from "./index";
@Component({ components: {} })
export default class Index extends BaseMessage {
private get positionData() {
return this.messageBody.msg as PositionMessage;
}
private get title() {
return this.positionData.title;
}
private get tags() {
return this.positionData.tags;
}
private get salary() {
return this.positionData.salary;
}
private get positionBody() {
return this.positionData.post_require;
}
private get summary() {
return [
this.positionData.address,
this.positionData.education_require,
this.positionData.recruit_count,
];
}
private get tail() {
return [
this.positionData.company_name,
this.positionData.business_scope,
];
}
private openPosition() {
CustomerServiceEvent.open(
this,
MessageEvent.PositionMessage,
this.positionData.post_id
);
}
}
</script>
<style lang="less" scoped>
.position-message {
border: 1px solid #ccc;
border-radius: 10px;
padding: 10px;
max-width: 300px;
cursor: pointer;
}
.title {
font-size: 16px;
font-weight: 500;
}
.tag {
border-radius: 4px;
padding: 0 2px;
margin-left: 10px;
color: #fff;
font-size: 12px;
}
.salary {
color: #e87005;
margin-left: 50px;
}
.summary {
border-bottom: 1px solid #f0f0f0;
margin: 6px -10px 10px -10px;
font-size: 12px;
color: #999;
padding: 0 10px 8px 10px;
span + span {
margin-left: 20px;
}
}
.msg-content {
line-height: 1.4;
}
.msg-tail {
margin: 15px -10px 0 -10px;
padding: 10px 10px 0 10px;
border-top: 1px solid #f0f0f0;
span {
max-width: 200px;
}
}
</style>
\ No newline at end of file
......@@ -24,7 +24,7 @@
:shape="shape"
@open="open"
@withdraw="refresh"
@open-pay-message="openPayMessage"
@open-message="openMessage"
/>
</div>
</template>
......@@ -49,6 +49,7 @@
import { ChatStore, chatStore } from "@/customer-service/store/model";
import { dbController } from "../database";
import { getLastMessageId } from "../store";
import { CustomerServiceEvent } from "../event";
@Component({ components: { message, ImagePreview, VideoPreview } })
export default class MessageList extends Vue {
......@@ -415,8 +416,8 @@
this.fetchNewMsg();
}
private openPayMessage(id: number) {
this.$emit("open-pay-message", id);
private openMessage(o: any) {
CustomerServiceEvent.emit(this, o);
}
}
</script>
......
......@@ -69,7 +69,7 @@
v-if="messageComponent"
v-model="data"
@open="openFile"
@open-pay-message="openPayMessage"
@open-message="openMessage"
/>
<avatar
v-if="!isQuestionAnswerMessage && !isWithdrawMessage"
......@@ -164,11 +164,13 @@
import PurchasePlanMessage from "./message-item/purchase-plan-message.vue";
import MyWelfareMessage from "./message-item/my-welfare-message.vue";
import QuestionAnswerMessage from "./message-item/question-answer-message.vue";
import PositionMessage from "./message-item/position-message.vue";
import PayMessage from "./message-item/pay-message.vue";
import NotifyMessage from "./message-item/notify-message.vue";
import { ChatRole } from "@/customer-service/model";
import { getUserMapping } from "../utils/user-info";
import Xim from "@/customer-service/xim";
import { CustomerServiceEvent } from "../event";
const twoMinutes = 2 * 60 * 1000;
const twoHours = 2 * 60 * 60 * 1000;
......@@ -191,6 +193,7 @@
[dto.MessageType.RefundV1, "pay-message"],
[dto.MessageType.PayResult, "notify-message"],
[dto.MessageType.Notify, "notify-message"],
[dto.MessageType.Position, "position-message"],
]);
@Component({
......@@ -209,6 +212,7 @@
ActionMessage,
PayMessage,
NotifyMessage,
PositionMessage,
},
})
export default class Message extends Vue {
......@@ -535,8 +539,8 @@
document.body.click();
}
private openPayMessage(id: number) {
this.$emit("open-pay-message", id);
private openMessage(o: any) {
CustomerServiceEvent.emit(this, o);
}
}
</script>
......
......@@ -16,6 +16,8 @@ class ChatCacheDatabaseController {
private setuping = false;
private setupError = false;
public readonly historyOrderModelName = 'order_info';
private waitSetupCompleted() {
return new Promise<void>((resolve, reject) => {
const checker = () => {
......
export const enum MessageEvent {
Default = "open-message",
PayMessage = "pay-message",
PositionMessage = "position-message",
}
export class CustomerServiceEvent {
public static open(vue: Vue, type: MessageEvent, model: any) {
return this.emit(vue, { type, model });
}
public static emit(vue: Vue, o: { type: MessageEvent; model: any }) {
return vue.$emit(MessageEvent.Default, o);
}
}
......@@ -121,6 +121,7 @@ export const enum MessageType {
RefundV1 = "grefund",
Refund = "grefund2",
Card = "card",
Position = "position",
}
export const enum MessageHandled {
......
import { Chat } from "../xim/models/chat";
import { GeneralOrderDirection } from './order-product';
export interface ChatGroup extends Chat {
children?: ChatGroup[];
......@@ -58,7 +59,11 @@ export interface OrderTableListItem {
lastMsgContent: string;
lastMsgTime: string;
unreadCount: number;
PayPaymentNum?: string | number; //付款笔数
/**
* 付款笔数
*/
PayPaymentNum?: string | number;
product: GeneralOrderDirection;
}
export const orderPredict = {
......@@ -82,6 +87,7 @@ export const orderPredict = {
lastMsgTime: "UniplatLastMsgTime",
unreadCount: 0,
PayPaymentNum: "PayPaymentNum",
product: 'ProductId#product.Code'
};
export const enum PayStatus {
......
......@@ -15,7 +15,7 @@ import { getChatModelInfo } from "../utils/chat-info";
import { getUserInfo } from "../utils/user-info";
import Chat from "../xim";
import { Chat as ChatType, Message } from "../xim/models/chat";
import xim, { ChatNotifyListener } from "../xim/xim";
import xim, { ChatNotifyListener, Xim } from "../xim/xim";
import { decodeJwt } from "uniplat-sdk";
import { ChatStatus, ChatStore, ChatStoreState } from "./model";
......@@ -32,7 +32,7 @@ function uniqueMessages(
messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY>
) {
const arr = [...messages];
return unique(arr, function(item, all) {
return unique(arr, function (item, all) {
return all.findIndex((k) => k.id === item.id);
});
}
......@@ -366,7 +366,7 @@ export default {
state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current];
}
},
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function() {
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function () {
const setTimeoutId: { [key: string]: number } = {};
return (
state: ChatStoreState,
......@@ -480,7 +480,9 @@ export default {
items
);
}
dispatch(ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT).finally(resolve);
dispatch(
ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).finally(resolve);
})
.catch(reject);
});
......@@ -508,7 +510,9 @@ export default {
ChatStore.MUTATION_SAVE_CHAT_LIST,
items
);
dispatch(ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT).finally(resolve);
dispatch(
ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).finally(resolve);
})
.catch(reject);
});
......@@ -547,8 +551,8 @@ export default {
p: { chat: number; unread: number }
) {
const list = state[ChatStore.STATE_MY_CHAT_ROOM_LIST] as ChatType[];
const t = list.find(i => i.id === p.chat)
t && (t.unread_msg_count = p.unread)
const t = list.find((i) => i.id === p.chat);
t && (t.unread_msg_count = p.unread);
return dbController
.updateChat4UnreadCount(p.chat, p.unread)
.then(() =>
......@@ -557,7 +561,9 @@ export default {
},
async [ChatStore.ACTION_GET_CHAT_MESSAGES]({ state, commit, getters }) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
const chat = getters[ChatStore.GETTER_CURRENT_CURRENT_CHAT] as ChatType;
const chat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType;
const isMember = state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER];
if (!chatId) return;
let data: Message[] = [];
......@@ -614,7 +620,7 @@ export default {
dbController.appendMessages(chatId, data);
return data;
},
async[ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID](
async [ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID](
{ state, commit, getters },
msgId: Parameters<ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID>[0]
) {
......@@ -639,7 +645,7 @@ export default {
dbController.appendMessages(chatId, data);
return data;
},
async[ChatStore.ACTION_SEND_MESSAGE](
async [ChatStore.ACTION_SEND_MESSAGE](
{ state, dispatch, getters, commit },
params: Parameters<ChatStore.ACTION_SEND_MESSAGE>[0]
) {
......@@ -667,7 +673,7 @@ export default {
return Promise.reject(error);
}
},
async[ChatStore.ACTION_GET_FRESH_MESSAGE]({
async [ChatStore.ACTION_GET_FRESH_MESSAGE]({
state,
dispatch,
commit,
......@@ -687,7 +693,7 @@ export default {
await preCacheImgs(newMsgsArr);
commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM);
},
async[ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN](
async [ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN](
{ commit, dispatch },
params: Parameters<ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN>[0]
) {
......@@ -704,7 +710,7 @@ export default {
);
return { chatId, catalog };
},
async[ChatStore.ACTION_CREATE_NEW_CHAT_BY_CLIENT](
async [ChatStore.ACTION_CREATE_NEW_CHAT_BY_CLIENT](
{ commit, dispatch },
params: Parameters<ChatStore.ACTION_CREATE_NEW_CHAT_BY_CLIENT>[0]
) {
......@@ -722,7 +728,7 @@ export default {
dispatch(ChatStore.ACTION_GET_MY_CHAT_LIST);
return chatId;
},
async[ChatStore.ACTION_REGISTER_EVENT]({
async [ChatStore.ACTION_REGISTER_EVENT]({
dispatch,
commit,
state,
......@@ -732,7 +738,10 @@ export default {
const onNewMsg = (e: Message) => {
const thenAction = () => {
if (e.type === MessageType.Withdraw) {
commit(ChatStore.MUTATION_WITHDRAW, e.msg.startsWith('[') ? JSON.parse(e.msg) : [+e.msg]);
commit(
ChatStore.MUTATION_WITHDRAW,
e.msg.startsWith("[") ? JSON.parse(e.msg) : [+e.msg]
);
}
const scroll = () =>
state[ChatStore.STATE_FUNC_ON_NEW_MSG](e);
......@@ -746,7 +755,10 @@ export default {
};
if (e.type === MessageType.Withdraw) {
dbController
.removeMessage(e.chat_id, e.msg.startsWith('[') ? JSON.parse(e.msg) : [+e.msg])
.removeMessage(
e.chat_id,
e.msg.startsWith("[") ? JSON.parse(e.msg) : [+e.msg]
)
.finally(() => thenAction());
} else {
thenAction();
......@@ -813,7 +825,7 @@ export default {
xim.on("chat_notify", "read", onMsgRead);
xim.on("chat_notify", "user.input", onInputing);
},
async[ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION](
async [ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION](
{ state, commit, dispatch },
chatId: ChatStore.STATE_CHAT_CURRENT_CHAT_ID
) {
......@@ -878,8 +890,9 @@ export default {
commit(ChatStore.MUTATION_INITING_CHAT_DONE);
commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM);
(<any>state)[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR] = null;
Chat.setRead(wantedChatRoom.model_name, wantedChatRoom.obj_id);
},
async[ChatStore.ACTION_CLEAR_CURRENT_CHAT_DATA]({ commit, state }) {
async [ChatStore.ACTION_CLEAR_CURRENT_CHAT_DATA]({ commit, state }) {
commit(ChatStore.MUTATION_CLEAR_CURRENT_CHAT_ID);
commit(ChatStore.MUTATION_CLEAR_MYSELF_ID);
commit(ChatStore.MUTATION_CLEAR_CHAT_MSG_HISTORY);
......@@ -887,7 +900,7 @@ export default {
commit(ChatStore.MUTATION_CLEAR_CURRENT_CHAT_MEMBERS);
(<any>state)[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR] = null;
},
async[ChatStore.ACTION_GET_CHAT_MEMBERS]({ commit, state }) {
async [ChatStore.ACTION_GET_CHAT_MEMBERS]({ commit, state }) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (!chatId) return;
const getChatMembersResult = await xim.fetchChatMembers(chatId);
......@@ -925,12 +938,12 @@ export default {
}
commit(
ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS,
unique(newChatMembers, function(item, all) {
unique(newChatMembers, function (item, all) {
return all.findIndex((k) => k.eid === item.eid);
})
);
},
async[ChatStore.ACTION_TERINATE_CHAT]({ state, dispatch }) {
async [ChatStore.ACTION_TERINATE_CHAT]({ state, dispatch }) {
const v = state[ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION];
if (v == null) return;
const id = Number(
......@@ -958,7 +971,7 @@ export default {
firstChat.chat_id
);
},
async[ChatStore.ACTION_CHAT_START_RECEPTION]({ getters, dispatch }) {
async [ChatStore.ACTION_CHAT_START_RECEPTION]({ getters, dispatch }) {
const currentChat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType;
......@@ -982,7 +995,7 @@ export default {
);
});
},
async[ChatStore.ACTION_CHAT_FINISH_RECEPTION]({ getters, dispatch }) {
async [ChatStore.ACTION_CHAT_FINISH_RECEPTION]({ getters, dispatch }) {
const currentChat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType;
......@@ -999,7 +1012,7 @@ export default {
.finishChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async[ChatStore.ACTION_CHAT_USER_EXIT]({ getters, dispatch }) {
async [ChatStore.ACTION_CHAT_USER_EXIT]({ getters, dispatch }) {
const currentChat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType;
......@@ -1017,7 +1030,7 @@ export default {
.userExitChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async[ChatStore.ACTION_CHAT_CS_EXIT]({ getters, dispatch }) {
async [ChatStore.ACTION_CHAT_CS_EXIT]({ getters, dispatch }) {
const currentChat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType;
......@@ -1035,7 +1048,7 @@ export default {
.csExitChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async[ChatStore.ACTION_CHAT_ADD_MEMBERS](
async [ChatStore.ACTION_CHAT_ADD_MEMBERS](
{ getters, dispatch },
uids: Parameters<ChatStore.ACTION_CHAT_ADD_MEMBERS>[0]
) {
......@@ -1055,7 +1068,7 @@ export default {
.addMember(uids.map((id) => +id))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async[ChatStore.ACTION_CHAT_REMOVE_MEMBER](
async [ChatStore.ACTION_CHAT_REMOVE_MEMBER](
{ getters, dispatch },
uids: Parameters<ChatStore.ACTION_CHAT_REMOVE_MEMBER>[0]
) {
......@@ -1075,7 +1088,7 @@ export default {
.removeMember(uids.map((id) => +id))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async[ChatStore.ACTION_CHAT_ADD_CS](
async [ChatStore.ACTION_CHAT_ADD_CS](
{ getters, dispatch },
uids: Parameters<ChatStore.ACTION_CHAT_ADD_CS>[0]
) {
......@@ -1095,7 +1108,7 @@ export default {
.addCs(uids.map((id) => Number(id)))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async[ChatStore.ACTION_CHAT_REMOVE_CS](
async [ChatStore.ACTION_CHAT_REMOVE_CS](
{ getters, dispatch },
uids: Parameters<ChatStore.ACTION_CHAT_REMOVE_CS>[0]
) {
......@@ -1182,8 +1195,8 @@ export default {
p.read_count = option.all
? p.total_read_count
: option.readed
? option.readed
: p.read_count + 1;
? option.readed
: p.read_count + 1;
}
}
} else {
......@@ -1192,8 +1205,8 @@ export default {
p.read_count = option.all
? p.total_read_count
: option.readed
? option.readed
: p.read_count + 1;
? option.readed
: p.read_count + 1;
}
}
}
......
......@@ -146,14 +146,16 @@ class Chat {
return Promise.resolve(uri);
}
return new Promise<void>((resolve, reject) => {
xim.open(uri, this.token).catch(reject).finally(() => {
this.registerXimEvent();
if (xim.isConnected()) {
resolve();
} else {
reject(new Error(`xim is not connected`));
}
});
xim.open(uri, this.token)
.catch(reject)
.finally(() => {
this.registerXimEvent();
if (xim.isConnected()) {
resolve();
} else {
reject(new Error(`xim is not connected`));
}
});
});
}
......@@ -203,6 +205,15 @@ class Chat {
public getAvatar() {
return this.defaultAvatar;
}
public setRead(model: string, obj: string) {
if (this.isBackend()) {
const sdk = this.getSdk();
if (sdk) {
sdk.getAxios().post(`/general/xim/model/${model}/${obj}/read`);
}
}
}
}
export default new Chat();
......@@ -219,6 +219,19 @@ export interface PayMessageBody {
totalMoney?: string;
}
export interface PositionMessage {
title: string;
tags: { title: string; color: string }[];
salary: string;
address: string;
education_require: string;
recruit_count: string;
post_require: string;
company_name: string;
business_scope: string;
post_id: number;
}
export interface CsUser {
id: number;
oid: string;
......
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