Commit 6c77b02d by Sixong.Zhu

update

parent 5a7a2574
import { MessageType } from "@/customer-service/model";
export function parserMessage(type: string, rawMsg: string) {
const mapping = new Map<MessageType, string>([
[MessageType.Image, '图片'],
[MessageType.Video, '视频'],
[MessageType.Voice, '语音'],
[MessageType.File, '文件'],
[MessageType.Withdraw, '撤回了一条消息'],
[MessageType.MyPurchasePlan, '我的采购计划'],
[MessageType.MyWelfare, '我的福利'],
[MessageType.QuestionAnswer, '问答'],
])
export function parserMessage(type: MessageType, rawMsg: string) {
if (!type) return "";
if (!rawMsg) return "";
if (type === MessageType.Text) {
......@@ -11,29 +22,9 @@ export function parserMessage(type: string, rawMsg: string) {
const msg = JSON.parse(rawMsg);
return msg.text;
}
if (type === MessageType.Image) {
return `[图片]`;
}
if (type === MessageType.Video) {
return `[视频]`;
}
if (type === MessageType.Voice) {
return `[语音]`;
}
if (type === MessageType.File) {
return `[文件]`;
}
if (type === MessageType.Withdraw) {
return `[撤回了一条消息]`;
}
if (type === MessageType.MyPurchasePlan) {
return `[我的采购计划]`;
}
if (type === MessageType.MyWelfare) {
return `[我的福利]`;
}
if (type === MessageType.QuestionAnswer) {
return `[问答]`;
const t = mapping.get(type)
if (t) {
return t;
}
return `[系统自动回复]`;
}
......@@ -102,6 +102,7 @@ export const enum MessageType {
MyWelfare = "my_welfare",
QuestionAnswer = "question_answer",
Action = "action",
Notify = 'notify'
}
export const enum MessageHandled {
......
......@@ -31,7 +31,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);
});
}
......@@ -334,7 +334,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,
......@@ -836,7 +836,7 @@ 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);
})
);
......@@ -1049,6 +1049,22 @@ export default {
[ChatStore.ACTION_SET_CHAT_ERROR]: ({ state }, chat: number) => {
(<any>state)[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR] = chat;
},
[ChatStore.ACTION_GET_USERINFO]: ({ state }, id: string) => {
const cache = state[ChatStore.STATE_CHAT_USERNAME] || {};
if (cache[id]) {
return Promise.resolve({ id, name: cache[id] });
}
return new Promise<{ id: string; name: string }>((resolve, reject) => {
Chat.getSdk().model("user")
.detail(id)
.query()
.then((userInfo: any) => {
const name = userInfo.row.first_name.display as string;
Vue.set(state[ChatStore.STATE_CHAT_USERNAME], id, name);
resolve({ id, name });
}).catch(reject);
});
},
},
getters: {
[ChatStore.STATE_CHAT_MSG_HISTORY](state) {
......
......@@ -3,6 +3,7 @@ import { namespace } from "vuex-class";
import * as dto from "../model";
import { Chat as ChatType } from "../xim/models/chat";
import * as chatDto from "../xim/models/chat";
export enum ChatStatus {
opening = 0,
terminated = 1,
......@@ -350,6 +351,9 @@ export namespace ChatStore {
export const ACTION_SET_CHAT_ERROR = "标记会话关键性错误";
export type ACTION_SET_CHAT_ERROR = (chat: number) => void;
export const ACTION_GET_USERINFO = '获取用户个人信息';
export type ACTION_GET_USERINFO = (id: string) => Promise<{ id: string; name: string }>
export interface ChatUpdateParameter {
chat: number;
type?: dto.MessageType;
......
......@@ -22,7 +22,7 @@ export interface Chat {
biz_id: string;
last_msg_sender: string;
last_msg_content: string;
last_msg_type: string;
last_msg_type: MessageType;
model_name: string;
obj_id: string;
is_finish: boolean;
......
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