Skip to content
This repository was archived by the owner on Jun 14, 2021. It is now read-only.

Commit ee59115

Browse files
committed
feat: support announcement
1 parent f6d29da commit ee59115

File tree

3 files changed

+235
-8
lines changed

3 files changed

+235
-8
lines changed

src/components/Admin.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
<AdminUser></AdminUser>
55
<a-divider dashed />
66
<AdminGroup></AdminGroup>
7+
<a-divider dashed />
8+
<AdminAnnouncement></AdminAnnouncement>
79
</div>
810
</template>
911

1012
<script>
1113
import AdminUser from './AdminUser'
1214
import AdminGroup from './AdminGroup'
15+
import AdminAnnouncement from './AdminAnnouncement'
1316
1417
export default {
1518
components: {
1619
AdminUser,
17-
AdminGroup
20+
AdminGroup,
21+
AdminAnnouncement
1822
},
1923
created: () => {
2024
document.title = 'Admin | JAVClub'

src/components/AdminAnnouncement.vue

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<template>
2+
<div>
3+
<a-button class="margin" type="primary" @click="caVisible=true">
4+
Create Announcements
5+
</a-button>
6+
<a-table
7+
:columns="columns"
8+
:row-key="record => record.id"
9+
:data-source="data"
10+
:pagination="pagination"
11+
:loading="loading"
12+
@change="handleTableChange"
13+
>
14+
<span slot="action" slot-scope="id, item">
15+
<a @click="changeAnnouncement" :data-id="item.id" :data-title="item.title" :data-content="item.content">Change Announcement</a>
16+
<a-divider type="vertical" />
17+
<a @click="removeAnnouncement" :data-id="item.id">Remove</a>
18+
</span>
19+
</a-table>
20+
<a-modal
21+
title="Create announcement"
22+
:visible="caVisible"
23+
@ok="caOk"
24+
@cancel="cancel"
25+
>
26+
<a-input class="margin" v-model="title" placeholder="Title" />
27+
<a-textarea
28+
v-model="content"
29+
placeholder="Content"
30+
:auto-size="{ minRows: 3, maxRows: 16 }"
31+
/>
32+
</a-modal>
33+
<a-modal
34+
title="Change Announcement"
35+
:visible="canVisible"
36+
@ok="canOk"
37+
@cancel="cancel"
38+
>
39+
<a-input class="margin" v-model="title" placeholder="Title" />
40+
<a-textarea
41+
v-model="content"
42+
placeholder="Content"
43+
:auto-size="{ minRows: 3, maxRows: 16 }"
44+
/>
45+
</a-modal>
46+
</div>
47+
</template>
48+
49+
<script>
50+
const columns = [
51+
{
52+
title: '#',
53+
dataIndex: 'id'
54+
},
55+
{
56+
title: 'Title',
57+
dataIndex: 'title'
58+
},
59+
{
60+
title: 'Create Time',
61+
dataIndex: 'createTime'
62+
},
63+
{
64+
title: 'Update Time',
65+
dataIndex: 'updateTime'
66+
},
67+
{
68+
title: 'Action',
69+
dataIndex: 'action',
70+
scopedSlots: { customRender: 'action' }
71+
}
72+
73+
]
74+
75+
export default {
76+
data: function() {
77+
return {
78+
data: [],
79+
pagination: {},
80+
loading: false,
81+
columns,
82+
caVisible: false,
83+
canVisible: false,
84+
title: '',
85+
content: '',
86+
aid: 0
87+
}
88+
},
89+
90+
mounted() {
91+
this.fetch()
92+
},
93+
94+
methods: {
95+
handleTableChange(pagination) {
96+
const pager = { ...this.pagination }
97+
pager.current = pagination.current
98+
this.pagination = pager
99+
this.fetch({
100+
size: pagination.pageSize,
101+
page: pagination.current
102+
});
103+
},
104+
105+
genTimeStr(time, msg = '') {
106+
if (!time) return msg
107+
const date = new Date(time)
108+
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString()
109+
},
110+
111+
fetch(params = {}) {
112+
this.loading = true
113+
114+
this.axios.get(this.apiHost + `/announcement/getAnnouncementList/${params.page || 1}/${params.size || 10}`).then((res) => {
115+
res = res.data.data
116+
for (const i in res.data) {
117+
res.data[i].action = res.data[i].id
118+
res.data[i].createTime = this.genTimeStr(parseInt(res.data[i].createTime))
119+
res.data[i].updateTime = this.genTimeStr(parseInt(res.data[i].updateTime))
120+
}
121+
122+
this.data = res.data
123+
const pagination = { ...this.pagination }
124+
if (res.total) pagination.total = res.total
125+
this.pagination = pagination
126+
this.loading = false
127+
})
128+
},
129+
130+
changeAnnouncement(ele) {
131+
this.aid = ele.target.dataset.id
132+
this.title = ele.target.dataset.title
133+
this.content = ele.target.dataset.content
134+
this.canVisible = true
135+
},
136+
137+
removeAnnouncement(ele) {
138+
const aid = ele.target.dataset.id
139+
this.$confirm({
140+
title: 'Are you sure delete this group?',
141+
content: 'This operation is irreversible',
142+
okText: 'Yes',
143+
okType: 'danger',
144+
cancelText: 'No',
145+
onOk: async () => {
146+
await this.axios.post(this.apiHost + '/announcement/removeAnnouncement', {
147+
id: aid
148+
}).then((res) => {
149+
res = res.data
150+
151+
if (res.code === 0) {
152+
this.$message.success('Success')
153+
} else {
154+
this.$message.error(res.msg)
155+
}
156+
this.fetch()
157+
})
158+
}
159+
})
160+
},
161+
162+
canOk() {
163+
this.axios.post(this.apiHost + '/announcement/changeAnnouncement', {
164+
id: this.aid,
165+
title: this.title,
166+
content: this.content
167+
}).then((res) => {
168+
res = res.data
169+
170+
if (res.code === 0) {
171+
this.$message.success('Success')
172+
} else {
173+
this.$message.error(res.msg)
174+
}
175+
this.canVisible = false
176+
this.fetch()
177+
})
178+
this.title = ''
179+
this.content = ''
180+
},
181+
182+
caOk() {
183+
this.axios.post(this.apiHost + '/announcement/createAnnouncement', {
184+
title: this.title,
185+
content: this.content
186+
}).then((res) => {
187+
res = res.data
188+
189+
if (res.code === 0) {
190+
this.$message.success('Success')
191+
} else {
192+
this.$message.error(res.msg)
193+
}
194+
this.caVisible = false
195+
this.fetch()
196+
})
197+
this.title = ''
198+
this.content = ''
199+
},
200+
201+
cancel() {
202+
this.caVisible = false
203+
this.canVisible = false
204+
}
205+
}
206+
}
207+
</script>
208+
209+
<style scoped>
210+
.margin {
211+
margin-bottom: 22px;
212+
}
213+
</style>

src/components/Home.vue

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<template>
22
<div>
33
<h1>JAVClub</h1>
4-
<div>
5-
6-
</div>
74
<a-row>
85
<a-col :span="6">
96
<a-statistic title="Metadatas" :value="numbers.metadatas" style="margin-right: 50px" />
@@ -21,13 +18,19 @@
2118
<a-statistic title="Drivers" :value="numbers.drivers" style="margin-right: 50px" />
2219
</a-col>
2320
</a-row>
21+
<div v-if="announcements.length !== 0">
22+
<a-divider>Announcements</a-divider>
23+
<a-collapse>
24+
<a-collapse-panel v-for="item in announcements" :key="item.id" :header="item.title">
25+
<div style="word-wrap:break-word;word-break:break-all" v-html="item.content"></div>
26+
</a-collapse-panel>
27+
</a-collapse>
28+
</div>
2429
</div>
2530
</template>
2631

2732
<script>
2833
export default {
29-
30-
3134
data: () => {
3235
return {
3336
numbers: {
@@ -38,7 +41,9 @@ export default {
3841
stars: 0,
3942
tags: 0,
4043
videos: 0
41-
}
44+
},
45+
announcements: [],
46+
activeKey: []
4247
}
4348
},
4449
@@ -48,7 +53,12 @@ export default {
4853
this.numbers = res.data
4954
})
5055
56+
this.axios.get(this.apiHost + '/announcement/getAnnouncementList').then((res) => {
57+
res = res.data
58+
this.announcements = res.data.data
59+
})
60+
5161
document.title = 'Homepage | JAVClub'
5262
}
5363
}
54-
</script>
64+
</script>

0 commit comments

Comments
 (0)