Commit be4ca619 by panjiangyi

创建会话

parent 513b4187
Showing with 199 additions and 83 deletions
<template> <template>
<el-dialog title="创建会话" :visible="visible" @close="hide"> <el-dialog
选择聊天对象 class="create-chat"
{{ userList.length }} title="创建会话"
<el-table :visible="visible"
v-loading="loading" @close="hide"
:data="userList"
style="width: 100%"
height="250"
@selection-change="handleSelectionChange"
> >
<el-table-column type="selection" width="55"> </el-table-column> <div class="search-bar">
<el-table-column prop="id" label="id" width="150"> </el-table-column> <span class="search-title">用户搜索: </span>
<el-table-column prop="name" label="name" width="150"> </el-table-column> <el-input class="search-input" v-model="searchText"></el-input>
</el-table> <el-button
<el-button @click="nextPage">加载下一页</el-button> style="margin-left: auto"
<span slot="footer" class="dialog-footer"> type="primary"
<el-button @click="hide">取 消</el-button> size="medium"
<el-button type="primary" @click="createChat">确 定</el-button> @click="search"
</span> >筛选</el-button
</el-dialog> >
</div>
<div v-loading="loading">
<div
v-for="user in userList"
:key="user.id"
class="user-con"
:class="{ isChoosed:isChoosed(user.id) }"
@click="onClickUser(user.id)"
>
<avatar />
<span class="user-name">{{ user.name }}</span>
</div>
</div>
<el-pagination
:current-page.sync="currentPage"
class="fs-pager"
layout="prev, pager, next"
:total="total"
:page-size="pageSize"
></el-pagination>
<span slot="footer" class="dialog-footer">
<el-button @click="hide">取 消</el-button>
<el-button type="primary" @click="createChat">确 定</el-button>
</span>
</el-dialog>
</template> </template>
<script lang="ts"> <script lang="ts">
import type { ListEasy, } from "uniplat-sdk"; import { ListEasy, ListTypes } from "uniplat-sdk";
import { Component, Vue } from "vue-property-decorator"; import { Component, Vue, Watch } from "vue-property-decorator";
import buttonThrottle from "./utils/button-throttle";
import avatar from "@/customer-service/components/avatar.vue";
import { ChatStore, chatStore } from "@/customer-service/store/model"; import { ChatStore, chatStore } from "@/customer-service/store/model";
import chat from "@/customer-service/xim/index"; 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: { avatar } })
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; @Watch("currentPage")
private userList: { private pageChange() {
id: any; this.nextPage();
name: any; }
}[] = [];
@Watch("visible")
private getList!: ThenArg<ReturnType<ListEasy["query"]>>["getList"]; private onvisibleChange() {
if (this.visible) {
public async created() { this.selectedUsers = [];
const list = chat.getSdk().model("user").list(); }
const { pageData, getList } = await list.query({ }
pageIndex: this.currentPage,
item_size: 50, private searchText = "";
}); private currentPage = 1;
this.getList = getList; private total = 0;
this.userList = this.exactUserList(pageData.rows); private pageSize = 15;
} private selectedUsers: number[] = [];
private userList: {
private exactUserList(rows: any[]) { id: any;
return rows.map((k) => { name: any;
return { }[] = [];
id: k.id.value,
name: k.first_name.value, private getList!: ThenArg<ReturnType<ListEasy["query"]>>["getList"];
};
}); public created() {
} this.getUserList();
}
private loading = false;
private async nextPage() { private async getUserList(searchText: string | null = null) {
this.loading = true; this.loading = true;
this.currentPage++; const list = chat.getSdk().model("user").list();
const data = await this.getList(this.currentPage); if (searchText) {
this.loading = false; list.addFilter({
this.userList = [...this.userList, ...this.exactUserList(data.rows)]; property: "first_name",
} value: searchText,
match: ListTypes.filterMatchType.fuzzy,
private selectedRows: string[] = []; });
private handleSelectionChange(selectedRows: User[]) { }
this.selectedRows = selectedRows.map((k) => String(k.id)); const { pageData, getList } = await list.query({
} pageIndex: this.currentPage,
item_size: this.pageSize,
private createChat() { });
const { keyvalue, model_name } = this.$route.params; this.total = pageData.record_count;
this._createChat({ this.getList = getList;
modelName: model_name, this.userList = this.exactUserList(pageData.rows);
selectedListId: keyvalue, this.loading = false;
uids: this.selectedRows, }
});
} private exactUserList(rows: any[]) {
return rows.map((k) => {
return {
id: k.id.value,
name: k.first_name.value,
};
});
}
private search() {
this.currentPage = 1;
this.getUserList(this.searchText);
}
private loading = false;
@buttonThrottle()
private async nextPage() {
this.loading = true;
const data = await this.getList(this.currentPage);
this.loading = false;
this.userList = this.exactUserList(data.rows);
}
private isChoosed(id: number) {
return this.selectedUsers.includes(id);
}
private onClickUser(id: number) {
if (this.isChoosed(id)) {
this.removeUser(id);
} else {
this.addUser(id);
}
}
private addUser(id: number) {
this.selectedUsers.push(id);
}
private removeUser(id: number) {
this.selectedUsers = this.selectedUsers.filter((_id) => _id !== id);
}
@buttonThrottle()
private createChat() {
const { keyvalue, model_name } = this.$route.params;
this._createChat({
modelName: model_name,
selectedListId: keyvalue,
uids: this.selectedUsers.map(id => String(id))
});
}
} }
</script> </script>
<style lang="less" scoped></style> <style lang="less" scoped>
.create-chat {
/deep/ .el-dialog__body {
padding: 30px 40px;
}
}
.user-con {
display: inline-flex;
vertical-align: top;
width: 33.33%;
align-items: center;
margin-bottom: 40px;
cursor: pointer;
&.isChoosed {
outline: 1px solid #3285FF;
}
}
.user-name {
height: 15px;
font-size: 15px;
color: #000000;
line-height: 15px;
margin-left: 20px;
}
.search-bar {
display: flex;
align-items: center;
background: #f5f6fa;
padding: 12px 20px;
box-sizing: border-box;
margin-bottom: 30px;
}
.search-input {
width: 160px;
margin-left: 10px;
/deep/ .el-input__inner {
border: 1px solid rgba(229, 230, 236, 1);
border-radius: 0;
padding-left: 21px;
}
}
</style>
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