Files
zb-table/pages/index/index.vue

417 lines
12 KiB
Vue
Raw Normal View History

2022-03-02 10:56:22 +08:00
<template>
<view class="content">
2022-03-10 15:03:34 +08:00
<uni-card title="全部功能" >
2022-03-16 10:28:25 +08:00
<view style="height: 300px">
2022-03-10 15:03:34 +08:00
<zb-table
:show-header="true"
:columns="column"
:fit="false"
2022-03-11 10:19:21 +08:00
@rowClick="rowClick"
2022-03-10 15:03:34 +08:00
@toggleRowSelection="toggleRowSelection"
@toggleAllSelection="toggleAllSelection"
:border="true"
@edit="buttonEdit"
@dele="dele"
:data="data"></zb-table>
</view>
</uni-card>
<uni-card title="普通表格" >
<view style="height: 200px">
<zb-table
:show-header="true"
:columns="column1"
:stripe="true"
:fit="false"
2022-03-11 10:19:21 +08:00
@rowClick="rowClick"
2022-03-10 15:03:34 +08:00
@toggleRowSelection="toggleRowSelection"
@toggleAllSelection="toggleAllSelection"
@edit="buttonEdit"
@dele="dele"
:data="data"></zb-table>
</view>
</uni-card>
<uni-card title="带边框表格" >
<view style="height: 200px">
<zb-table
:show-header="true"
:columns="column1"
:stripe="true"
:fit="false"
2022-03-11 10:19:21 +08:00
@rowClick="rowClick"
2022-03-10 15:03:34 +08:00
@toggleRowSelection="toggleRowSelection"
@toggleAllSelection="toggleAllSelection"
:border="true"
@edit="buttonEdit"
@dele="dele"
:data="data"></zb-table>
</view>
</uni-card>
<uni-card title="多选,多行数据时使用 Checkbox" >
<view style="height: 200px">
<zb-table
:show-header="true"
:columns="column2"
:stripe="true"
:fit="false"
2022-03-11 10:19:21 +08:00
@rowClick="rowClick"
2022-03-10 15:03:34 +08:00
@toggleRowSelection="toggleRowSelection"
@toggleAllSelection="toggleAllSelection"
:border="true"
@edit="buttonEdit"
@dele="dele"
:data="data"></zb-table>
</view>
</uni-card>
<uni-card title="固定多列和表头" >
<view style="height: 200px">
<zb-table
:show-header="true"
:columns="column3"
:stripe="true"
:fit="false"
2022-03-11 10:19:21 +08:00
@rowClick="rowClick"
2022-03-10 15:03:34 +08:00
@toggleRowSelection="toggleRowSelection"
@toggleAllSelection="toggleAllSelection"
:border="true"
@edit="buttonEdit"
@dele="dele"
:data="data"></zb-table>
</view>
</uni-card>
<uni-card title="年纪、日期排序" >
<view style="height: 200px">
<zb-table
:show-header="true"
:columns="column4"
:stripe="true"
:fit="false"
2022-03-11 10:19:21 +08:00
@rowClick="rowClick"
2022-03-10 15:03:34 +08:00
@toggleRowSelection="toggleRowSelection"
@toggleAllSelection="toggleAllSelection"
:border="true"
@edit="buttonEdit"
@dele="dele"
:data="data"></zb-table>
</view>
</uni-card>
2022-03-17 17:16:24 +08:00
<uni-card title="表尾合计" >
<view style="height: 300px">
<zb-table
:show-header="true"
:columns="column"
:fit="false"
:show-summary="true"
:summary-method="getSummaries"
@rowClick="rowClick"
@toggleRowSelection="toggleRowSelection"
@toggleAllSelection="toggleAllSelection"
:border="true"
@edit="buttonEdit"
@dele="dele"
2022-03-18 14:58:06 +08:00
:data="data1"></zb-table>
</view>
</uni-card>
<uni-card title="上拉加载" >
<view style="height: 300px">
<zb-table
:show-header="true"
:columns="column"
:fit="false"
:summary-method="getSummaries"
@rowClick="rowClick"
@toggleRowSelection="toggleRowSelection"
@toggleAllSelection="toggleAllSelection"
:border="true"
@edit="buttonEdit"
@dele="dele"
:data="data1"></zb-table>
2022-03-17 17:16:24 +08:00
</view>
</uni-card>
2022-03-09 19:20:51 +08:00
2022-03-02 10:56:22 +08:00
</view>
</template>
<script>
2022-03-10 15:03:34 +08:00
import {column1,column2,column3,column4} from './all.js'
2022-03-02 10:56:22 +08:00
export default {
components:{
},
data() {
return {
2022-03-10 15:03:34 +08:00
column1,
column2,
column3,
column4,
2022-03-02 10:56:22 +08:00
title: 'Hello',
2022-03-14 11:34:29 +08:00
2022-03-02 10:56:22 +08:00
column:[
2022-03-16 10:28:25 +08:00
{ type:'selection', fixed:true,width:60 },
2022-03-14 11:34:29 +08:00
{ name: 'name', label: '姓名',fixed:true,width:80,emptyString:'--' },
{ name: 'age', label: '年纪',sorter:true,align:'right',fixed:false, },
2022-03-09 11:53:54 +08:00
{ name: 'sex', label: '性别',filters:{0:'男',1:'女'}},
2022-03-16 10:28:25 +08:00
{ name: 'price', label: '价格'},
2022-03-02 10:56:22 +08:00
{ name: 'address', label: '地址' },
{ name: 'date', label: '日期',sorter:true },
{ name: 'province', label: '省份' },
{ name: 'city', label: '城市' },
{ name: 'zip', label: '邮编' },
2022-03-14 11:34:29 +08:00
{ name: 'img', label: '图片',type:"img",align: "center" },
2022-03-09 11:53:54 +08:00
{ name: 'operation', type:'operation',label: '操作',renders:[
2022-03-08 17:54:47 +08:00
{
name:'编辑',
func:'edit' // func 代表子元素点击的事件 父元素接收的事件 父元素 @edit
},
{
name:'删除',
type:'warn',
func:"dele"
2022-03-09 11:53:54 +08:00
},
2022-03-08 17:54:47 +08:00
]},
2022-03-02 10:56:22 +08:00
],
data:[
{
date: '2016-05-02',
2022-03-08 17:54:47 +08:00
name: '',
2022-03-16 10:28:25 +08:00
price: 1,
2022-03-02 10:56:22 +08:00
province: '上海',
2022-03-09 11:53:54 +08:00
sex:'1',
2022-03-11 10:19:21 +08:00
checked:true,
2022-03-09 19:20:51 +08:00
id:"20",
2022-03-14 11:34:29 +08:00
img:"https://img1.baidu.com/it/u=300787145,1214060415&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
2022-03-08 17:54:47 +08:00
age:'',
2022-03-02 10:56:22 +08:00
city: '普陀区',
2022-03-02 15:00:38 +08:00
address: '上海市普上海市普上海市普上海市普',
2022-03-02 10:56:22 +08:00
zip: 200333
},
{
date: '2016-05-01',
name: '王小虎2',
province: '上海',
2022-03-09 11:53:54 +08:00
sex:'0',
2022-03-16 10:28:25 +08:00
price: 22,
2022-03-09 11:53:54 +08:00
id:"2",
2022-03-02 10:56:22 +08:00
age:12,
city: '普陀区',
2022-03-14 11:34:29 +08:00
img:"https://img.pddpic.com/mms-material-img/2020-11-27/84c7fad3-d945-4e71-ab09-7a1ed80f6055.jpeg.a.jpeg",
2022-03-02 10:56:22 +08:00
address: '上海市普',
zip: 200333
},
{
date: '2016-05-02',
name: '王小虎3',
province: '上海',
2022-03-09 11:53:54 +08:00
sex:1,
2022-03-16 10:28:25 +08:00
price: 33,
2022-03-09 11:53:54 +08:00
id:"3",
2022-03-02 10:56:22 +08:00
age:'15',
2022-03-14 11:34:29 +08:00
img:"https://img1.baidu.com/it/u=300787145,1214060415&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
2022-03-02 10:56:22 +08:00
city: '普陀区',
address: '上海市普',
zip: 200333
},
{
date: '2016-04-02',
name: '王小虎4',
province: '上海',
2022-03-09 11:53:54 +08:00
sex:1,
2022-03-02 10:56:22 +08:00
age:'11',
2022-03-16 10:28:25 +08:00
price: 33,
2022-03-09 11:53:54 +08:00
id:"4",
2022-03-14 11:34:29 +08:00
img:"https://img1.baidu.com/it/u=300787145,1214060415&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
2022-03-02 10:56:22 +08:00
city: '普陀区',
address: '上海市普',
zip: 200333
},
{
date: '2016-03-02',
name: '王小虎5',
province: '上海',
2022-03-16 10:28:25 +08:00
price: 33,
2022-03-09 11:53:54 +08:00
sex:1,
2022-03-02 10:56:22 +08:00
age:'14',
2022-03-14 11:34:29 +08:00
img:"https://img1.baidu.com/it/u=300787145,1214060415&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
2022-03-09 11:53:54 +08:00
id:"5",
2022-03-02 10:56:22 +08:00
city: '普陀区',
address: '上海市普',
zip: 200333
},{
date: '2014-05-02',
name: '王小虎6',
province: '上海',
2022-03-16 10:28:25 +08:00
price: 33,
2022-03-09 11:53:54 +08:00
sex:1,
id:"6",
2022-03-02 10:56:22 +08:00
age:'12',
2022-03-14 11:34:29 +08:00
img:"https://img1.baidu.com/it/u=300787145,1214060415&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
2022-03-02 10:56:22 +08:00
city: '普陀区',
address: '上海市普',
zip: 200333
},{
date: '2019-05-02',
name: '王小虎7',
2022-03-16 10:28:25 +08:00
price: 33,
2022-03-02 10:56:22 +08:00
province: '上海',
2022-03-09 11:53:54 +08:00
sex:1,
2022-03-02 10:56:22 +08:00
age:'10',
2022-03-09 11:53:54 +08:00
id:"7",
2022-03-02 10:56:22 +08:00
city: '普陀区',
2022-03-14 11:34:29 +08:00
img:"https://img1.baidu.com/it/u=300787145,1214060415&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
2022-03-02 10:56:22 +08:00
address: '上海市普',
zip: 200333
},{
date: '2012-05-02',
name: '王小虎8',
province: '上海',
2022-03-16 10:28:25 +08:00
price: 33,
2022-03-09 11:53:54 +08:00
sex:1,
2022-03-02 10:56:22 +08:00
age:'29',
2022-03-09 11:53:54 +08:00
id:"8",
2022-03-02 10:56:22 +08:00
city: '普陀区',
2022-03-14 11:34:29 +08:00
img:"https://img1.baidu.com/it/u=300787145,1214060415&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
2022-03-02 10:56:22 +08:00
address: '上海市普',
zip: 200333
},{
date: '2011-05-02',
2022-03-16 10:28:25 +08:00
name: '王小虎91',
price: 33,
2022-03-14 11:34:29 +08:00
img:"https://img1.baidu.com/it/u=300787145,1214060415&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
2022-03-02 10:56:22 +08:00
province: '上海',
2022-03-09 11:53:54 +08:00
sex:1,
id:"9",
2022-03-02 10:56:22 +08:00
age:'30',
city: '普陀区',
address: '上海市普',
zip: 200333
2022-03-08 17:54:47 +08:00
},{
date: '2011-05-02',
2022-03-16 10:28:25 +08:00
name: '王小虎10',
2022-03-08 17:54:47 +08:00
province: '上海',
2022-03-09 11:53:54 +08:00
sex:1,
id:"10",
2022-03-08 17:54:47 +08:00
age:'30',
2022-03-14 11:34:29 +08:00
img:"https://img1.baidu.com/it/u=300787145,1214060415&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
2022-03-08 17:54:47 +08:00
city: '普陀区',
address: '上海市普',
zip: 200333
},{
date: '2011-05-02',
2022-03-16 10:28:25 +08:00
name: '王小虎20',
2022-03-08 17:54:47 +08:00
province: '上海',
2022-03-09 11:53:54 +08:00
sex:1,
2022-03-16 10:28:25 +08:00
price: 33,
2022-03-09 11:53:54 +08:00
id:"11",
2022-03-08 17:54:47 +08:00
age:'30',
city: '普陀区',
address: '上海市普',
zip: 200333
2022-03-02 10:56:22 +08:00
}
2022-03-18 14:58:06 +08:00
],
data1:[]
2022-03-02 10:56:22 +08:00
}
},
onLoad() {
},
2022-03-18 14:58:06 +08:00
mounted(){
this.data1 = JSON.parse(JSON.stringify(this.data))
setTimeout(()=>{
this.data1.shift()
},3000)
},
2022-03-08 17:54:47 +08:00
methods:{
buttonEdit(ite,index){
2022-03-08 18:12:32 +08:00
uni.showToast({
icon:'none',
duration:3000,
title:'点击编辑'
})
2022-03-08 17:54:47 +08:00
console.log(ite,index)
},
dele(ite,index){
2022-03-08 18:12:32 +08:00
uni.showToast({
icon:'none',
duration:3000,
title:'点击删除'
})
// alert('点击删除')
2022-03-08 17:54:47 +08:00
console.log(ite,index)
2022-03-09 19:20:51 +08:00
},
toggleAllSelection(checked,arr){
2022-03-10 15:03:34 +08:00
uni.showToast({
icon:'none',
duration:3000,
title:'点击全选'
})
2022-03-09 19:20:51 +08:00
console.log('全选',checked,arr)
},
toggleRowSelection(checked,arr){
2022-03-10 15:03:34 +08:00
uni.showToast({
icon:'none',
duration:3000,
title:'点击单选'
})
2022-03-09 19:20:51 +08:00
console.log('单选',checked,arr)
2022-03-11 10:19:21 +08:00
},
rowClick(row,index){
uni.showToast({
icon:'none',
duration:3000,
title:'单击某行'
})
console.log('单击某行',row,index)
2022-03-16 10:28:25 +08:00
},
getSummaries(param){
const { columns, data } = param;
const sums = [];
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '总价';
return;
}
if(column.name==='price'){
const values = data.map(item => Number(item[column.name]));
if (!values.every(value => isNaN(value))) {
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
sums[index] += ' 元';
}
}else{
sums[index] = 'N/A';
}
});
return sums;
2022-03-08 17:54:47 +08:00
}
},
2022-03-02 10:56:22 +08:00
}
</script>
2022-03-10 15:03:34 +08:00
<style scoped lang="scss">
::v-deep{
.uni-card{
margin: 8px!important;
padding: 0!important;
.uni-card__content{
padding: 0!important;
}
}
}
2022-03-02 10:56:22 +08:00
.content{
2022-03-10 15:03:34 +08:00
//height: 600rpx;
//.title{
// font-weight: bold;
// padding: 20rpx 0;
//}
2022-03-02 10:56:22 +08:00
}
2022-03-10 15:03:34 +08:00
2022-03-02 10:56:22 +08:00
</style>