Commit f4b0a55e by Sixong.Zhu

add new parameter

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