ArticleManager.vue
13.5 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
<template>
<div class="page">
<!--工具条-->
<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
<el-form>
<el-form-item>
<div class="tool-wrap fl">
<el-select v-model="curClassify" placeholder="请选择" @change="HandleSelectChange">
<el-option
v-for="(item,index) in totalData.classifyList"
:key="index"
:label="item.name"
:value="item.classify"
></el-option>
</el-select>
<el-button @click="handleAdd()" v-if="true" type="primary">新增</el-button>
</div>
</el-form-item>
</el-form>
</el-col>
<!-- 列表 -->
<el-table
:data="totalData.dataList"
highlight-current-row
v-loading="listLoading"
style="width: 100%;"
>
<el-table-column prop="title" label="标题"></el-table-column>
<el-table-column label="所属分类">
<template slot-scope="scope">{{formatClassify(scope.row)}}</template>
</el-table-column>
<!-- <el-table-column prop="thumb" label="封面"></el-table-column> -->
<el-table-column label="封面图">
<template slot-scope="scope">
<img class="poster" :src="scope.row.thumb" alt>
</template>
</el-table-column>
<el-table-column prop="descript" label="描述"></el-table-column>
<el-table-column prop="url" label="链接地址"></el-table-column>
<!-- <el-table-column prop="content" label="文章内容">
</el-table-column>-->
<el-table-column prop="months" label="月份" :formatter="formatterMonths"></el-table-column>
<el-table-column prop="tags" label="标签" :formatter="formatterTags"></el-table-column>
<el-table-column prop="pv" label="pv"></el-table-column>
<el-table-column prop="share" label="分享"></el-table-column>
<el-table-column label="操作" width="150">
<template slot-scope="scope">
<el-button size="small" @click="modifyHandler(scope.$index, scope.row)">修改</el-button>
<el-button size="small" type="danger" @click="deleteHandler(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<!--编辑界面-->
<el-dialog :title="dialogTitle" :visible.sync="editFormVisible" :close-on-click-modal="false">
<el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
<el-form-item label="分类" prop="classify">
<el-select
v-model="editForm.classify"
placeholder="请选择"
@change="HandleSelectDialogChange"
>
<el-option
v-for="(item,index) in totalData.classifyDialogList"
:key="index"
:label="item.name"
:value="item.classify"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="标题" prop="title">
<el-input v-model="editForm.title"></el-input>
</el-form-item>
<el-form-item label="封面图" prop="thumb">
<img class="upload-poster-image" v-show="editForm.thumb" :src="editForm.thumb" alt>
<upload-item pid="p1" v-on:upload-success="onUploadSuccess"></upload-item>
</el-form-item>
<el-form-item label="描述" prop="descript">
<el-input v-model="editForm.descript"></el-input>
</el-form-item>
<el-form-item label="链接地址" prop="url">
<el-input v-model="editForm.url"></el-input>
</el-form-item>
<el-form-item label="标签" prop="tags">
<el-select
:disabled="editForm.classify == ''"
v-model="editForm.tags"
multiple
placeholder="请选择"
style="width:100%;"
>
<el-option
v-for="(item,index) in totalData.tagList"
:key="index"
:label="item.tag"
:value="item.tagCode"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="月龄" prop="months">
<el-select v-model="editForm.months" multiple placeholder="请选择" style="width:100%;">
<el-option v-for="(item,index) in months" :key="index" :label="item" :value="item"></el-option>
</el-select>
</el-form-item>
<!-- <el-form-item label="文章内容" prop="content">
<el-input v-model="editForm.content"></el-input>
<quill-editor
class="quill"
v-model="editForm.content"
ref="quillEditor"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ready="onEditorReady($event)"
></quill-editor>
</el-form-item>-->
<!-- 月份,是个数组 -->
<!-- <el-form-item label="月份" prop="months">
<el-input v-model="editForm.months"></el-input>
</el-form-item>-->
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click.native="editFormVisible = false">取消</el-button>
<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
</div>
</el-dialog>
<!--分页导航-->
<el-col :span="24" class="toolbar fl pagination-wrap">
<div class="page-tips">总共{{total}}条记录,每页{{pageSize}}条,总共{{pageNum}}页</div>
<el-pagination
layout="prev, pager, next"
@current-change="handleCurrentChange"
:page-size="pageSize"
:total="total"
style="float:right;"
></el-pagination>
</el-col>
</div>
</template>
<script>
import {
getClassifyList,
getArticleList,
saveArticle,
deleteArticle,
getTagList
} from '../../api/api.js'
import UploadItem from '../../components/UploadItem'
export default {
data() {
return {
key: 'value',
page: 1,
pageSize: 10,
total: 0,
totalData: {
dataList: [],
classifyList: [],
classifyDialogList: [],
tagList: []
},
classifyMap: {},
listLoading: false,
editLoading: false,
editFormVisible: false,
dialogTitle: '编辑',
//编辑界面数据
editForm: {
title: '',
thumb: '',
descript: '',
url: '',
content: '',
months: [],
tags: [],
contentType: '',
pv: '',
share: '',
classify: ''
},
editFormRules: {
title: [
{
required: true,
message: '请输入标题',
trigger: 'blur'
}
],
thumb: [
{
required: true,
message: '请输入封面图',
trigger: 'blur'
}
],
descript: [
{
required: true,
message: '请输入描述',
trigger: 'blur'
}
],
url: [
{
required: true,
message: '请输入文章连接',
trigger: 'blur'
}
],
tags: [
{
required: true,
message: '请选择标签',
trigger: 'change'
}
],
months: [
{
required: true,
message: '请选择月龄',
trigger: 'change'
}
],
classify: [{ required: true, message: '请选择分类', trigger: 'blur' }]
},
curClassify: '',
editorOption: {
/* quill options */
},
months: []
}
},
computed: {
pageNum() {
return Math.ceil(this.total / this.pageSize)
},
editor() {
return this.$refs.myQuillEditor.quill
}
},
methods: {
name() {},
onUploadSuccess(evtAny) {
let { pid, url } = evtAny
if (pid == 'p1') {
this.$set(this.editForm, 'thumb', url)
} else if (pid == 'v1') {
// this.$set(this.editForm, 'vedioUrl', url)
}
},
formatterMonths(row, column) {
let result = row.months
return result.join(',')
},
formatterTags(row, column) {
let result = []
row.tags.forEach((element, idx) => {
this.totalData.tagList.forEach((element2, idx2) => {
if (element == element2.tagCode) {
result.push(element2.tag)
}
})
})
return result.join(',')
},
// 获取列表
reqQuery() {
let data = {
page: this.page,
size: this.pageSize,
classify: this.curClassify
}
getArticleList(data).then(result => {
let { content, code } = result
let { list, total } = content
this.total = total
this.$set(this.totalData, 'dataList', list)
})
// getTagList(data).then(result => {
// let { content, code } = result
// let { list, total } = content
// this.total = total
// this.$set(this.totalData, 'tagList', list)
// })
},
// 获取分类列表
reqGetClassifyList() {
let data = {}
getClassifyList(data)
.then(result => {
let { content, code } = result
this.$set(this.totalData, 'classifyDialogList', content)
//深复制
let content2 = Object.assign([], content)
content2.forEach(element => {
this.classifyMap[element.classify] = element.name;
});
content2.unshift({
classify: '',
dispayType: '',
name: '全部'
})
this.$set(this.totalData, 'classifyList', content2)
this.reqQuery()
})
.catch(err => {})
},
// 获取话题列表
reqTagList() {
let data = {
classify: this.editForm.classify
}
console.log('this.curClassify:', this.curClassify)
getTagList(data).then(result => {
let { content, code } = result
let { list, total } = content
this.total = total
console.log('list:', list)
this.$set(this.totalData, 'tagList', list)
})
},
// 修改 显示修改对话框
modifyHandler(index, row) {
this.$set(this.totalData, 'tagList', [])
this.dialogTitle = '修改'
try {
this.$refs['editForm'].resetFields()
} catch (error) {}
this.editFormVisible = true
this.editForm = Object.assign({}, row)
this.reqTagList()
console.log('editForm:', this.editForm)
},
formatClassify(data) {
return this.classifyMap[data.classify];
},
deleteHandler(index, row) {
let data = {
articleCode: row.articleCode
}
console.log('deleteHandler data:', data)
this.$confirm('确认删除吗?', '提示', {}).then(() => {
deleteArticle(data)
.then(result => {
let { code, content } = result
if (code == 200) {
this.$notify({
title: '成功',
message: '删除成功',
type: 'success'
})
} else {
}
this.editFormVisible = false
this.reqQuery()
})
.catch(err => {})
})
},
// 新增
handleAdd() {
this.editForm = {
title: '',
thumb: '',
descript: '',
url: '',
content: '',
months: [],
tags: [],
contentType: '1',
pv: '',
share: '',
classify: ''
}
try {
this.$refs['editForm'].resetFields()
} catch (error) {}
this.editFormVisible = true
this.dialogTitle = '新增'
},
// 提交 新增/修改
editSubmit() {
let data = this.editForm
// 默认传1
if (!data.contentType) data.contentType = '1'
this.$refs.editForm.validate(valid => {
if (valid) {
this.editLoading = true
saveArticle(data)
.then(result => {
let { code, content } = result
if (code == 200) {
this.$notify({
title: '成功',
message: '提交成功',
type: 'success'
})
} else {
}
this.editLoading = false
this.editFormVisible = false
this.reqQuery()
})
.catch(err => {})
}
})
},
// 点击页数
handleCurrentChange(val) {
this.page = val
this.reqQuery()
},
HandleSelectChange() {
this.reqQuery()
},
// 编辑时选择分类
HandleSelectDialogChange() {
this.editForm.tags = []
this.reqTagList()
},
// 富文本响应事件
onEditorBlur(quill) {
console.log('editor blur!', quill)
},
onEditorFocus(quill) {
console.log('editor focus!', quill)
},
onEditorReady(quill) {
console.log('editor ready!', quill)
}
},
created() {
this.reqGetClassifyList()
for (let index = 0; index < 37; index++) {
this.months.push(index + '')
}
},
components: {
UploadItem
}
}
</script>
<style lang="less" scoped>
// @import '../../styles/element-ui.less';
.tool-wrap {
color: #333333;
}
.pagination-wrap {
.page-tips {
height: 32px;
line-height: 32px;
color: #333333;
}
}
.fl {
display: flex;
justify-content: space-between;
}
.fle {
display: flex;
justify-content: flex-end;
}
.quill {
}
</style>