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

uniapp微信小程序简单表格展示

很简单的一个表格展示,自己写的,功能一般般。

<template><view class="x-simple-table" :style="{ width: width, height: height, maxHeight: maxHeight  }"><view class="x-simple-table-panel"><view class="table-header tui-flex-align-center"><view class="table-cell border-rb" v-for="header in effectiveHeaders" :key="header.onlyId":class="header.class":style="header.style">{{ header.title }}</view></view><view v-for="cellOption in effectiveDataList" :key="cellOption.onlyId" class="table-row tui-flex-align-center"><view v-for="cell in cellOption.cellList" :key="cell.onlyId"class="table-cell border-rb" :style="cell.style":class="cell.class">{{ cell.value }}</view></view></view></view>
</template>
<script>export default {props: {width: {type: String,default: 'auto'},height: {type: String,default: 'auto'},maxHeight: {type: String,default: 'auto'},headers: {type: Array,default: new Array()},dataList: {type: Array,default: new Array()}},data () {return {tableFieldWidth: 100,autoHeaderWidth: []}},computed: {effectiveHeaders () {let onlyId = Date.now()return this.headers.map((e, index) => {const { field, width, hStyle = '', hClass = '' } = econst { width: autoWidth } = this.autoHeaderWidth.find(ah => ah.field === field) || {}const newHeader = { ...e, onlyId: onlyId++ * 2}const styleArray = []const classArray = [hClass]// if (index < this.headers.length - 1) {//     classArray.push('border-r')// }// if (this.dataList.length) {//     classArray.push('border-b')// }if (width || autoWidth) {newHeader.widthUnit = width ? 'rpx' : 'px'styleArray.push(`width: ${width || autoWidth}${newHeader.widthUnit}`)} else {newHeader.autoWidthFlag = truestyleArray.push('flex: 1')classArray.push(`x-auto-width-header-${field}`)}hStyle && styleArray.push(hStyle)Object.assign(newHeader, {width: width || autoWidth,style: styleArray.join(';'),class: classArray.join(' ')})return newHeader})},effectiveDataList () {if (!this.effectiveHeaders.length) {return []}const nullValueArray = [void (0), null]const newDataList = []let onlyId = Date.now()for (let rowIndex = 0; rowIndex < this.dataList.length; rowIndex++) {const row = this.dataList[rowIndex]const tableCellValue = []for (let cellIndex = 0; cellIndex < this.effectiveHeaders.length; cellIndex++) {const header = this.effectiveHeaders[cellIndex]const tClass = row[`${header.field}_class`]const classArray = []// if (cellIndex < this.effectiveHeaders.length - 1) {//     classArray.push('border-r')// }// if (rowIndex < this.dataList.length - 1) {//     classArray.push('border-b')// }tClass && classArray.push(tClass)const tStyle = row[`${header.field}_style`]const styleArray = [ `width: ${header.width || 0}${header.widthUnit || 'rpx'}` ]tStyle && styleArray.push(tStyle)const value = nullValueArray.includes(row[header.field]) ? '' : row[header.field] + (header.suffix || '')tableCellValue.push({$row: row,style: styleArray.join(';'),class: classArray.join(' '),field: header.field,value,onlyId: onlyId++})}newDataList.push({onlyId: onlyId++,cellList: tableCellValue})}return newDataList}},mounted () {this.refactorCellWidth()},methods: {refactorCellWidth () {this.$nextTick(_ => {const autoWidthHeaderList = this.effectiveHeaders.filter(e => e.autoWidthFlag)if (!autoWidthHeaderList.length) {return}const $el = uni.createSelectorQuery().in(this)autoWidthHeaderList.forEach(header => {$el.select(`.x-auto-width-header-${header.field}`).boundingClientRect(({ width }) => {const ahRow = this.autoHeaderWidth.find(ah => ah.field === header.field)if (ahRow) {ahRow.width !== width && this.$set(ahRow, 'width', width)} else {this.autoHeaderWidth.push({field: header.field,width})}}).exec()})})}}}
</script>
<style lang="scss" scoped>$border: 2rpx solid rgba(229, 229, 229, 1);.x-simple-table {border: $border;border-radius: 12rpx;font-size: 28rpx;color: rgba(102, 102, 102, 1);overflow: hidden;.x-simple-table-panel {overflow: auto;}.table-header, .table-row {align-items: stretch;}.table-cell {text-align: center;padding: 14rpx 8rpx;flex-shrink: 0;box-sizing: border-box;overflow: hidden;white-space: nowrap;min-width: 100rpx;}.border-r, .border-rb {border-right: $border;}.border-b, .border-rb {border-bottom: $border;}}
</style>


没什么单元格合并,但支持左右滑动,上下滑动,单元格自定义样式。


http://www.dtcms.com/a/523528.html

相关文章:

  • 【html】每日打卡页面
  • Server 15 ,VMware ESXi 实战指南:Ubuntu 20.04.6 版本虚拟机静态 IP 配置、分辨率固定及远程访问实践
  • 吴恩达深度学习课程一:神经网络和深度学习 第三周:浅层神经网络(三)
  • Copilot使用体验
  • uniapp video 加载完成后全屏播放
  • 从MongoDB到国产数据库:一场2TB电子证照系统的“平滑着陆”实践
  • 电子商务网站开发与建设试卷wordpress如何删除已安装主题
  • 内蒙古城乡建设网站免费详情页模板网站
  • Android EDLA开发认证说明和开发流程
  • DevExpress WPF中文教程:Data Grid - 如何使用虚拟源?(三)
  • UniApp缓存系统详解
  • 【LLM】用 FastAPI 搭建「OpenAI 兼容」DeepSeek-OCR 服务 + 简洁WebUI
  • 企业内部SRE/DevOps向精通Linux课程培训大纲
  • 《Effective Java》第13条:谨慎的覆盖clone
  • 第一章、React + TypeScript + Webpack项目构建
  • 前端:金丝雀部署(Canary Deployment)/ A、B部署 / 灰度部署
  • Spark微博舆情分析系统 情感分析 爬虫 Hadoop和Hive 贴吧数据 双平台 讲解视频 大数据 Hadoop ✅
  • 宁波公司网站建设价格dw建设手机网站
  • 长沙做网站价格有哪些网站可以做青旅义工
  • 怎么查看网站打开速度企业网站用vps还是虚拟主机
  • Vue3 模板引用——ref
  • XGBoost完整学习指南:从数据清洗到模型调参
  • 【深度学习新浪潮】AI Agent工具流产品:从原理到落地,打造智能协作新范式
  • 页面滚动加载更多
  • 除了provide和inject,Vue3还有哪些用于组件通信的方式?
  • React 表单与事件
  • AI代码开发宝库系列:FAISS向量数据库
  • 前端埋点学习
  • Spring AI与DeepSeek实战:打造企业级知识库+系统API调用
  • 秦皇岛市建设局网站关于装配式专家做运动特卖的网站