vue动态table 动态表头数据+动态列表数据

效果图:

javascript 复制代码
<template>
  <div style="padding: 20px">
    <el-scrollbar>
    <div class="scrollbar-flex-content">
    <div class="opt-search">
      <div style="width: 100px"> </div>
      <div class="opt-box">
        <el-button type="primary" @click="selectClounm"> 选择列 </el-button>
        <el-dropdown placement="bottom-start" style="margin: 0 15px">
          <el-button type="primary"> 批量操作 </el-button>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>
                <el-icon><View /></el-icon>批量转换工作项状态
              </el-dropdown-item>
              <el-dropdown-item @click="handleBatch('copy')">
                <el-icon><CopyDocument /></el-icon> 批量复制
              </el-dropdown-item>
              <el-dropdown-item @click="deleteDatil">
                <el-icon><DeleteFilled /></el-icon>批量删除
              </el-dropdown-item>
              <el-dropdown-item @click="handleBatch('move')">
                <el-icon><Switch /></el-icon> 批量移动
              </el-dropdown-item>
              <el-dropdown-item>
                <el-icon><HelpFilled /></el-icon> 导入需求
              </el-dropdown-item>
              <el-dropdown-item>
                <el-icon><HelpFilled /></el-icon> 导出需求
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>

    <div>选择结果: {{ multipleSelection }}</div>
    <el-table :data="tableData" style="width: 100%" @selection-change="handleSelectionChange" v-loading="loading" table-layout="auto">
      <el-table-column type="selection" width="55" />
      <el-table-column
        v-for="item in showTableColumn"
        :key="item.prop"
        :fixed="item.fixed"
        :align="item.align"
        :prop="item.prop"
        :min-width="item.minWidth"
        :width="item.width"
        :show-overflow-tooltip="item.tooltip"
        :resizable="item.resizable"
        :label="item.label"
      >
      </el-table-column>
      <!-- <el-table-column prop="action" label="操作" width="100">
      <template #default="scope">
          <el-button
            size="small"
            type="primary"
            link
            icon="Edit"
            @click="edit(scope.row)"
            >编辑</el-button
          >
     </template>
     </el-table-column> -->
    </el-table>
    <el-pagination
      style="margin-top: 20px"
      v-model:current-page="pager.num"
      v-model:page-size="pager.size"
      :page-sizes="[10, 20, 30, 50]"
      layout="total,sizes, prev, pager, next"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
   />
  </div>
  </el-scrollbar>
    </div>

    <listTable ref="rowRef" />
    <batchActionDialog
      v-model="batchTypeV"
      v-model:visible="batchTypeV"
      :batchType="batchType"
      :title="`${batchType === 'move' ? '移动' : '复制'}工作项`"
    ></batchActionDialog>
    <showDialog ref="showDialogRef" :showTableColumn="citiesArr" :itemsArr="items" :visible.sync="visible" @closeShowDialog="closeShowDialog"></showDialog>
</template>

<script setup>
import { ref, onMounted, computed, watch, nextTick } from 'vue'
import { ArrowDown, Search, ChromeFilled, CaretBottom } from '@element-plus/icons-vue'
import { treeTask , listColumns, tabledrawer, workitemInstIds,projectId } from '../info'
import listTable from './listComponents/list-table.vue'
import { deleteInst,allFilterFields,getlist } from '@/api/workitem'
import batchActionDialog from './detailComponents/batchAction.vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import showDialog  from './components/workflow/listShowDialog.vue'
const checkedValues = ref([])
const expandableColumns = ref([])

let loading = ref(true)
let showTableColumn = ref([])
let visible = ref(false)


const multipleSelection = ref([]);
const handleSelectionChange = (rows) => {
  // console.log(rows)
  workitemInstIds.value = rows.map((item) => item.workitemInstId)
  multipleSelection.value = workitemInstIds.value
  // console.log(workitemInstIds.value.join(','))
}
watch(
  () => treeTask.value.workitemTypeId,
  () => {
    // drawTable()
    reqGetProjectViews()
    reqGetlist()
  }
)

