Commit f4b0a55e by Sixong.Zhu

add new parameter

parent 7089483d
......@@ -127,6 +127,7 @@ import {
TimeFormatRule,
} from "@/customer-service/utils/time";
import { Chat as ChatType } from "@/customer-service/xim/models/chat";
import xim from "@/customer-service/xim";
interface SelectChatType extends ChatType {
checked?: boolean;
......@@ -231,7 +232,7 @@ export default class ModelChatList extends Vue {
async created() {
await this.getList();
this.setSource(ChatStore.StateChatSourceDirection.Server);
this.setSource(xim.getServiceType());
this.scrollbar && this.scrollbar.update();
await this.sdk
.model("UniplatChat")
......
......@@ -13,7 +13,7 @@ import ChatInput, {
FILE_INFO_CLASS,
isImageOrFile,
} from "../hybrid-input/index.vue";
import { Message } from "../model";
import { Message, MessageType } from "../model";
import { uploadFile } from "../service/upload";
import { ChatLoggerService } from "../xim/logger";
import xim from "../xim/xim";
......@@ -67,9 +67,9 @@ export default class MessageInput extends Vue {
for (const item of msg) {
if (isImageOrFile(item)) {
if ((item as Element).classList.contains(FILE_INFO_CLASS)) {
await this.sendFile(item, "file");
await this.sendFile(item, MessageType.File);
} else {
await this.sendFile(item, "image");
await this.sendFile(item, MessageType.Image);
}
continue;
}
......@@ -94,11 +94,11 @@ export default class MessageInput extends Vue {
if (this.source) {
Object.assign(msg, { source: this.source });
}
return this.sendMsg({ msgType: "text", msg: JSON.stringify(msg) });
return this.sendMsg({ msgType: MessageType.Text, msg: JSON.stringify(msg) });
}
}
private async sendFile(file: any, type: "image" | "file") {
private async sendFile(file: any, type: MessageType.Image | MessageType.File) {
const src = JSON.parse(
file.attributes[`data-${type}`]?.value || ""
) as {
......@@ -112,7 +112,7 @@ export default class MessageInput extends Vue {
if (file) {
let w = 0;
let h = 0;
if (type === "image") {
if (type === MessageType.Image) {
const img = new Image();
img.src = src.url;
img.onload = function () {
......
......@@ -55,6 +55,7 @@
type="text"
@click="sendMsg(reply)"
v-if="!editingItem[reply.id]"
:disabled="!isChatMember"
>发送</el-button
>
<el-button
......@@ -87,6 +88,7 @@
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { MessageType } from "../model";
import { ChatStore, chatStore } from "../store/model";
import buttonThrottle from "../utils/button-throttle";
......@@ -109,6 +111,9 @@ export default class MsgShortCut extends Vue {
@chatStore.Getter(ChatStore.STATE_CHAT_SOURCE)
private readonly source!: ChatStore.STATE_CHAT_SOURCE;
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER)
private readonly isChatMember!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER;
private replyList: Reply[] = [];
private uid = this.sdk.global.uid;
private replyInputVisible = false;
......@@ -129,7 +134,7 @@ export default class MsgShortCut extends Vue {
@buttonThrottle()
private sendMsg(reply: Reply) {
return this._sendMsg({
msgType: "text",
msgType: MessageType.Text,
msg: JSON.stringify({ text: reply.content, source: this.source }),
});
}
......
......@@ -33,6 +33,17 @@ export interface Chat {
unread_msg_count: number;
}
export const enum CustomerServiceProduct {
Default,
Fulibao,
Hrs,
}
export const enum ServiceType {
Frontend,
Backend,
}
export type TokenStringGetter = () => Promise<string>;
export interface ChatOption {
......@@ -44,6 +55,13 @@ export interface ChatOption {
sdk: () => UniplatSdk;
orgId: () => string | number;
product?: CustomerServiceProduct;
/**
* 用于标记会话启动是在客户端(用户)还是服务端(后端)
*/
serviceType?: ServiceType;
}
export interface ChatServiceLogger {
......@@ -131,10 +149,12 @@ export interface CreateChatByServicemanRequestResult {
members_updated: number;
user_updated: number;
}
export type ChatMemberExtraInfo = {
name?: string;
phone?: string;
};
export interface ChatMember {
id: number;
org_id: string;
......
......@@ -2,7 +2,7 @@ import Vue from "vue";
import { Module } from "vuex";
import { dbController } from "../database";
import { ChatMember } from "../model";
import { ChatMember, ServiceType } from "../model";
import { isAccessibleUrl } from "../service/tools";
import { unique } from "../utils";
import { getChatModelInfo } from "../utils/chat-info";
......@@ -105,7 +105,7 @@ export default {
[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]: null,
[ChatStore.STATE_CHAT_MY_ID]: null,
[ChatStore.STATE_CHAT_MY_UID]: null,
[ChatStore.STATE_CHAT_SOURCE]: 0,
[ChatStore.STATE_CHAT_SOURCE]: ServiceType.Frontend,
[ChatStore.STATE_CURRENT_CHAT_MEMBERS]: null,
[ChatStore.STATE_CURRENT_CHAT_TITLE]: "",
[ChatStore.STATE_FUNC_SCROLL_TO_BOTTOM]: () => true,
......
......@@ -56,7 +56,7 @@ export namespace ChatStore {
export type STATE_CHAT_MY_UID = string | null;
export const STATE_CHAT_SOURCE = "stateChatSource";
export type STATE_CHAT_SOURCE = StateChatSourceDirection;
export type STATE_CHAT_SOURCE = dto.ServiceType;
export const STATE_CURRENT_CHAT_INPUTING = "当前会话正在输入的人";
export type STATE_CURRENT_CHAT_INPUTING = string[];
......@@ -67,14 +67,6 @@ export namespace ChatStore {
export const STATE_CHAT_SEND_FAIL_MESSAGE = "最新一条发送失败消息";
export type STATE_CHAT_SEND_FAIL_MESSAGE = string | null;
/**
* 消息来源,是来自客服端(Server),还是来自于顾客端(Client)
*/
export const enum StateChatSourceDirection {
Server = 1,
Client = 0,
}
export const STATE_CURRENT_CHAT_MEMBERS = "当前会话参与者";
export type STATE_CURRENT_CHAT_MEMBERS =
| readonly (dto.ChatMember & dto.ChatMemberExtraInfo)[]
......@@ -182,9 +174,7 @@ export namespace ChatStore {
export type MUTATION_CLEAR_MYSELF_ID = () => void;
export const MUTATION_SET_CHAT_SOURCE = "setChatSource";
export type MUTATION_SET_CHAT_SOURCE = (
payload: StateChatSourceDirection
) => void;
export type MUTATION_SET_CHAT_SOURCE = (payload: dto.ServiceType) => void;
export const MUTATION_SAVE_CURRENT_CHAT_MEMBERS = "保存当前会话参与者";
export type MUTATION_SAVE_CURRENT_CHAT_MEMBERS = (
......@@ -312,7 +302,7 @@ export namespace ChatStore {
export const ACTION_SEND_MESSAGE = "发送消息";
export type ACTION_SEND_MESSAGE = (params: {
msgType: "text" | "image" | "file" | "voice" | "video";
msgType: dto.MessageType;
msg: string;
ts?: number;
}) => Promise<void>;
......
......@@ -2,7 +2,12 @@ import type { UniplatSdk } from "uniplat-sdk";
import { EmojiService } from "../service/emoji";
import { ChatOption, TokenStringGetter } from "./../model";
import {
ChatOption,
TokenStringGetter,
ServiceType,
CustomerServiceProduct,
} from "./../model";
import { ChatLoggerService } from "./logger";
import tokenManager from "./token";
import xim from "./xim";
......@@ -12,6 +17,8 @@ class Chat {
private _sdk?: () => UniplatSdk;
private _orgId: () => string | number = () => "0";
private token!: TokenStringGetter;
private serviceType = ServiceType.Backend;
private product = CustomerServiceProduct.Default;
private userMapping: { [key: string]: { name: string; avatar: string } } =
{};
......@@ -30,6 +37,8 @@ class Chat {
}
this._sdk = option.sdk;
this._orgId = option.orgId;
option.serviceType && (this.serviceType = option.serviceType);
option.product && (this.product = option.product);
dbController.setup(this._sdk().global.uid);
......@@ -56,6 +65,14 @@ class Chat {
return this._sdk();
};
public getServiceType() {
return this.serviceType;
}
public getProduct() {
return this.product;
}
public getOrgId = () => {
return this._orgId();
};
......
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