首页 > 其他分享 >前端页面实现【矩阵表格与列表】

前端页面实现【矩阵表格与列表】

时间:2024-06-22 17:29:54浏览次数:3  
标签:colIndex name 表格 text 矩阵 label numRows width 页面

实现页面: 

1.动态表绘制(可用于矩阵构建)

<template>
  <div>
    <h4><b>基于层次分析法的权重计算</b></h4>
    <table table-layout="fixed">
      <thead>
      <tr>
        <th v-for="(_, colIndex) in (numRows + 1)" :key="colIndex">{{colIndex===0?"图层":layers[colIndex-1]}}</th>
      </tr>
      </thead>
      <tbody >
      <tr v-for="(rowData, rowIndex) in generateTableData(numRows)" :key="rowIndex" :style="{ '--wid': wid}">
        <td
          v-for="(cell, colIndex) in rowData"
          :key="colIndex"
          :class="{ nonEditable: isNonEditable(rowIndex, colIndex) }"
        >
          {{rowData[colIndex]}}
          <input
            v-if="colIndex!==0&&!isNonEditable(rowIndex, colIndex)"
            type="text"
            v-model="rowData.values[colIndex]"
            style="width: 100%;border: none;text-align: center"
          />
          <span v-else>{{ value }}</span>
        </td>
      </tr>
      </tbody>
    </table>
  </div>
</template>
<script>
export default {
  name: 'TimeManagementTable',
  props:{
    layers:{
      type:Array,
      required: true,
      default: ()=>['地质', '水文', '其他','W']
    },
  },
  data() {
    return {
      numRows:null ,
      wid:null
    };
  },

  created() {
    this.numRows = this.layers.length;
    this.wid = 100/(this.numRows+1) + '%';
  },
  methods: {
    isNonEditable(rowIndex, colIndex) {
      // 假设我们想让第二列的第二个单元格(索引为1, 1)为灰色且不可编辑
      // 你可以根据实际需求调整这个逻辑
      return colIndex!==0&rowIndex+1>=colIndex||colIndex===this.numRows;
    },
    generateTableData(numRows) {
      const tableData = [];
      for (let i = 0; i < numRows-1; i++) {
        let arr= Array(numRows + 1).fill('')
        arr[0]=this.layers[i]
        tableData.push(arr); // 填充空字符串或你需要的默认值
      }
      return tableData;
    }
  },
};
</script>

<style scoped>
/* 样式可以根据需要添加 */
table {
  width: 100%;
}
th, td {
  border: 1px solid black;
  padding: 8px;
  text-align: center;
  width: var(--wid);
}

核心要点:

  • 动态性:可根据不同数据项动态自适应构建表格

 记录数组长度,根据数组长度动态设置行列号数以及其列宽

<tr v-for="(rowData, rowIndex) in generateTableData(numRows)" :key="rowIndex" :style="{ '--wid': wid}">

data() {
    return {
      numRows:null ,
      wid:null
    };
  },

  created() {
    this.numRows = this.layers.length;
    this.wid = 100/(this.numRows+1) + '%';

  },

th, td {
  border: 1px solid black;
  padding: 8px;
  text-align: center;
  width: var(--wid);
}

  • 表格单元格权限控制:只有指定单元格可编辑,收集用户输入数据,其余为灰色且不可编辑

        <td
          v-for="(cell, colIndex) in rowData"
          :key="colIndex"
          :class="{ nonEditable: isNonEditable(rowIndex, colIndex) }"
        >
          {{rowData[colIndex]}}
          <input
            v-if="colIndex!==0&&!isNonEditable(rowIndex, colIndex)"
            type="text"
            v-model="rowData.values[colIndex]"
            style="width: 100%;border: none;text-align: center"
          />
          <span v-else>{{ value }}</span>

 isNonEditable(rowIndex, colIndex) {
      // 假设我们想让第二列的第二个单元格(索引为1, 1)为灰色且不可编辑
      // 你可以根据实际需求调整这个逻辑
      return colIndex!==0&rowIndex+1>=colIndex||colIndex===this.numRows;
    },

  • 表格标题行和列设置:设置表格头和表格第一列为指定数组内的名称

 <thead>
      <tr>
        <th v-for="(_, colIndex) in (numRows + 1)" :key="colIndex">{{colIndex===0?"图层":layers[colIndex-1]}}</th>
      </tr>
      </thead>
      <tbody >
      <tr v-for="(rowData, rowIndex) in generateTableData(numRows)" :key="rowIndex" :style="{ '--wid': wid}">
        <td
          v-for="(cell, colIndex) in rowData"
          :key="colIndex"
          :class="{ nonEditable: isNonEditable(rowIndex, colIndex) }"
        >
          {{rowData[colIndex]}}
          <input
            v-if="colIndex!==0&&!isNonEditable(rowIndex, colIndex)"
            type="text"
            v-model="rowData.values[colIndex]"
            style="width: 100%;border: none;text-align: center"
          />
          <span v-else>{{ value }}</span>
        </td>
      </tr>
      </tbody>

