vue el-table组件实现展开行 默认展开全部

时间:2024-11-06 08:41:57
    <el-table :data="tableData" style="width: 100%; height: 100%;font-size:1em;" :row-key="get_row"
        :expand-row-keys="expand_rowkeys">
        <el-table-column type="expand">
          <template #default="props">
            <div style="box-sizing:border-box;padding:10px">
              <el-table :data="props.row.user" :border="false">
                <el-table-column label="执行人" prop="user_name" />
                <el-table-column label="任务" prop="title" :show-overflow-tooltip="true" />
                <el-table-column label="任务状态" prop="status">
                  <template v-slot="scope">
                    <span :class="getStatusColor(scope.row.status)">{{
                      getStatusName(scope.row.status) }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="截止时间" prop="finish_time" />
                <el-table-column label="操作" min-width="30" fixed="right">
                  <template v-slot="scope">
                    <div class="opera">
                      <span class="link btncomplete iconfont icon-ziyuan165"
                        v-if="scope.row.status != 2 && scope.row.status != 4 && (((userStore.info.id == scope.row.link_user_id || userStore.info.id == props.row.user_id)&&props.row.type!=3)||(userStore.info.id == scope.row.link_user_id&&props.row.type==3))"
                        @click="handle_complete(scope.row, props.row)">&nbsp;&nbsp;确认</span>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="create_user" label="创建人" show-overflow-tooltip />
        <el-table-column prop="date" label="截止时间" show-overflow-tooltip />
        <el-table-column prop="created_at" label="创建时间" show-overflow-tooltip />

        <el-table-column label="操作" min-width="30" fixed="right">
          <template v-slot="scope">
            <div class="opera">
              <el-tooltip class="box-item" effect="dark"
                v-if="(scope.row.type == 3 || scope.row.user_id == userStore.info.id && scope.row.type != 3) && scope.row.status != 2"
                content="编辑" placement="top">
                <span class="iconfont icon-bianji" @click="handle_edit(scope.row)"></span>
              </el-tooltip>
              <el-tooltip class="box-item" effect="dark" content="关闭"
                v-if="scope.row.task_status != 4 && scope.row.status != 2 && (scope.row.type != 1 || (scope.row.type == 1 && scope.row.user_id == userStore.info.id))"
                placement="top">
                <span class="iconfont icon-guanbi" @click="handle_close(scope.row)"></span>
              </el-tooltip>
            </div>
          </template>
        </el-table-column>
      </el-table>

获取数据的时候 

 expand_rowkeys.value = tableData.value.map(x => x.id);

文档地址