dev类似于excel的数据编辑

其实这个不是我最后的结果,只是中间demo,因为我的场景数据量很大,2w左右,有数据合并,我更倾向于el-table是实现,但不想el-input一直显示,想用if-else 去做隐藏,但是用type=textarea发现高度适配有点问题,其中做了两种实验:

(1)失去焦点和获取焦点获取容器的高度再赋值给 textarea

(2)textarea点位设置 position: absolute设置显示和隐藏样式,但是同样发现需要很多歌el-input做显示隐藏 ,但是我不想这么处理。

(3)用dev去实现el-table,用flex 或grid 布局去实现

以下为dev用flex去实现的方法

<template>
  <div class="page">
    <div class="table table-input-box">
      <div
        style="flex: 1"
        v-for="(item, index) in tableData"
        :key="index"
        class="textarea-item"
      >
        <div class="textarea-row">
          <div
            style="flex: 1"
            @click.prevent="inputBlurHandler($event, item)"
            class="column-item item1"
          >
            <el-input
              class="item__input"
              v-model="tableData[index].date"
              type="textarea"
              resize="none"
              placeholder="请输入内容"
              autosize
            ></el-input>
          </div>
          <div
            style="flex: 1"
            @click.prevent="inputBlurHandler($event, item)"
            class="column-item item2"
          >
            <el-input
              class="item__input"
              v-model="tableData[index].name"
              type="textarea"
              resize="none"
              placeholder="请输入内容"
              autosize
            ></el-input>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Batch",
  data() {
    return {
      // 下拉选项
      showedit: false,
      // 表格数据
      tableData: [],
      // 需要编辑的属性
      editProp: ["date", "name"],

      columns: [
        { label: "流程顺序", prop: "date", width: 100, align: "center" },
        { label: "流程名称", prop: "name", width: null },
      ],
      current_Y_X: null,
    };
  },
  computed: {
    foodLabel() {
      return (val) => {
        return this.options.find((o) => o.value === val).label;
      };
    },
  },
  mounted() {
    this.tableData = [
      {
        date: "你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好.",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好.",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好.",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好.",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好.",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好.",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好.",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好.",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "-02",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "-02",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "2016-05-04",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "2016-05-01",
        name: "王小虎",
        food: "选项5",
      },
      {
        date: "2016-05-03",
        name: "王小虎",
        food: "选项5",
      },
    ];
  },
  methods: {
    inputBlurHandler(event, data) {
      const span = event.target;
      if (span.className.includes("column-item")) {
        span.children[0].children[0].focus();
      }
    },
  },
};
</script>

<style lang="scss">
.textarea-item {
  border-bottom: #f1f1f1 1px solid;

  .textarea-row {
    display: flex;
    justify-content: start;
    flex-wrap: nowrap;
    .column-item {
      &:first-child {
        border-right: #f1f1f1 1px solid;
      }
      .item__input {
        padding: 5px;
        textarea {
          background-color: rebeccapurple;
          width: 100%;
          border: none; /* 去除边框 */
          background-color: transparent; /* 透明背景 */
          padding: 0 !important;
          outline: none; /* 去除聚焦时的轮廓线 */
          margin: 0; /* 去除外边距 */
          font-size: 12px !important; /* 设置字体大小,与 p 标签一致 */
          color: inherit; /* 继承父元素的字体颜色 */
          line-height: 1;
          // white-space: pre-wrap;
          text-align: start;
          font-family: Avenir, Helvetica, Arial, sans-serif !important;
          overflow: hidden;
          // word-break: break-all !important;

          // font-family: youjian !important;
        }
      }
    }
  }
}
.table-input-box {
  overflow-y: auto;
}
</style>
相关推荐
请你喝好果汁64136 分钟前
GTF转为excel文件
java·linux·excel
杨荧1 小时前
【开源免费】基于Vue和SpringBoot的渔具租赁系统(附论文)
前端·javascript·jvm·vue.js·spring boot·spring cloud·开源
小跳不会Coding1 小时前
vue实现【粘贴地址信息,自动拆分姓名、电话、地址】
javascript·vue.js·ecmascript
七月pro2 小时前
前端通过 jspdf 和 html2canvas 工具将网页生成 pdf
javascript·pdf
憶巷2 小时前
Vue 的响应式原理
前端·javascript·vue.js
小马超会养兔子3 小时前
vue2实现答题组件
开发语言·前端·javascript·vue
笨笨狗吞噬者3 小时前
为了解决路径问题,我写了一个eslint plugin
前端·javascript·eslint
杨荧4 小时前
【开源免费】基于Vue和SpringBoot的电影评论网站(附论文)
前端·javascript·vue.js·spring boot·spring cloud·java-ee·开源
上趣工作室4 小时前
vue2中在组件内部通过this.$watch监听数据变化总结
前端·javascript·vue.js