Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
66d412c1
authored
Mar 28, 2023
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vue3 重构:REVIEW 公众号标签统计
parent
c4e5419d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
49 deletions
+36
-49
src/views/mp/account/index.vue
+7
-7
src/views/mp/statistics/index.vue
+29
-42
No files found.
src/views/mp/account/index.vue
View file @
66d412c1
...
@@ -121,13 +121,13 @@ const queryFormRef = ref() // 搜索的表单
...
@@ -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
)
// 执行查询
list
.
value
=
data
.
list
const
data
=
await
AccountApi
.
getAccountPage
(
params
)
total
.
value
=
data
.
total
list
.
value
=
data
.
list
}
finally
{
total
.
value
=
data
.
total
loading
.
value
=
false
loading
.
value
=
false
}
}
}
/** 搜索按钮操作 */
/** 搜索按钮操作 */
...
...
src/views/mp/statistics/index.vue
View file @
66d412c1
...
@@ -5,7 +5,7 @@
...
@@ -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 account
s
"
v-for=
"item in account
List
"
: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 @@
...
@@ -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([
...
@@ -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({
...
@@ -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
(
account
s
.
value
.
length
>
0
)
{
if
(
account
List
.
value
.
length
>
0
)
{
accountId
.
value
=
account
s
.
value
[
0
].
id
accountId
.
value
=
account
List
.
value
[
0
].
id
}
}
}
}
// TODO 一些方法的注释补全下
const
getSummary
=
()
=>
{
const
getSummary
=
()
=>
{
// 如果没有选中公众号账号,则进行提示。
// 如果没有选中公众号账号,则进行提示。
if
(
!
accountId
)
{
if
(
!
accountId
)
{
...
@@ -286,7 +276,7 @@ const getSummary = () => {
...
@@ -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 = () => {
...
@@ -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 () => {
...
@@ -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 () => {
...
@@ -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 () => {
...
@@ -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 () => {
...
@@ -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 () => {
...
@@ -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 () => {
...
@@ -402,4 +381,12 @@ const interfaceSummaryChart = async () => {
interfaceSummaryChart
.
setOption
(
interfaceSummaryOption
)
interfaceSummaryChart
.
setOption
(
interfaceSummaryOption
)
}
catch
{}
}
catch
{}
}
}
/** 初始化 */
onMounted
(
async
()
=>
{
// 获取公众号下拉列表
await
getAccountList
()
// 加载数据
getSummary
()
})
</
script
>
</
script
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment