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 () => {
loading.value = true
//
let params = { ...queryParams }
//
const data = await AccountApi.getAccountPage(params)
list.value = data.list
total.value = data.total
loading.value = false
try {
const data = await AccountApi.getAccountPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */

View File

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