yangys
2025-08-31 6a0eeb9bb5da23341327fddb11aa47579dd7d372
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
<template>
  <el-menu class="top-menu" :default-active="activeIndex" mode="horizontal" text-color="#333">
    <el-menu-item index="0" @click="openHome(itemHome)">
      <template #title>
        <i :class="itemHome.source" style="padding-right: 5px"></i>
        <span>{{ itemHome.name }}</span>
      </template>
    </el-menu-item>
    <el-menu-item index="0" @click="openTodo(itemHome)">
      
      <template #title>
            <el-badge :value="logsLen" :max="99" :offset="[10, 15]" class="todoItems">
              <el-tooltip
              class="box-item"
              effect="dark"
              :content="`您有${logsLen}条任务需要处理`"
              placement="top-start"
            >
             {{ itemTodo.name }}
              </el-tooltip>
            </el-badge>
          <!-- <span >{{ itemTodo.name }}</span>-->
           
       
        
      </template>
    </el-menu-item>
 
    <template v-for="(item, index) in items" :key="index">
      <el-menu-item :index="item.id + ''" @click="openMenu(item)">
        <template #title>
          <i :class="item.source" style="padding-right: 5px"></i>
          <span>{{ item.name }}</span>
        </template>
      </el-menu-item>
    </template>
  </el-menu>
</template>
 
<style lang="scss" scoped>
.todoItems {
  margin-left:15px;
}
</style>
<script>
import { mapGetters } from 'vuex';
import { getList } from '@/api/flow/todolist'; //任务提醒
export default {
  name: 'top-menu',
  data() {
    return {
      itemHome: {
        name: '首页',
        source: 'iconfont iconicon_work',
      },
      itemTodo: {
        name: '任务提醒',
        source: 'iconfont iconicon_work',
      },
      activeIndex: '0',
      items: [],
 
      logsLen: 0,//任务提醒数量
      intervalId : undefined
    };
  },
  inject: ['index'],
  
  created() {
    this.getMenu();
 
    this.getCount();
    
    window.remindIntervalId = setInterval(() => {
      this.getCount();
    }, 2*60*1000)//
    window.myemitter.on('todochange', (data)=>{
      this.getCount();
    });
  },
  
  computed: {
    ...mapGetters(['tagCurrent', 'menu', 'tagWel']),
  },
  methods: {
    openMenu(item) {
      this.index.openMenu(item);
    },
    openHome(itemHome) {
      this.index.openMenu(itemHome);
      this.$router.push(this.tagWel);
    },
    getMenu() {
      this.$store.dispatch('GetTopMenu').then(res => {
        this.items = res;
      });
    },
    openTodo() {
        this.$router.push({ path: '/flow/todoindex' });
        //this.box = false;
    },
    getCount() {
      try{
        getList(1,10).then((res) => {
          this.logsLen = res.data.data.total;
          this.dataList = res.data.data.records;
        }).catch(e=>{
          console.log('3333',this.intervalId)
          clearInterval(this.intervalId);
        });
      }catch(e2){
        console.log('e2',e2);
      }
    }
  },
};
</script>