Skip to content

Commit 1f4862e

Browse files
committed
✨ 公告飘带上下轮播
1 parent 3a6a811 commit 1f4862e

File tree

6 files changed

+153
-12
lines changed

6 files changed

+153
-12
lines changed

src/api/notify/announcement.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,19 @@ export function uploadImage (resultFiles) {
5454
});
5555
return request.post('/notify/announcement/image', formData, { contentType: false, processData: false })
5656
}
57+
58+
59+
export function getUserAnnouncements() {
60+
return request({
61+
url: '/notify/announcement/user',
62+
method: 'get'
63+
})
64+
}
65+
66+
67+
export function readAnnouncement(announcementId) {
68+
return request({
69+
url: '/notify/announcement/user/read/' + announcementId,
70+
method: 'patch'
71+
})
72+
}

src/components/notify/AnnouncementModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { Modal } from 'ant-design-vue'
66
77
export default {
8-
name: 'AnnouncementPage',
8+
name: 'AnnouncementModal',
99
methods: {
1010
show(announcement){
1111
Modal.info({
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<template>
2+
<div class="text-container" v-if="announcementNum > 0">
3+
<transition class="" name="slide" mode="out-in">
4+
<span :key="announcement.id" class="announcement-content">
5+
<a-icon type="sound" theme="filled"/>
6+
<a href="javascript:" class="text" @click="readAnnouncement">{{ announcement.title }}</a>
7+
</span>
8+
</transition>
9+
<announcement-modal ref="announcementModal"></announcement-modal>
10+
</div>
11+
</template>
12+
13+
<script>
14+
import AnnouncementModal from '@/components/notify/AnnouncementModal'
15+
import { getUserAnnouncements, readAnnouncement } from '@/api/notify/announcement'
16+
import { mapGetters } from 'vuex'
17+
18+
export default {
19+
name: 'AnnouncementRibbon',
20+
components: {AnnouncementModal},
21+
data () {
22+
return {
23+
activeIndex: 0, // 当前索引
24+
intervalId: null, // 定时器ID
25+
playTime: 4000, // 定时器执行间隔
26+
announcements: [] // 公告信息
27+
}
28+
},
29+
computed: {
30+
announcementNum() {
31+
return this.announcements.length
32+
},
33+
announcement () {
34+
return this.announcements[this.activeIndex]
35+
}
36+
},
37+
created () {
38+
// 获取公告信息
39+
getUserAnnouncements().then(res => {
40+
this.announcements = res.data
41+
})
42+
// 定义定时器
43+
this.intervalId = setInterval(() => {
44+
if (this.activeIndex < this.announcementNum - 1) {
45+
this.activeIndex++ // 自增
46+
} else {
47+
this.activeIndex = 0
48+
}
49+
}, this.playTime)
50+
51+
},
52+
destroyed () {
53+
// 清除定时器
54+
clearInterval(this.intervalId)
55+
},
56+
methods: {
57+
readAnnouncement(){
58+
// 展示公告
59+
this.$refs.announcementModal.show(this.announcement)
60+
// 已读上报
61+
readAnnouncement(this.announcement.id).resolve();
62+
}
63+
}
64+
}
65+
</script>
66+
67+
<style scoped>
68+
69+
.text-container {
70+
font-size: 14px;
71+
color: #f56b6b;
72+
width: 100%;
73+
margin: 0 auto;
74+
overflow: hidden;
75+
min-height: 32px;
76+
position: relative;
77+
background: rgb(230, 247, 255);
78+
padding-left: 18px;
79+
}
80+
81+
.text {
82+
color: #f56b6b;
83+
display: inline;
84+
padding-left: 12px
85+
}
86+
87+
.announcement-content {
88+
width: 100%;
89+
position: absolute;
90+
text-align: left;
91+
line-height: 32px;
92+
}
93+
94+
.slide-enter-active, .slide-leave-active {
95+
transition: all 0.8s linear;
96+
}
97+
98+
.slide-enter {
99+
transform: translateY(20px);
100+
opacity: 1;
101+
}
102+
103+
.slide-leave-to {
104+
transform: translateY(-20px);
105+
opacity: 0;
106+
}
107+
</style>
108+

src/layouts/BasicLayout.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
@toggle="toggle"
4040
/>
4141

42+
<announcement-ribbon/>
43+
4244
<!-- layout content -->
4345
<a-layout-content :style="{ height: '100%', margin: '18px 18px 0', paddingTop: fixedHeader ? '64px' : '0' }">
4446
<multi-tab v-if="multiTab"></multi-tab>
@@ -70,11 +72,13 @@ import SideMenu from '@/components/Menu/SideMenu'
7072
import GlobalHeader from '@/components/GlobalHeader'
7173
import GlobalFooter from '@/components/GlobalFooter'
7274
import SettingDrawer from '@/components/SettingDrawer'
75+
import AnnouncementRibbon from '@/components/notify/AnnouncementRibbon'
7376
7477
export default {
7578
name: 'BasicLayout',
7679
mixins: [mixin, mixinDevice],
7780
components: {
81+
AnnouncementRibbon,
7882
RouteView,
7983
SideMenu,
8084
GlobalHeader,

src/views/notify/announcement/AnnouncementForm.vue

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,23 @@
7676
</dict-check-box-group>
7777
</a-form-item>
7878

79-
<a-form-item label="失效时间">
80-
<a-date-picker
81-
v-decorator="['deadline']"
82-
placeholder="不选则永久有效"
83-
format="YYYY-MM-DD HH:mm:ss"
84-
value-format="YYYY-MM-DD HH:mm:ss"
85-
:show-time="true"
86-
/>
79+
<a-form-item label="永久有效">
80+
<a-row>
81+
<a-col :xs="5" :md="2">
82+
<a-switch v-model="isImmortal"></a-switch>
83+
</a-col>
84+
<a-col :xs="16" :md="16">
85+
<a-form-item label="">
86+
<a-date-picker
87+
v-if="!isImmortal"
88+
v-decorator="['deadline']"
89+
format="YYYY-MM-DD HH:mm:ss"
90+
value-format="YYYY-MM-DD HH:mm:ss"
91+
:show-time="true"
92+
/>
93+
</a-form-item>
94+
</a-col>
95+
</a-row>
8796
</a-form-item>
8897

8998
<a-form-item :wrapperCol="{offset: 7 }">
@@ -137,6 +146,8 @@ export default {
137146
sm: { span: 16 }
138147
},
139148
149+
// 是否永久有效
150+
isImmortal: true,
140151
// 接收人筛选类型
141152
recipientFilterType: null,
142153
// 创建公告的默认状态
@@ -157,6 +168,7 @@ export default {
157168
},
158169
methods: {
159170
echoDataProcess (data) {
171+
this.isImmortal = data.immortal === 1
160172
this.recipientFilterType = data.recipientFilterType
161173
},
162174
recipientFilterTypeChange (val) {
@@ -172,6 +184,7 @@ export default {
172184
this.$refs.announcementModal.show(data)
173185
},
174186
submitDataProcess (formData) {
187+
formData.immortal = this.isImmortal ? 1 : 0
175188
formData.status = this.newAnnouncementStatus
176189
return formData
177190
},

src/views/notify/announcement/AnnouncementPage.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const statusFilterArr = [
127127
},
128128
{
129129
state: 'processing',
130-
text: '发布中',
130+
text: '已发布',
131131
value: 1
132132
},
133133
{
@@ -187,8 +187,8 @@ export default {
187187
{
188188
title: '失效时间',
189189
dataIndex: 'deadline',
190-
customRender: function (text) {
191-
return text ? text : '永久有效'
190+
customRender: function (text, record) {
191+
return record.immortal ? '永久有效' : text
192192
}
193193
},
194194
{

0 commit comments

Comments
 (0)