使用oracle数据库做的数据上传系统前端
kongdeqiang
2026-03-23 2adf0b60f951746518feb88a11501b10455d83d6
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<template>
  <div class="unit-statistics">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>各单位数据统计</span>
        </div>
      </template>
 
      <el-form :inline="true" :model="searchForm" class="search-form">
        <el-form-item label="单位">
          <el-select
            v-model="searchForm.unitCode"
            placeholder="请选择单位"
            clearable
            filterable
            style="width: 250px"
          >
            <el-option
              v-for="dept in flatDepartmentList"
              :key="dept.deptCode"
              :label="`${dept.deptCode} - ${dept.deptName}`"
              :value="dept.deptCode"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :icon="Search" @click="handleSearch">搜索</el-button>
          <el-button :icon="Refresh" @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
 
      <el-table :data="tableData" v-loading="loading" border stripe>
        <el-table-column prop="unitCode" label="单位编码" width="150" />
        <el-table-column prop="unitName" label="单位名称" width="300" />
        <el-table-column prop="taskCount" label="任务条数" width="120" />
        <el-table-column prop="successCount" label="完成条数" width="120" />
        <el-table-column prop="status" label="完成状态" width="100">
          <template #default="{ row }">
            <el-tag :type="row.status === 1 ? 'success' : 'warning'">
              {{ row.status === 1 ? '已完成' : '未完成' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="lastTime" label="最后上传时间" />
      </el-table>
 
      <el-pagination
        v-model:current-page="pagination.currentPage"
        v-model:page-size="pagination.pageSize"
        :page-sizes="[10, 20, 50, 100]"
        :total="pagination.total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        style="margin-top: 20px; justify-content: flex-end"
      />
    </el-card>
  </div>
</template>
 
<script setup>
import { ref, reactive, computed, onMounted } from 'vue'
import { Search, Refresh } from '@element-plus/icons-vue'
import { getDepartmentTree } from '@/api/department'
import { getUnitStatisticsPage } from '@/api/statistics'
 
const loading = ref(false)
const tableData = ref([])
const departmentList = ref([])
 
const searchForm = reactive({
  unitCode: ''
})
 
const pagination = reactive({
  currentPage: 1,
  pageSize: 10,
  total: 0
})
 
const flatDepartmentList = computed(() => {
  const flatten = (list) => {
    let result = []
    list.forEach(item => {
      result.push(item)
      if (item.children && item.children.length > 0) {
        result = result.concat(flatten(item.children))
      }
    })
    return result
  }
  return flatten(departmentList.value)
})
 
const buildTree = (list) => {
  const map = {}
  const roots = []
 
  list.forEach(item => {
    map[item.deptCode] = { ...item, children: [] }
  })
 
  list.forEach(item => {
    const parent = map[item.parentCode]
    if (parent) {
      parent.children.push(map[item.deptCode])
    } else {
      roots.push(map[item.deptCode])
    }
  })
 
  const cleanEmptyChildren = (nodes) => {
    nodes.forEach(node => {
      if (node.children && node.children.length === 0) {
        delete node.children
      } else {
        cleanEmptyChildren(node.children)
      }
    })
  }
 
  cleanEmptyChildren(roots)
  return roots
}
 
const fetchDepartmentList = async () => {
  try {
    const res = await getDepartmentTree()
    departmentList.value = buildTree(res.data)
  } catch (error) {
    console.error('获取部门列表失败:', error)
  }
}
 
const fetchData = async () => {
  loading.value = true
  try {
    const res = await getUnitStatisticsPage({
      page: pagination.currentPage,
      size: pagination.pageSize,
      unitCode: searchForm.unitCode
    })
    tableData.value = res.data.records || res.data
    pagination.total = res.data.total || res.data.length
  } catch (error) {
    console.error('获取统计数据失败:', error)
  } finally {
    loading.value = false
  }
}
 
const handleSearch = () => {
  pagination.currentPage = 1
  fetchData()
}
 
const handleReset = () => {
  searchForm.unitCode = ''
  pagination.currentPage = 1
  fetchData()
}
 
const handleSizeChange = (val) => {
  pagination.pageSize = val
  fetchData()
}
 
const handleCurrentChange = (val) => {
  pagination.currentPage = val
  fetchData()
}
 
onMounted(() => {
  fetchDepartmentList()
  fetchData()
})
</script>
 
<style scoped>
.unit-statistics {
  padding: 20px;
}
 
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
.search-form {
  margin-bottom: 20px;
}
</style>