Commit 87fbe974 by luyt

fix:修复省略计算方法

1 parent d51cb098
......@@ -44,9 +44,9 @@
<p>Here's some contact info</p>
</template>
</gl-tooltip> -->
<el-tooltip class="item" content="hello tooltip" placement="top-start">
<!-- <el-tooltip class="item" content="hello tooltip" placement="top-start">
<el-button>上左</el-button>
</el-tooltip>
</el-tooltip> -->
<el-popover popper-class="gl-popover" placement="top" width="600" trigger="click">
<div class="gl-popover-content">
......@@ -58,28 +58,36 @@
</div>
<el-button slot="reference">click 激活</el-button>
</el-popover>
<GLFooter></GLFooter>
<!-- width="200" -->
<!-- title="标题" -->
<el-popover
<!-- title="标题" -->
<!-- <el-popover
placement="bottom"
trigger="manual"
content="这是一段内容,这是一段内容,这是一段内容,这是一段内容。"
v-model="visible">
<el-button slot="reference" @click="visible = !visible">手动激活</el-button>
</el-popover>
</el-popover> -->
<!-- <el-popover
placement="top"
width="160"
v-model="visible">
<p>这是一段内容这是一段内容确定删除吗?</p>
<div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="visible = false">取消</el-button>
<el-button type="primary" size="mini" @click="visible = false">确定</el-button>
</div>
<el-button slot="reference">删除</el-button>
</el-popover> -->
placement="top"
width="160"
v-model="visible">
<p>这是一段内容这是一段内容确定删除吗?</p>
<div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="visible = false">取消</el-button>
<el-button type="primary" size="mini" @click="visible = false">确定</el-button>
</div>
<el-button slot="reference">删除</el-button>
</el-popover> -->
<hr />
<!-- 测试 GlTableSearch -->
<GlTableSearch></GlTableSearch>
<hr />
<!-- 测试 GLFooter -->
<GLFooter></GLFooter>
</div>
</template>
<script>
......@@ -99,14 +107,14 @@ export default {
formatter: cellValue => {
return cellValue.startTime + '-' + cellValue.endTime
},
columnattrs:{},
columnlisteners:{}
columnattrs: {},
columnlisteners: {}
},
{
label: '直播间名称',
prop: 'name',
line: 2,
width:350
line: 1,
width: 90
// children:[
// {
// label: '直播间名称1',
......@@ -250,7 +258,7 @@ export default {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
},
}
// {
// date: '2016-05-01',
// name: '王小虎',
......@@ -314,5 +322,6 @@ export default {
// padding-top: 60px;
padding-bottom: 50px;
height: 2000px;
font-size: 14px;
}
</style>
\ No newline at end of file
// const lineEllipsis = (value,columnWidth,line = 1) => {
// if (!value) return ''
// // 假设一行的宽是字的个数10 160px的宽度 一个汉字16px
// const strleng = Math.ceil(columnWidth/16) * line - 2
// if (value.length > strleng) {
// return value.substring(0, strleng) + '...'
// }
// }
// export default {
// lineEllipsis
// }
const lineEllipsis = (value,columnWidth,line = 1) => {
if (!value) return ''
// 假设一行的宽是字的个数10 160px的宽度 一个汉字16px
const strleng = Math.ceil(columnWidth/16) * line - 2
// 单元格左右的宽为16
const strleng = Math.ceil((columnWidth-36)/16) * line - 2
if (value.length > strleng) {
return value.substring(0, strleng) + '...'
}
......
import GlTableSearch from './src/index.vue'
// 为组件提供 install 安装方法,供按需引入
GlTableSearch.install = function(Vue) {
Vue.component(GlTableSearch.name, GlTableSearch)
}
// 默认导出组件
export default GlTableSearch
\ No newline at end of file
<template>
<div class="gl-table-search" :class="operateText?'':'gl-tableh56'">
<div class="gl-search">
<div class="gl-search-right">
<i class="gl-right-icon">*</i>
标签文本栏:
</div>
<div class="gl-search-left">
<el-input size="medium" placeholder="请输入内容" suffix-icon="el-icon-date" v-model="input2"></el-input>
</div>
</div>
<div class="gl-search">
<div class="gl-search-right">
<i class="gl-right-icon">*</i>
标签文本栏:
</div>
<div class="gl-search-left">
<el-input size="medium" placeholder="请输入内容" suffix-icon="el-icon-date" v-model="input2"></el-input>
</div>
</div>
<div class="gl-search-btn">
<el-button size="small" plain>重置</el-button>
<el-button size="small" type="primary">查询</el-button>
</div>
<div class="gl-operate" @click="opeOrCloseFn">
<span class="gl-operate-text">{{operateText?'收起':'展开'}}</span>
<i :class="operateText? 'el-icon-arrow-up':'el-icon-arrow-down'"></i>
</div>
</div>
</template>
<script>
export default {
name: 'GlTableSearch',
props: {},
data() {
return {
input2: '',
operateText:false
}
},
created() {},
mounted() {},
methods: {
opeOrCloseFn(){
this.operateText = !this.operateText
}
},
components: {},
computed: {}
}
</script>
<style lang='scss'>
.gl-table-search {
// padding-bottom: 20px;
&.gl-tableh56{
height:56px;
}
display: flex;
align-items: flex-start;
height:200px;
.gl-search {
padding-bottom: 20px;
width: 100%;
display: flex;
align-items: center;
.gl-search-right {
width: 118px;
text-align: right;
.gl-right-icon {
color: #eb4e4e;
}
}
.gl-search-left {
flex: 1;
min-width: 136px;
}
}
.gl-search-btn{
height: 36px;
padding-top:2px;
padding-bottom:2px;
display: flex;
padding-left: 30px;
padding-right: 20px;
box-sizing: border-box;
.el-button+.el-button{
margin-left: 12px;
}
}
.gl-operate{
width: 130px;
height: 36px;
display: flex;
align-items: center;
color: $color-primary;
cursor: pointer;
.gl-operate-text{
margin-right: 5px;
}
}
}
</style>
\ No newline at end of file
......@@ -13,7 +13,7 @@
<template slot-scope="scope">
<slot v-if="item.addHtml" :name="item.addHtml" :scope="scope.row" :prop="item.prop" :width="item.width"></slot>
<template v-else-if="item.formatter">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil(item.width / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="item.formatter(scope.row)">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil((item.width-36) / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="item.formatter(scope.row)">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ item.formatter(scope.row) | lineEllipsis(item.width, item.line) }}
</span>
......@@ -23,7 +23,7 @@
</span>
</template>
<template v-else-if="getListApi">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil(item.width / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="scope.row[item.prop]">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil((item.width-36) / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="scope.row[item.prop]">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ scope.row[item.prop] | lineEllipsis(item.width, item.line) }}
</span>
......@@ -35,7 +35,7 @@
<template v-else>
<!-- 大于10或 20个字节长度 宽度160px -->
<el-popover v-if="tableData[scope.$index][item.prop] && tableData[scope.$index][item.prop].length >= Math.ceil(item.width / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="tableData[scope.$index][item.prop]">
<el-popover v-if="tableData[scope.$index][item.prop] && tableData[scope.$index][item.prop].length >= Math.ceil((item.width-36) / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="tableData[scope.$index][item.prop]">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ tableData[scope.$index][item.prop] | lineEllipsis(item.width, item.line) }}
</span>
......
......@@ -4,7 +4,7 @@
<template slot-scope="scope">
<slot v-if="item.addHtml" :name="item.addHtml" :scope="scope.row" :prop="item.prop" :width="item.width"></slot>
<template v-else-if="item.formatter">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil(item.width / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="item.formatter(scope.row)">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil((item.width-36) / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="item.formatter(scope.row)">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ item.formatter(scope.row) | lineEllipsis(item.width, item.line) }}
</span>
......@@ -13,7 +13,7 @@
</template>
<template v-else-if="getListApi">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil(item.width / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="scope.row[item.prop]">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil((item.width-36) / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="scope.row[item.prop]">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ scope.row[item.prop] | lineEllipsis(item.width, item.line) }}
</span>
......@@ -24,7 +24,7 @@
<template v-else>
<!-- 大于10或 20个字节长度 -->
<el-popover v-if="tableData[scope.$index][item.prop] && tableData[scope.$index][item.prop].length >= Math.ceil(item.width / 16) * item.line" placement="top" width="200" trigger="hover" :content="tableData[scope.$index][item.prop]">
<el-popover v-if="tableData[scope.$index][item.prop] && tableData[scope.$index][item.prop].length >= Math.ceil((item.width-36) / 16) * item.line" placement="top" width="200" trigger="hover" :content="tableData[scope.$index][item.prop]">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ tableData[scope.$index][item.prop] | lineEllipsis(item.width, item.line) }}
</span>
......
......@@ -15,7 +15,7 @@
*
*/
import Vue from 'vue'
import { Table, TableColumn, Popover, Button, ButtonGroup, Loading, Input, Form, FormItem, Pagination, Tooltip } from 'element-ui'
import { Table, TableColumn, Popover, Button, ButtonGroup, Loading, Input, Form, FormItem, Pagination, Tooltip,Icon } from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css' //todo 按需引入插件样式
import 'element-ui/lib/theme-chalk/table.css'
import 'element-ui/lib/theme-chalk/table-column.css'
......@@ -28,6 +28,7 @@ import 'element-ui/lib/theme-chalk/form.css'
import 'element-ui/lib/theme-chalk/form-item.css'
import 'element-ui/lib/theme-chalk/pagination.css'
import 'element-ui/lib/theme-chalk/tooltip.css'
import 'element-ui/lib/theme-chalk/icon.css'
// 解决 ElTable 自动宽度高度导致的「ResizeObserver loop limit exceeded」问题
const fixElTableErr = table => {
......@@ -50,9 +51,9 @@ Vue.use(Form)
Vue.use(FormItem)
Vue.use(Pagination)
Vue.use(Tooltip)
Vue.use(Icon)
//打包后的组件dist 测试组件可能需要的
export {
Table, TableColumn, Popover, Button, ButtonGroup, Loading, Input, Form, FormItem, Pagination, Tooltip
Table, TableColumn, Popover, Button, ButtonGroup, Loading, Input, Form, FormItem, Pagination, Tooltip, Icon
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!