Ant Design 抽屉(tabel)
效果图如下,因部分涉及到人员隐私,所以打码了,就是一些图片文字信息。
有不足的地方可以麻烦提出来的,一起学习的。
<template>
<a-drawer
v-model:visible="visible"
class="custom-class"
style="color: red"
:title="titles"
size="large"
width="1000px"
placement="right"
:footer-style="{ textAlign: 'right' }"
@after-visible-change="afterVisibleChange"
>
<div class="top">
<a-select
ref="select"
v-model:value="select_value"
style="width: 260px;"
size="large"
:options="select_options"
@change="handleChange"
>
</a-select>
<a-input-search
v-model:value="search_value"
style="width: 260px; margin-left: 30px;"
size="large"
placeholder="输入昵称搜索"
enter-button
@search="onSearch"
/>
</div>
<div class="zm-alert flex">
<img src="@/assets/chat/tip.png" alt="">
<div>已选择 {{numberLength}}个客户</div>
<span @click="empty">清空</span>
</div>
<div>
<a-table
:row-selection="{
selectedRowKeys: selectedRowKeys,
onChange: onSelectChange,
onSelect: onSelect,
onSelectAll: onSelectAll,
}"
:columns="columns"
:data-source="data"
:pagination="false"
>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'name'">
<span><img :src="record.img" alt="" style="width:40px;"></span>
<span style="margin-left:10px">{{ record.name }}{{record.room_name}}</span>
<span class="yellow margin-left-10" v-if="record.corp_name">@{{record.corp_name}}</span>
</template>
<template v-else-if="column.dataIndex === 'type'">
<span>
<a-tag :color="record.room_ext_type === '0'?'blue':'purple'">
{{record.room_ext_type === "0"?"内部群":"外部群"}}
</a-tag>
</span>
</template>
<template v-else>
<span>
{{record.staff}}
</span>
<a v-if="record.staff_corp_name">
@{{record.staff_corp_name}}
</a>
</template>
</template>
</a-table>
<div style="text-align:end;margin-top:10px">
<a-pagination
v-model:current="pagination.current"
:showSizeChanger="false"
:total="pagination.total"
@change="paginationChange"
show-less-items />
</div>
</div>
<template #footer>
<a-button style="margin-right: 8px" @click="onClose('no')">取消</a-button>
<a-button type="primary" @click="onClose('yes')">确定</a-button>
</template>
</a-drawer>
</template>
<script>
import {
userAllList,
roomAllList,
setBlockContact,
setBlockGroup,
} from "@/api/staffReception/otherSetting";
import { message } from "ant-design-vue";
import { reactive, ref, toRefs, getCurrentInstance } from 'vue';
export default {
emits: ["getAdminConfig"],
setup() {
const { proxy } = getCurrentInstance();
const visible = ref(false);
const state = reactive({
titles:'',//标题
select_value:'0',//Select 选择器
numberLength:0,//已选择 的客户
search_value:'',//搜索框的值
type:'',//判断是单聊还是群聊
allSingleSelectedRowKeys: [],
allGroupSelectedRowKeys: [],
selectedRowKeys:[],//已选择的客户
onceAgainRowKeys:[],//从接口返回的客户,回显
select_options:[{
value: '0',
label: '全部员工',
}],
columns : [],
data : [],
pagination:{
current:1,
pageSize:10,
total:null
}
})
const afterVisibleChange = bool => {
//抽屉关闭时清空数据
if(!bool){
state.data = []
state.selectedRowKeys = []
}
};
// 获取所有客户数据
const getUserAllList = (parmar) =>{
userAllList(parmar).then(res=>{
let selectedRowKeys = [];
//列表的数据
state.data = []
res.list.map(i =>{
let key = i.user_id+":"+i.staff_info.staff_id;
if(state.allSingleSelectedRowKeys.indexOf(key) > -1){
selectedRowKeys.push(key)
}
state.data.push({
key: key,
user_id:i.user_id,
name:i.name,
corp_name:i.corp_name,
staff:i.staff_info.name,
img:i.avatar,
staff_corp_name:i.staff_info.corp_name,
staff_id:i.staff_info.staff_id
})
})
state.selectedRowKeys = selectedRowKeys;
state.pagination.pageSize = res.pagination.pageSize
state.pagination.current = res.pagination.curPage
state.pagination.total = res.pagination.total
})
}
// 获取所有客户数据
const getRoomAllList = (parmar) =>{
roomAllList(parmar).then(res=>{
//列表的数据
let selectedRowKeys = [];
//列表的数据
state.data = []
res.list.map(i =>{
let key = i.room_chat_id +":"+ i.staff_info.staff_id;
if(state.allGroupSelectedRowKeys.indexOf(key) > -1){
selectedRowKeys.push(key)
}
state.data.push({
key:key,
room_chat_id:i.room_chat_id,
room_name:i.room_name,
room_ext_type:i.room_ext_type,
staff:i.staff_info.name,
staff_id:i.staff_info.staff_id,
corp_id:i.staff_info.corp_id,
staff_corp_name:i.staff_info.corp_name,
staff_id:i.staff_info.staff_id
})
})
state.selectedRowKeys = selectedRowKeys;
state.pagination.pageSize = res.pagination.pageSize
state.pagination.current = res.pagination.curPage
state.pagination.total = res.pagination.total
})
}
//接收父组件传过来的数据
const showDrawer = (item) => {
state.type = item.type //两个抽屉,就需要看这个type
visible.value = true; //抽屉的显示与隐藏
state.numberLength = item.specify_number
//抽屉的标题
state.titles = item.title
//列表的标题
state.columns = item.columns
//下拉框数据
state.select_options = [{
value: '0',
label: '全部员工',
}]
//select_options下拉框的数据
if(state.type === 'Single'){
item.list.map(i =>{
state.select_options.push({
value:i.open_kf_id,
label:i.channel_name,
})
})
state.onceAgainRowKeys = [] //回显示的数据
item.block_contact_list.map(k =>{
state.onceAgainRowKeys.push(k.user_id+":"+k.staff_id)
})
state.allSingleSelectedRowKeys = state.onceAgainRowKeys
getUserAllList() //调接口
}else{
item.list.map(i =>{
state.select_options.push({
value:i.open_kf_id,
label:i.channel_name,
})
})
state.onceAgainRowKeys = []
item.block_group_list.map(k =>{
state.onceAgainRowKeys.push(k.room_id+":"+k.staff_id)
})
state.allGroupSelectedRowKeys = state.onceAgainRowKeys
getRoomAllList()
}
};
//页码或 pageSize 改变的回调,参数是改变后的页码及每页条数
const paginationChange = () =>{
if(state.type === 'Single'){
getUserAllList({page:state.pagination.current})
}else{
state.data = []
getRoomAllList({page:state.pagination.current})
}
}
//Select 选择器 选中 option,或 input 的 value 变化(combobox 模式下)时
const handleChange = value => {
if(state.type === 'Single'){
getUserAllList({staff_id:value})
}else{
getRoomAllList({staff_id:value})
}
};
//搜索框事件
const onSearch = searchValue => {
if(state.type === 'Single'){
getUserAllList({search:searchValue})
}else{
getRoomAllList({search:searchValue})
}
};
//Drawer 抽屉确定保存和取消事件
const onClose = (type) => {
if(type === 'no'){ //点取消关闭就可以了
visible.value = false;
}else{
visible.value = false;
if(state.type === 'Single'){ //第一个抽屉
state.selectedRowKeys = state.allSingleSelectedRowKeys //已经选择中的数据
let obj = Object.assign({}, state.selectedRowKeys)
let obj2 = {}
let block_list = []
for(let i in obj){
let arr =obj[i].split(":")
obj2 = {
user_id:arr[0],
staff_id:arr[1]
}
block_list.push(obj2)
}
block_list = JSON.stringify(block_list)
setBlockContact({block_list:block_list}).then(res=>{
message.success("保存成功");
proxy.$emit('getAdminConfig');
})
}else{
state.selectedRowKeys = state.allGroupSelectedRowKeys
let obj = Object.assign({}, state.selectedRowKeys)
let obj2 = {}
let block_list = []
for(let i in obj){
let arr =obj[i].split(":")
obj2 = {
room_id:arr[0]+":"+arr[1],
staff_id:arr[2]
}
block_list.push(obj2)
}
block_list = JSON.stringify(block_list)
setBlockGroup({block_list:block_list}).then(res=>{
message.success("保存成功");
proxy.$emit('getAdminConfig');
})
}
}
};
//清空已选择的客户
const empty = () =>{
state.selectedRowKeys = []
if(state.type === 'Single'){
state.allSingleSelectedRowKeys = []
}else{
state.allGroupSelectedRowKeys = []
}
}
const onSelect = (record, selected, selectedRows) => {
if(state.type === 'Single'){
let index = state.allSingleSelectedRowKeys.indexOf(record.key)
if (index == -1) {
state.allSingleSelectedRowKeys.push(record.key)
}else{
state.allSingleSelectedRowKeys.splice(index, 1)
}
}else{
let index = state.allGroupSelectedRowKeys.indexOf(record.key)
if (index == -1) {
state.allGroupSelectedRowKeys.push(record.key)
}else{
state.allGroupSelectedRowKeys.splice(index, 1)
}
}
}
const onSelectAll = (selected, selectedRows, changeRows) => {
changeRows.map(item => {
onSelect(item, selected, selectedRows)
})
}
// 表格勾选事件
const onSelectChange = (selectedRowKeys,selectedRows) => {
state.selectedRowKeys = selectedRowKeys;
};
return {
...toRefs(state),
visible,
afterVisibleChange,
showDrawer,
handleChange,
onSearch,
onClose,
empty,
onSelectChange,
onSelect,
onSelectAll,
paginationChange
};
},
}
</script>
<style scoped lang="less">
.top{
display: flex;
justify-content: flex-start;
align-items: center;
}
:deep(.ant-table-thead > tr > th),
:deep(.ant-table-tbody > tr > td),
:deep(.ant-table tfoot > tr > th),
:deep(.ant-table tfoot > tr > td){
padding: 10px 16px;
}
.zm-alert{
margin:15px 0;
padding: 8px;
border-radius: 5px;
color:#000;
border:1px solid rgb(161,218,253);
background: rgb(230,247,255,0.5);
img{
width: 20px;
margin-right:6px;
}
span{
color:rgb(0, 157, 255);
font-weight: bold;
margin-left:15px;
cursor: pointer;
}
}
</style>
Ant Design 抽屉(tabel)的更多相关文章
- Ant Design(ui框架)
官方文档:https://ant.design/docs/react/introduce-cn 说明:Ant Design 是一个 ui框架,和 bootstrap 一样是ui框架.里面的组件很完善, ...
- 使用Ant Design写一个仿微软ToDo
实习期的第一份活,自己看Ant Design的官网学习,然后用Ant Design写一个仿微软ToDo. 不做教学目的,只是记录一下. 1.学习 Ant Design 是个组件库,想要会用,至少要知道 ...
- Ant Design 的一个练习小Demo
Ant Design 由蚂蚁金服团队出品, 基于 React 的组件化开发模式,封装了一套丰富而实用的 UI 组件库. 在这个练习Demo 中,按照 Ant Design 官网的教程示例,尝试使用 A ...
- 实现Ant Design 自定义表单组件
Ant Design 组件提供了Input,InputNumber,Radio,Select,uplod等表单组件,但实际开发中这是不能满足需求,同时我们希望可以继续使用Form提供的验证和提示等方法 ...
- Ant Design UI组件
Ant Design 是面向中台的 UI 设计语言. http://ant.design/
- Ant Design Pro+Electron+electron-builder实现React应用脱离浏览器,桌面安装运行
ant-design-pro ----> version :2.3.1 由于网上Ant Design Pro+Electron的资料太少,我就贡献一点经验 最近需要讲AntD Pro项目(以 ...
- button样式篇一(ant Design React)
这篇来介绍button中elementUi.iview.ant中样式结构 ant Design react ant-react中button分两个文件less: mixins.less:根据butto ...
- elementUi、iview、ant Design源码button结构篇
在看elementUI的button组件的时候,一起和iview.ant Design的button组件比 较功能.样式.代码结构,看他们的一些不同点,不同的写法哪种会好些,button的对外开放的功 ...
- 使用selenium操作ant design前端的页面,感觉页面没加载完
因需要收集页面数据,遂准备使用selenium爬取瓦斯阅读页面, 瓦斯网站使用的是ant design,元素定位非常困难,页面元素都没有ID,现在还只是能做到操作登录,不能自动打开订阅,查询某公众号, ...
- 使用Ant Design的select组件时placeholder不生效/不起作用的解决办法
先来说说使用Ant Design和Element-ui的感觉吧. 公司的项目开发中用的是vue+element-ui,使用了一通下来后,觉得element-ui虽然也有一些问题或坑,但这些小问题或坑凭 ...
随机推荐
- 利用Opencv+Python 实现二维码识别
pip3 install pyzbar 准备工作: 二维码图片,我这里直接打印在了一张A4纸上,或者直接在草料网站上生成 草料二维码生成器,存放在手机上进行显示.在安装条码扫描库的时候大家注意:z ...
- SQL CASE 标注
根据 状态值 显示中文备注 case when a.zht='0' then '录入' when a.zht='1' then '待审核' when a.zht='2' then '已审核' end ...
- 自我介绍&学习心得
这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2023learning/join?id=CfDJ8GXQNXLgcs5PrnWvMs4xAGN4cH ...
- 【B站】B站计算集数时长,调节任意倍速
打开浏览器,任意收藏一个网址,将URL替换为下面的代码并保存 打开任意B站视频页面,点击这个收藏的网址,即可在页面右边看到如下窗口 javascript: (function () { var hou ...
- 【java数据结构与算法】选择排序
选择排序原理剖析: 假设数组arr使用选择排序 每一轮选出数组最小的元素 arr.lenth个元素,只需要找出arr.length-1个元素的正确位置 选择排序便进行结束 外层for循环控制选择排序的 ...
- linux check folder files how many files
https://linuxhandbook.com/count-number-files/ tree -a
- Unity 关于可寻址资源系统Addressables的使用和理解(一) 准备工作
一.打开Unity的PackageManager,安装Addressables包 二.打开分组面板,对未来要分类的资源包进行分组,并对组进行设置. 1.菜单栏选择Window/AssetManagen ...
- Python-celery介绍与快速上手
1.celery介绍: celery是一个基于Python开发的模块,可以帮助我们在开发过程中,对任务进行分发和处理. 详细介绍取自:Python之celery的简介与 ...
- oracle学习undo之事务槽和oracle的多种提交方式
1.事务槽数量参数 每一个oracle数据块里面在数据块头部都有事务槽,事务槽的数量可以去查一下,如果数据库中的表T2: select INI_TRANS,MAX_TRANS from dba_tab ...
- 所谓的安装phpmyadmin
所谓的安装phpmyadmin, 或者 安装drush, 都是下载一个文件, 然后URL访问或者命令行访问这个文件, 进入到某个页面或者获得某个结果.刚开始觉得很神秘哦, 为什么?--安装软件分两种1 ...