index.vue 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  1. <template>
  2. <div class="app-container">
  3. <!-- 查询条件 -->
  4. <div class="filter-section">
  5. <el-card>
  6. <div class="filter-container">
  7. <el-form :model="queryParams" ref="queryFormRef" :inline="true" class="search-form">
  8. <el-form-item label="考核月份" prop="assessmentMonth">
  9. <el-date-picker v-model="queryParams.assessmentMonth" type="month" placeholder="请选择考核月份"
  10. value-format="YYYY-MM" style="width: 200px" />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
  14. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <div class="export-button">
  18. <el-button type="warning" icon="Document" @click="handleExport">导出文档</el-button>
  19. </div>
  20. </div>
  21. </el-card>
  22. </div>
  23. <!-- 非干部月度考核分数汇总 -->
  24. <div class="main-section">
  25. <h2 class="section-title">非干部月度考核分数汇总</h2>
  26. <!-- 第一行:两个区块 -->
  27. <div class="chart-row">
  28. <!-- 整体分值分布柱状图 -->
  29. <el-card class="chart-card">
  30. <div class="chart-header">整体分值分布柱状图</div>
  31. <div ref="overallBarChart" class="chart-container"></div>
  32. </el-card>
  33. <!-- 参与人数占比饼图 -->
  34. <el-card class="chart-card">
  35. <div class="chart-header">参与人数占比饼图</div>
  36. <div ref="participantPieChart" class="chart-container"></div>
  37. </el-card>
  38. </div>
  39. <!-- 第二行:两个区块 -->
  40. <div class="chart-row">
  41. <!-- 各部门分值分布对比图 -->
  42. <el-card class="chart-card">
  43. <div class="chart-header">各部门分值分布对比图</div>
  44. <div ref="departmentComparisonChart" class="chart-container"></div>
  45. </el-card>
  46. <!-- 汇总表 -->
  47. <el-card class="chart-card">
  48. <div class="chart-header">汇总表</div>
  49. <el-table :data="summaryTableData" border style="width: 100%; margin-top: 10px;">
  50. <el-table-column prop="rangeLabel" label="区间" align="center" min-width="100" />
  51. <el-table-column prop="totalCount" :label="summaryTableTitle" align="center" min-width="150" />
  52. <el-table-column v-for="col in summaryTableColumns" :key="col.deptId" :prop="'team' + col.deptId"
  53. :label="col.deptName" align="center" min-width="100" />
  54. </el-table>
  55. </el-card>
  56. </div>
  57. </div>
  58. <!-- 非干部月度考核分类结果汇总 -->
  59. <div class="main-section">
  60. <h2 class="section-title">非干部月度考核分类结果汇总</h2>
  61. <!-- 汇总统计表格 -->
  62. <el-card class="summary-table-card">
  63. <div class="chart-header">汇总统计</div>
  64. <el-table :data="classificationTableData" border style="width: 100%; margin-top: 10px;">
  65. <el-table-column prop="assessmentTeamCount" label="考核组人数" align="center" min-width="120" />
  66. <el-table-column prop="estimatedImprovementCount" label="测算待改进人数" align="center" min-width="140" />
  67. <el-table-column prop="improvementTotalCount" label="待改进总人数" align="center" min-width="120" />
  68. <el-table-column prop="improvementExemptedCount" label="待改进豁免" align="center" min-width="100" />
  69. <el-table-column prop="actualImprovementCount" label="实际待改进总人数" align="center" min-width="140" />
  70. <el-table-column prop="incompetentTotalCount" label="不称职总人数" align="center" min-width="120" />
  71. <el-table-column prop="incompetentExemptedCount" label="不称职豁免" align="center" min-width="100" />
  72. <el-table-column prop="actualIncompetentCount" label="实际不称职人数" align="center" min-width="140" />
  73. </el-table>
  74. </el-card>
  75. <!-- 第四行:两个区块 -->
  76. <div class="chart-row">
  77. <!-- 大队分布统计图 -->
  78. <el-card class="chart-card">
  79. <div class="chart-header">大队分布统计图</div>
  80. <div class="pie-charts-container">
  81. <div ref="brigadePieChart1" class="pie-chart"></div>
  82. <div ref="brigadePieChart2" class="pie-chart"></div>
  83. </div>
  84. </el-card>
  85. <!-- 岗位分布统计图 -->
  86. <el-card class="chart-card">
  87. <div class="chart-header">岗位分布统计图</div>
  88. <div class="pie-charts-container">
  89. <div ref="positionPieChart1" class="pie-chart"></div>
  90. <div ref="positionPieChart2" class="pie-chart"></div>
  91. </div>
  92. </el-card>
  93. </div>
  94. </div>
  95. <!-- 第一个遍历:表格和两个饼状图 -->
  96. <div class="traversal-section">
  97. <div v-for="(item, index) in traversalData1" :key="index" class="traversal-container">
  98. <div class="traversal-header">{{ item.title }}</div>
  99. <div class="traversal-content">
  100. <!-- 左边表格 -->
  101. <div class="table-section">
  102. <el-table :data="item.tableData" border style="width: 100%;">
  103. <el-table-column prop="assessmentTeam" label="考核组" align="center" min-width="100" />
  104. <el-table-column prop="assessmentTeamCount" label="考核组人数" align="center" min-width="120" />
  105. <el-table-column prop="estimatedImprovementCount" label="测算待改进人数" align="center" min-width="140" />
  106. <el-table-column prop="improvementTotalCount" label="待改进总人数" align="center" min-width="120" />
  107. <el-table-column prop="improvementExemptedCount" label="待改进豁免人数" align="center" min-width="140" />
  108. <el-table-column prop="actualImprovementCount" label="实际待改进人数" align="center" min-width="140" />
  109. <el-table-column prop="incompetentTotalCount" label="不称职总人数" align="center" min-width="120" />
  110. <el-table-column prop="incompetentExemptedCount" label="不称职豁免人数" align="center" min-width="140" />
  111. <el-table-column prop="actualIncompetentCount" label="实际不称职人数" align="center" min-width="140" />
  112. </el-table>
  113. </div>
  114. <!-- 右边两个饼状图 -->
  115. <div class="chart-section">
  116. <div class="pie-chart-container">
  117. <div class="pie-chart-title">{{ item.title }}实际待改进人数分布</div>
  118. <div :ref="el => setTraversalChartRef(el, `pieChart1_${index}`)" class="pie-chart"></div>
  119. </div>
  120. <div class="pie-chart-container">
  121. <div class="pie-chart-title">{{ item.title }}实际不称职人数分布</div>
  122. <div :ref="el => setTraversalChartRef(el, `pieChart2_${index}`)" class="pie-chart"></div>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. </div>
  128. <!-- 第二个遍历:表格、柱状图和饼状图 -->
  129. <div class="traversal-section">
  130. <div v-for="(item, index) in traversalData2" :key="index" class="traversal-container">
  131. <div class="traversal-header">{{ item.title }}</div>
  132. <div class="traversal-content">
  133. <!-- 左边表格 -->
  134. <div class="table-section">
  135. <el-table :data="item.tableData" border style="width: 100%;">
  136. <el-table-column prop="assessmentTeam" label="考核组" align="center" min-width="100" />
  137. <el-table-column prop="assessmentTeamCount" label="考核组人数" align="center" min-width="120" />
  138. <el-table-column prop="estimatedImprovementCount" label="测算待改进人数" align="center" min-width="140" />
  139. <el-table-column prop="improvementTotalCount" label="待改进人数" align="center" min-width="120" />
  140. <el-table-column prop="improvementExemptedCount" label="豁免" align="center" min-width="80" />
  141. <el-table-column prop="actualImprovementCount" label="实际待改进人数" align="center" min-width="140" />
  142. <el-table-column prop="incompetentTotalCount" label="不称职人数" align="center" min-width="120" />
  143. <el-table-column prop="incompetentExemptedCount" label="豁免" align="center" min-width="80" />
  144. <el-table-column prop="actualIncompetentCount" label="实际不称职人数" align="center" min-width="140" />
  145. </el-table>
  146. </div>
  147. <!-- 右边柱状图和饼状图 -->
  148. <div class="chart-section">
  149. <div class="bar-chart-container">
  150. <div class="chart-title">{{ item.title }}考核人数与待改进情况</div>
  151. <div :ref="el => setTraversalChartRef(el, `barChart_${index}`)" class="bar-chart"></div>
  152. </div>
  153. <div class="pie-chart-container">
  154. <div class="pie-chart-title">{{ item.title }}考核人数占比</div>
  155. <div :ref="el => setTraversalChartRef(el, `pieChart3_${index}`)" class="pie-chart"></div>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. </template>
  163. <script setup>
  164. import { ref, reactive, onMounted, onUnmounted, nextTick, computed } from 'vue'
  165. import { ElMessage, ElLoading } from 'element-plus'
  166. import * as echarts from 'echarts'
  167. import html2canvas from 'html2canvas'
  168. import { Document, Packer, Paragraph, ImageRun, HeadingLevel, AlignmentType } from 'docx'
  169. import { saveAs } from 'file-saver'
  170. // API导入
  171. import {
  172. getScoreDistribution,
  173. getDeptParticipation,
  174. getDeptScoreDistribution,
  175. getAssessmentSummary,
  176. getActualImprovementDistribution,
  177. getActualIncompetentDistribution,
  178. getAssessmentTeamImprovementDistribution,
  179. getAssessmentTeamIncompetentDistribution,
  180. getDeptAssessmentTeamStatistics,
  181. getBrigadeImprovementDistribution,
  182. getBrigadeIncompetentDistribution,
  183. getFunctionalDeptSummary,
  184. getFunctionalDeptPersonnelDistribution,
  185. getFunctionalDeptDistributionPie
  186. } from '@/api/performance/monthlyAssessSum.js'
  187. import { listDept } from '@/api/system/dept.js'
  188. import { useDict } from '@/utils/dict'
  189. import { selectDictLabel } from '@/utils/ruoyi'
  190. // 获取字典数据
  191. const { assessment_team } = useDict('assessment_team')
  192. // 响应式数据
  193. const loading = ref(false)
  194. const queryFormRef = ref()
  195. // 查询参数
  196. const currentMonth = `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, '0')}`
  197. const queryParams = reactive({
  198. assessmentMonth: currentMonth
  199. })
  200. const summaryTableTitle = computed(() => {
  201. if (queryParams.assessmentMonth) {
  202. const [year, month] = queryParams.assessmentMonth.split('-')
  203. return `${year}年${parseInt(month)}月模拟分数汇总`
  204. }
  205. return '模拟分数汇总'
  206. })
  207. // 图表引用
  208. const overallBarChart = ref(null)
  209. const participantPieChart = ref(null)
  210. const departmentComparisonChart = ref(null)
  211. const brigadePieChart1 = ref(null)
  212. const brigadePieChart2 = ref(null)
  213. const positionPieChart1 = ref(null)
  214. const positionPieChart2 = ref(null)
  215. // 遍历图表引用
  216. const traversalChartsRefs = ref({})
  217. // 表格数据
  218. const summaryTableData = ref([])
  219. const summaryTableColumns = ref([])
  220. const classificationTableData = ref([
  221. ])
  222. // 遍历数据
  223. const traversalData1 = ref([
  224. ])
  225. const traversalData2 = ref([
  226. ])
  227. // 图表实例
  228. let overallBarChartInstance = null
  229. let participantPieChartInstance = null
  230. let departmentComparisonChartInstance = null
  231. let brigadePieChart1Instance = null
  232. let brigadePieChart2Instance = null
  233. let positionPieChart1Instance = null
  234. let positionPieChart2Instance = null
  235. // 初始化图表
  236. const initCharts = () => {
  237. nextTick(() => {
  238. // 整体分值分布柱状图
  239. if (overallBarChart.value) {
  240. overallBarChartInstance = echarts.init(overallBarChart.value)
  241. overallBarChartInstance.setOption({
  242. tooltip: { trigger: 'axis' },
  243. xAxis: { type: 'category', data: ['90-100分', '80-89分', '70-79分', '60-69分', '60分以下'] },
  244. yAxis: { type: 'value' },
  245. series: [{ type: 'bar', data: [85, 120, 95, 60, 20], itemStyle: { color: '#3b82f6' } }]
  246. })
  247. }
  248. // 参与人数占比饼图
  249. if (participantPieChart.value) {
  250. participantPieChartInstance = echarts.init(participantPieChart.value)
  251. participantPieChartInstance.setOption({
  252. tooltip: { trigger: 'item' },
  253. series: [{
  254. type: 'pie',
  255. radius: '70%',
  256. data: [
  257. { value: 380, name: '参与考核' },
  258. { value: 20, name: '未参与考核' }
  259. ]
  260. }]
  261. })
  262. }
  263. // 各部门分值分布对比图
  264. if (departmentComparisonChart.value) {
  265. departmentComparisonChartInstance = echarts.init(departmentComparisonChart.value)
  266. departmentComparisonChartInstance.setOption({
  267. tooltip: { trigger: 'axis' },
  268. legend: { data: ['一队', '二队', '三队'] },
  269. xAxis: { type: 'category', data: ['90-100分', '80-89分', '70-79分', '60-69分', '60分以下'] },
  270. yAxis: { type: 'value' },
  271. series: [
  272. { name: '一队', type: 'bar', data: [15, 30, 25, 15, 5] },
  273. { name: '二队', type: 'bar', data: [20, 35, 30, 20, 8] },
  274. { name: '三队', type: 'bar', data: [25, 40, 35, 25, 7] }
  275. ]
  276. })
  277. }
  278. // 大队分布饼图1
  279. if (brigadePieChart1.value) {
  280. brigadePieChart1Instance = echarts.init(brigadePieChart1.value)
  281. brigadePieChart1Instance.setOption({
  282. tooltip: { trigger: 'item' },
  283. series: [{
  284. type: 'pie',
  285. radius: '50%',
  286. data: [
  287. { value: 120, name: '一队' },
  288. { value: 150, name: '二队' },
  289. { value: 130, name: '三队' }
  290. ]
  291. }]
  292. })
  293. }
  294. // 大队分布饼图2
  295. if (brigadePieChart2.value) {
  296. brigadePieChart2Instance = echarts.init(brigadePieChart2.value)
  297. brigadePieChart2Instance.setOption({
  298. tooltip: { trigger: 'item' },
  299. series: [{
  300. type: 'pie',
  301. radius: '50%',
  302. data: [
  303. { value: 45, name: '优秀' },
  304. { value: 280, name: '合格' },
  305. { value: 75, name: '待改进' }
  306. ]
  307. }]
  308. })
  309. }
  310. // 岗位分布饼图1
  311. if (positionPieChart1.value) {
  312. positionPieChart1Instance = echarts.init(positionPieChart1.value)
  313. positionPieChart1Instance.setOption({
  314. tooltip: { trigger: 'item' },
  315. series: [{
  316. type: 'pie',
  317. radius: '50%',
  318. data: [
  319. { value: 150, name: '安检员' },
  320. { value: 120, name: '设备操作员' },
  321. { value: 80, name: '管理人员' },
  322. { value: 50, name: '其他' }
  323. ]
  324. }]
  325. })
  326. }
  327. // 岗位分布饼图2
  328. if (positionPieChart2.value) {
  329. positionPieChart2Instance = echarts.init(positionPieChart2.value)
  330. positionPieChart2Instance.setOption({
  331. tooltip: { trigger: 'item' },
  332. series: [{
  333. type: 'pie',
  334. radius: '50%',
  335. data: [
  336. { value: 35, name: '优秀' },
  337. { value: 320, name: '合格' },
  338. { value: 45, name: '待改进' }
  339. ]
  340. }]
  341. })
  342. }
  343. })
  344. }
  345. // 设置遍历图表引用
  346. const setTraversalChartRef = (el, key) => {
  347. if (el) {
  348. traversalChartsRefs.value[key] = el
  349. }
  350. }
  351. // 初始化遍历图表
  352. const initTraversalCharts = () => {
  353. nextTick(() => {
  354. // 第一个遍历的饼状图
  355. traversalData1.value.forEach((item, index) => {
  356. // 饼状图1:考核结果分布
  357. const pieChart1Key = `pieChart1_${index}`
  358. if (traversalChartsRefs.value[pieChart1Key]) {
  359. const pieChart1 = echarts.init(traversalChartsRefs.value[pieChart1Key])
  360. pieChart1.setOption({
  361. tooltip: { trigger: 'item' },
  362. series: [{
  363. type: 'pie',
  364. radius: '50%',
  365. data: [
  366. { value: 120, name: '优秀' },
  367. { value: 280, name: '合格' },
  368. { value: 75, name: '待改进' }
  369. ]
  370. }]
  371. })
  372. }
  373. // 饼状图2:改进情况分布
  374. const pieChart2Key = `pieChart2_${index}`
  375. if (traversalChartsRefs.value[pieChart2Key]) {
  376. const pieChart2 = echarts.init(traversalChartsRefs.value[pieChart2Key])
  377. pieChart2.setOption({
  378. tooltip: { trigger: 'item' },
  379. series: [{
  380. type: 'pie',
  381. radius: '50%',
  382. data: [
  383. { value: 15, name: '已改进' },
  384. { value: 60, name: '待改进' },
  385. { value: 5, name: '未改进' }
  386. ]
  387. }]
  388. })
  389. }
  390. })
  391. // 第二个遍历的图表
  392. traversalData2.value.forEach((item, index) => {
  393. // 柱状图:考核分数分布
  394. const barChartKey = `barChart_${index}`
  395. if (traversalChartsRefs.value[barChartKey]) {
  396. const barChart = echarts.init(traversalChartsRefs.value[barChartKey])
  397. barChart.setOption({
  398. tooltip: { trigger: 'axis' },
  399. xAxis: { type: 'category', data: ['90-100分', '80-89分', '70-79分', '60-69分', '60分以下'] },
  400. yAxis: { type: 'value' },
  401. series: [{ type: 'bar', data: [85, 120, 95, 60, 20], itemStyle: { color: '#3b82f6' } }]
  402. })
  403. }
  404. // 饼状图:岗位分布
  405. const pieChart3Key = `pieChart3_${index}`
  406. if (traversalChartsRefs.value[pieChart3Key]) {
  407. const pieChart3 = echarts.init(traversalChartsRefs.value[pieChart3Key])
  408. pieChart3.setOption({
  409. tooltip: { trigger: 'item' },
  410. series: [{
  411. type: 'pie',
  412. radius: '50%',
  413. data: [
  414. { value: 150, name: '安检员' },
  415. { value: 120, name: '设备操作员' },
  416. { value: 80, name: '管理人员' },
  417. { value: 50, name: '其他' }
  418. ]
  419. }]
  420. })
  421. }
  422. })
  423. })
  424. }
  425. // 窗口大小变化时重绘图表
  426. const handleResize = () => {
  427. const charts = [
  428. overallBarChartInstance,
  429. participantPieChartInstance,
  430. departmentComparisonChartInstance,
  431. brigadePieChart1Instance,
  432. brigadePieChart2Instance,
  433. positionPieChart1Instance,
  434. positionPieChart2Instance
  435. ]
  436. charts.forEach(chart => {
  437. if (chart) chart.resize()
  438. })
  439. }
  440. // 获取数据
  441. const getList = async () => {
  442. loading.value = true
  443. try {
  444. // 格式化参数:YYYY-MM -> YYYYMM
  445. const formatParams = (params) => {
  446. const formatted = { ...params }
  447. if (formatted.assessmentMonth) {
  448. formatted.assessmentMonth = formatted.assessmentMonth.replace('-', '')
  449. }
  450. return formatted
  451. }
  452. // 获取大队列表
  453. const brigadeListRes = await listDept()
  454. const brigadeList = (brigadeListRes.data || []).filter(item => item.deptType === 'BRIGADE' && item.isFunctionalDept == 0)
  455. // 其他接口调用
  456. const formattedQueryParams = formatParams(queryParams)
  457. const results = await Promise.allSettled([
  458. getScoreDistribution(formattedQueryParams),
  459. getDeptParticipation(formattedQueryParams),
  460. getDeptScoreDistribution(formattedQueryParams),
  461. getAssessmentSummary(formattedQueryParams),
  462. getActualImprovementDistribution(formattedQueryParams),
  463. getActualIncompetentDistribution(formattedQueryParams),
  464. getAssessmentTeamImprovementDistribution(formattedQueryParams),
  465. getAssessmentTeamIncompetentDistribution(formattedQueryParams),
  466. getFunctionalDeptSummary(formattedQueryParams),
  467. getFunctionalDeptPersonnelDistribution(formattedQueryParams),
  468. getFunctionalDeptDistributionPie(formattedQueryParams)
  469. ])
  470. const [scoreDistRes, deptPartRes, deptScoreRes, assessmentSumRes, actualImproveRes, actualIncompRes, teamImproveRes, teamIncompRes, functionalDeptRes, functionalDeptPersonnelRes, functionalDeptPieRes] = results
  471. // 对每个大队调用三个接口
  472. const brigadeDataPromises = brigadeList.map(async (brigade) => {
  473. const brigadeParams = formatParams({ ...queryParams, deptId: brigade.deptId })
  474. const brigadeResults = await Promise.allSettled([
  475. getDeptAssessmentTeamStatistics(brigadeParams),
  476. getBrigadeImprovementDistribution(brigadeParams),
  477. getBrigadeIncompetentDistribution(brigadeParams)
  478. ])
  479. const [deptTeamStatRes, brigadeImproveRes, brigadeIncompRes] = brigadeResults
  480. const statisticsData = deptTeamStatRes.status === 'fulfilled' ? (deptTeamStatRes.value.data || []) : []
  481. const brigadeImproveData = brigadeImproveRes.status === 'fulfilled' ? (brigadeImproveRes.value.data || []) : []
  482. const brigadeIncompData = brigadeIncompRes.status === 'fulfilled' ? (brigadeIncompRes.value.data || []) : []
  483. // 解析表格数据
  484. let tableData = []
  485. if (statisticsData.length > 0 && statisticsData[0].assessmentTeams) {
  486. tableData = statisticsData[0].assessmentTeams.map(item => ({
  487. ...item,
  488. assessmentTeam: selectDictLabel(assessment_team.value, item.assessmentTeam)
  489. }))
  490. }
  491. // 计算总计用于标题
  492. const totalImprovement = tableData.reduce((sum, item) => sum + (item.actualImprovementCount || 0), 0)
  493. const totalIncompetent = tableData.reduce((sum, item) => sum + (item.actualIncompetentCount || 0), 0)
  494. return {
  495. title: brigade.deptName,
  496. deptId: brigade.deptId,
  497. tableData,
  498. improveData: brigadeImproveData,
  499. incompData: brigadeIncompData,
  500. totalImprovement,
  501. totalIncompetent
  502. }
  503. })
  504. traversalData1.value = await Promise.all(brigadeDataPromises)
  505. traversalData1.value = traversalData1.value.filter(item => item.tableData?.length > 0 || item.improveData?.length > 0 || item.incompData?.length > 0)
  506. console.log(traversalData1.value)
  507. // debugger
  508. if (scoreDistRes.status === 'fulfilled' && scoreDistRes.value.data) {
  509. const data = scoreDistRes.value.data
  510. if (overallBarChartInstance && Array.isArray(data)) {
  511. overallBarChartInstance.setOption({
  512. xAxis: { data: data.map(item => item.scoreRange) },
  513. series: [{ data: data.map(item => item.count) }]
  514. })
  515. }
  516. }
  517. if (deptPartRes.status === 'fulfilled' && deptPartRes.value.data) {
  518. const data = deptPartRes.value.data
  519. if (participantPieChartInstance && Array.isArray(data)) {
  520. participantPieChartInstance.setOption({
  521. series: [{ data: data.map(item => ({ name: item.deptName, value: item.count })) }]
  522. })
  523. }
  524. }
  525. if (deptScoreRes.status === 'fulfilled' && deptScoreRes.value.data) {
  526. const data = deptScoreRes.value.data
  527. if (departmentComparisonChartInstance && Array.isArray(data)) {
  528. const xAxisData = data.map(item => item.rangeLabel)
  529. const firstDeptCounts = data.length > 0 ? data[0].deptCounts : []
  530. const series = firstDeptCounts.map(dept => ({
  531. name: dept.deptName,
  532. type: 'bar',
  533. data: data.map(item => {
  534. const deptData = item.deptCounts.find(d => d.deptId === dept.deptId)
  535. return deptData ? deptData.count : 0
  536. })
  537. }))
  538. departmentComparisonChartInstance.setOption({
  539. legend: { data: firstDeptCounts.map(d => d.deptName) },
  540. xAxis: { data: xAxisData },
  541. series: series
  542. })
  543. summaryTableColumns.value = firstDeptCounts
  544. summaryTableData.value = data.map(item => {
  545. const row = {
  546. rangeLabel: item.rangeLabel,
  547. totalCount: item.totalCount
  548. }
  549. item.deptCounts.forEach(dept => {
  550. row['team' + dept.deptId] = dept.count
  551. })
  552. return row
  553. })
  554. }
  555. }
  556. if (assessmentSumRes.status === 'fulfilled' && assessmentSumRes.value.data) {
  557. const data = assessmentSumRes.value.data
  558. if (data && typeof data === 'object') {
  559. classificationTableData.value = [data]
  560. }
  561. }
  562. if (actualImproveRes.status === 'fulfilled' && actualImproveRes.value.data) {
  563. const data = actualImproveRes.value.data
  564. if (brigadePieChart1Instance && Array.isArray(data)) {
  565. brigadePieChart1Instance.setOption({
  566. series: [{ data: data.map(item => ({ name: item.deptName, value: item.count })) }]
  567. })
  568. }
  569. }
  570. if (actualIncompRes.status === 'fulfilled' && actualIncompRes.value.data) {
  571. const data = actualIncompRes.value.data
  572. if (brigadePieChart2Instance && Array.isArray(data)) {
  573. brigadePieChart2Instance.setOption({
  574. series: [{ data: data.map(item => ({ name: item.deptName, value: item.count })) }]
  575. })
  576. }
  577. }
  578. if (teamImproveRes.status === 'fulfilled' && teamImproveRes.value.data) {
  579. const data = teamImproveRes.value.data
  580. if (positionPieChart1Instance && Array.isArray(data)) {
  581. positionPieChart1Instance.setOption({
  582. series: [{ data: data.map(item => ({ name: selectDictLabel(assessment_team.value, item.assessmentTeam), value: item.count })) }]
  583. })
  584. }
  585. }
  586. if (teamIncompRes.status === 'fulfilled' && teamIncompRes.value.data) {
  587. const data = teamIncompRes.value.data
  588. if (positionPieChart2Instance && Array.isArray(data)) {
  589. positionPieChart2Instance.setOption({
  590. series: [{ data: data.map(item => ({ name: selectDictLabel(assessment_team.value, item.assessmentTeam), value: item.count })) }]
  591. })
  592. }
  593. }
  594. // 初始化traversalData1对应的图表
  595. nextTick(() => {
  596. traversalData1.value.forEach((item, index) => {
  597. const chartKey1 = `pieChart1_${index}`
  598. const chartKey2 = `pieChart2_${index}`
  599. if (traversalChartsRefs.value[chartKey1] && item.improveData) {
  600. const pieChart1 = echarts.init(traversalChartsRefs.value[chartKey1])
  601. pieChart1.setOption({
  602. tooltip: { trigger: 'item' },
  603. series: [{
  604. type: 'pie',
  605. radius: '50%',
  606. data: item.improveData.map(d => ({ name: selectDictLabel(assessment_team.value, d.assessmentTeam), value: d.count }))
  607. }]
  608. })
  609. }
  610. if (traversalChartsRefs.value[chartKey2] && item.incompData) {
  611. const pieChart2 = echarts.init(traversalChartsRefs.value[chartKey2])
  612. pieChart2.setOption({
  613. tooltip: { trigger: 'item' },
  614. series: [{
  615. type: 'pie',
  616. radius: '50%',
  617. data: item.incompData.map(d => ({ name: selectDictLabel(assessment_team.value, d.assessmentTeam), value: d.count }))
  618. }]
  619. })
  620. }
  621. })
  622. })
  623. if (functionalDeptRes.status === 'fulfilled' && functionalDeptRes.value.data) {
  624. const summaryData = functionalDeptRes.value.data || []
  625. const personnelData = functionalDeptPersonnelRes.status === 'fulfilled' ? (functionalDeptPersonnelRes.value.data || []) : []
  626. const pieData = functionalDeptPieRes.status === 'fulfilled' ? (functionalDeptPieRes.value.data || []) : []
  627. traversalData2.value = summaryData.map(item => {
  628. // 匹配人员数据
  629. const personnelItem = personnelData.find(p => p.deptId === item.deptId)
  630. // 匹配饼图数据
  631. const deptPieData = pieData.filter(p => p.deptId === item.deptId)
  632. return {
  633. title: item.deptName,
  634. deptId: item.deptId,
  635. tableData: (item.assessmentTeams || []).map(t => ({
  636. ...t,
  637. assessmentTeam: selectDictLabel(assessment_team.value, t.assessmentTeam)
  638. })),
  639. barData: personnelItem ? [
  640. { name: '考核组人数', value: personnelItem.assessmentTeamCount || 0 },
  641. { name: '实际待改进人数', value: personnelItem.actualImprovementCount || 0 },
  642. { name: '实际不称职人数', value: personnelItem.actualIncompetentCount || 0 }
  643. ] : [],
  644. pieData: deptPieData.map(p => ({ name: selectDictLabel(assessment_team.value, p.assessmentTeam), value: p.count }))
  645. }
  646. })
  647. nextTick(() => {
  648. traversalData2.value.forEach((item, index) => {
  649. const chartKey = `barChart_${index}`
  650. const pieChartKey = `pieChart3_${index}`
  651. if (traversalChartsRefs.value[chartKey] && item.barData.length > 0) {
  652. const barChart = echarts.init(traversalChartsRefs.value[chartKey])
  653. barChart.setOption({
  654. tooltip: { trigger: 'axis' },
  655. xAxis: { type: 'category', data: item.barData.map(d => d.name) },
  656. yAxis: { type: 'value' },
  657. series: [{ type: 'bar', data: item.barData.map(d => d.value), itemStyle: { color: '#3b82f6' } }]
  658. })
  659. }
  660. if (traversalChartsRefs.value[pieChartKey] && item.pieData.length > 0) {
  661. const pieChart = echarts.init(traversalChartsRefs.value[pieChartKey])
  662. pieChart.setOption({
  663. tooltip: { trigger: 'item' },
  664. series: [{ type: 'pie', radius: '50%', data: item.pieData }]
  665. })
  666. }
  667. })
  668. })
  669. }
  670. } catch (error) {
  671. console.error('获取汇总数据失败:', error)
  672. ElMessage.error('获取汇总数据失败')
  673. } finally {
  674. loading.value = false
  675. }
  676. }
  677. // 查询
  678. const handleQuery = () => {
  679. getList()
  680. }
  681. // 重置查询
  682. const resetQuery = () => {
  683. queryFormRef.value?.resetFields()
  684. getList()
  685. }
  686. // 导出
  687. const handleExport = async () => {
  688. const loading = ElLoading.service({
  689. lock: true,
  690. text: '正在生成Word文档...',
  691. background: 'rgba(0, 0, 0, 0.7)'
  692. })
  693. try {
  694. const children = []
  695. // 生成动态文档标题
  696. let reportTitle = '非干部月度考核汇总报告'
  697. if (queryParams.assessmentMonth) {
  698. const [year, month] = queryParams.assessmentMonth.split('-')
  699. reportTitle = `${year}年${parseInt(month)}月非干部月度考核汇总报告`
  700. }
  701. // 添加文档标题
  702. children.push(
  703. new Paragraph({
  704. text: reportTitle,
  705. heading: HeadingLevel.TITLE,
  706. alignment: AlignmentType.CENTER,
  707. }),
  708. new Paragraph({
  709. text: `导出时间: ${new Date().toLocaleString('zh-CN')}`,
  710. alignment: AlignmentType.CENTER,
  711. }),
  712. new Paragraph({ text: '' })
  713. )
  714. // 获取所有 main-section(两大区块)
  715. const mainSections = document.querySelectorAll('.main-section')
  716. for (let i = 0; i < mainSections.length; i++) {
  717. const section = mainSections[i]
  718. const sectionTitle = section.querySelector('.section-title')
  719. const sectionName = sectionTitle ? sectionTitle.textContent : `第${i + 1}部分`
  720. children.push(
  721. new Paragraph({
  722. text: `${i + 1}. ${sectionName}`,
  723. heading: HeadingLevel.HEADING_1,
  724. }),
  725. new Paragraph({ text: '' })
  726. )
  727. if (i === 0) {
  728. // 第一部分:非干部月度考核分数汇总
  729. // 处理第一行的两个图表
  730. const chartRow1 = section.querySelector('.chart-row')
  731. if (chartRow1) {
  732. const chartCards = chartRow1.querySelectorAll('.chart-card')
  733. for (let j = 0; j < chartCards.length; j++) {
  734. const card = chartCards[j]
  735. const header = card.querySelector('.chart-header')
  736. const chartTitle = header ? header.textContent : `图表${j + 1}`
  737. children.push(
  738. new Paragraph({
  739. text: `${i + 1}.${j + 1} ${chartTitle}`,
  740. heading: HeadingLevel.HEADING_2,
  741. }),
  742. new Paragraph({ text: '' })
  743. )
  744. const chartContainer = card.querySelector('.chart-container')
  745. if (chartContainer) {
  746. await captureAndAddImage(chartContainer, children)
  747. }
  748. }
  749. }
  750. // 处理第二行的图表和汇总表
  751. const chartRow2 = section.querySelectorAll('.chart-row')
  752. if (chartRow2.length > 1) {
  753. const secondRow = chartRow2[1]
  754. const cards = secondRow.querySelectorAll('.chart-card')
  755. for (let j = 0; j < cards.length; j++) {
  756. const card = cards[j]
  757. const header = card.querySelector('.chart-header')
  758. const chartTitle = header ? header.textContent : `图表${j + 1}`
  759. children.push(
  760. new Paragraph({
  761. text: `${i + 1}.${j + 3} ${chartTitle}`,
  762. heading: HeadingLevel.HEADING_2,
  763. }),
  764. new Paragraph({ text: '' })
  765. )
  766. if (j === 0) {
  767. // 各部门分值分布对比图
  768. const chartContainer = card.querySelector('.chart-container')
  769. if (chartContainer) {
  770. await captureAndAddImage(chartContainer, children)
  771. }
  772. } else {
  773. // 汇总表
  774. const table = card.querySelector('.el-table')
  775. if (table) {
  776. await captureTable(table, children)
  777. }
  778. }
  779. }
  780. }
  781. } else {
  782. // 第二部分:非干部月度考核分类结果汇总
  783. // 汇总统计表格
  784. const summaryTableCard = section.querySelector('.summary-table-card')
  785. if (summaryTableCard) {
  786. const header = summaryTableCard.querySelector('.chart-header')
  787. const tableTitle = header ? header.textContent : '汇总统计'
  788. children.push(
  789. new Paragraph({
  790. text: `${i + 1}.1 ${tableTitle}`,
  791. heading: HeadingLevel.HEADING_2,
  792. }),
  793. new Paragraph({ text: '' })
  794. )
  795. const table = summaryTableCard.querySelector('.el-table')
  796. if (table) {
  797. await captureTable(table, children)
  798. }
  799. }
  800. // 第四行的两个图表
  801. const chartRows = section.querySelectorAll('.chart-row')
  802. if (chartRows.length > 0) {
  803. const chartRow = chartRows[0]
  804. const chartCards = chartRow.querySelectorAll('.chart-card')
  805. for (let j = 0; j < chartCards.length; j++) {
  806. const card = chartCards[j]
  807. const header = card.querySelector('.chart-header')
  808. const chartTitle = header ? header.textContent : `图表${j + 1}`
  809. children.push(
  810. new Paragraph({
  811. text: `${i + 1}.${j + 2} ${chartTitle}`,
  812. heading: HeadingLevel.HEADING_2,
  813. }),
  814. new Paragraph({ text: '' })
  815. )
  816. const pieChartsContainer = card.querySelector('.pie-charts-container')
  817. if (pieChartsContainer) {
  818. await captureAndAddImage(pieChartsContainer, children)
  819. }
  820. }
  821. }
  822. }
  823. }
  824. // 处理第一个遍历区域(traversalData1)
  825. const traversalSections = document.querySelectorAll('.traversal-section')
  826. let sectionCounter = mainSections.length + 1
  827. if (traversalSections.length > 0) {
  828. const firstTraversal = traversalSections[0]
  829. const traversalContainers = firstTraversal.querySelectorAll('.traversal-container')
  830. for (let t = 0; t < traversalContainers.length; t++) {
  831. const container = traversalContainers[t]
  832. const headerEl = container.querySelector('.traversal-header')
  833. const title = headerEl ? headerEl.textContent : `部门${t + 1}`
  834. children.push(
  835. new Paragraph({
  836. text: `${sectionCounter}. ${title}`,
  837. heading: HeadingLevel.HEADING_1,
  838. }),
  839. new Paragraph({ text: '' })
  840. )
  841. const content = container.querySelector('.traversal-content')
  842. if (content) {
  843. // 左边表格
  844. const tableSection = content.querySelector('.table-section')
  845. if (tableSection) {
  846. const table = tableSection.querySelector('.el-table')
  847. if (table) {
  848. children.push(
  849. new Paragraph({
  850. text: `${sectionCounter}.1 考核组统计表`,
  851. heading: HeadingLevel.HEADING_2,
  852. }),
  853. new Paragraph({ text: '' })
  854. )
  855. await captureTable(table, children)
  856. }
  857. }
  858. // 右边两个饼状图
  859. const chartSection = content.querySelector('.chart-section')
  860. if (chartSection) {
  861. const pieContainers = chartSection.querySelectorAll('.pie-chart-container')
  862. for (let p = 0; p < pieContainers.length; p++) {
  863. const pieContainer = pieContainers[p]
  864. const pieTitleEl = pieContainer.querySelector('.pie-chart-title')
  865. const pieTitle = pieTitleEl ? pieTitleEl.textContent : `饼图${p + 1}`
  866. children.push(
  867. new Paragraph({
  868. text: `${sectionCounter}.${p + 2} ${pieTitle}`,
  869. heading: HeadingLevel.HEADING_2,
  870. }),
  871. new Paragraph({ text: '' })
  872. )
  873. const pieChart = pieContainer.querySelector('.pie-chart')
  874. if (pieChart) {
  875. await captureAndAddImage(pieChart, children)
  876. }
  877. }
  878. }
  879. }
  880. sectionCounter++
  881. }
  882. }
  883. // 处理第二个遍历区域(traversalData2)
  884. if (traversalSections.length > 1) {
  885. const secondTraversal = traversalSections[1]
  886. const traversalContainers = secondTraversal.querySelectorAll('.traversal-container')
  887. for (let t = 0; t < traversalContainers.length; t++) {
  888. const container = traversalContainers[t]
  889. const headerEl = container.querySelector('.traversal-header')
  890. const title = headerEl ? headerEl.textContent : `部门${t + 1}`
  891. children.push(
  892. new Paragraph({
  893. text: `${sectionCounter}. ${title}`,
  894. heading: HeadingLevel.HEADING_1,
  895. }),
  896. new Paragraph({ text: '' })
  897. )
  898. const content = container.querySelector('.traversal-content')
  899. if (content) {
  900. // 左边表格
  901. const tableSection = content.querySelector('.table-section')
  902. if (tableSection) {
  903. const table = tableSection.querySelector('.el-table')
  904. if (table) {
  905. children.push(
  906. new Paragraph({
  907. text: `${sectionCounter}.1 考核组统计表`,
  908. heading: HeadingLevel.HEADING_2,
  909. }),
  910. new Paragraph({ text: '' })
  911. )
  912. await captureTable(table, children)
  913. }
  914. }
  915. // 右边柱状图和饼状图
  916. const chartSection = content.querySelector('.chart-section')
  917. if (chartSection) {
  918. const barContainer = chartSection.querySelector('.bar-chart-container')
  919. if (barContainer) {
  920. const chartTitleEl = barContainer.querySelector('.chart-title')
  921. const chartTitle = chartTitleEl ? chartTitleEl.textContent : '考核分数分布'
  922. children.push(
  923. new Paragraph({
  924. text: `${sectionCounter}.2 ${chartTitle}`,
  925. heading: HeadingLevel.HEADING_2,
  926. }),
  927. new Paragraph({ text: '' })
  928. )
  929. const barChart = barContainer.querySelector('.bar-chart')
  930. if (barChart) {
  931. await captureAndAddImage(barChart, children)
  932. }
  933. }
  934. const pieContainer = chartSection.querySelector('.pie-chart-container')
  935. if (pieContainer) {
  936. const pieTitleEl = pieContainer.querySelector('.pie-chart-title')
  937. const pieTitle = pieTitleEl ? pieTitleEl.textContent : '岗位分布'
  938. children.push(
  939. new Paragraph({
  940. text: `${sectionCounter}.3 ${pieTitle}`,
  941. heading: HeadingLevel.HEADING_2,
  942. }),
  943. new Paragraph({ text: '' })
  944. )
  945. const pieChart = pieContainer.querySelector('.pie-chart')
  946. if (pieChart) {
  947. await captureAndAddImage(pieChart, children)
  948. }
  949. }
  950. }
  951. }
  952. sectionCounter++
  953. }
  954. }
  955. // 创建文档
  956. const doc = new Document({
  957. sections: [{
  958. properties: {},
  959. children: children
  960. }]
  961. })
  962. // 生成并下载
  963. const blob = await Packer.toBlob(doc)
  964. const fileName = `${reportTitle}_${new Date().toISOString().slice(0, 10)}.docx`
  965. saveAs(blob, fileName)
  966. ElMessage.success('Word文档导出成功')
  967. } catch (error) {
  968. console.error('导出失败:', error)
  969. ElMessage.error('导出失败: ' + (error.message || '请重试'))
  970. } finally {
  971. loading.close()
  972. }
  973. }
  974. // 截图图表容器并添加为图片
  975. const captureAndAddImage = async (element, children) => {
  976. try {
  977. const canvas = await html2canvas(element, {
  978. backgroundColor: '#ffffff',
  979. scale: 2,
  980. logging: false
  981. })
  982. const imageData = canvas.toDataURL('image/png')
  983. const base64Data = imageData.replace(/^data:image\/png;base64,/, '')
  984. if (!base64Data || base64Data.trim() === '') {
  985. return
  986. }
  987. const maxWidth = 500
  988. const originalWidth = canvas.width
  989. const originalHeight = canvas.height
  990. const aspectRatio = originalWidth / originalHeight
  991. let finalWidth = maxWidth
  992. let finalHeight = maxWidth / aspectRatio
  993. const maxHeight = 400
  994. if (finalHeight > maxHeight) {
  995. finalHeight = maxHeight
  996. finalWidth = maxHeight * aspectRatio
  997. }
  998. const imageBytes = Uint8Array.from(atob(base64Data), c => c.charCodeAt(0))
  999. children.push(
  1000. new Paragraph({
  1001. children: [
  1002. new ImageRun({
  1003. data: imageBytes,
  1004. transformation: {
  1005. width: Math.round(finalWidth),
  1006. height: Math.round(finalHeight)
  1007. }
  1008. })
  1009. ],
  1010. alignment: AlignmentType.CENTER,
  1011. }),
  1012. new Paragraph({ text: '' })
  1013. )
  1014. } catch (error) {
  1015. console.error('截图失败:', error)
  1016. }
  1017. }
  1018. // 截图表格并添加为图片
  1019. const captureTable = async (table, children) => {
  1020. try {
  1021. const originalMaxHeight = table.style.maxHeight || ''
  1022. const originalOverflowY = table.style.overflowY || ''
  1023. const originalOverflowX = table.style.overflowX || ''
  1024. const originalTableWidth = table.style.width || ''
  1025. table.style.maxHeight = 'none'
  1026. table.style.overflowY = 'visible'
  1027. table.style.overflowX = 'visible'
  1028. table.style.width = '800px'
  1029. let originalTableHeight = ''
  1030. let originalTableWidthStyle = ''
  1031. originalTableHeight = table.style.height || ''
  1032. originalTableWidthStyle = table.style.width || ''
  1033. table.style.height = 'auto'
  1034. table.style.width = '800px'
  1035. const bodyWrapper = table.querySelector('.el-table__body-wrapper')
  1036. if (bodyWrapper) {
  1037. bodyWrapper.style.overflowX = 'visible'
  1038. bodyWrapper.style.overflowY = 'visible'
  1039. }
  1040. await new Promise(resolve => setTimeout(resolve, 200))
  1041. const canvas = await html2canvas(table, {
  1042. backgroundColor: '#ffffff',
  1043. scale: 1.5,
  1044. logging: false,
  1045. useCORS: true,
  1046. allowTaint: true,
  1047. scrollX: 0,
  1048. scrollY: 0,
  1049. width: 800,
  1050. height: table.scrollHeight
  1051. })
  1052. table.style.maxHeight = originalMaxHeight
  1053. table.style.overflowY = originalOverflowY
  1054. table.style.overflowX = originalOverflowX
  1055. table.style.width = originalTableWidth
  1056. table.style.height = originalTableHeight
  1057. table.style.width = originalTableWidthStyle
  1058. if (bodyWrapper) {
  1059. bodyWrapper.style.overflowX = ''
  1060. bodyWrapper.style.overflowY = ''
  1061. }
  1062. const imageData = canvas.toDataURL('image/png')
  1063. const base64Data = imageData.replace(/^data:image\/png;base64,/, '')
  1064. if (!base64Data || base64Data.trim() === '') {
  1065. return
  1066. }
  1067. const maxWidth = 500
  1068. const originalWidth = canvas.width
  1069. const originalHeight = canvas.height
  1070. const aspectRatio = originalWidth / originalHeight
  1071. let finalWidth = maxWidth
  1072. let finalHeight = maxWidth / aspectRatio
  1073. const maxHeight = 400
  1074. if (finalHeight > maxHeight) {
  1075. finalHeight = maxHeight
  1076. finalWidth = maxHeight * aspectRatio
  1077. }
  1078. const imageBytes = Uint8Array.from(atob(base64Data), c => c.charCodeAt(0))
  1079. children.push(
  1080. new Paragraph({
  1081. children: [
  1082. new ImageRun({
  1083. data: imageBytes,
  1084. transformation: {
  1085. width: Math.round(finalWidth),
  1086. height: Math.round(finalHeight)
  1087. }
  1088. })
  1089. ],
  1090. alignment: AlignmentType.CENTER,
  1091. }),
  1092. new Paragraph({ text: '' })
  1093. )
  1094. } catch (error) {
  1095. console.error('表格截图失败:', error)
  1096. }
  1097. }
  1098. onMounted(() => {
  1099. initCharts()
  1100. initTraversalCharts()
  1101. window.addEventListener('resize', handleResize)
  1102. getList()
  1103. })
  1104. // 组件卸载时移除事件监听器
  1105. onUnmounted(() => {
  1106. window.removeEventListener('resize', handleResize)
  1107. // 销毁图表实例
  1108. const charts = [
  1109. overallBarChartInstance,
  1110. participantPieChartInstance,
  1111. departmentComparisonChartInstance,
  1112. brigadePieChart1Instance,
  1113. brigadePieChart2Instance,
  1114. positionPieChart1Instance,
  1115. positionPieChart2Instance
  1116. ]
  1117. charts.forEach(chart => {
  1118. if (chart) chart.dispose()
  1119. })
  1120. })
  1121. </script>
  1122. <style lang="less" scoped>
  1123. .app-container {
  1124. padding: 20px;
  1125. }
  1126. .filter-section {
  1127. margin-bottom: 20px;
  1128. }
  1129. .filter-container {
  1130. display: flex;
  1131. justify-content: space-between;
  1132. align-items: center;
  1133. }
  1134. .search-form {
  1135. display: flex;
  1136. align-items: center;
  1137. gap: 10px;
  1138. }
  1139. .export-button {
  1140. margin-left: auto;
  1141. }
  1142. .main-section {
  1143. margin-bottom: 30px;
  1144. }
  1145. .section-title {
  1146. font-size: 20px;
  1147. font-weight: bold;
  1148. color: #333;
  1149. margin-bottom: 20px;
  1150. text-align: center;
  1151. }
  1152. .chart-row {
  1153. display: grid;
  1154. grid-template-columns: 1fr 1fr;
  1155. gap: 20px;
  1156. margin-bottom: 20px;
  1157. }
  1158. .chart-card {
  1159. height: 400px;
  1160. }
  1161. .summary-table-card {
  1162. margin-bottom: 20px;
  1163. }
  1164. .chart-header {
  1165. font-size: 16px;
  1166. font-weight: 600;
  1167. color: #333;
  1168. margin-bottom: 10px;
  1169. text-align: center;
  1170. }
  1171. .chart-container {
  1172. width: 100%;
  1173. height: 350px;
  1174. }
  1175. .pie-charts-container {
  1176. display: grid;
  1177. grid-template-columns: 1fr 1fr;
  1178. gap: 10px;
  1179. height: 350px;
  1180. }
  1181. .pie-chart {
  1182. width: 100%;
  1183. height: 100%;
  1184. }
  1185. :deep(.el-table) {
  1186. .el-table__header th {
  1187. background-color: #f5f7fa;
  1188. font-weight: 600;
  1189. }
  1190. }
  1191. /* 遍历样式 */
  1192. .traversal-section {
  1193. margin-bottom: 30px;
  1194. }
  1195. .traversal-container {
  1196. border: 1px solid #dcdfe6;
  1197. border-radius: 8px;
  1198. overflow: hidden;
  1199. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  1200. margin-bottom: 20px;
  1201. }
  1202. .traversal-header {
  1203. background-color: #f5f7fa;
  1204. padding: 15px 20px;
  1205. font-size: 18px;
  1206. font-weight: 600;
  1207. color: #303133;
  1208. border-bottom: 1px solid #dcdfe6;
  1209. text-align: left;
  1210. }
  1211. .traversal-content {
  1212. display: flex;
  1213. gap: 20px;
  1214. padding: 20px;
  1215. }
  1216. .table-section {
  1217. flex: 1;
  1218. min-width: 0;
  1219. min-height: 400px;
  1220. }
  1221. .chart-section {
  1222. flex: 1;
  1223. min-width: 0;
  1224. display: grid;
  1225. grid-template-columns: 1fr 1fr;
  1226. gap: 15px;
  1227. height: 400px;
  1228. }
  1229. .pie-chart-container,
  1230. .bar-chart-container {
  1231. display: flex;
  1232. flex-direction: column;
  1233. border: 1px solid #e4e7ed;
  1234. border-radius: 6px;
  1235. padding: 10px;
  1236. background-color: #fff;
  1237. }
  1238. .pie-chart-title,
  1239. .chart-title {
  1240. font-size: 14px;
  1241. font-weight: 600;
  1242. color: #606266;
  1243. margin-bottom: 10px;
  1244. text-align: center;
  1245. }
  1246. .pie-chart,
  1247. .bar-chart {
  1248. flex: 1;
  1249. min-height: 300px;
  1250. }
  1251. /* 响应式布局 */
  1252. @media (max-width: 1200px) {
  1253. .chart-row {
  1254. grid-template-columns: 1fr;
  1255. }
  1256. .pie-charts-container {
  1257. grid-template-columns: 1fr;
  1258. }
  1259. .traversal-content {
  1260. flex-direction: column;
  1261. gap: 15px;
  1262. }
  1263. .table-section,
  1264. .chart-section {
  1265. min-width: 0;
  1266. }
  1267. .chart-section {
  1268. grid-template-columns: 1fr;
  1269. height: auto;
  1270. }
  1271. .pie-chart,
  1272. .bar-chart {
  1273. min-height: 250px;
  1274. }
  1275. }
  1276. @media (max-width: 768px) {
  1277. .traversal-content {
  1278. padding: 15px;
  1279. }
  1280. .chart-section {
  1281. gap: 10px;
  1282. }
  1283. .pie-chart-container,
  1284. .bar-chart-container {
  1285. padding: 8px;
  1286. }
  1287. }
  1288. </style>