Vue3 重构:REVIEW 公众号标签统计

This commit is contained in:
YunaiV 2023-03-28 09:24:12 +08:00
parent c4e5419d65
commit 66d412c10a
2 changed files with 36 additions and 49 deletions

View File

@ -121,13 +121,13 @@ const queryFormRef = ref() // 搜索的表单
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
// try {
let params = { ...queryParams } const data = await AccountApi.getAccountPage(queryParams)
//
const data = await AccountApi.getAccountPage(params)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally {
loading.value = false loading.value = false
}
} }
/** 搜索按钮操作 */ /** 搜索按钮操作 */

View File

@ -5,7 +5,7 @@
<el-form-item label="公众号" prop="accountId"> <el-form-item label="公众号" prop="accountId">
<el-select v-model="accountId" @change="getSummary"> <el-select v-model="accountId" @change="getSummary">
<el-option <el-option
v-for="item in accounts" v-for="item in accountList"
:key="parseInt(item.id)" :key="parseInt(item.id)"
:label="item.name" :label="item.name"
:value="parseInt(item.id)" :value="parseInt(item.id)"
@ -83,17 +83,16 @@
</template> </template>
<script setup lang="ts" name="MpStatistics"> <script setup lang="ts" name="MpStatistics">
//
import * as echarts from 'echarts' import * as echarts from 'echarts'
import { import {
getInterfaceSummary, getInterfaceSummary,
getUpstreamMessage, getUpstreamMessage,
getUserCumulate, getUserCumulate,
getUserSummary getUserSummary
} from '@/api/mp/statistics' } from '@/api/mp/statistics' // TODO StatisticsApi
import { addTime, beginOfDay, betweenDay, endOfDay, formatDate } from '@/utils/dateUtils' import { addTime, beginOfDay, betweenDay, endOfDay } from '@/utils/dateUtils' // TODO formatTime
import { getSimpleAccountList } from '@/api/mp/account' import { formatDate } from '@/utils/formatTime'
import * as MpAccountApi from '@/api/mp/account'
const message = useMessage() // const message = useMessage() //
const defaultTime = ref<[Date, Date]>([ const defaultTime = ref<[Date, Date]>([
@ -105,18 +104,13 @@ const dateRange = ref([
endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24)) endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24))
]) // -1 ]) // -1
const accountId = ref() const accountId = ref()
const accounts = ref([ const accountList = ref<MpAccountApi.AccountVO[]>([]) //
{
id: '0',
name: ''
}
])
const userSummaryChartRef = ref() const userSummaryChartRef = ref()
const userCumulateChartRef = ref() const userCumulateChartRef = ref()
const upstreamMessageChartRef = ref() const upstreamMessageChartRef = ref()
const interfaceSummaryChartRef = ref() const interfaceSummaryChartRef = ref()
// TODO https://kailong110120130.gitee.io/vue-element-plus-admin-doc/components/echart.html
const xAxisDate = ref([] as any[]) // X const xAxisDate = ref([] as any[]) // X
const userSummaryOption = reactive({ const userSummaryOption = reactive({
// //
@ -257,20 +251,16 @@ const interfaceSummaryOption = reactive({
] ]
}) })
onMounted(async () => { /** 加载公众号账号的列表 */
//
await getAccountList()
//
getSummary()
})
const getAccountList = async () => { const getAccountList = async () => {
const data = await getSimpleAccountList() accountList.value = await MpAccountApi.getSimpleAccountList()
accounts.value = data
// //
if (accounts.value.length > 0) { if (accountList.value.length > 0) {
accountId.value = accounts.value[0].id accountId.value = accountList.value[0].id
} }
} }
// TODO
const getSummary = () => { const getSummary = () => {
// //
if (!accountId) { if (!accountId) {
@ -286,7 +276,7 @@ const getSummary = () => {
const days = betweenDay(dateRange.value[0], dateRange.value[1]) // const days = betweenDay(dateRange.value[0], dateRange.value[1]) //
for (let i = 0; i <= days; i++) { for (let i = 0; i <= days; i++) {
xAxisDate.value.push( xAxisDate.value.push(
formatDate(addTime(dateRange.value[0], 3600 * 1000 * 24 * i), 'yyyy-MM-dd') formatDate(addTime(dateRange.value[0], 3600 * 1000 * 24 * i), 'YYYY-MM-DD')
) )
} }
@ -296,6 +286,7 @@ const getSummary = () => {
initUpstreamMessageChart() initUpstreamMessageChart()
interfaceSummaryChart() interfaceSummaryChart()
} }
const initUserSummaryChart = async () => { const initUserSummaryChart = async () => {
userSummaryOption.xAxis.data = [] userSummaryOption.xAxis.data = []
userSummaryOption.series[0].data = [] userSummaryOption.series[0].data = []
@ -303,18 +294,14 @@ const initUserSummaryChart = async () => {
try { try {
const data = await getUserSummary({ const data = await getUserSummary({
accountId: accountId.value, accountId: accountId.value,
date: [ date: [formatDate(dateRange.value[0]), formatDate(dateRange.value[1])]
formatDate(dateRange.value[0], 'yyyy-MM-dd HH:mm:ss'),
formatDate(dateRange.value[1], 'yyyy-MM-dd HH:mm:ss')
]
}) })
userSummaryOption.xAxis.data = xAxisDate.value userSummaryOption.xAxis.data = xAxisDate.value
// //
xAxisDate.value.forEach((date, index) => { xAxisDate.value.forEach((date, index) => {
data.forEach((item) => { data.forEach((item) => {
// //
const refDate = formatDate(new Date(item.refDate), 'yyyy-MM-dd') const refDate = formatDate(new Date(item.refDate), 'YYYY-MM-DD')
if (refDate.indexOf(date) === -1) { if (refDate.indexOf(date) === -1) {
return return
} }
@ -328,6 +315,7 @@ const initUserSummaryChart = async () => {
userSummaryChart.setOption(userSummaryOption) userSummaryChart.setOption(userSummaryOption)
} catch {} } catch {}
} }
const initUserCumulateChart = async () => { const initUserCumulateChart = async () => {
userCumulateOption.xAxis.data = [] userCumulateOption.xAxis.data = []
userCumulateOption.series[0].data = [] userCumulateOption.series[0].data = []
@ -335,10 +323,7 @@ const initUserCumulateChart = async () => {
try { try {
const data = await getUserCumulate({ const data = await getUserCumulate({
accountId: accountId.value, accountId: accountId.value,
date: [ date: [formatDate(dateRange.value[0]), formatDate(dateRange.value[1])]
formatDate(dateRange.value[0], 'yyyy-MM-dd HH:mm:ss'),
formatDate(dateRange.value[1], 'yyyy-MM-dd HH:mm:ss')
]
}) })
userCumulateOption.xAxis.data = xAxisDate.value userCumulateOption.xAxis.data = xAxisDate.value
// //
@ -358,10 +343,7 @@ const initUpstreamMessageChart = async () => {
try { try {
const data = await getUpstreamMessage({ const data = await getUpstreamMessage({
accountId: accountId.value, accountId: accountId.value,
date: [ date: [formatDate(dateRange.value[0]), formatDate(dateRange.value[1])]
formatDate(dateRange.value[0], 'yyyy-MM-dd HH:mm:ss'),
formatDate(dateRange.value[1], 'yyyy-MM-dd HH:mm:ss')
]
}) })
upstreamMessageOption.xAxis.data = xAxisDate.value upstreamMessageOption.xAxis.data = xAxisDate.value
// //
@ -384,10 +366,7 @@ const interfaceSummaryChart = async () => {
try { try {
const data = await getInterfaceSummary({ const data = await getInterfaceSummary({
accountId: accountId.value, accountId: accountId.value,
date: [ date: [formatDate(dateRange.value[0]), formatDate(dateRange.value[1])]
formatDate(dateRange.value[0], 'yyyy-MM-dd HH:mm:ss'),
formatDate(dateRange.value[1], 'yyyy-MM-dd HH:mm:ss')
]
}) })
interfaceSummaryOption.xAxis.data = xAxisDate.value interfaceSummaryOption.xAxis.data = xAxisDate.value
// //
@ -402,4 +381,12 @@ const interfaceSummaryChart = async () => {
interfaceSummaryChart.setOption(interfaceSummaryOption) interfaceSummaryChart.setOption(interfaceSummaryOption)
} catch {} } catch {}
} }
/** 初始化 */
onMounted(async () => {
//
await getAccountList()
//
getSummary()
})
</script> </script>