vue3+element-plus 表格table实现树状结构父子级互不影响

2024-01-31 08:05:58 浏览数 (2)

代码部分

html部分

代码语言:javascript复制
<el-dialog
      :model-value="dialog.showFlag"
      title="授权"
      @open="getCompany"
      @close="updateRoleMenuFlag"
    >
      <!--公司列表页-->
      <el-table
        :data="companyList"
        row-key="id"
        border
        default-expand-all
        class="table-style"
        ref="companyTableRef"
        @select="handleSelectionChange"
      
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="companyName" label="公司名称" sortable />
        <el-table-column prop="endTime" label="到期时间" sortable>
          <template v-slot="scope">
            {{ dayjs(scope.row.endTime).format('YYYY-MM-DD') }}
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="updateRoleMenuFlag">关闭</el-button>
        </span>
      </template>
    </el-dialog>

js部分

代码语言:javascript复制
//选择选中时会触发该事件
const handleSelectionChange = (selection:Array<TreeCompanyVO>, row:TreeCompanyVO) => {
  selection.forEach(item=>{
    console.log(item.id!==row.id)
    if(item.id!==row.id){
      companyTableRef.value.toggleRowSelection(item,false)
    }else{
      companyTableRef.value.toggleRowSelection(row,true)
    }
  })
 
  selectCompany.value = row
  
}

0 人点赞