Skip to content

Commit b842986

Browse files
committed
refactor:【MP标签】应用【公众号选择器】组件
1 parent af18201 commit b842986

File tree

1 file changed

+13
-69
lines changed

1 file changed

+13
-69
lines changed

src/views/mp/tag/index.vue

Lines changed: 13 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,16 @@
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="请选择公众号" class="!w-240px">
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 label="标签名称" prop="name">
24-
<el-input
25-
v-model="queryParams.name"
26-
placeholder="请输入标签名称"
27-
clearable
28-
@keyup.enter="handleQuery"
29-
class="!w-240px"
30-
/>
31-
</el-form-item>
32-
<el-form-item>
33-
<el-form-item>
34-
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
35-
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
36-
</el-form-item>
6+
<WxAccountSelect @change="(accountId) => accountChanged(accountId)">
7+
<template #actions>
378
<el-button type="primary" plain @click="openForm('create')" v-hasPermi="['mp:tag:create']">
389
<Icon icon="ep:plus" class="mr-5px" /> 新增
3910
</el-button>
4011
<el-button type="success" plain @click="handleSync" v-hasPermi="['mp:tag:sync']">
4112
<Icon icon="ep:refresh" class="mr-5px" /> 同步
4213
</el-button>
43-
</el-form-item>
44-
</el-form>
14+
</template>
15+
</WxAccountSelect>
4516
</ContentWrap>
4617

4718
<!-- 列表 -->
@@ -92,8 +63,8 @@
9263
</template>
9364
<script setup lang="ts" name="MpTag">
9465
import { dateFormatter } from '@/utils/formatTime'
66+
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
9567
import * as MpTagApi from '@/api/mp/tag'
96-
import * as MpAccountApi from '@/api/mp/account'
9768
import TagForm from './TagForm.vue'
9869
const message = useMessage() // 消息弹窗
9970
const { t } = useI18n() // 国际化
@@ -104,19 +75,18 @@ const list = ref([]) // 列表的数据
10475
const queryParams = reactive({
10576
pageNo: 1,
10677
pageSize: 10,
107-
accountId: undefined,
108-
name: null
78+
accountId: undefined
10979
})
110-
const queryFormRef = ref() // 搜索的表单
111-
const accountList = ref<MpAccountApi.AccountVO[]>([]) // 公众号账号列表
80+
81+
/** 侦听公众号变化 **/
82+
const accountChanged = (accountId) => {
83+
queryParams.pageNo = 1
84+
queryParams.accountId = accountId
85+
getList()
86+
}
11287
11388
/** 查询列表 */
11489
const getList = async () => {
115-
// 如果没有选中公众号账号,则进行提示。
116-
if (!queryParams.accountId) {
117-
await message.error('未选中公众号,无法查询标签')
118-
return
119-
}
12090
try {
12191
loading.value = true
12292
const data = await MpTagApi.getTagPage(queryParams)
@@ -127,22 +97,6 @@ const getList = async () => {
12797
}
12898
}
12999
130-
/** 搜索按钮操作 */
131-
const handleQuery = () => {
132-
queryParams.pageNo = 1
133-
getList()
134-
}
135-
136-
/** 重置按钮操作 */
137-
const resetQuery = () => {
138-
queryFormRef.value.resetFields()
139-
// 默认选中第一个
140-
if (accountList.value.length > 0) {
141-
queryParams.accountId = accountList.value[0].id
142-
}
143-
handleQuery()
144-
}
145-
146100
/** 添加/修改操作 */
147101
const formRef = ref()
148102
const openForm = (type: string, id?: number) => {
@@ -172,14 +126,4 @@ const handleSync = async () => {
172126
await getList()
173127
} catch {}
174128
}
175-
176-
/** 初始化 **/
177-
onMounted(async () => {
178-
accountList.value = await MpAccountApi.getSimpleAccountList()
179-
// 选中第一个
180-
if (accountList.value.length > 0) {
181-
queryParams.accountId = accountList.value[0].id
182-
}
183-
await getList()
184-
})
185129
</script>

0 commit comments

Comments
 (0)