Ant Design Vue table中列超长显示...并加提示语的实例


Posted in Javascript onOctober 31, 2020

我就废话不多说了,大家还是直接看代码吧~

<template>
 <a-row class="a-left">
 <a-row>
 <p class="a-title">今日考勤状况</p>
 <a-row type="flex" justify="space-around">
 <a-col :span="4" class="block">
  <h3>出勤状况总览</h3>
  {{ cntAll.cnt }}/
  <span style="color: #F0FF00">{{ cntAll.exceptionCount }}</span>
 </a-col>
 <a-col :span="4" class="block">
  <h3>管理人员出勤状况</h3>
  {{ cntLeader.cnt }}/
  <span style="color: #F0FF00">{{ cntLeader.exceptionCount }}</span>
 </a-col>
 <a-col :span="4" class="block">
  <h3>施工人员出勤状况</h3>
  {{ cntSpecial.cnt }}/
  <span style="color: #F0FF00">{{ cntSpecial.exceptionCount }}</span>
 </a-col>
 <a-col :span="4" class="block">
  <h3>特种设备人员出勤状况</h3>
  {{ cntEmployee.cnt }}/
  <span style="color: #F0FF00">{{ cntEmployee.exceptionCount }}</span>
 </a-col>
 </a-row>
 </a-row>
 <a-row class="a-mt-20">
 <h3 class="a-title">考勤记录查询</h3>
 </a-row>
 <!--查询条件-->
 <a-form :form="form" layout="inline">
 <a-form-item label="姓名">
 <a-input class="a-input" v-model="queryParam.name" placeholder="请输入姓名" :disabled="loading" />
 </a-form-item>
 <a-form-item label="日期">
 <y-date-picker :start.sync="queryParam.startDate1" :end.sync="queryParam.endDate1" :disabled="loading" />
 </a-form-item>
 <a-form-item>
 <a-button :disabled="loading" class="a-ml-10 a-btn" icon="search" @click="searchData">查询</a-button>
 <a-button :disabled="loading" class="a-btn a-ml-10" icon="reload" @click="reset">刷新</a-button>
 </a-form-item>
 </a-form>
 <!--查询结果-->
 <a-row class="a-pt-20 a-pt-10">
 <a-col :span="6">
 <p class="a-title">查询结果</p>
 </a-col>
 <a-col :span="6" :offset="12" class="a-right">
 <a-button :disabled="loading" class="a-ml-10 a-btn" icon="file-pdf" @click="exportData">导出</a-button>
 </a-col>
 <a-table
 class="ant-table"
 :row-key="uuid"
 :columns="columns"
 :data-source="RenYuanKaoQin.data"
 :loading="loading"
 :pagination="{
  position: 'bottom',
  total: Number(RenYuanKaoQin.total),
  current: Number(queryParam.pageNumber),
  pageSize: Number(queryParam.pageSize),
  showSizeChanger: true,
  pageSizeOptions: ['7', '14', '21'],
  showTotal: total => `总共有${total}条`
 }"
 :scroll="{x:1300, y: 'calc(100vh - 600px)' }"
 :locale="{ emptyText: '暂未找到符合条件的结果' }"
 @change="tableChange"
 >
 <!--操作-->
 <template slot="action" slot-scope="text, record">
  <a href="javascript:;" rel="external nofollow" @click="intoDetail(record)">详情</a>
 </template>
 <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
 //处理超长生成...,并加上提示文字代码
 <div :style="{maxWidth: '180px',whiteSpace: 'nowrap',textOverflow: 'ellipsis',overflow: 'hidden', wordWrap: 'break-word', wordBreak: 'break-all' }" slot="groupName" slot-scope="text, record">
  <a-tooltip placement="left">
  <template slot="title">
  <span>{{record.groupName}}</span>
  </template>
  {{record.groupName}}
  </a-tooltip>
 </div>
 </a-table>
 </a-row>
 </a-row>
</template>
<script>
import { YDatePicker } from '@/components/Form'
import { mapGetters, mapActions } from 'vuex'
import { clone, get, now } from 'lodash'

