zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
<template>
  <div class='page-header-index-wide'>
    <a-row :gutter='24'>
      <a-col class='pointer' @click='cardClick(1)' :sm='24' :md='12' :xl='6' :style="{ marginBottom: '12px' }">
        <chart-card :loading='loading' title='研发中心' :total='totalUser|| "0"'>
          <a-tooltip title='指标说明' slot='action'>
            <a-icon type='info-circle-o' />
          </a-tooltip>
          <div>
            <trend flag='up' style='margin-right: 16px;'>
              <span slot='term'>较去年</span>
              -
            </trend>
 
          </div>
          <template slot='footer'>部门总人数<span></span></template>
        </chart-card>
      </a-col>
      <a-col class='pointer' @click='cardClick(2)' :sm='24' :md='12' :xl='6' :style="{ marginBottom: '12px' }">
        <chart-card :loading='loading' title='正式员工' :total='regularEmployee'>
          <a-tooltip title='指标说明' slot='action'>
            <a-icon type='info-circle-o' />
          </a-tooltip>
          <div>
 
 
          </div>
          <template slot='footer'>正式员工人数<span></span></template>
        </chart-card>
      </a-col>
      <a-col class='pointer' @click='cardClick(3)' :sm='24' :md='12' :xl='6' :style="{ marginBottom: '12px' }">
        <chart-card :loading='loading' title='试用期员工' :total='probEmployee'>
          <a-tooltip title='指标说明' slot='action'>
            <a-icon type='info-circle-o' />
          </a-tooltip>
          <div>
 
 
          </div>
          <template slot='footer'>试用期员工人数<span></span></template>
        </chart-card>
      </a-col>
      <a-col class='pointer' @click='cardClick(4)' :sm='24' :md='12' :xl='6' :style="{ marginBottom: '12px' }">
        <chart-card :loading='loading' title='应届生' :total='gradEmployee'>
          <a-tooltip title='指标说明' slot='action'>
            <a-icon type='info-circle-o' />
          </a-tooltip>
          <div>
 
 
          </div>
          <template slot='footer'>应届生人数<span></span></template>
        </chart-card>
      </a-col>
    </a-row>
 
 
    <div style='width: 100%;height: 600px;'>
      <a-row justify='space-between'>
 
        <a-col :xl='12' :lg='12' :md='24' :sm='24' :xs='24'>
          <a-card style='margin-right: 12px' :loading='loading' :bordered='false' :body-style="{padding: '0'}">
            <div style='text-align: center;' class='chart-box'>
              <div style='height: 40px;font-size: 14px;line-height: 40px'> 各部门人员(正式、试用、实习)分布</div>
              <div id='chart1' />
            </div>
          </a-card>
        </a-col>
 
        <a-col :xl='12' :lg='12' :md='24' :sm='24' :xs='24'>
          <a-card style='margin-left: 12px' :loading='loading' :bordered='false' :body-style="{padding: '0'}">
            <div style='text-align: center;' class='chart-box'>
              <div style='height: 40px;font-size: 14px'>各部门人员(编制)分布</div>
              <div id='chart2' />
            </div>
          </a-card>
        </a-col>
 
 
      </a-row>
 
      <a-row justify='space-between' style='margin-top: 12px'>
        <a-col :xl='6' :lg='6' :md='12' :sm='12' :xs='12'>
          <a-card style='margin-right: 12px' :loading='loading' :bordered='false' :body-style="{padding: '0'}">
            <div style='text-align: center;' class='chart-box'>
              <div style='height: 40px;font-size: 14px'>部门人员(性别)</div>
              <div id='chart3' />
            </div>
          </a-card>
        </a-col>
 
        <a-col :xl='6' :lg='6' :md='12' :sm='12' :xs='12'>
          <a-card style='margin-right: 12px' :loading='loading' :bordered='false' :body-style="{padding: '0'}">
            <div style='text-align: center;' class='chart-box'>
              <div style='height: 40px;font-size: 14px'>部门人员(学历)</div>
              <div id='chart4' />
            </div>
          </a-card>
        </a-col>
 
 
        <a-col :xl='6' :lg='6' :md='12' :sm='12' :xs='12'>
          <a-card style='margin-left: 12px' :loading='loading' :bordered='false' :body-style="{padding: '0'}">
            <div style='text-align: center;' class='chart-box'>
              <div style='height: 40px;font-size: 14px'>部门人员(等阶)</div>
              <div id='chart5' />
            </div>
          </a-card>
        </a-col>
 
        <a-col :xl='6' :lg='6' :md='12' :sm='12' :xs='12'>
          <a-card style='margin-left: 12px' :loading='loading' :bordered='false' :body-style="{padding: '0'}">
            <div style='text-align: center;' class='chart-box'>
              <div style='height: 40px;font-size: 14px'>部门人员(构成)</div>
              <div id='chart6' />
            </div>
          </a-card>
        </a-col>
      </a-row>
    </div>
 
 
  </div>
