Skip to content

Commit 0974ece

Browse files
committed
【功能优化】公众号:未配置公众号账号的情况下,自动跳转账号管理的菜单
1 parent 9d0e77b commit 0974ece

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

src/views/mp/components/wx-account-select/main.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
<script lang="ts" setup>
88
import * as MpAccountApi from '@/api/mp/account'
9+
import { useTagsViewStore } from '@/store/modules/tagsView'
10+
11+
const message = useMessage() // 消息弹窗
12+
const { delView } = useTagsViewStore() // 视图操作
13+
const { push, currentRoute } = useRouter() // 路由
914
1015
defineOptions({ name: 'WxAccountSelect' })
1116
@@ -22,6 +27,12 @@ const emit = defineEmits<{
2227
2328
const handleQuery = async () => {
2429
accountList.value = await MpAccountApi.getSimpleAccountList()
30+
if (accountList.value.length == 0) {
31+
message.error('未配置公众号,请在【公众号管理 -> 账号管理】菜单,进行配置')
32+
delView(unref(currentRoute))
33+
await push({ name: 'MpAccount' })
34+
return
35+
}
2536
// 默认选中第一个
2637
if (accountList.value.length > 0) {
2738
account.id = accountList.value[0].id

src/views/mp/statistics/index.vue

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
<ContentWrap>
44
<el-form class="-mb-15px" ref="queryForm" :inline="true" label-width="68px">
55
<el-form-item label="公众号" prop="accountId">
6-
<el-select v-model="accountId" @change="getSummary" class="!w-240px">
7-
<el-option
8-
v-for="item in accountList"
9-
:key="item.id"
10-
:label="item.name"
11-
:value="item.id"
12-
/>
13-
</el-select>
6+
<WxAccountSelect @change="onAccountChanged" />
147
</el-form-item>
158
<el-form-item label="时间范围" prop="dateRange">
169
<el-date-picker
@@ -76,7 +69,7 @@
7669
<script lang="ts" setup>
7770
import { formatDate, addTime, betweenDay, beginOfDay, endOfDay } from '@/utils/formatTime'
7871
import * as StatisticsApi from '@/api/mp/statistics'
79-
import * as MpAccountApi from '@/api/mp/account'
72+
import WxAccountSelect from '@/views/mp/components/wx-account-select'
8073
8174
defineOptions({ name: 'MpStatistics' })
8275
@@ -88,7 +81,6 @@ const dateRange = ref([
8881
endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24))
8982
])
9083
const accountId = ref(-1) // 选中的公众号编号
91-
const accountList = ref<MpAccountApi.AccountVO[]>([]) // 公众号账号列表
9284
9385
const xAxisDate = ref([] as any[]) // X 轴的日期范围
9486
// 用户增减数据图表配置项
@@ -230,13 +222,10 @@ const interfaceSummaryOption = reactive({
230222
]
231223
})
232224
233-
/** 加载公众号账号的列表 */
234-
const getAccountList = async () => {
235-
accountList.value = await MpAccountApi.getSimpleAccountList()
236-
// 默认选中第一个
237-
if (accountList.value.length > 0) {
238-
accountId.value = accountList.value[0].id!
239-
}
225+
/** 侦听公众号变化 **/
226+
const onAccountChanged = (id: number) => {
227+
accountId.value = id
228+
getSummary()
240229
}
241230
242231
/** 加载数据 */
@@ -357,12 +346,4 @@ const interfaceSummaryChart = async () => {
357346
})
358347
} catch {}
359348
}
360-
361-
/** 初始化 */
362-
onMounted(async () => {
363-
// 获取公众号下拉列表
364-
await getAccountList()
365-
// 加载数据
366-
getSummary()
367-
})
368349
</script>

0 commit comments

Comments
 (0)