Commit 86932012 by panjiangyi

格式化代码

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