2.类C#中控件前端实现: 

<template>
  <div class="app-container standard-level">
    <el-row>
      <el-col :span="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>StandardLevel</span>
          </div>
          <div>
            <!-- 指标选择 -->
            <div id="indicator" style="border: gray 1px dashed; padding: 5px;">
              <span class="title"> 指标创建</span>
              <el-form size="small" :inline="true">
                <el-form-item label="指标类别" class="form-label" >
                  <el-input
                    v-model="indicatorType"
                    placeholder="请输入指标类别"
                    clearable
                    size="small"
                  />
                </el-form-item>
                <el-form-item  class="flex-container" >
                  <div class="flex-container">
                    <div class="flex-item" v-for="item in layers" :key="item.id">
                      <el-checkbox :label="item.id" style="margin: 8px 0;">{{ item.name }}</el-checkbox>
                    </div>
                  </div>
                </el-form-item>
              </el-form>
              <!-- 操作按钮 -->
              <div class="buttons" style="display: flex;justify-content: center;">
                <el-button type="primary" size="mini" @click="addNode">添加</el-button>
                <el-button type="warning" size="mini" @click="modifyNode">确定</el-button>
                <el-button type="danger"  size="mini" @click="cancel">取消</el-button>
              </div>
            </div>
            <div id="list" style="margin-top: 10%;border: gray 1px dashed; padding: 5px;">
              <span class="title">层次结构</span>
              <!-- 层次结构 -->
              <el-tree
                :data="treeData"
                :props="defaultProps"
                show-checkbox
                node-key="id"
                ref="tree">
              </el-tree>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
</div>
</template>

<script>
import ElementForm from '@/plugins/package/panel/form/ElementForm.vue'

export default {
  components: { ElementForm },
  data() {
    return {
      indicatorType:'',
      selectedCategory: '',
      selectedIndicators: [],
      layers:[
        { id: '001', name: '塌陷点buf' },
        { id: '002', name: '断裂buf' },
        { id: '003', name: '水系buf300' },
        { id: '004', name: '轨道交通buf' },
        { id: '005', name: '地下水变幅' },
        { id: '006', name: '第四系厚度' },
        { id: '007', name: '工程地质' },
        { id: '008', name: '岩溶水富水性' },
      ],
      treeData: [
        {
          label: '地层条件',
          children: [
            { label: '剥蚀buf' },
            { label: '第四系厚度' },
            { label: '工程地质' },
          ],
        },
        { label: '水文条件' },
        { label: '其他条件' },
      ],
      defaultProps: {
        children: 'children',
        label: 'label',
      },
    };
  },
  methods: {
    addNode() {
      // 添加节点的逻辑
    },
    modifyNode() {
      // 修改节点的逻辑
    },
    cancel() {
      // 取消操作的逻辑
    },
  },
};
</script>

<style scoped>
.standard-level {
  padding: 20px;
  width: 30%;
}
.form-label {
  margin-bottom: 10px;
}
.buttons {
  margin-top: 20px;
}
.flex-container {
  display: flex;
  flex-wrap: wrap;
  .flex-item {
    width: 50%;
  }
}
span.title{
  display : block;
  width : 25%;
  height: 15px;
  font-weight: bold;
  font-size: 16px;
  position: relative;
  top:-15px;
  text-align: center;
  background: white;
}

</style>

核心要点:

  • checkbox列对齐设置

Element ui 丨el-checkbox-group 布局对齐_el-checkbox-group 对齐方式-CSDN博客

  • 边框上显示字体设置

 <div id="indicator" style="border: gray 1px dashed; padding: 5px;">
              <span class="title"> 指标创建</span>

</div>

 span.title{
  display : block;
  width : 25%;
  height: 15px;
  font-weight: bold;
  font-size: 16px;
  position: relative;
  top:-15px;
  text-align: center;
  background: white;
}

