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

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

实现页面: 

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}"><tdv-for="(cell, colIndex) in rowData":key="colIndex":class="{ nonEditable: isNonEditable(rowIndex, colIndex) }">{{rowData[colIndex]}}<inputv-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-inputv-model="indicatorType"placeholder="请输入指标类别"clearablesize="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-checkboxnode-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;
}

http://www.lryc.cn/news/377038.html

相关文章:

  • GPT4v和Gemini-Pro调用对比
  • 破布叶(Microcos paniculata)单倍型染色体级别基因组-文献精读22
  • 浅谈RC4
  • uniapp微信小程序开发物料
  • 大数据工程师如何做到数据可视化?
  • Java 序列化与反序列化
  • 自定义防抖注解
  • 【尚庭公寓SpringBoot + Vue 项目实战】登录管理(十八)
  • 【html】用html+css做地表最强王者荣耀辅助工具
  • TF-IDF、BM25传统算法总结
  • 项目五 OpenStack镜像管理与制作
  • LabVIEW回热系统热经济性分析及故障诊断
  • 设计模式-迭代器模式
  • UV胶带和UV胶水的应用场景有哪些不同吗?
  • 监控员工上网软件有哪些|4款好用的员工上网行为管理软件推荐
  • 【IPython的使用技巧】
  • 最新AI智能聊天对话问答系统源码(详细图文搭建部署教程)+AI绘画系统(Midjourney),DALL-E3文生图,TTS语音识别输入,文档分析
  • 项目四 OpenStack身份管理
  • 【后端】websocket学习笔记
  • DataWhale - 吃瓜教程学习笔记(一)
  • Attention Is All You Need论文地址
  • 如何优雅的一键下载OpenHarmony活跃分支代码?请关注【itopen: ohos_download】
  • torch.topk用法
  • 终极版本的Typora上传到博客园和csdn
  • 洛谷:P5707【深基2.例12】上学迟到
  • 数据治理:数据提取过程中的合规性与安全性
  • 24计算机应届生的活路是什么
  • HTML页面布局-使用div示例
  • 怎么把webp文件转换为jpg?快来试试这四种转换方法!
  • 计算机网络(7) 错误检测