export default {
 name: 'RenYuan-KaoQin',
 components: { YDatePicker },
 metaInfo: {
 title: '考勤记录'
 },
 data() {
 return {
 loading: false,
 form: this.$form.createForm(this),
 initQueryParam: {},
 queryParam: {
 pageNumber: 1,
 pageSize: 7,
 name: '',
 startDate1: '',
 endDate1: ''
 },
 columns: [
 { title: '序号', align: 'center', width: 80, scopedSlots: { customRender: 'serial' } },
 { title: '姓名', align: 'center', width: 150, dataIndex: 'memberName' },
 { title: '签到时间', align: 'center', width: 250, dataIndex: 'inTimeNew' },
 { title: '签退时间', align: 'center', width: 250, dataIndex: 'outTimeNew' },
 { title: '出勤时间', align: 'center', width: 150, dataIndex: 'jgHour' },
 { title: '所属劳动组织', align: 'center', width: 200, scopedSlots: { customRender: 'groupName' } },//这里groupName指向 div中slot="groupName"
 { title: '专业分工', align: 'center', width: 150, dataIndex: 'workTypeNew' },
 { title: '人员类别', align: 'center', dataIndex: 'personnelTypeStr' }
 ]
 }
 },
 computed: {
 ...mapGetters(['RenYuanKaoQin']),
 cntAll() {
 return { cnt: get(this.RenYuanKaoQin, 'count.cntAll[0].cnt'), exceptionCount: get(this.RenYuanKaoQin, 'count.cntAll[0].exceptionCount') }
 },
 cntSpecial() {
 return {
 cnt: get(this.RenYuanKaoQin, 'count.cntSpecial[0].cnt'),
 exceptionCount: get(this.RenYuanKaoQin, 'count.cntSpecial[0].exceptionCount')
 }
 },
 cntLeader() {
 return { cnt: get(this.RenYuanKaoQin, 'count.cntLeader[0].cnt'), exceptionCount: get(this.RenYuanKaoQin, 'count.cntLeader[0].exceptionCount') }
 },
 cntEmployee() {
 return {
 cnt: get(this.RenYuanKaoQin, 'count.cntEmployee[0].cnt'),
 exceptionCount: get(this.RenYuanKaoQin, 'count.cntEmployee[0].exceptionCount')
 }
 }
 },
 beforeRouteUpdate(to, from, next) {
 next()
 this.getData()
 },
 beforeRouteEnter(to, from, next) {
 next(async vm => {
 vm.initQueryParam = clone(vm.queryParam) // 初始表单
 vm.getRenYuanKaoQinCount({ xmbh: vm.$store.state.route.params.xmbh })
 vm.getData()
 })
 },
 methods: {
 ...mapActions(['getRenYuanKaoQin', 'getRenYuanKaoQinCount']),
 uuid() {
 return now() + Math.random()
 },
 /** 清空查询条件 */
 reset() {
 this.queryParam = clone(this.initQueryParam)
 this.form.resetFields()
 this.getData()
 },
 /** 获取表格数据 */
 async getData() {
 this.loading = true
 await this.getRenYuanKaoQin({
 xmbh: this.$store.state.route.params.xmbh,
 ...this.queryParam
 })
 this.loading = false
 },
 /** 表格数据变化 */
 tableChange(pagination) {
 this.queryParam.pageSize = pagination.pageSize
 this.queryParam.pageNumber = pagination.current
 this.getData()
 },
 searchData() {
 this.queryParam.pageNumber = 1
 this.getData()
 }
 }
}
</script>
<style lang="stylus" scoped>
.block {
 height: 86px;
 padding: 10px 0;
 box-sizing: border-box;
 background: url('../../../assets/home/bg.png') no-repeat;
 background-size: 100% 100%;
 text-align: center;
 font-size: 20px;

 h3 {
 text-align: center;
 font-size: 18px;
 }

 span {
 font-size: 20px;
 }
}
</style>

补充知识:ant-design table 中的td 数据过多显示部分,鼠标放上去显示全部

第一:表格中的数据自动换行,所以表格中的行高不一致

目标实现:防止自动换行,

代码实现://*** 是主要实现

