1
1
<template >
2
- <div class =" app-container" >
3
- <doc-alert title =" 公众号图文" url =" https://doc.iocoder.cn/mp/article/" />
4
-
5
- <!-- 搜索工作栏 -->
6
- <el-form :model =" queryParams" ref =" queryFormRef" size =" small" :inline =" true" label-width =" 68px" >
2
+ <doc-alert title =" 公众号图文" url =" https://doc.iocoder.cn/mp/article/" />
3
+
4
+ <!-- 搜索工作栏 -->
5
+ <ContentWrap >
6
+ <el-form
7
+ class =" -mb-15px"
8
+ :model =" queryParams"
9
+ ref =" queryFormRef"
10
+ :inline =" true"
11
+ label-width =" 68px"
12
+ >
7
13
<el-form-item label =" 公众号" prop =" accountId" >
8
14
<el-select v-model =" queryParams.accountId" placeholder =" 请选择公众号" >
9
15
<el-option
10
16
v-for =" item in accountList"
11
- :key =" parseInt( item.id) "
17
+ :key =" item.id"
12
18
:label =" item.name"
13
- :value =" parseInt( item.id) "
19
+ :value =" item.id"
14
20
/>
15
21
</el-select >
16
22
</el-form-item >
17
23
<el-form-item >
18
- <el-button type = " primary " @click =" handleQuery" ><Icon icon =" ep:search" />搜索</el-button >
24
+ <el-button @click =" handleQuery" ><Icon icon =" ep:search" />搜索</el-button >
19
25
<el-button @click =" resetQuery" ><Icon icon =" ep:refresh" />重置</el-button >
26
+ <el-button type =" primary" plain @click =" handleAdd" v-hasPermi =" ['mp:draft:create']" >
27
+ <Icon icon =" ep:plus" />新增
28
+ </el-button >
20
29
</el-form-item >
21
30
</el-form >
31
+ </ContentWrap >
22
32
23
- <!-- 操作工具栏 -->
24
- <el-row :gutter =" 10" class =" mb8" >
25
- <el-col :span =" 1.5" >
26
- <el-button
27
- type =" primary"
28
- plain
29
- size =" small"
30
- @click =" handleAdd"
31
- v-hasPermi =" ['mp:draft:create']"
32
- ><Icon icon =" ep:plus" />新增
33
- </el-button >
34
- </el-col >
35
- </el-row >
36
-
37
- <!-- 列表 -->
33
+ <!-- 列表 -->
34
+ <ContentWrap >
38
35
<div class =" waterfall" v-loading =" loading" >
39
36
<template v-for =" item in list " :key =" item .articleId " >
40
37
<div class =" waterfall-item" v-if =" item.content && item.content.newsItem" >
46
43
circle
47
44
@click =" handlePublish(item)"
48
45
v-hasPermi =" ['mp:free-publish:submit']"
49
- ><Icon icon =" fa:upload"
50
- /></el-button >
46
+ >
47
+ <Icon icon =" fa:upload" />
48
+ </el-button >
51
49
<el-button
52
50
type =" primary"
53
51
circle
54
52
@click =" handleUpdate(item)"
55
53
v-hasPermi =" ['mp:draft:update']"
56
- ><Icon icon =" ep:edit"
57
- /></el-button >
54
+ >
55
+ <Icon icon =" ep:edit" />
56
+ </el-button >
58
57
<el-button
59
58
type =" danger"
60
59
circle
61
60
@click =" handleDelete(item)"
62
61
v-hasPermi =" ['mp:draft:delete']"
63
- ><Icon icon =" ep:delete"
64
- /></el-button >
62
+ >
63
+ <Icon icon =" ep:delete" />
64
+ </el-button >
65
65
</el-row >
66
66
</div >
67
67
</template >
68
68
</div >
69
69
<!-- 分页记录 -->
70
- <pagination
71
- v-show =" total > 0"
70
+ <Pagination
72
71
:total =" total"
73
72
v-model:page =" queryParams.pageNo"
74
73
v-model:limit =" queryParams.pageSize"
75
74
@pagination =" getList"
76
75
/>
76
+ </ContentWrap >
77
77
78
+ <!-- TODO @Dhb52:迁移成独立路由 -->
79
+ <div class =" app-container" >
78
80
<!-- 添加或修改草稿对话框 -->
79
81
<Teleport to =" body" >
80
82
<el-dialog
254
256
</Teleport >
255
257
</div >
256
258
</template >
257
-
258
259
<script setup name="MpDraft">
259
- import { ref , onMounted , reactive , nextTick } from ' vue'
260
260
import WxEditor from ' @/views/mp/components/wx-editor/WxEditor.vue'
261
261
import WxNews from ' @/views/mp/components/wx-news/main.vue'
262
262
import WxMaterialSelect from ' @/views/mp/components/wx-material-select/main.vue'
263
263
import { getAccessToken } from ' @/utils/auth'
264
264
import { createDraft , deleteDraft , getDraftPage , updateDraft } from ' @/api/mp/draft'
265
265
import { getSimpleAccountList } from ' @/api/mp/account'
266
266
import { submitFreePublish } from ' @/api/mp/freePublish'
267
+ const message = useMessage () // 消息
267
268
// 可以用改本地数据模拟,避免API调用超限
268
269
// import drafts from './mock'
269
270
270
- const BASE_URL = import .meta.env.VITE_BASE_URL
271
-
272
- const message = useMessage ()
273
-
274
- const materialSelectRef = ref ()
275
- const queryFormRef = ref ()
276
-
277
- // 遮罩层
278
- const loading = ref (false )
279
- // 显示搜索条件
280
- // 总条数
281
- const total = ref (0 )
282
- // 数据列表
283
- const list = ref ([])
271
+ const loading = ref (true ) // 列表的加载中
272
+ const total = ref (0 ) // 列表的总页数
273
+ const list = ref ([]) // 列表的数据
284
274
const queryParams = reactive ({
285
275
pageNo: 1 ,
286
276
pageSize: 10 ,
287
277
accountId: undefined
288
278
})
279
+ const queryFormRef = ref () // 搜索的表单
280
+ const accountList = ref ([]) // 公众号账号列表
289
281
290
282
// ========== 文件上传 ==========
283
+ const materialSelectRef = ref ()
284
+ const BASE_URL = import .meta.env.VITE_BASE_URL
291
285
const actionUrl = ref (BASE_URL + ' /admin-api/mp/material/upload-permanent' ) // 上传永久素材的地址
292
286
const headers = ref ({ Authorization: ' Bearer ' + getAccessToken () }) // 设置上传的请求头部
293
287
const fileList = ref ([])
@@ -305,9 +299,8 @@ const dialogImageVisible = ref(false)
305
299
const operateMaterial = ref (' add' )
306
300
const articlesMediaId = ref (' ' )
307
301
const hackResetEditor = ref (false )
308
- // 公众号账号列表
309
- const accountList = ref ([])
310
302
303
+ /** 初始化 **/
311
304
onMounted (async () => {
312
305
accountList .value = await getSimpleAccountList ()
313
306
// 选中第一个
@@ -393,6 +386,7 @@ const handleUpdate = (item) => {
393
386
394
387
/** 提交按钮 */
395
388
const submitForm = () => {
389
+ // TODO @Dhb52: 参考别的模块写法,改成 await 方式
396
390
addMaterialLoading .value = true
397
391
if (operateMaterial .value === ' add' ) {
398
392
createDraft (queryParams .accountId , articlesAdd .value )
@@ -560,23 +554,23 @@ const handlePublish = async (item) => {
560
554
try {
561
555
await message .confirm (content)
562
556
await submitFreePublish (accountId, mediaId)
563
- getList ()
564
557
message .notifySuccess (' 发布成功' )
558
+ await getList ()
565
559
} catch {}
566
560
}
567
561
562
+ /** 删除按钮操作 */
568
563
const handleDelete = async (item ) => {
569
564
const accountId = queryParams .accountId
570
565
const mediaId = item .mediaId
571
566
try {
572
567
await message .confirm (' 此操作将永久删除该草稿, 是否继续?' )
573
568
await deleteDraft (accountId, mediaId)
574
- getList ()
575
569
message .notifySuccess (' 删除成功' )
570
+ await getList ()
576
571
} catch {}
577
572
}
578
573
</script >
579
-
580
574
<style lang="scss" scoped>
581
575
.pagination {
582
576
float : right ;
0 commit comments