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 >
0 commit comments