const edit = (row) => { 
  console.log(row);
}
//
let citiesArr = computed(() => {
  let cities =  showTableColumn.value.map(item => item.label)
  return cities
})
let items = computed(() => {
  let items = citiesArr.value.map((item, index) => {
  return {
    label: item,
    id: index + 1,
    checked: true
  };
});
  return items
})
onMounted(() => {
  // drawTable()
  reqGetProjectViews()
  reqGetlist()
})
const pager =reactive({
  num: 1,
  size: 10
})
const handleSizeChange = (val) => {
  pager.size = val
  reqGetlist()
}
const handleCurrentChange = (val) => {
  pager.num = val
  reqGetlist()
}

let showDialogRef = ref('')
const selectClounm = async () => {
  visible.value = true
}
// 关闭弹层
const closeShowDialog = () => { 
  visible.value = false
}

// 表头
const reqGetProjectViews = async()=>{ 
  const { rows:res } = await allFilterFields(projectId.value, treeTask.value.workitemTypeId ||'202501101355540000079e3d84c60223')
  showTableColumn.value = res.map(item => ({
    label: item.label,
    prop: item.name,
    tooltip: true,
    align: 'center'
  }));
  console.log(showTableColumn.value);
}

const SearchText = ref(null)
const total = ref(0)
const tableData = ref([])
// 列表
const reqGetlist = async () => {
  loading.value = true 
  const res = await getlist({
    pageNum: pager.num,
    pageSize: pager.size,
    title: SearchText.value
  });
  tableData.value = res.rows.map(item => ({
    workitemType: item.workitemTypeName,
    status: item.status,
    testResult: item.title,
    title: item.title,
    assignee: item.assignee,
    testSteps: item.title,
    description: item.description,
    project: item.projectName,
    priority:item.priority,
    author: item.createBy,
    workitemId: item.workitemId,
    workitemInstId:item.workitemInstId
  }))
  total.value = res.total
  loading.value = false
}

const rowRef = ref(null)

//删除,移动,复制-------------------------------------------------
let handleNodeClick = inject('handleNodeClick')
const deleteDatil = () => {
  deleteInst(workitemInstIds.value.join(',')).then(({ code }) => {
    handleNodeClick(treeTask.value)
    VFormRenderV.value = false
    checkListIndex.value = null
    listTask.value = {}
    infoTaskIcon.value = ''
    ElMessage.success('删除成功!')
  })
}
const batchType = ref('')
const batchTypeV = ref(false)
const handleBatch = (type) => {
  batchType.value = type
  batchTypeV.value = true
}
const getTableHeight = computed(() => {
  console.log(window.innerHeight - 440, 's duosao')
  return window.innerHeight - 440
})
</script>
<style lang="scss" scoped>
.check {
  display: flex;
  align-items: center;
}
.checkbox-group-flex {
  margin-left: 10px;
  display: flex;
  flex-direction: column; /* 设置为列方向布局,使内部元素垂直排列 */
}
.opt-search {
  flex-shrink: 0;
  padding: 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #fdfdfd;
  .opt-box {
    display: flex;
    align-items: center;
  }
}
.borderno {
  --el-tag-border-color: none;
}

</style>
相关推荐
JSON_L24 分钟前
Vue 响应式渲染 - 列表渲染
前端·javascript·vue.js
User:你的影子26 分钟前
WPF进度条渲染
前端·javascript·c#·wpf
bin91531 小时前
DeepSeek与Vue.js组件开发:解锁AI与前端开发的融合密码
vue.js·deepseek
不会&编程1 小时前
第3章 使用 Vue 脚手架
前端·javascript·vue.js
ttod_qzstudio1 小时前
基于Typescript,使用Vite构建融合Vue.js的Babylon.js开发环境
vue.js·typescript·babylon.js
杨晓风-linda1 小时前
Angular-hello world
前端·javascript·angular.js
一只理智恩1 小时前
Cesium 离线加载瓦片图
前端·javascript·arcgis
幸福右手牵2 小时前
WPS如何接入DeepSeek(通过JS宏调用)
javascript·人工智能·深度学习·wps·deepseek
GISer_Jing3 小时前
Javascript包管理工具——NPM常见内容
javascript·npm
_未知_开摆4 小时前
运行npm install卡住不动的
前端·vue.js·vscode·elementui·npm·node.js