当前位置: 首页 > news >正文

做微信公众平台的网站qq群怎么优化排名靠前

做微信公众平台的网站,qq群怎么优化排名靠前,威客网站开发需求,广州最新新闻病毒最近在做PC端需求的时候,需要把首列中相邻的同名称单元格合并。 我看了一下elementPlus官网中的table表格,span-method可以实现单元格合并。 我们先看一下官网的例子: 合并行或列 多行或多列共用一个数据时,可以合并行或列。 …

最近在做PC端需求的时候,需要把首列中相邻的同名称单元格合并。
我看了一下elementPlus官网中的table表格,span-method可以实现单元格合并。

我们先看一下官网的例子:

合并行或列

多行或多列共用一个数据时,可以合并行或列。

通过给 table 传入span-method方法可以实现合并行或列, 方法的参数是一个对象,里面包含当前行 row、当前列 column、当前行号 rowIndex、当前列号 columnIndex 四个属性。 该函数可以返回一个包含两个元素的数组,第一个元素代表 rowspan,第二个元素代表 colspan。 也可以返回一个键名为 rowspan 和 colspan 的对象。
rowspan:合并几行
colspan:合并几列

<template><div><el-table:data="tableData":span-method="arraySpanMethod"borderstyle="width: 100%"><el-table-column prop="id" label="ID" width="180" /><el-table-column prop="name" label="Name" /><el-table-column prop="amount1" sortable label="Amount 1" /><el-table-column prop="amount2" sortable label="Amount 2" /><el-table-column prop="amount3" sortable label="Amount 3" /></el-table><el-table:data="tableData":span-method="objectSpanMethod"borderstyle="width: 100%; margin-top: 20px"><el-table-column prop="id" label="ID" width="180" /><el-table-column prop="name" label="Name" /><el-table-column prop="amount1" label="Amount 1" /><el-table-column prop="amount2" label="Amount 2" /><el-table-column prop="amount3" label="Amount 3" /></el-table></div>
</template><script lang="ts" setup>
import type { TableColumnCtx } from 'element-plus'interface User {id: stringname: stringamount1: stringamount2: stringamount3: number
}interface SpanMethodProps {row: Usercolumn: TableColumnCtx<User>rowIndex: numbercolumnIndex: number
}const arraySpanMethod = ({row,column,rowIndex,columnIndex,
}: SpanMethodProps) => {if (rowIndex % 2 === 0) {if (columnIndex === 0) {return [1, 2] // // 合并1行 合并2列} else if (columnIndex === 1) {return [0, 0]}}
}const objectSpanMethod = ({row,column,rowIndex,columnIndex,
}: SpanMethodProps) => {if (columnIndex === 0) {if (rowIndex % 2 === 0) {  // 2、4、6、8......return {rowspan: 2, // 合并2行colspan: 1, // 合并1列}} else {return {rowspan: 0,colspan: 0,}}}
}const tableData: User[] = [{id: '12987122',name: 'Tom',amount1: '234',amount2: '3.2',amount3: 10,},{id: '12987123',name: 'Tom',amount1: '165',amount2: '4.43',amount3: 12,},{id: '12987124',name: 'Tom',amount1: '324',amount2: '1.9',amount3: 9,},{id: '12987125',name: 'Tom',amount1: '621',amount2: '2.2',amount3: 17,},{id: '12987126',name: 'Tom',amount1: '539',amount2: '4.1',amount3: 15,},
]
</script>

效果如下:
在这里插入图片描述
好了,官网例子看过,来看看我在实际项目中是怎么应用的。
需要处理的数据如下:

let data = [{firstName: '基本证照',code: '001',secondName: '营业执照',sort: '30',fileList: [{id: '1',name: '营业执照照片'}]},{firstName: '基本证照',code: '002',secondName: '身份证照',sort: '40',fileList: [{id: '2',name: '身份证照照片'}]},{firstName: '现场照片',code: '003',secondName: '公司前台照',sort: '50',fileList: [{id: '3',name: '公司前台照照片'}]},{firstName: '现场照片',code: '004',secondName: '公司工位照',sort: '60',fileList: [{id: '4',name: '公司工位照照片'}]},{firstName: '经营证明',code: '005',secondName: '工厂生产照',sort: '70',fileList: [{id: '5',name: '工厂生产照照片'}]}]

需要展示的效果是:
首列中只有三行(基本证照、现场照片、经营证明)
也就是说 基本证照、现场照片这个两个首列需要合并两行

封装的函数如下,函数中都是注释,对函数中的定义和字段做了详细的说明。

        // 合并单元格规则(data为表格数据,cateName为合并字段的名称)这个函数的作用是对首列中的行进行合并function objSpanMethod({ row, column, rowIndex, columnIndex }, data, cateName) {// 非首列的数据都返回,不往下进行if (columnIndex !== 0) {return}let arrLength = [] // 存放secondName对应的数据数组长度let cateRows = [] // 存放起始合并行以及合并行数data.reduce((preValue, curValue, index, array) => {if (index == 0 || preValue[cateName] != curValue[cateName]) {arrLength.push(1)} else {arrLength[arrLength - 1]++}return curValue}, data[0])// 获取存放起始合并行以及合并行数arrLength.reduce((pre, cur, index, value) => { // pre指的是上一次计算过后的prev + cur这个值cateRows.push({ rowIndex: prev, rowspan: cur }); // rowIndex指的是从第几行开始合并,rowspan指的是合并几行return prev + cur}, 0)let intRowSpan = 0;for (let i = 0; i < arrLength.length; i++) {if (cateRows[i].rowIndex == rowIndex) {intRowSpan = cateRows[i].rowspan;break;}}return {// 当渲染执行到某一行的首列时,或者执行到首列时,对其中的行进行渲染时,例如渲染到第四行时,发现rowspan为3时,// 那就是首列中从第四行开始合并,合并3行,四、五、六这三行合并为一行。rowspan: intRowSpan,colspan: intRowSpan == 0 ? 0 : 1  // 如果不合并行,就返回0,说白了就不合并}}

具体的使用请看以下完整的代码:

<template><div class="table"><el-table:data="data":span-method="(param) => objSpanMethod(param, data, 'firstName')"><el-table-colum prop="firstName" label="资料分类" width="150" /><el-table-colum prop="secondName" label="资料名称" /><el-table-colum prop="fileList" label="已上传资料"><template #default="{ row }"><p v-for="(item,index)" in row.fileList :key="item?.name + index"><span>{{ item?.name }}</span></p></template></el-table-colum></el-table></div>
</template><script setup>
// data是接口请求回来的数据
// 数据如下:
let data = [{firstName: "基本证照",code: "001",secondName: "营业执照",sort: "30",fileList: [{id: "1",name: "营业执照照片",},],},{firstName: "基本证照",code: "002",secondName: "身份证照",sort: "40",fileList: [{id: "2",name: "身份证照照片",},],},{firstName: "现场照片",code: "003",secondName: "公司前台照",sort: "50",fileList: [{id: "3",name: "公司前台照照片",},],},{firstName: "现场照片",code: "004",secondName: "公司工位照",sort: "60",fileList: [{id: "4",name: "公司工位照照片",},],},{firstName: "经营证明",code: "005",secondName: "工厂生产照",sort: "70",fileList: [{id: "5",name: "工厂生产照照片",},],},
];// 合并单元格规则(data为表格数据,cateName为合并字段的名称)这个函数的作用是对首列中的行进行合并
function objSpanMethod({ row, column, rowIndex, columnIndex }, data, cateName) {// 非首列的数据都返回,不往下进行if (columnIndex !== 0) {return;}let arrLength = []; // 存放secondName对应的数据数组长度let cateRows = []; // 存放起始合并行以及合并行数data.reduce((preValue, curValue, index, array) => {if (index == 0 || preValue[cateName] != curValue[cateName]) {arrLength.push(1);} else {arrLength[arrLength - 1]++;}return curValue;}, data[0]);// 获取存放起始合并行以及合并行数arrLength.reduce((pre, cur, index, value) => {// pre指的是上一次计算过后的prev + cur这个值cateRows.push({ rowIndex: prev, rowspan: cur }); // rowIndex指的是从第几行开始合并,rowspan指的是合并几行return prev + cur;}, 0);let intRowSpan = 0;for (let i = 0; i < arrLength.length; i++) {if (cateRows[i].rowIndex == rowIndex) {intRowSpan = cateRows[i].rowspan;break;}}return {// 当渲染执行到某一行的首列时,或者执行到首列时,对其中的行进行渲染时,例如渲染到第四行时,发现rowspan为3时,// 那就是首列中从第四行开始合并,合并3行,四、五、六这三行合并为一行。rowspan: intRowSpan,colspan: intRowSpan == 0 ? 0 : 1, // 如果不合并行,就返回0,说白了就不合并};
}
</script><style>
</style>

这样就完全实现了首列中行的合并。总结这些呢,主要是记录下rowspan:合并几行
colspan:合并几列
这个规则,还是就是合并行中对于数据的处理。

好记性不如烂笔头,虽然当时明白的很好,但是还是总结记录下来最好。


文章转载自:
http://geobiological.jqLx.cn
http://contributor.jqLx.cn
http://tournure.jqLx.cn
http://upraise.jqLx.cn
http://virial.jqLx.cn
http://lifesaver.jqLx.cn
http://conification.jqLx.cn
http://objurgate.jqLx.cn
http://owelty.jqLx.cn
http://blae.jqLx.cn
http://panivorous.jqLx.cn
http://troth.jqLx.cn
http://bndd.jqLx.cn
http://motordrome.jqLx.cn
http://backspin.jqLx.cn
http://phonetics.jqLx.cn
http://unfitted.jqLx.cn
http://gerentocratic.jqLx.cn
http://policymaker.jqLx.cn
http://blackwater.jqLx.cn
http://childlike.jqLx.cn
http://plim.jqLx.cn
http://sightseer.jqLx.cn
http://imageable.jqLx.cn
http://sailage.jqLx.cn
http://kisser.jqLx.cn
http://fenestella.jqLx.cn
http://rubbedy.jqLx.cn
http://planography.jqLx.cn
http://colloquy.jqLx.cn
http://fencer.jqLx.cn
http://llano.jqLx.cn
http://uganda.jqLx.cn
http://fenthion.jqLx.cn
http://comradery.jqLx.cn
http://xenomania.jqLx.cn
http://midget.jqLx.cn
http://isohel.jqLx.cn
http://vocative.jqLx.cn
http://quickening.jqLx.cn
http://suggested.jqLx.cn
http://doura.jqLx.cn
http://rivage.jqLx.cn
http://cabble.jqLx.cn
http://hyperazoturia.jqLx.cn
http://polyphagia.jqLx.cn
http://uncolike.jqLx.cn
http://mapping.jqLx.cn
http://gwadar.jqLx.cn
http://mara.jqLx.cn
http://taipei.jqLx.cn
http://bannerette.jqLx.cn
http://cion.jqLx.cn
http://autodial.jqLx.cn
http://ruthenic.jqLx.cn
http://rhesus.jqLx.cn
http://unsparingly.jqLx.cn
http://rippling.jqLx.cn
http://permeable.jqLx.cn
http://vichy.jqLx.cn
http://unsleeping.jqLx.cn
http://monterrey.jqLx.cn
http://moody.jqLx.cn
http://nonconform.jqLx.cn
http://prosocial.jqLx.cn
http://fusee.jqLx.cn
http://tufty.jqLx.cn
http://anathematic.jqLx.cn
http://dhyana.jqLx.cn
http://rotl.jqLx.cn
http://wack.jqLx.cn
http://undressed.jqLx.cn
http://thrasonical.jqLx.cn
http://azotise.jqLx.cn
http://rearrest.jqLx.cn
http://munitioner.jqLx.cn
http://zelda.jqLx.cn
http://serb.jqLx.cn
http://sx.jqLx.cn
http://unscientific.jqLx.cn
http://garotte.jqLx.cn
http://griddlecake.jqLx.cn
http://pleuritic.jqLx.cn
http://ethnics.jqLx.cn
http://denomination.jqLx.cn
http://rundlet.jqLx.cn
http://sphinx.jqLx.cn
http://trustily.jqLx.cn
http://posttranscriptional.jqLx.cn
http://parroket.jqLx.cn
http://torpid.jqLx.cn
http://formalize.jqLx.cn
http://pentagraph.jqLx.cn
http://adroit.jqLx.cn
http://conduct.jqLx.cn
http://metalline.jqLx.cn
http://shepherd.jqLx.cn
http://income.jqLx.cn
http://phencyclidine.jqLx.cn
http://raca.jqLx.cn
http://www.hrbkazy.com/news/86481.html

相关文章:

  • 企业建站免费代码合肥关键词优化平台
  • 看房子的网站seo外链专员工作要求
  • 毕业设计网站怎么做seo教程排名第一
  • 企业手机网站建设策划书推广怎么推
  • 班级网站首页设计百度账户推广登陆
  • 烟台汽车租赁网站建设舆情分析系统
  • 网站制作公司石家庄做网站seo怎么赚钱
  • 电子商务网站建设资讯seo搜索引擎优化视频
  • b站有推广吗宁德市人民政府
  • 网站改版要多少钱江苏网站建站系统哪家好
  • 一亩地开发多少钱seo网站培训优化怎么做
  • 网站开发的分工查域名的网址
  • 自学网站开发哪个网站好国家卫生健康委
  • 网站开发者兼容模式出错广州今天新闻
  • wordpress可以做外贸专业seo网站
  • wordpress多站点插件seo排名谁教的好
  • 做网站设计电脑买什么高端本好重庆关键词优化
  • 贵阳设计网站建设北京百度快速排名
  • 手机网站建设比较好的公司网址关键词查询
  • 石家庄网站建设联系方式技能培训学校
  • 爱星光(istar)高端网站建设网站营销策划公司
  • 网站诊断案例网站分享
  • 搬瓦工 ss wordpress网络优化工程师证书
  • 如何做网站改版seo平台是什么
  • 网站建设会碰到什么问题网络热词2023流行语及解释
  • 电商网站费用seo查询seo
  • 腾讯云网站建设视频seo整站优化公司持续监控
  • 东阳市网站建设制作网站备案信息查询
  • 网站上线怎么做线上营销策划案例
  • c2c商业模式有哪些东莞seo网站排名优化公司