当前位置:网站首页>Table custom table encapsulation
Table custom table encapsulation
2022-07-24 00:23:00 【Haoxing】
Preface :
For native table encapsulate , Let him meet our different needs .
Realization effect : As shown in the figure , One line shows different amounts of content


Implementation code :
1、 Packaged components :custom_table.vue, See the source code below
(1) A line shows several td

(2) Header data , Tabular data

(3)js Encapsulate core methods

2、 Calling method : Yes form It is required * effect , It can be added or deleted according to the actual situation
<Form :model="orderDetail" label-position="left" :label-width="120">
<!--<Card style="margin-bottom: 20px;">-->
<custom_table :tableObj="tableObj1" :orderList="orderDetail"></custom_table>
</Form>3、data Parameters defined in
// Order number custom list
tableObj1:[
{
title:' The order no. ', // Header name
key:'orderSn', // The header corresponds to the field that gets the data
},{
title:' External order number ',
key:'sourceOrderSn',
},{
title:' Order type ',
key:'type',
enumFilter:'OrderTypeEnum' // Overall filter Filtration method
},{
title:' The order status ',
key:'status',
enumFilter:'OrderStatusEnum'
},{
title:' Organization ',
key:'merchantName',
},{
title:' The store it belongs to ',
key:'shopName',
},{
title:' Distribution channel ',
key:'platform',
},{
title:' Source of order ',
key:'source',
},{
title:' Delivery method ',
key:'deliveryType',
},{
title:' Logic bin ',
key:'logicName',
},{
title:' Physical warehouse ',
key:'physicName',
},{
title:' Expected arrival time ',
key:'expectedDeliveryTime',
},{
title:' founder ',
key:'createUser',
},{
title:' Salesperson ',
key:'saleUser',
},{
title:' Courier ',
key:'expressName',
col:'2' // Merge
}
],
// All data
orderDetail: {
orderSn:'111'
},Package component source code :custom_table.vue
<template>
<!-- Type 1 :-->
<table class="comTable" v-if="uploadCustomTable">
<tr v-for="(trItem,trIndex) in tableColumn" :key="'custom_tr_'+trIndex">
<td v-for="(tdItem,tdIndex) in trItem" :colspan="tdItem.col?tdItem.col:1" :key="'custom_td_'+tdIndex" >
<FormItem :label="tdItem.title + ':'">
<p v-if="orderDetail[tdItem.key] && tdItem.enumFilter">{
{ orderDetail[tdItem.key] | enumFilter(tdItem.enumFilter) }}</p>
<p v-if="orderDetail[tdItem.key] && !tdItem.enumFilter">{
{ orderDetail[tdItem.key] }}</p>
<p v-if="!orderDetail[tdItem.key] && orderDetail[tdItem.key] === 0">{
{orderDetail[tdItem.key]}}</p>
<p v-if="!orderDetail[tdItem.key] && orderDetail[tdItem.key] !== 0"> -- </p>
</FormItem>
</td>
</tr>
</table>
</template>
<script>
export default {
props: {
// How many are displayed in one row of the header
custom_table_col_num:{
type: String,
default:'4'
},
/**
* Custom form - Header data
[
{
title:' The order no. ', // Header data
key:'orderSn', // Header field
col:'2' // Number of merges
}
]
* */
tableObj:{
type:Array,
default:()=>{
return []
}
},
// The list of data
orderList:{
type:Object,
default:()=>{
return {}
}
}
},
watch: {
// Customize header data
tableObj: {
handler: "setTableCol",
immediate: true,
},
// Custom table data
orderList: {
handler: "setTableList",
immediate: true,
},
},
data() {
return {
uploadCustomTable:true,
orderDetail: {},
tableColumn:[], // Header data
}
},
methods: {
// Process header data
setTableCol(arr){
let all_arr = [] // According to the total
arr.forEach((item,index)=>{
item.index = index
if(item.col){
// Merge content
for(let i=0; i< +item.col;i++){
all_arr.push(item)
}
}else{
all_arr.push(item)
}
})
let allData = []; // Used to load the processed array
let currData = []; // Subarray is used to store the divided data
let now_num = this.custom_table_col_num
for(var i = 0; i < all_arr.length; i++) {
currData.push(all_arr[i]);
if((i != 0 && (i + 1) % now_num == 0) || i == all_arr.length - 1) {
allData.push(currData);
currData = [];
}
}
// Update the data again
allData.forEach(item=>{
let oldArr = item
let newArr = this.unique(oldArr,'index')
this.tableColumn.push(newArr)
})
},
// Update table data
setTableList(obj){
this.orderDetail = obj
this.uploadCustomTable = false
this.$nextTick(()=>{
this.uploadCustomTable = true
})
},
/**
* De duplication according to a field of the array object
* item.name yes [{name:1}] According to the of each data name Value comes and goes
* */
unique(arr,val) {
const res = new Map();
return arr.filter(item => !res.has(item[val]) && res.set(item[val], 1))
},
}
}
</script>
<style lang='less' scoped>
.comTable {
width: 100%;
border-collapse: collapse;
margin: 15px 0;
td, th {
border: 1px solid #ccc;
}
tr {
width: 100%;
p {
padding-left: 3px;
background: #F7F7FB;
height: 34px;
}
}
}
</style>
边栏推荐
- How to open a low commission account? Is it safe?
- 北峰通信亮相中国(厦门)应急展|智能化通信手段强势吸睛!
- GBase 8c 会话信息函数(四)
- Redis主从同步机制
- Delete all data of specified query criteria in Oracle
- Gbase 8C access authority query function (I)
- GBase 8c 字符串操作符
- Pytest interface automation testing framework | multi process running case
- Customize an object
- 腾讯将关闭“幻核”,数字藏品领域发展是否面临阻力?
猜你喜欢

Multi knapsack explanation of dynamic programming knapsack problem

English语法_指示代词 - So

Delete all data of specified query criteria in Oracle

Overview of data model design method

English语法_指示代词 -such / the same

Docker pulls the redis image and runs it

二叉搜索树的简易实现及剖析

高数_第2章多元函数微分学__偏导数的几何应用_空间曲线的切线与法平面

【Android Kotlin】Property、Getter 和 Setter

数据模型设计方法概述
随机推荐
Educational Codeforces Round 132 (Rated for Div. 2)(A-D)
MySQL之数据查询(SELECT)
Customize an object
Robot dog back submachine gun shooting video fire, netizens shivering: stoooooooopppp!
Pipeline pipeline project is built by declarative and jenkinsfile under Jenkins
Redis 主从、哨兵、集群架构有缺点比较
How to improve data quality
GBase 8c 模式可见性查询函数(一)
GBase 8c 访问权限查询函数(一)
Gbase 8C session information function (I)
docker搭建sonarqube,mysql5.7环境
[wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)
The prediction of domestic AI protein structure reproduced a breakthrough and solved the 3D structure with a single sequence. Peng Jian's team: "the last piece of puzzle since alphafold2 has been comp
尝试新的方法
iNFTnews | 呵护“雪山精灵”,42VERSE“数字生态保护”公益项目即将盛启
Inode, soft link, hard link
如何提升数据质量
Gbase 8C system table information function (I)
Redis persistence mechanism RDB, AOF
投资的物质回报