Skip to content

Commit e035eb2

Browse files
committed
refactor: 【草稿,素材】应用【公众号选择器】组件
1 parent c33e4de commit e035eb2

File tree

2 files changed

+85
-147
lines changed

2 files changed

+85
-147
lines changed

src/views/mp/draft/index.vue

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,21 @@
33

44
<!-- 搜索工作栏 -->
55
<ContentWrap>
6-
<el-form
7-
class="-mb-15px"
8-
:model="queryParams"
9-
ref="queryFormRef"
10-
:inline="true"
11-
label-width="68px"
12-
>
13-
<el-form-item label="公众号" prop="accountId">
14-
<el-select v-model="queryParams.accountId" placeholder="请选择公众号">
15-
<el-option
16-
v-for="item in accountList"
17-
:key="item.id"
18-
:label="item.name"
19-
:value="item.id"
20-
/>
21-
</el-select>
22-
</el-form-item>
23-
<el-form-item>
24-
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
25-
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
6+
<WxAccountSelect @change="(accountId) => accountChanged(accountId)">
7+
<template #actions>
268
<el-button type="primary" plain @click="handleAdd" v-hasPermi="['mp:draft:create']">
279
<Icon icon="ep:plus" />新增
2810
</el-button>
29-
</el-form-item>
30-
</el-form>
11+
</template>
12+
</WxAccountSelect>
3113
</ContentWrap>
3214

3315
<!-- 列表 -->
3416
<ContentWrap>
3517
<div class="waterfall" v-loading="loading">
3618
<template v-for="item in list" :key="item.articleId">
3719
<div class="waterfall-item" v-if="item.content && item.content.newsItem">
38-
<wx-news :articles="item.content.newsItem" />
20+
<WxNews :articles="item.content.newsItem" />
3921
<!-- 操作按钮 -->
4022
<el-row class="ope-row">
4123
<el-button
@@ -239,7 +221,7 @@
239221
</div>
240222
<!--富文本编辑器组件-->
241223
<el-row>
242-
<wx-editor
224+
<WxEditor
243225
v-model="articlesAdd[isActiveAddNews].content"
244226
:account-id="uploadData.accountId"
245227
v-if="hackResetEditor"
@@ -258,14 +240,15 @@
258240
import WxEditor from '@/views/mp/components/wx-editor/WxEditor.vue'
259241
import WxNews from '@/views/mp/components/wx-news/main.vue'
260242
import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue'
243+
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
261244
import { getAccessToken } from '@/utils/auth'
262-
import * as MpAccountApi from '@/api/mp/account'
263245
import * as MpDraftApi from '@/api/mp/draft'
264246
import * as MpFreePublishApi from '@/api/mp/freePublish'
265-
const message = useMessage() // 消息
266247
// 可以用改本地数据模拟,避免API调用超限
267248
// import drafts from './mock'
268249
250+
const message = useMessage() // 消息
251+
269252
const loading = ref(true) // 列表的加载中
270253
const total = ref(0) // 列表的总页数
271254
const list = ref([]) // 列表的数据
@@ -274,8 +257,6 @@ const queryParams = reactive({
274257
pageSize: 10,
275258
accountId: undefined
276259
})
277-
const queryFormRef = ref() // 搜索的表单
278-
const accountList = ref([]) // 公众号账号列表
279260
280261
// ========== 文件上传 ==========
281262
const materialSelectRef = ref()
@@ -298,16 +279,11 @@ const operateMaterial = ref('add')
298279
const articlesMediaId = ref('')
299280
const hackResetEditor = ref(false)
300281
301-
/** 初始化 **/
302-
onMounted(async () => {
303-
accountList.value = await MpAccountApi.getSimpleAccountList()
304-
// 选中第一个
305-
if (accountList.value.length > 0) {
306-
// @ts-ignore
307-
queryParams.accountId = accountList.value[0].id
308-
}
309-
await getList()
310-
})
282+
/** 侦听公众号变化 **/
283+
const accountChanged = (accountId) => {
284+
setAccountId(accountId)
285+
getList()
286+
}
311287
312288
// ======================== 列表查询 ========================
313289
/** 设置账号编号 */
@@ -341,26 +317,6 @@ const getList = async () => {
341317
}
342318
}
343319
344-
/** 搜索按钮操作 */
345-
const handleQuery = () => {
346-
queryParams.pageNo = 1
347-
// 默认选中第一个
348-
if (queryParams.accountId) {
349-
setAccountId(queryParams.accountId)
350-
}
351-
getList()
352-
}
353-
354-
/** 重置按钮操作 */
355-
const resetQuery = () => {
356-
queryFormRef.value.resetFields()
357-
// 默认选中第一个
358-
if (accountList.value.length > 0) {
359-
setAccountId(accountList.value[0].id)
360-
}
361-
handleQuery()
362-
}
363-
364320
// ======================== 新增/修改草稿 ========================
365321
/** 新增按钮操作 */
366322
const handleAdd = () => {

0 commit comments

Comments
 (0)