Skip to content

Commit 053ee54

Browse files
committed
refactor: 【MP粉丝管理】应用【公众号选择器】组件
1 parent b842986 commit 053ee54

File tree

1 file changed

+18
-77
lines changed

1 file changed

+18
-77
lines changed

src/views/mp/user/index.vue

Lines changed: 18 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,13 @@
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="openid">
24-
<el-input
25-
v-model="queryParams.openid"
26-
placeholder="请输入用户标识"
27-
clearable
28-
@keyup.enter="handleQuery"
29-
class="!w-240px"
30-
/>
31-
</el-form-item>
32-
<el-form-item label="昵称" prop="nickname">
33-
<el-input
34-
v-model="queryParams.nickname"
35-
placeholder="请输入昵称"
36-
clearable
37-
@keyup.enter="handleQuery"
38-
class="!w-240px"
39-
/>
40-
</el-form-item>
41-
<el-form-item>
42-
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
43-
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
6+
<WxAccountSelect @change="(accountId) => accountChanged(accountId)">
7+
<template #actions>
448
<el-button type="success" plain @click="handleSync" v-hasPermi="['mp:user:sync']">
459
<Icon icon="ep:refresh" class="mr-5px" /> 同步
4610
</el-button>
47-
</el-form-item>
48-
</el-form>
11+
</template>
12+
</WxAccountSelect>
4913
</ContentWrap>
5014

5115
<!-- 列表 -->
@@ -101,11 +65,12 @@
10165
<UserForm ref="formRef" @success="getList" />
10266
</template>
10367
<script lang="ts" setup name="MpUser">
68+
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
10469
import { dateFormatter } from '@/utils/formatTime'
105-
import * as MpAccountApi from '@/api/mp/account'
10670
import * as MpUserApi from '@/api/mp/user'
10771
import * as MpTagApi from '@/api/mp/tag'
10872
import UserForm from './UserForm.vue'
73+
10974
const message = useMessage() // 消息
11075
11176
const loading = ref(true) // 列表的加载中
@@ -118,17 +83,22 @@ const queryParams = reactive({
11883
openid: null,
11984
nickname: null
12085
})
121-
const queryFormRef = ref() // 搜索的表单
122-
const accountList = ref([]) // 公众号账号列表
12386
const tagList = ref([]) // 公众号标签列表
12487
88+
/** 初始化 */
89+
onMounted(async () => {
90+
tagList.value = await MpTagApi.getSimpleTagList()
91+
})
92+
93+
/** 侦听公众号变化 **/
94+
const accountChanged = (accountId) => {
95+
queryParams.pageNo = 1
96+
queryParams.accountId = accountId
97+
getList()
98+
}
99+
125100
/** 查询列表 */
126101
const getList = async () => {
127-
// 如果没有选中公众号账号,则进行提示。
128-
if (!queryParams.accountId) {
129-
message.error('未选中公众号,无法查询用户')
130-
return false
131-
}
132102
try {
133103
loading.value = true
134104
const data = await MpUserApi.getUserPage(queryParams)
@@ -139,22 +109,6 @@ const getList = async () => {
139109
}
140110
}
141111
142-
/** 搜索按钮操作 */
143-
const handleQuery = () => {
144-
queryParams.pageNo = 1
145-
getList()
146-
}
147-
148-
/** 重置按钮操作 */
149-
const resetQuery = () => {
150-
queryFormRef.value.resetFields()
151-
// 默认选中第一个
152-
if (accountList.value.length > 0) {
153-
queryParams.accountId = accountList.value[0].id
154-
}
155-
handleQuery()
156-
}
157-
158112
/** 添加/修改操作 */
159113
const formRef = ref()
160114
const openForm = (id: number) => {
@@ -171,17 +125,4 @@ const handleSync = async () => {
171125
await getList()
172126
} catch {}
173127
}
174-
175-
/** 初始化 */
176-
onMounted(async () => {
177-
// 加载标签
178-
tagList.value = await MpTagApi.getSimpleTagList()
179-
180-
// 加载账号
181-
accountList.value = await MpAccountApi.getSimpleAccountList()
182-
if (accountList.value.length > 0) {
183-
queryParams.accountId = accountList.value[0].id
184-
}
185-
await getList()
186-
})
187128
</script>

0 commit comments

Comments
 (0)