linwe
2023-12-21 ad0a536bd7534a8eaf477d41294de21c7d7b25df
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
<template>
    <div class="noticeBtn" @click="noticeBtn">
        <el-badge v-if="!view">
            <img src="img/notice/xiaoxi-png.png" style="width: 26px;height: 26px; display: flex;" />
        </el-badge>
        <el-badge v-if="view">
            <!-- <i class="el-icon-bell"></i> -->
            <img src="img/notice/xiaoxi-gif.gif" style="width: 26px;height: 26px; display: flex;" />
        </el-badge>
    </div>
    <!-- <el-popover placement="bottom"
              width="0"
              trigger="click"> -->
 
    <!-- <el-tabs v-model="activeName">
      <el-tab-pane label="邮件(1)"
                   name="first"></el-tab-pane>
      <el-tab-pane label="消息(2)"
                   name="second"></el-tab-pane>
      <el-tab-pane label="通知"
                   name="third"></el-tab-pane>
    </el-tabs>
    <el-scrollbar style="height:300px">
      <avue-notice :data="data"
                   :option="option"
                   @page-change="pageChange"></avue-notice>
    </el-scrollbar> -->
    <!-- <div slot="reference">
      <el-badge is-dot>
        <i class="el-icon-bell"></i>
      </el-badge>
    </div> -->
    <!-- </el-popover> -->
</template>
 
<script>
import { updateView, getList } from "@/api/task/reportForRepairs"
let list = [{
    img: '/img/bg/vip1.png',
    title: '史蒂夫·乔布斯 关注了你',
    subtitle: '05-08 15:08',
    tag: '已经开始',
    status: 0
}, {
    img: '/img/bg/vip2.png',
    title: '斯蒂夫·沃兹尼亚克 关注了你',
    subtitle: '05-08 15:08',
    tag: '未开始',
    status: 1
}, {
    img: '/img/bg/vip3.png',
    title: '蒂姆·库克 关注了你',
    subtitle: '05-08 15:08',
    status: 3,
    tag: '有错误'
}, {
    img: '/img/bg/vip4.png',
    title: '比尔·费尔南德斯 关注了你',
    subtitle: '05-08 15:08',
    status: 4,
    tag: '已完成'
}]
export default {
    name: "top-notice",
    data () {
        return {
            baseUrl: "https://sk.hubeishuiyi.cn",
            total: 0,
            view: false,
            activeName: 'first',
            option: {
                props: {
                    img: 'img',
                    title: 'title',
                    subtitle: 'subtitle',
                    tag: 'tag',
                    status: 'status'
                },
            },
            data: list,
        }
    },
    created () {
        this.getNoticeNumber()
    },
    mounted () {
        this.createEventSource()
    },
    methods: {
        getNoticeNumber () {
            var values = {
                viewType: 2
            }
            var that = this
            // 获取通知数量
            getList(1, 10, values).then((res) => {
                const data = res.data.data
                that.total = data.total
                if (that.total > 0) {
                    that.view = true
                } else {
                    that.view = false
                }
            })
 
        },
        noticeBtn () {
            this.view = false
            const data = {}
            // 更新状态
            updateView(data).then((res) => {
            })
            // 菜单跳转
            this.$router.push({ path: '/task/index' })
        },
        createEventSource () {
            this.baseUrl = `${window.location.protocol}//${window.location.host}`
            var that = this
            if (window.EventSource) {
                this.source = new EventSource(
                    this.baseUrl +
                    "/api/sse/sse/connect?type=web&userId=1"
                )
                this.source.addEventListener(
                    "open",
                    function () {
                        console.log("建立连接。。。")
                    },
                    false
                )
                this.source.addEventListener("message", function (e) {
                    console.log("收到消息", e.data)
                    // const data = JSON.parse(e.data)
                    // that.number = data.count
                    // 获取消息列表
                    that.getNoticeNumber()
                })
                this.source.addEventListener(
                    "error",
                    function (e) {
                        if (e.readyState === EventSource.CLOSED) {
                            console.log("连接关闭")
                        } else {
                            console.log(e)
                        }
                    },
                    false
                )
            } else {
                console.log("你的浏览器不支持SSE")
            }
        },
        pageChange (page, done) {
            setTimeout(() => {
                this.$message.success('页码' + page)
                this.data = this.data.concat(list)
                done()
            }, 1000)
 
        },
    }
}
</script>
 
<style lang="scss" scoped></style>