Commit 86932012 by panjiangyi

格式化代码

parent 03c9c8d6
<template> <template>
<el-dialog <el-dialog
class="chat-dialog-con" class="chat-dialog-con"
:close-on-click-modal="false" :close-on-click-modal="false"
:visible="visible" :visible="visible"
@close="hide" @close="hide"
> >
<div class="chat-con h-100"> <div class="chat-con h-100">
<div class="h-100 chat-list"> <div class="h-100 chat-list">
<chat-list /> <chat-list />
</div> </div>
<div v-if="chatId != null" class="h-100 chat-area"> <div v-if="chatId != null" class="h-100 chat-area">
<chat-room :close="hide" /> <chat-room :close="hide" />
</div> </div>
<div class="chat-panel h-100"> <div class="chat-panel h-100">
<el-button @click="terminate">结束</el-button> <el-button @click="terminate">结束</el-button>
</div> </div>
</div> </div>
</el-dialog> </el-dialog>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Vue } from "vue-property-decorator"; import { Component, Vue } from "vue-property-decorator";
...@@ -29,52 +29,52 @@ import { ChatStore, chatStore } from "@/customer-service/store/model"; ...@@ -29,52 +29,52 @@ import { ChatStore, chatStore } from "@/customer-service/store/model";
@Component({ components: { MessageList, ChatRoom, ChatList } }) @Component({ components: { MessageList, ChatRoom, ChatList } })
export default class Chat extends Vue { export default class Chat extends Vue {
@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.State(ChatStore.STATE_CHAT_DIALOG_VISIBLE) @chatStore.State(ChatStore.STATE_CHAT_DIALOG_VISIBLE)
private readonly visible: ChatStore.STATE_CHAT_DIALOG_VISIBLE private readonly visible!: ChatStore.STATE_CHAT_DIALOG_VISIBLE;
@chatStore.Mutation(ChatStore.MUTATION_HIDE_CHAT) @chatStore.Mutation(ChatStore.MUTATION_HIDE_CHAT)
private readonly hide: ChatStore.MUTATION_HIDE_CHAT private readonly hide!: ChatStore.MUTATION_HIDE_CHAT;
@chatStore.Action(ChatStore.ACTION_TERINATE_CHAT) @chatStore.Action(ChatStore.ACTION_TERINATE_CHAT)
private readonly _terminate: ChatStore.ACTION_TERINATE_CHAT private readonly _terminate!: ChatStore.ACTION_TERINATE_CHAT;
private terminate() { private terminate() {
this._terminate(); this._terminate();
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.chat-dialog-con { .chat-dialog-con {
/deep/ .el-dialog__header { /deep/ .el-dialog__header {
display: none; display: none;
} }
/deep/ .el-dialog { /deep/ .el-dialog {
width: 80%; width: 80%;
max-width: 1200px; max-width: 1200px;
} }
--chat-side-width: 200px; --chat-side-width: 200px;
} }
.chat-con { .chat-con {
height: 500px; height: 500px;
} }
.chat-list, .chat-list,
.chat-area, .chat-area,
.chat-panel { .chat-panel {
display: inline-block; display: inline-block;
vertical-align: top; vertical-align: top;
} }
.chat-list { .chat-list {
width: var(--chat-side-width); width: var(--chat-side-width);
border-right: 1px solid #e1e1e1; border-right: 1px solid #e1e1e1;
} }
.chat-area { .chat-area {
width: calc(100% - 2 * var(--chat-side-width) - 2px); width: calc(100% - 2 * var(--chat-side-width) - 2px);
} }
.chat-panel { .chat-panel {
width: var(--chat-side-width); width: var(--chat-side-width);
border-left: 1px solid #e1e1e1; border-left: 1px solid #e1e1e1;
} }
</style> </style>
<template> <template>
<el-dialog title="创建会话" :visible="visible" @close="hide"> <el-dialog title="创建会话" :visible="visible" @close="hide">
选择聊天对象 选择聊天对象
{{ userList.length }} {{ userList.length }}
<el-table <el-table
v-loading="loading" v-loading="loading"
:data="userList" :data="userList"
style="width: 100%" style="width: 100%"
height="250" height="250"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
> >
<el-table-column type="selection" width="55"> </el-table-column> <el-table-column type="selection" width="55"> </el-table-column>
<el-table-column prop="id" label="id" width="150"> <el-table-column prop="id" label="id" width="150"> </el-table-column>
</el-table-column> <el-table-column prop="name" label="name" width="150"> </el-table-column>
<el-table-column prop="name" label="name" width="150"> </el-table>
</el-table-column> <el-button @click="nextPage">加载下一页</el-button>
</el-table> <span slot="footer" class="dialog-footer">
<el-button @click="nextPage">加载下一页</el-button> <el-button @click="hide">取 消</el-button>
<span slot="footer" class="dialog-footer"> <el-button type="primary" @click="createChat">确 定</el-button>
<el-button @click="hide">取 消</el-button> </span>
<el-button type="primary" @click="createChat">确 定</el-button> </el-dialog>
</span>
</el-dialog>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Vue } from "vue-property-decorator" import { Component, Vue } from "vue-property-decorator";
import { ChatStore, chatStore } from "@/customer-service/store/model" import { ChatStore, chatStore } from "@/customer-service/store/model";
import { List, ListEasy, ListTypes } from "uniplat-sdk" import type { List, ListEasy, ListTypes } from "uniplat-sdk";
import chat from "@/customer-service/xim/index"
type User = { type User = {
id: string id: string;
name: string name: string;
} };
type ThenArg<T> = T extends PromiseLike<infer U> ? U : T type ThenArg<T> = T extends PromiseLike<infer U> ? U : T;
@Component({ components: {} }) @Component({ components: {} })
export default class ChatCreator extends Vue { export default class ChatCreator extends Vue {
@chatStore.State(ChatStore.STATE_CHAT_CREATOR_VISIBLE) @chatStore.State(ChatStore.STATE_CHAT_CREATOR_VISIBLE)
private readonly visible: ChatStore.STATE_CHAT_CREATOR_VISIBLE private readonly visible!: ChatStore.STATE_CHAT_CREATOR_VISIBLE;
@chatStore.Mutation(ChatStore.MUTATION_HIDE_CHAT_CREATOR) @chatStore.Mutation(ChatStore.MUTATION_HIDE_CHAT_CREATOR)
private readonly hide: ChatStore.MUTATION_HIDE_CHAT_CREATOR private readonly hide!: ChatStore.MUTATION_HIDE_CHAT_CREATOR;
@chatStore.Action(ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN) @chatStore.Action(ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN)
private readonly _createChat: ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN private readonly _createChat!: ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN;
private currentPage = 1 private currentPage = 1;
private userList = [] private userList: {
private getList: ThenArg<ReturnType<ListEasy["query"]>>["getList"] id: any;
name: any;
}[] = [];
private getList!: ThenArg<ReturnType<ListEasy["query"]>>["getList"];
public async created() { public async created() {
const list = this.sdk.model("user").list() const list = chat.getSdk().model("user").list();
const { pageData, getList } = await list.query({ const { pageData, getList } = await list.query({
pageIndex: this.currentPage, pageIndex: this.currentPage,
item_size: 50, item_size: 50,
}) });
this.getList = getList this.getList = getList;
this.userList = this.exactUserList(pageData.rows) this.userList = this.exactUserList(pageData.rows);
} }
private exactUserList(rows: any[]) { private exactUserList(rows: any[]) {
return rows.map((k) => { return rows.map((k) => {
return { return {
id: k.id.value, id: k.id.value,
name: k.first_name.value, name: k.first_name.value,
} };
}) });
} }
private loading = false private loading = false;
private async nextPage() { private async nextPage() {
this.loading = true this.loading = true;
this.currentPage++ this.currentPage++;
const data = await this.getList(this.currentPage) const data = await this.getList(this.currentPage);
this.loading = false this.loading = false;
this.userList = [...this.userList, ...this.exactUserList(data.rows)] this.userList = [...this.userList, ...this.exactUserList(data.rows)];
} }
private selectedRows: string[] = [] private selectedRows: string[] = [];
private handleSelectionChange(selectedRows: User[]) { private handleSelectionChange(selectedRows: User[]) {
this.selectedRows = selectedRows.map((k) => String(k.id)) this.selectedRows = selectedRows.map((k) => String(k.id));
} }
private createChat() { private createChat() {
const { keyvalue, model_name } = this.$route.params const { keyvalue, model_name } = this.$route.params;
this._createChat({ this._createChat({
modelName: model_name, modelName: model_name,
selectedListId: keyvalue, selectedListId: keyvalue,
uids: this.selectedRows, uids: this.selectedRows,
}) });
} }
} }
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>
import Axios from "axios"; import Axios from "axios";
import qs from "qs"; import qs from "qs";
import chat from "../xim/index";
export function buildConfig(token: string, url: string) { export function buildConfig(token: string, url: string) {
if (url && url.includes("/general")) { if (url && url.includes("/general")) {
return { headers: { Authorization: token, CurrentOrg: this.station } }; return { headers: { Authorization: token, CurrentOrg: chat.getOrgId() } };
} }
return { headers: { Authorization: token } }; return { headers: { Authorization: token } };
} }
......
...@@ -29,7 +29,7 @@ function uniqueMessages( ...@@ -29,7 +29,7 @@ function uniqueMessages(
messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY> messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY>
) { ) {
const arr = [...messages]; const arr = [...messages];
return unique(arr, function (item, all) { return unique(arr, function(item, all) {
return all.findIndex((k) => k.id === item.id); return all.findIndex((k) => k.id === item.id);
}); });
} }
...@@ -254,7 +254,7 @@ export default { ...@@ -254,7 +254,7 @@ export default {
state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current]; 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 } = {}; const setTimeoutId: { [key: string]: number } = {};
return ( return (
state: ChatStoreState, state: ChatStoreState,
...@@ -432,7 +432,7 @@ export default { ...@@ -432,7 +432,7 @@ export default {
detailManager.done(); detailManager.done();
const { id } = await action.dryExecute(); const { id } = await action.dryExecute();
// 无法得到chat id // 无法得到chat id
await sdk() await sdk()
.model(UniplatChatModelName) .model(UniplatChatModelName)
.action("createXimChat") .action("createXimChat")
.updateInitialParams({ .updateInitialParams({
...@@ -441,9 +441,12 @@ export default { ...@@ -441,9 +441,12 @@ export default {
.dryExecute(); .dryExecute();
commit(ChatStore.MUTATION_HIDE_CHAT_CREATOR); commit(ChatStore.MUTATION_HIDE_CHAT_CREATOR);
await dispatch(ChatStore.ACTION_GET_MY_CHAT_LIST); await dispatch(ChatStore.ACTION_GET_MY_CHAT_LIST);
const newChat = state[ChatStore.STATE_MY_CHAT_ROOM_LIST].list.find( const roomList = state[ChatStore.STATE_MY_CHAT_ROOM_LIST];
if (roomList == null) return
const newChat = roomList.list.find(
(k) => k.uniplatId === id (k) => k.uniplatId === id
); );
if (newChat == null) return
commit(ChatStore.MUTATION_SHOW_CHAT); commit(ChatStore.MUTATION_SHOW_CHAT);
await dispatch(ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION, { await dispatch(ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION, {
chatId: newChat.chat_id, chatId: newChat.chat_id,
...@@ -538,10 +541,11 @@ export default { ...@@ -538,10 +541,11 @@ export default {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatId == null) return; if (chatId == null) return;
const getChatMembersResult = await xim.fetchChatMembers(chatId); const getChatMembersResult = await xim.fetchChatMembers(chatId);
if (getChatMembersResult == null) return
const chatMembers = getChatMembersResult.args[0] as ChatMember[]; const chatMembers = getChatMembersResult.args[0] as ChatMember[];
const newChatMembers = await Promise.all( const newChatMembers = await Promise.all(
chatMembers.map(async (member) => { chatMembers.map(async (member) => {
let result: ChatStore.STATE_CURRENT_CHAT_MEMBERS[number]; let result: NonNullable<ChatStore.STATE_CURRENT_CHAT_MEMBERS>[number];
try { try {
const info = await sdk() const info = await sdk()
.model("user") .model("user")
...@@ -562,13 +566,14 @@ export default { ...@@ -562,13 +566,14 @@ export default {
); );
commit( commit(
ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS, ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS,
unique(newChatMembers, function (item, all) { unique(newChatMembers, function(item, all) {
return all.findIndex((k) => k.eid === item.eid); 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]; const v = state[ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION];
if (v == null) return
const id = Number( const id = Number(
state[ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID] state[ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID]
); );
......
...@@ -30,7 +30,7 @@ export namespace ChatStore { ...@@ -30,7 +30,7 @@ export namespace ChatStore {
is_finish: 0 | 1; is_finish: 0 | 1;
}[]; }[];
total: number; total: number;
} } | null
export const STATE_CHAT_MSG_HISTORY = "某个会话聊天记录"; export const STATE_CHAT_MSG_HISTORY = "某个会话聊天记录";
export type STATE_CHAT_MSG_HISTORY = dto.MessageRequestResult | null export type STATE_CHAT_MSG_HISTORY = dto.MessageRequestResult | null
......
...@@ -44,7 +44,9 @@ class Chat { ...@@ -44,7 +44,9 @@ class Chat {
} }
public getSdk = () => { public getSdk = () => {
if (this._sdk == null) return; if (this._sdk == null) {
throw new Error("sdk shouldn't undefined")
};
return this._sdk(); return this._sdk();
}; };
...@@ -90,7 +92,7 @@ class Chat { ...@@ -90,7 +92,7 @@ class Chat {
} }
public getUserMapping() { public getUserMapping() {
return {}; return {} as any;
} }
private debug(message: string) { private debug(message: string) {
......
...@@ -145,7 +145,9 @@ export class Xim { ...@@ -145,7 +145,9 @@ export class Xim {
desc = true desc = true
): Promise<Message[]> { ): Promise<Message[]> {
this.checkConnected(); this.checkConnected();
if (this.client == null) return; if (this.client == null) {
throw new Error("client shouldn't undefined")
};
const res = await this.client.fetchChatMsgs(chatType, chatId, { const res = await this.client.fetchChatMsgs(chatType, chatId, {
lid, lid,
rid, rid,
......
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