gaoluyang
4 天以前 c4b339705e5d2d1a33f4f3d6b5d7e19ac7d68faa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<template>
  <div class="app-container">
    <!-- 简单的搜索区域 -->
    <el-card class="search-card">
      <el-form :inline="true">
        <el-form-item label="部门">
          <el-input v-model="searchForm.department" placeholder="请输入部门" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">搜索</el-button>
          <el-button @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
 
    <!-- 动态表格 -->
    <el-card class="table-card">
      <template #header>
        <div class="card-header">
          <span>员工信息表</span>
          <el-button type="primary" size="small" @click="handleAdd">新增员工</el-button>
        </div>
      </template>
      
      <DynamicTable
        :data="tableData"
        :dict-types="dictTypes"
        :loading="loading"
        :show-selection="true"
        :show-actions="true"
        height="400px"
        @selection-change="handleSelectionChange"
        @edit="handleEdit"
        @delete="handleDelete"
      />
    </el-card>
  </div>
</template>
 
<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'
import DynamicTable from '@/components/DynamicTable/index.vue'
 
// 搜索表单
const searchForm = reactive({
  department: ''
})
 
// 表格数据
const tableData = ref([
  {
    id: 1,
    department: '技术部',
    name: '张三',
    employeeId: 'EMP001',
    sys_normal_disable: '1',  // 状态
    sys_user_level: '2',      // 级别
    sys_user_position: '1'    // 职位
  },
  {
    id: 2,
    department: '人事部',
    name: '李四',
    employeeId: 'EMP002',
    sys_normal_disable: '0',  // 状态
    sys_user_level: '1',      // 级别
    sys_user_position: '2'    // 职位
  }
])
 
// 字典类型
const dictTypes = ref([
  'sys_normal_disable', // 状态:启用/禁用
  'sys_user_level',     // 级别:初级/中级/高级
  'sys_user_position'   // 职位:员工/主管/经理
])
 
// 加载状态
const loading = ref(false)
 
// 事件处理
const handleSearch = () => {
  loading.value = true
  // 模拟搜索
  setTimeout(() => {
    loading.value = false
    ElMessage.success('搜索完成')
  }, 1000)
}
 
const handleReset = () => {
  searchForm.department = ''
}
 
const handleAdd = () => {
  ElMessage.info('新增功能待实现')
}
 
const handleSelectionChange = (selection) => {
  console.log('选中的行:', selection)
}
 
const handleEdit = (row, index) => {
  ElMessage.info(`编辑第${index + 1}行数据`)
}
 
const handleDelete = (row, index) => {
  ElMessage.warning(`删除第${index + 1}行数据`)
}
</script>
 
<style scoped>
.app-container {
  padding: 20px;
}
 
.search-card {
  margin-bottom: 20px;
}
 
.table-card {
  margin-bottom: 20px;
}
 
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
:deep(.el-form-item) {
  margin-bottom: 0;
}
</style>