Skip to content

Commit af18201

Browse files
committed
refactor:【自动回复、图文】应用【公众号选择器】组件
1 parent 7711ceb commit af18201

File tree

3 files changed

+33
-134
lines changed

3 files changed

+33
-134
lines changed

src/views/mp/autoReply/index.vue

Lines changed: 21 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,7 @@
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>
24-
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
25-
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
26-
</el-form-item>
27-
</el-form>
6+
<WxAccountSelect @change="(accountId) => accountChanged(accountId)" />
287
</ContentWrap>
298

309
<!-- tab 切换 -->
@@ -181,28 +160,21 @@
181160
</ContentWrap>
182161
</template>
183162
<script setup name="MpAutoReply">
184-
import { ref, reactive, onMounted, nextTick } from 'vue'
185163
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
186164
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
187165
import WxMusic from '@/views/mp/components/wx-music/main.vue'
188166
import WxNews from '@/views/mp/components/wx-news/main.vue'
189167
import WxReplySelect from '@/views/mp/components/wx-reply/main.vue'
190-
import { getSimpleAccountList } from '@/api/mp/account'
191-
import {
192-
createAutoReply,
193-
deleteAutoReply,
194-
getAutoReply,
195-
getAutoReplyPage,
196-
updateAutoReply
197-
} from '@/api/mp/autoReply'
168+
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
169+
import * as MpAutoReplyApi from '@/api/mp/autoReply'
198170
199171
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
200172
import { dateFormatter } from '@/utils/formatTime'
201173
import { ContentWrap } from '@/components/ContentWrap'
202174
203175
const message = useMessage()
204176
205-
const queryFormRef = ref()
177+
// const queryFormRef = ref()
206178
const formRef = ref()
207179
208180
// tab 类型(1、关注时回复;2、消息回复;3、关键词回复)
@@ -240,43 +212,27 @@ const rules = {
240212
requestMatch: [{ required: true, message: '请求的关键字的匹配不能为空', trigger: 'blur' }]
241213
}
242214
243-
const hackResetWxReplySelect = ref(false) // 重置 WxReplySelect 组件,解决无法清除的问题
215+
// 重置 WxReplySelect 组件,解决无法清除的问题
216+
const hackResetWxReplySelect = ref(false)
244217
245-
// 公众号账号列表
246-
const accountList = ref([])
247-
248-
onMounted(() => {
249-
getSimpleAccountList().then((data) => {
250-
accountList.value = data
251-
// 默认选中第一个
252-
if (accountList.value.length > 0) {
253-
queryParams.accountId = accountList.value[0].id
254-
}
255-
// 加载数据
256-
getList()
257-
})
258-
})
218+
const accountChanged = (accountId) => {
219+
queryParams.accountId = accountId
220+
getList()
221+
}
259222
260223
/** 查询列表 */
261224
const getList = async () => {
262-
// 如果没有选中公众号账号,则进行提示。
263-
if (!queryParams.accountId) {
264-
message.error('未选中公众号,无法查询自动回复')
265-
return false
266-
}
267-
268225
loading.value = false
269-
// 处理查询参数
270-
let params = {
271-
...queryParams,
272-
type: type.value
273-
}
274-
// 执行查询
275-
getAutoReplyPage(params).then((data) => {
226+
try {
227+
const data = await MpAutoReplyApi.getAutoReplyPage({
228+
...queryParams,
229+
type: type.value
230+
})
276231
list.value = data.list
277232
total.value = data.total
233+
} finally {
278234
loading.value = false
279-
})
235+
}
280236
}
281237
282238
/** 搜索按钮操作 */
@@ -285,16 +241,6 @@ const handleQuery = () => {
285241
getList()
286242
}
287243
288-
/** 重置按钮操作 */
289-
const resetQuery = () => {
290-
queryFormRef.value?.resetFields()
291-
// 默认选中第一个
292-
if (accountList.value.length > 0) {
293-
queryParams.accountId = accountList.value[0].id
294-
}
295-
handleQuery()
296-
}
297-
298244
const handleTabChange = (tabName) => {
299245
type.value = tabName
300246
handleQuery()
@@ -319,7 +265,7 @@ const handleUpdate = (row) => {
319265
resetEditor()
320266
console.log(row)
321267
322-
getAutoReply(row.id).then((data) => {
268+
MpAutoReplyApi.getAutoReply(row.id).then((data) => {
323269
// 设置属性
324270
form.value = { ...data }
325271
delete form.value['responseMessageType']
@@ -370,13 +316,13 @@ const handleSubmit = () => {
370316
form.responseHqMusicUrl = objData.value.hqMusicUrl
371317
372318
if (form.value.id !== undefined) {
373-
updateAutoReply(form).then(() => {
319+
MpAutoReplyApi.updateAutoReply(form).then(() => {
374320
message.success('修改成功')
375321
open.value = false
376322
getList()
377323
})
378324
} else {
379-
createAutoReply(form).then(() => {
325+
MpAutoReplyApi.createAutoReply(form).then(() => {
380326
message.success('新增成功')
381327
open.value = false
382328
getList()
@@ -414,7 +360,7 @@ const resetEditor = () => {
414360
415361
const handleDelete = async (row) => {
416362
await message.confirm('是否确认删除此数据?')
417-
await deleteAutoReply(row.id)
363+
await MpAutoReplyApi.deleteAutoReply(row.id)
418364
await getList()
419365
message.success('删除成功')
420366
}

src/views/mp/freePublish/index.vue

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,7 @@
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>
24-
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
25-
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
26-
</el-form-item>
27-
</el-form>
6+
<WxAccountSelect @change="(accountId) => accountChanged(accountId)" />
287
</ContentWrap>
298

309
<!-- 列表 -->
@@ -59,10 +38,11 @@
5938
</ContentWrap>
6039
</template>
6140

62-
<script setup lang="ts" name="MpFreePublish">
41+
<script setup name="MpFreePublish">
6342
import * as FreePublishApi from '@/api/mp/freePublish'
64-
import * as MpAccountApi from '@/api/mp/account'
6543
import WxNews from '@/views/mp/components/wx-news/main.vue'
44+
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
45+
6646
const message = useMessage() // 消息弹窗
6747
const { t } = useI18n() // 国际化
6848
@@ -72,18 +52,17 @@ const list = ref([]) // 列表的数据
7252
const queryParams = reactive({
7353
pageNo: 1,
7454
pageSize: 10,
75-
accountId: undefined // 当前页数
55+
accountId: undefined
7656
})
77-
const queryFormRef = ref() // 搜索的表单
78-
const accountList = ref<MpAccountApi.AccountVO[]>([]) // 公众号账号列表
57+
58+
/** 侦听公众号变化 **/
59+
const accountChanged = (accountId) => {
60+
queryParams.accountId = accountId
61+
getList()
62+
}
7963
8064
/** 查询列表 */
8165
const getList = async () => {
82-
// 如果没有选中公众号账号,则进行提示。
83-
if (!queryParams.accountId) {
84-
message.error('未选中公众号,无法查询已发表图文')
85-
return false
86-
}
8766
try {
8867
loading.value = true
8968
const data = await FreePublishApi.getFreePublishPage(queryParams)
@@ -94,22 +73,6 @@ const getList = async () => {
9473
}
9574
}
9675
97-
/** 搜索按钮操作 */
98-
const handleQuery = () => {
99-
queryParams.pageNo = 1
100-
getList()
101-
}
102-
103-
/** 重置按钮操作 */
104-
const resetQuery = () => {
105-
queryFormRef.value.resetFields()
106-
// 默认选中第一个
107-
if (accountList.value.length > 0) {
108-
queryParams.accountId = accountList.value[0].id
109-
}
110-
handleQuery()
111-
}
112-
11376
/** 删除按钮操作 */
11477
const handleDelete = async (item) => {
11578
try {
@@ -122,16 +85,8 @@ const handleDelete = async (item) => {
12285
await getList()
12386
} catch {}
12487
}
125-
126-
onMounted(async () => {
127-
accountList.value = await MpAccountApi.getSimpleAccountList()
128-
// 选中第一个
129-
if (accountList.value.length > 0) {
130-
queryParams.accountId = accountList.value[0].id
131-
}
132-
await getList()
133-
})
13488
</script>
89+
13590
<style lang="scss" scoped>
13691
.ope-row {
13792
margin-top: 5px;

src/views/mp/material/index.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@
241241
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
242242
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
243243
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
244-
// import * as MpAccountApi from '@/api/mp/account'
245244
import * as MpMaterialApi from '@/api/mp/material'
246245
import * as authUtil from '@/utils/auth'
247246
import { dateFormatter } from '@/utils/formatTime'
@@ -252,7 +251,6 @@ const BASE_URL = import.meta.env.VITE_BASE_URL
252251
const actionUrl = BASE_URL + '/admin-api/mp/material/upload-permanent'
253252
const headers = { Authorization: 'Bearer ' + authUtil.getAccessToken() }
254253
255-
// const queryFormRef = ref()
256254
const uploadFormRef = ref()
257255
const uploadVideoRef = ref()
258256

0 commit comments

Comments
 (0)