</template>
 
<script>
import ChartCard from '@/components/ChartCard'
import Trend from '@/components/Trend'
import MiniProgress from '@/components/chart/MiniProgress'
import MiniArea from '@/components/chart/MiniArea'
import MiniBar from '@/components/chart/MiniBar'
import { getAction } from '@api/manage'
import get from 'lodash.get'
import { Chart, registerInteraction } from '@antv/g2'
import DataSet from '@antv/data-set';
 
export default {
  name: 'home',
  components: {
    ChartCard,
    Trend,
    MiniProgress,
    MiniArea,
    MiniBar
  },
  data() {
    return {
      loading: false,
      model: {
        departList: []
      }
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    //查询所有部门数据,树形结构
    loadData() {
      getAction('/hrm/board/departUserList', { departName: '研发中心' }).then(res => {
        if (res.success) {
          console.info(res.result)
          this.model.departList = res.result || []
          this.createData()
        }
 
      })
    },
    createData() {
      let chartData1 = []
      let chartData2 = []
      let chartData3 = []
      let chartData4 = []
      let chartData5 = []
      let chartData6 = {
        name: 'root',
        children: []
      }
      this.model.departList.forEach(i => {
 
        const userList = i.userList || []
        //统计各类型用户
        //未分配
        let blankUserList = userList.filter(u => u.employ == null)
        let item1 = { year: i.departName, type: '未分配', sales: blankUserList.length }
        //正式
        let zsUserList = userList.filter(u => u.employ == 1)
        let item2 = { year: i.departName, type: '正式', sales: zsUserList.length }
        //试用
        let syUserList = userList.filter(u => u.employ == 2)
        let item3 = { year: i.departName, type: '试用', sales: syUserList.length }
        //实习
        let sxUserList = userList.filter(u => u.employ == 3)
        let item4 = { year: i.departName, type: '实习', sales: sxUserList.length }
        chartData1.push(item1)
 
        chartData1.push(item2)
        chartData1.push(item3)
        chartData1.push(item4)
 
 
        let wUserList = userList.filter(u => u.staffing == null)
        let bzUserList = userList.filter(u => u.staffing == 1)
        let mbzUserList = userList.filter(u => u.staffing == 0)
 
        let item21 = { company: '未分配', type: i.departName, value: wUserList.length }
        let item22 = { company: '有编制', type: i.departName, value: bzUserList.length }
        let item23 = { company: '无编制', type: i.departName, value: mbzUserList.length }
        chartData2.push(item21)
        chartData2.push(item22)
        chartData2.push(item23)
        if( i.departName !=  '研发中心' && userList.length > 0){
          const item61 = { name: i.departName, value: userList.length }
          chartData6.children.push(item61)
        }
 
 
 
      })
 
 
      this.initChart1(chartData1)
      this.initChart2(chartData2)
      this.initChart6(chartData6)
 
      if (this.model.departList.length == 0) {
        return false
      }
 
      //不需要分部门计算
      const userList = this.model.departList[0].userList
      const total = userList.length
      if (total == 0) {
        return false
      }
      let nSexList = userList.filter(u => u.sex == null)
      let manList = userList.filter(u => u.sex == 1)
      let womenList = userList.filter(u => u.sex == 2)
      let nSize = this.fixed2(nSexList.length, total)
      let manSize = this.fixed2(manList.length, total)
      let womenSize = this.fixed2(womenList.length, total)
 
      let item31 = { type: '未分配', value: nSexList.length, percent: Number(nSize) }
      let item32 = { type: '男', value: manList.length, percent: Number(manSize) }
      let item33 = { type: '女', value: womenList.length, percent: Number(womenSize) }
      if (nSexList.length > 0) {
        chartData3.push(item31)
      }
      if (manList.length > 0) {
        chartData3.push(item32)
      }
      if (womenList.length > 0) {
        chartData3.push(item33)
      }
 
      this.initChart3(chartData3)
 
      const wxlList = userList.filter(item => item.education == null)
      const dxlList = userList.filter(item => item.education == 1)
      const bxlList = userList.filter(item => item.education == 2)
      const sxlList = userList.filter(item => item.education == 3)
      const oxlList = userList.filter(item => item.education == 10)
      let wxlSize = this.fixed2(wxlList.length, total)
      let dxlSize = this.fixed2(dxlList.length, total)
      let bxlSize = this.fixed2(bxlList.length, total)
      let sxlSize = this.fixed2(sxlList.length, total)
      let oxlSize = this.fixed2(oxlList.length, total)
 
      let item41 = { type: '未分配', value: wxlList.length, percent: Number(wxlSize) }
      let item42 = { type: '大专', value: dxlList.length, percent: Number(dxlSize) }
      let item43 = { type: '本科', value: bxlList.length, percent: Number(bxlSize) }
      let item44 = { type: '硕士', value: sxlList.length, percent: Number(sxlSize) }
      let item45 = { type: '其它', value: oxlList.length, percent: Number(oxlSize) }
      if (wxlSize.length > 0) {
        chartData4.push(item41)
      }
      if (dxlSize.length > 0) {
        chartData4.push(item42)
      }
      if (bxlSize.length > 0) {
        chartData4.push(item43)
      }
      if (sxlSize.length > 0) {
        chartData4.push(item44)
      }
      if (oxlSize.length > 0) {
        chartData4.push(item45)
      }
      this.initChart4(chartData4)
 
      const wdjList = userList.filter(item => item.level == null)
      const djList1 = userList.filter(item => item.level >= 11 && item.level <= 14)
      const djList2 = userList.filter(item => item.level >= 21 && item.level <= 24)
      const djList3 = userList.filter(item => item.level >= 31 && item.level <= 34)
      const djList4 = userList.filter(item => item.level >= 41 && item.level <= 44)
      const djList5 = userList.filter(item => item.level >= 51 && item.level <= 54)
      let wdjSize = this.fixed2(wdjList.length, total)
      let djSize1 = this.fixed2(djList1.length, total)
      let djSize2 = this.fixed2(djList2.length, total)
      let djSize3 = this.fixed2(djList3.length, total)
      let djSize4 = this.fixed2(djList4.length, total)
      let djSize5 = this.fixed2(djList5.length, total)
 
      let item51 = { type: '未分配', value: wdjList.length, percent: Number(wdjSize) }
      let item52 = { type: '一等阶', value: djList1.length, percent: Number(djSize1) }
      let item53 = { type: '二等阶', value: djList2.length, percent: Number(djSize2) }
      let item54 = { type: '三等阶', value: djList3.length, percent: Number(djSize3) }
      let item55 = { type: '四等阶', value: djList4.length, percent: Number(djSize4) }
      let item56 = { type: '五等阶', value: djList5.length, percent: Number(djSize5) }
      if (wdjSize.length > 0) {
        chartData5.push(item51)
      }
      if (djSize1.length > 0) {
        chartData5.push(item52)
      }
      if (djSize2.length > 0) {
        chartData5.push(item53)
      }
      if (djSize3.length > 0) {
        chartData5.push(item54)
      }
      if (djSize4.length > 0) {
        chartData5.push(item55)
      }
      if (djSize5.length > 0) {
        chartData5.push(item56)
      }
 
      this.initChart5(chartData5)
 
    },
    /**
     * 保留2位小数
     * @param value
     * @param total
     * @returns {string|number}
     */
    fixed2(value, total) {
      if (value > 0) {
        value = value / total
        value = value.toFixed(2)
        return value
      }
      return 0
    },
 
 
    initChart1(chartData1) {
      console.info(chartData1)
      registerInteraction('element-link', {
        start: [
          { trigger: 'interval:mouseenter', action: 'element-link-by-color:link' }
        ],
        end: [
          { trigger: 'interval:mouseleave', action: 'element-link-by-color:unlink' }
        ]
      })
 
 
      const chart = new Chart({
        container: 'chart1',
        autoFit: true,
        height: 300
      })
 
      chart.data(chartData1)
      /*     chart.scale({
             sales: {
               max: 2400,
               tickInterval: 600,
               nice: true
             }
           })*/
 
      chart.tooltip({
        showMarkers: false
      })
 
      chart
        .interval()
        .position('year*sales')
        .color('type')
        .adjust('stack')
 
      chart.interaction('element-highlight-by-color')
      chart.interaction('element-link')
      chart.render()
 
    },
    initChart2(chartData2) {
 
 
      const chart = new Chart({
        container: 'chart2',
        autoFit: true,
        height: 300
      })
 
      chart.data(chartData2)
 
      chart.scale('value', { nice: true })
 
      /* chart.legend({
         position: 'top'
       });*/
 
      chart.tooltip({
        showMarkers: false
      })
 
      chart
        .interval()
        .position('type*value').color('company')
        .label('value', {
          position: 'top', // 在柱子中间显示标签
          style: {
            fill: 'gray'
          },
          formatter: (text, item) => {
            // 当值为 0 时不显示标签
            return item.value !== 0 ? text : ''
          }
        })
        .adjust([{
          type: 'dodge',
          marginRatio: 0
        }])
 
      chart.interaction('element-list-highlight')
 
 
      chart.render()
    },
    initChart3(chartData3) {
 
 
      const chart = new Chart({
        container: 'chart3',
        autoFit: true,
        height: 300
      })
      chart.coordinate('theta', {
        radius: 0.75
      })
 
      chart.data(chartData3)
 
      chart.scale('percent', {
        formatter: (val) => {
          if (!val) return val
          val = val * 100
          val = val.toFixed(2)
          val = val + '%'
          return val
        }
      })
 
      chart.tooltip({
        showTitle: false,
        showMarkers: false
      })
 
      chart
        .interval()
        .position('percent')
        .color('type')
        .label('percent', {
          layout: [{ type: 'limit-in-plot', cfg: { action: 'ellipsis'/** 或 translate */ } }],
          content: (data) => {
            /* var percent  =   data.percent * 100
             console.info(percent)
             percent  =  percent.toFixed(2)
             percent  =  percent + '%'*/
            return `${data.type}:  ${data.value} `
          }
        })
        .adjust('stack')
 
      chart.interaction('element-active')
 
      chart.render()
    },
    initChart4(chartData4) {
 
 
      const chart = new Chart({
        container: 'chart4',
        autoFit: true,
        height: 300
      })
      chart.coordinate('theta', {
        radius: 0.75
      })
 
      chart.data(chartData4)
 
      chart.scale('percent', {
        formatter: (val) => {
          if (!val) return val
          val = val * 100
          val = val.toFixed(2)
          val = val + '%'
          return val
        }
      })
 
      chart.tooltip({
        showTitle: false,
        showMarkers: false
      })
 
      chart
        .interval()
        .position('percent')
        .color('type')
        .label('percent', {
          layout: [{ type: 'limit-in-plot', cfg: { action: 'ellipsis'/** 或 translate */ } }],
          content: (data) => {
            /* var percent  =   data.percent * 100
             console.info(percent)
             percent  =  percent.toFixed(2)
             percent  =  percent + '%'*/
            return `${data.type}:  ${data.value} `
          }
        })
        .adjust('stack')
 
      chart.interaction('element-active')
 
      chart.render()
    },
    initChart5(chartData5) {
 
 
      const chart = new Chart({
        container: 'chart5',
        autoFit: true,
        height: 300
      })
      chart.coordinate('theta', {
        radius: 0.75
      })
 
      chart.data(chartData5)
 
      chart.scale('percent', {
        formatter: (val) => {
          if (!val) return val
          val = val * 100
          val = val.toFixed(2)
          val = val + '%'
          return val
        }
      })
 
      chart.tooltip({
        showTitle: false,
        showMarkers: false
      })
 
      chart
        .interval()
        .position('percent')
        .color('type')
        .label('percent', {
          layout: [{ type: 'limit-in-plot', cfg: { action: 'ellipsis'/** 或 translate */ } }],
          content: (data) => {
            /* var percent  =   data.percent * 100
             console.info(percent)
             percent  =  percent.toFixed(2)
             percent  =  percent + '%'*/
            return `${data.type}:  ${data.value} `
          }
        })
        .adjust('stack')
 
      chart.interaction('element-active')
 
      chart.render()
    },
    initChart6(chartData6){
      const { DataView } = DataSet;
 
      const dv = new DataView();
      dv.source(chartData6, {
        type: 'hierarchy',
      }).transform({
        field: 'value',
        type: 'hierarchy.treemap',
        tile: 'treemapResquarify',
        as: ['x', 'y'],
      });
 
// 将 DataSet 处理后的结果转换为 G2 接受的数据
      const nodes = [];
      for (const node of dv.getAllNodes()) {
        if (node.data.name === 'root') {
          continue;
        }
        const eachNode  = {
          name: node.data.name,
          x: node.x,
          y: node.y,
          value: node.data.value,
        };
 
        nodes.push(eachNode);
      }
      const chart = new Chart({
        container: 'chart6',
        autoFit: true,
        height: 300,
      });
      chart.data(nodes);
      chart.scale({
        x: {
          nice: true,
        },
        y: {
          nice: true,
        },
      });
 
      chart.axis(false);
      chart.legend(false);
      chart.tooltip({
        showTitle: false,
        showMarkers: false,
        itemTpl:
          '<li style="list-style: none;">' +
          '<span style="background-color:{color};" class="g2-tooltip-marker"></span>' +
          '{name}<br/>' +
          '<span style="padding-left: 16px">览数:{count}</span><br/>' +
          '</li>',
      });
      chart
        .polygon()
        .position('x*y')
        .color('name')
        .tooltip('name*value', (name, count) => {
          return {
            name,
            count,
          };
        })
        .style({
          lineWidth: 1,
          stroke: '#fff'
        })
        .label('name', {
          offset: 0,
          style: {
            textBaseline: 'middle',
          },
          content: (obj) => {
            if (obj.name !== 'root') {
              return obj.name + "(" +obj.value+ ")";
            }
          },
        });
      chart.interaction('element-active');
 
      chart.render();
 
    },
    cardClick(index) {
      console.info(index)
    }
  },
  computed: {
    totalUser() {
      let total = get(this.model, 'departList[0].userList.length') || 0
      return total + ''
    },
    regularEmployee() {
      let departList = get(this.model, 'departList')
      if (departList.length > 0) {
        if (departList[0].userList) {
          let userList = departList[0].userList
          userList = userList.filter(item => item.staffing == 1)
          return userList.length + ''
        }
 
      }
      return '0'
    },
    probEmployee() {
      let departList = get(this.model, 'departList')
      if (departList.length > 0) {
        if (departList[0].userList) {
          let userList = departList[0].userList
          userList = userList.filter(item => item.employ == 2)
          return userList.length + ''
        }
 
      }
      return '0'
    },
    gradEmployee() {
      let departList = get(this.model, 'departList')
      if (departList.length > 0) {
        if (departList[0].userList) {
          let userList = departList[0].userList
          userList = userList.filter(item => item.grad == 1)
          return userList.length + ''
        }
 
      }
      return '0'
    }
 
  }
 
}
</script>
 
<style lang='less' scoped>
.chart-box {
  padding: 10px;
}
 
.pointer {
  cursor: pointer;
}
 
</style>