田源
2023-05-30 81ad9f333218d63473436d6bb8077c6ed8919bff
动态表格单元格编辑
已修改1个文件
77 ■■■■■ 文件已修改
Source/UBCS-WEB/src/components/Crud/Crud.vue 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS-WEB/src/components/Crud/Crud.vue
@@ -1,15 +1,43 @@
<template>
<basic-container>
  <avue-crud ref="crud"
               v-loading="loading"
             :data="data"
             :option="option"
             @sort-change="sortChange"
             v-loading="loading"
             :page="page"
               @sort-change="sortChange"
             @selection-change="selectionChange"
             @on-load="onLoad">
      <template slot="menu">
        <el-button type="text">文字按钮</el-button>
      </template>
      <template slot="menuLeft">
          <div>
            <el-table :data="tableData" style="width: 100%" @cell-click="handleCellClick" @cell-dblclick="dbclick">
              <div v-for="(item,index) in this.tableHeadData" :key="index">
                <el-table-column :label="item.label" :prop="item.prop">
<!--              编辑和展示逻辑 -->
                  <template slot-scope="{ row }">
                  <el-input v-if="editingRow === row && editShow== item.prop" v-model="row[item.prop]" @blur="saveRow"></el-input>
                  <span v-else>{{row[item.prop]}}</span>
                </template>
                </el-table-column>
              </div>
              <el-table-column fixed="right" label="操作" width="120">
                <template slot-scope="scope">
                  <el-button size="small" type="text" @click.native.prevent="enumDeleteRow(scope.$index, tableData)">
                    移除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
            <template>
              <div style="display: flex;justify-content: right;margin-top: 15px">
                <el-button type="primary"  size="small">保存</el-button>
                <el-button size="small" @click="enumVisible=false">取消</el-button>
              </div>
            </template>
          </div>
      </template>
  </avue-crud>
</basic-container>
@@ -17,10 +45,14 @@
<script>
import { MasterTable,TableData } from "@/api/GetItem";
export default {
  name: "Crud.vue",
  data(){
    return{
      editingRow:null,
      editShow: "",
      editAttr:"",
      loading:false,
      data:[],
      option:{
@@ -48,6 +80,17 @@
        pageSize: 10,
        pageSizes: [10, 30, 50, 100, 200],
      },
      tableData:[],
      tableHeadData:[],
      items:{}
    }
  },
  computed:{
    editable(){
      this.tableData.forEach(item=>{
        this.items=item
      })
      return this.editShow === this.editingRow[this.items.prop];
    }
  },
  created() {
@@ -58,6 +101,21 @@
    this.doLayout()
  },
  methods:{
    // 监听单元格点击事件并存储正在编辑的行
    handleCellClick(row, column) {
      this.editingRow = row;
      this.editShow = column.property;
      console.log( this.editingRow['name'], this.editShow)
    },
    //枚举注入删除
    enumDeleteRow(row) {
      console.log(row)
      this.tableData.splice(row, 1)
    },
    // 将正在编辑的行的状态变为 null ,即退出编辑状态
    saveRow() {
      this.editingRow = null;
    },
    doLayout() {
      this.$nextTick(() => {
        this.$refs.crud.doLayout();
@@ -65,7 +123,11 @@
    },
    //表格头渲染
    CrudHeaderRend(){
      MasterTable({codeClassifyOid:"D9CF223F-317D-71EB-BD11-433A94CAD9F3",functionId: 5,_: 1685067339479}).then(res=>{
      MasterTable({
        codeClassifyOid: "D9CF223F-317D-71EB-BD11-433A94CAD9F3",
        functionId: 5,
        _: 1685067339479
      }).then(res => {
        this.List=res.data.tableDefineVO.cols[0];
        this.List.forEach(item=>{
          let columnItem={
@@ -76,13 +138,14 @@
            width:item.minWidth
          };
          this.option.column.push(columnItem);
          this.option.column=this.tableHeadData;
        })
      })
    },
    //表格数据
    CrudRend(){
      TableData({templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
      TableData({
        templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
        codeClassifyOid: "D9CF223F-317D-71EB-BD11-433A94CAD9F3",
        page: this.page.currentPage,
        limit: this.page.pageSize,
@@ -90,6 +153,7 @@
      }).then(res=>{
        this.page.total=res.data.total;
        this.data=res.data.data;
        this.tableData=res.data.data;
      })
    },
    // 排序
@@ -118,7 +182,8 @@
    //分页刷新
    async onLoad(val){
      console.log(val)
     await TableData({templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
      await TableData({
        templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
        codeClassifyOid: "D9CF223F-317D-71EB-BD11-433A94CAD9F3",
        page: val.currentPage,
        limit: val.pageSize,