Skip to content

Commit 129766f

Browse files
YunaiVgitee-org
authored andcommitted
!113 refactor: 抽离组件【公众号下拉选择】并重构相关页面
Merge pull request !113 from dhb52/dev
2 parents 30cf800 + 1397767 commit 129766f

File tree

14 files changed

+431
-636
lines changed

14 files changed

+431
-636
lines changed

.env.front

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ VITE_API_URL=/admin-api
1717

1818
# 打包路径
1919
VITE_BASE_PATH=/
20+
21+
# 项目本地运行端口号, 与.vscode/launch.json配合
22+
VITE_PORT=5173
23+
24+
# 是否删除debugger
25+
VITE_DROP_DEBUGGER=false
26+
27+
# 是否删除console.log
28+
VITE_DROP_CONSOLE=false
29+
30+
# 是否sourcemap
31+
VITE_SOURCEMAP=true
32+
33+
# 验证码的开关
34+
VITE_APP_CAPTCHA_ENABLE=false

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "msedge",
9+
"request": "launch",
10+
"name": "Launch Edge against localhost",
11+
"url": "http://localhost:5173",
12+
"webRoot": "${workspaceFolder}/src",
13+
"sourceMaps": true
14+
}
15+
]
16+
}

build/vite/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ export function createVitePlugins() {
9898
deleteOriginFile: false //压缩后是否删除源文件
9999
}),
100100
ViteEjsPlugin(),
101-
topLevelAwait({ // https://juejin.cn/post/7152191742513512485
101+
topLevelAwait({
102+
// https://juejin.cn/post/7152191742513512485
102103
// The export name of top-level await promise for each chunk module
103104
promiseExportName: '__tla',
104105
// The function to generate import names of top-level await promise in each chunk module

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"vite-plugin-purge-icons": "^0.9.2",
128128
"vite-plugin-svg-icons": "^2.0.1",
129129
"vite-plugin-top-level-await": "^1.3.0",
130-
"vite-plugin-vue-setup-extend": "^0.4.0",
130+
"vite-plugin-vue-setup-extend-plus": "^0.1.0",
131131
"vite-plugin-windicss": "^1.8.10",
132132
"vue-tsc": "^1.2.0",
133133
"windicss": "^3.5.6"

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
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<template>
2+
<el-select
3+
v-model="accountId"
4+
placeholder="请选择公众号"
5+
class="!w-240px"
6+
@change="accountChanged"
7+
>
8+
<el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id" />
9+
</el-select>
10+
</template>
11+
12+
<script lang="ts" setup name="WxMpSelect">
13+
import * as MpAccountApi from '@/api/mp/account'
14+
15+
const accountId: Ref<number | undefined> = ref()
16+
const accountList: Ref<MpAccountApi.AccountVO[]> = ref([])
17+
18+
const emit = defineEmits<{
19+
(e: 'change', id: number | undefined): void
20+
}>()
21+
22+
onMounted(async () => {
23+
handleQuery()
24+
})
25+
26+
const handleQuery = async () => {
27+
const data = await MpAccountApi.getSimpleAccountList()
28+
accountList.value = data
29+
// 默认选中第一个
30+
if (accountList.value.length > 0) {
31+
accountId.value = accountList.value[0].id
32+
emit('change', accountId.value)
33+
}
34+
}
35+
36+
const accountChanged = () => {
37+
emit('change', accountId.value)
38+
}
39+
</script>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template>
2+
<el-form class="-mb-15px" ref="queryFormRef" :inline="true" label-width="68px">
3+
<el-form-item label="公众号" prop="accountId">
4+
<el-select
5+
v-model="accountId"
6+
placeholder="请选择公众号"
7+
class="!w-240px"
8+
@change="accountChanged()"
9+
>
10+
<el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id" />
11+
</el-select>
12+
</el-form-item>
13+
<el-form-item>
14+
<slot name="actions"></slot>
15+
</el-form-item>
16+
</el-form>
17+
</template>
18+
19+
<script setup name="WxAccountSelect">
20+
import * as MpAccountApi from '@/api/mp/account'
21+
const accountId = ref()
22+
const accountList = ref([])
23+
const queryFormRef = ref()
24+
25+
const emit = defineEmits(['change'])
26+
27+
onMounted(async () => {
28+
handleQuery()
29+
})
30+
31+
const handleQuery = async () => {
32+
const data = await MpAccountApi.getSimpleAccountList()
33+
accountList.value = data
34+
// 默认选中第一个
35+
if (accountList.value.length > 0) {
36+
accountId.value = accountList.value[0].id
37+
emit('change', accountId.value)
38+
}
39+
}
40+
41+
const accountChanged = () => {
42+
emit('change', accountId.value)
43+
}
44+
</script>

0 commit comments

Comments
 (0)