新大宝股票管理后台
1
admin
2026-01-21 ebe3dedaa73b16be906c9bc8c4c11f0270cd92ed
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
<template>
  <div v-if="totalCount > 0" class="notification-badge">
    <div class="badge-wrapper" @click="handleClick">
      <a-badge :count="totalCount" :number-style="{ backgroundColor: '#ff4d4f' }">
        <a-icon type="bell" :style="{ fontSize: '24px', color: '#1890ff', cursor: 'pointer' }" />
      </a-badge>
    </div>
    <div class="notification-popover" v-if="showPopover" @click.stop>
      <div class="notification-item" @click="goToRecharge">
        <span>充值待处理</span>
        <a-badge :count="rechargeCount" :number-style="{ backgroundColor: '#ff4d4f' }" />
      </div>
      <div class="notification-item" @click="goToWithdraw">
        <span>提现待处理</span>
        <a-badge :count="withdrawCount" :number-style="{ backgroundColor: '#ff4d4f' }" />
      </div>
      <div class="notification-item" @click="goToAuth">
        <span>实名认证待处理</span>
        <a-badge :count="authCount" :number-style="{ backgroundColor: '#ff4d4f' }" />
      </div>
    </div>
    <div v-if="showPopover" class="popover-mask" @click="closePopover"></div>
  </div>
</template>
 
<script>
import { getPendingCount } from '@/api/home'
 
export default {
  name: 'NotificationBadge',
  data() {
    return {
      rechargeCount: 0,
      withdrawCount: 0,
      authCount: 0,
      totalCount: 0,
      showPopover: false,
      timer: null
    }
  },
  mounted() {
    this.fetchPendingCount()
    this.startPolling()
    document.addEventListener('click', this.handleDocumentClick)
  },
  beforeDestroy() {
    this.stopPolling()
    document.removeEventListener('click', this.handleDocumentClick)
  },
  methods: {
    fetchPendingCount() {
      getPendingCount()
        .then((res) => {
          if (res.status === 0 && res.data) {
            this.rechargeCount = res.data.rechargeCount || 0
            this.withdrawCount = res.data.withdrawCount || 0
            this.authCount = res.data.authCount || 0
            this.totalCount = res.data.totalCount || 0
          }
        })
        .catch((error) => {
          console.error('获取待处理数量失败', error)
        })
    },
    startPolling() {
      this.timer = setInterval(() => {
        this.fetchPendingCount()
      }, 30000) // 每30秒轮询一次
    },
    stopPolling() {
      if (this.timer) {
        clearInterval(this.timer)
        this.timer = null
      }
    },
    handleClick(e) {
      e.stopPropagation()
      this.showPopover = !this.showPopover
    },
    closePopover() {
      this.showPopover = false
    },
    handleDocumentClick(e) {
      if (this.showPopover && !this.$el.contains(e.target)) {
        this.showPopover = false
      }
    },
    goToRecharge() {
      this.$router.push('/capital/rechargelist')
      this.showPopover = false
    },
    goToWithdraw() {
      this.$router.push('/capital/withdrawallist')
      this.showPopover = false
    },
    goToAuth() {
      this.$router.push('/userlist')
      this.showPopover = false
    }
  }
}
</script>
 
<style lang="less" scoped>
.notification-badge {
  position: fixed;
  right: 30px;
  bottom: 30px;
  z-index: 1000;
}
 
.badge-wrapper {
  cursor: pointer;
}
 
.popover-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
}
 
.notification-popover {
  position: absolute;
  bottom: 50px;
  right: 0;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 12px 0;
  min-width: 200px;
}
 
.notification-item {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.3s;
 
  &:hover {
    background-color: #f5f5f5;
  }
 
  span {
    font-size: 14px;
    color: #333;
  }
}
</style>