标签:colIndex,name,表格,text,矩阵,label,numRows,width,页面
From: https://blog.csdn.net/m0_55049655/article/details/139814599

相关文章

  • HTML表格宽度
    HTML表格宽度参考:htmltablewidthHTML表格是网页设计中常用的元素之一,可以用来展示数据、创建布局等。表格的宽度是一个重要的参数,可以通过不同的方式来设置表格的宽度,本文将详细介绍HTML表格宽度的不同设置方式和示例代码。1.设置表格宽度为固定值可以通过width属性来设置......
  • 鸿蒙案例-欢迎页面的实现
    前言‘案例来源于b站课程’实现过程1.首页面主要有三部分<1>中央slogan;<2>logo;<3>文字描述设置中央slogan要使用layoutWeight(1)实现布局全中;Row(){Image($r('app.media.home_slogan')).width(260)}.layoutWeight(1)logo即图片设置好图片......
  • excel电子表格双表多列修改,点击式。
        excel的xlookup确实非常简单,有部分功能也非常快。但是有的人不会公式,或者不喜欢用公式,或者没有excel2021以上的版本。而且xlookup确实也有些还不是很完美的地方,比如对多列关联查询很慢。所以我们还是有必要增加类似的办法,hpctb提供了“双表多列修改”,我们来看一看。......
  • 高性能并行计算华为云实验一:MPI矩阵运算
    目录一、实验目的二、实验说明三、实验过程3.1创建矩阵乘法源码3.1.1实验说明3.1.2实验步骤3.2创建卷积和池化操作源码3.2.1实验说明3.2.2实验步骤3.3创建Makefile文件并完成编译3.4建立主机配置文件与运行监测四、实验结果与分析4.1矩阵乘法实验4.1.1......
  • Silence 主题暗黑模式根据浏览器配置,以及切换页面闪白屏的问题处理
    最近使用Silencev3.0.0-rc2主题遇到两个偏好问题(感谢作者提供了这么好用的主题),记录下处理的过程。暗黑/亮色模式跟随浏览器的主题切换由于主题当前支持的配置项auto是根据时间定的,而不是根据浏览器的配置来的,而我个人偏向于跟随浏览器的配置来自动设置,于是用js先判断浏......
  • Java:创建一个SpringBoot架构,并尝试访问一个简单的HTML页面:Hello HTML.创建SpringBoot
    下面我们开始教程:第一步:创建Maven工程我这里是Maven工程:之后再在pom文件导入SpringBoot坐标:注:我的平台版本是2020.1,有可能跟大家的不太一样,但创建项目大体类似。Maven即可。直接SpringBoot也可。Next下一步:取名项目名称:InfomanageNext下一步:Fish:然后进入pom.xml......
  • 多维表格场景及实现公式(持续更新)
    1.获取目录中最后一级目录场景:获取目录中最后一级目录(CTC公共技术知识库/架构/开发规范/电信软件研发规范)实现公式:LAST(SPLIT([目录],"/")解析:SPLIT按照/拆分字符串,结果:CTC公共技术知识库,架构,开发规范,电信软件研发规范LAST获取列表最后一个,结果:电信软件研发规范......
  • C++矩阵库:Eigen 3.4.90 中文使用文档 (一)
    写在前面:我在学习Eigen库时,没找到好的中文文档,因此萌发了汉化Eigen官网文档的想法。其中一些翻译可能不是特别准确,欢迎批评指正。感兴趣的同学可以跳转到官网查看原文:Eigen:MainPagehttps://eigen.tuxfamily.org/dox/index.html       Eigen库,是一个开源的C......
  • element的table获取当前表格行
    需求:验证表格同一行的最低限价不能超过销售定价思路:先获取当前行table的index,然后在做大小比较1.局部html<el-table-columnlabel="销售定价(元)"min-width="200px"><templateslot="header"><spanclass="star">*</span><spanclas......
  • 10个超好看的 404 页面(附源码)
    今天来分享10个超好看的404页面,带动画效果。代码:https://codepen.io/AsyrafHussin/pen/KxWRrK代码:https://codepen.io/salehriaz/pen/erJrZM代码:https://codepen.io/andrew-lawendy/pen/deOpMZ代码:https://codepen.io/Mahi-K/pen/rNzBGgq代码:https://codepen.......