:global {
 .ant-table-tbody > tr > td,
 .ant-table-thead > tr > th {
 height: 62px;
 white-space:nowrap;//***
 overflow: auto;//***
 }
 .ant-table-thead > tr > th {
 background: #2db7f5;
 white-space:nowrap;//***
 overflow: auto;//***
 }

第二:上述目标实现,但是全部显示出来

目标实现:指定td的数据显示部分以及...,当鼠标放上去显示全部

代码实现:

const webColumns = [
 {
 title: 'IP',
 dataIndex: 'srcIp',
 key: 'srcIp',
 width:'15%',
 },{
 title: '描述',
 dataIndex: 'msg',
 key: 'msg',
 //width:'8%',
 onCell: ()=>{
 return {
  style:{
  maxWidth:260,
  overflow:'hidden',
  whiteSpace:'nowrap',
  textOverflow:'ellipsis',
  cursor:'pointer',
  }
 }
 },
 render: (text) => <span placement="topLeft" title={text}>{text}</span>,
 }
 ]

其中 oncell()以下为主要实现。

以上这篇Ant Design Vue table中列超长显示...并加提示语的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
用一段js程序来实现动画功能
Mar 06 Javascript
ExtJS中文乱码之GBK格式编码解决方案及代码
Jan 20 Javascript
使用非html5实现js板连连看游戏示例代码
Sep 22 Javascript
javascript设计模式--策略模式之输入验证
Nov 27 Javascript
javascript实现自动填写表单实例简析
Dec 02 Javascript
jQuery循环遍历子节点并获取值的方法
Apr 14 Javascript
jQuery实现的选择商品飞入文本框动画效果完整实例
Aug 10 Javascript
浅谈jquery页面初始化的4种方式
Nov 27 Javascript
详解使用fetch发送post请求时的参数处理
Apr 05 Javascript
vue-router 中router-view不能渲染的解决方法
May 23 Javascript
微信小程序实现顶部选项卡(swiper)
Jun 19 Javascript
利用d3.js制作连线动画图与编辑器的方法实例
Sep 05 Javascript
vue中可编辑树状表格的实现代码
Oct 31 #Javascript
Ant Design Pro 之 ProTable使用操作
Oct 31 #Javascript
react ant Design手动设置表单的值操作
Oct 31 #Javascript
解决pycharm双击但是无法打开的情况
Oct 31 #Javascript
antd的select下拉框因为数据量太大造成卡顿的解决方式
Oct 31 #Javascript
antd design table更改某行数据的样式操作
Oct 31 #Javascript
antd配置config-overrides.js文件的操作
Oct 31 #Javascript
You might like
使用PHP实现二分查找算法代码分享
2011/06/24 PHP
PHP中的闭包(匿名函数)浅析
2015/02/07 PHP
tp5实现微信小程序多图片上传到服务器功能
2018/07/16 PHP
PHP上传图片到数据库并显示的实例代码
2019/12/20 PHP
基于JQuery框架的AJAX实例代码
2009/11/03 Javascript
js实现动态改变字体大小代码
2014/01/02 Javascript
AngularJS基础知识笔记之表格
2015/05/10 Javascript
原生JS实现拖拽图片效果
2020/08/27 Javascript
AngularJS教程 ng-style 指令简单示例
2016/08/03 Javascript
js原生跨域_用script标签的简单实现
2016/09/24 Javascript
bootstrap table之通用方法( 时间控件,导出,动态下拉框, 表单验证 ,选中与获取信息)代码分享
2017/01/24 Javascript
vue.js实现条件渲染的实例代码
2017/06/22 Javascript
一步步教你利用Canvas对图片进行处理
2017/09/19 Javascript
js传递数组参数到后台controller的方法
2018/03/29 Javascript
vue-router 起步步骤详解
2019/03/26 Javascript
微信小程序表单验证插件WxValidate的二次封装功能(终极版)
2019/09/03 Javascript
layer.open 获取不到表单信息的解决方法
2019/09/26 Javascript
[01:16]2014DOTA2 TI专访C9战队EE:中国五强中会占三席
2014/07/10 DOTA
从源码解析Python的Flask框架中request对象的用法
2016/06/02 Python
Python基于jieba库进行简单分词及词云功能实现方法
2018/06/16 Python
Python使用matplotlib实现基础绘图功能示例
2018/07/03 Python
Python中使用pypdf2合并、分割、加密pdf文件的代码详解
2019/05/21 Python
pyqt5 comboBox获得下标、文本和事件选中函数的方法
2019/06/14 Python
Python中的四种交换数值的方法解析
2019/11/18 Python
Python判断远程服务器上Excel文件是否被人打开的方法
2020/07/13 Python
全面总结使用CSS实现水平垂直居中效果的方法
2016/03/10 HTML / CSS
选购世界上最好的美妆品:Cult Beauty
2017/11/03 全球购物
Move Free官方海外旗舰店:美国骨关节健康专业品牌
2017/12/06 全球购物
陈安之励志演讲稿
2014/08/21 职场文书
2014年庆祝国庆65周年演讲稿
2014/09/21 职场文书
向女朋友道歉的话
2015/01/20 职场文书
交通事故起诉书
2015/05/19 职场文书
只需要12页,掌握撰写一流商业计划书的技巧
2019/05/07 职场文书
应届生们该怎么书写求职信?
2019/07/05 职场文书
Python 图片添加美颜效果
2022/04/28 Python
python神经网络Xception模型
2022/05/06 Python