fix: some
Some checks failed
构建并部署前端到测试环境 / build-and-deploy (push) Failing after 28m40s

This commit is contained in:
luo
2026-09-18 18:11:53 +08:00
parent 5e7f5eaba4
commit 08889d2e42
55 changed files with 2888 additions and 414 deletions

View File

@@ -0,0 +1,277 @@
<template>
<ArtTableFullScreen>
<div class="operations-report-page" id="table-full-screen">
<!-- 搜索栏 -->
<ArtSearchBar
v-model:filter="searchForm"
:items="searchFormItems"
show-expand
label-width="100px"
@reset="handleReset"
@search="handleSearch"
></ArtSearchBar>
<ElCard shadow="never" class="art-table-card">
<!-- 表格头部 -->
<ArtTableHeader
:columnList="columnOptions"
v-model:columns="columnChecks"
@refresh="handleRefresh"
>
<template #left>
<span v-if="snapshotText" class="report-snapshot">{{ snapshotText }}</span>
<ElTag v-if="exportTask" :type="exportStatusType" class="report-export-tag">
{{ exportTask.status_name || '处理中' }}
</ElTag>
<ElButton v-if="canDownload" type="success" link @click="downloadExport">
下载
</ElButton>
<ElButton type="primary" :loading="exporting" @click="handleExport">导出</ElButton>
</template>
</ArtTableHeader>
<!-- 表格 -->
<ArtTable :loading="loading" :data="tableData" :pagination="false" :marginTop="10">
<template #default>
<ElTableColumn v-for="col in columns" :key="col.prop || col.type" v-bind="col" />
</template>
</ArtTable>
</ElCard>
</div>
</ArtTableFullScreen>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { ExportTaskService, OperationsReportsService } from '@/api/modules'
import { useAsyncTaskPolling } from '@/composables/useAsyncTaskPolling'
import { useCheckedColumns } from '@/composables/useCheckedColumns'
import { ExportTaskStatus, type ExportTaskDetail } from '@/types/api'
import type { ActivationSummaryData, ActivationSummaryItem } from '@/types/api'
import type { SearchFormItem } from '@/types'
import { ACTIVATION_GROUP_OPTIONS, ACTIVATION_METRIC_COLUMNS, formatMetric } from '../constants'
defineOptions({ name: 'OperationsActivationReport' })
const pad = (value: number) => String(value).padStart(2, '0')
const formatDateTimeValue = (date: Date) => {
const offset = -date.getTimezoneOffset()
const sign = offset >= 0 ? '+' : '-'
const abs = Math.abs(offset)
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(
date.getHours()
)}:${pad(date.getMinutes())}:${pad(date.getSeconds())}${sign}${pad(
Math.floor(abs / 60)
)}:${pad(abs % 60)}`
}
const getDefaultRange = () => {
const end = new Date()
const start = new Date(end.getTime() - 29 * 24 * 60 * 60 * 1000)
start.setHours(0, 0, 0, 0)
return [formatDateTimeValue(start), formatDateTimeValue(end)]
}
const searchForm = reactive({
dateRange: getDefaultRange() as string[],
group_by: ''
})
const loading = ref(false)
const exporting = ref(false)
const summary = ref<ActivationSummaryData | null>(null)
const searchFormItems: SearchFormItem[] = [
{
label: '统计时间',
prop: 'dateRange',
type: 'datetimerange',
config: {
type: 'datetimerange',
rangeSeparator: '至',
startPlaceholder: '开始时间',
endPlaceholder: '结束时间',
valueFormat: 'YYYY-MM-DDTHH:mm:ssZ'
}
},
{
label: '分组维度',
prop: 'group_by',
type: 'select',
config: { clearable: true, placeholder: '请选择分组维度' },
options: () => ACTIVATION_GROUP_OPTIONS
}
]
const columnOptions = [
{ label: '分组', prop: 'group_name' },
...ACTIVATION_METRIC_COLUMNS.map((col) => ({ label: col.label, prop: col.key }))
]
const { columnChecks, columns } = useCheckedColumns(() => [
{
prop: 'group_name',
label: '分组',
minWidth: 160,
fixed: 'left',
showOverflowTooltip: true,
formatter: (row: ActivationSummaryItem) => row.group_name || row.group_key || '-'
},
...ACTIVATION_METRIC_COLUMNS.map((col) => ({
prop: col.key,
label: col.label,
minWidth: col.minWidth,
align: 'right' as const,
formatter: (row: ActivationSummaryItem) => formatMetric(row[col.key], col)
}))
])
const snapshotText = computed(() => {
const dates = summary.value?.snapshot_dates
return dates?.length ? `数据快照:${dates.join('、')}` : ''
})
const tableData = computed(() => {
const data = summary.value
if (!data) return []
const rows = [...(data.items || [])]
if (data.totals) {
rows.push({ ...data.totals, group_name: '合计' })
}
return rows
})
const buildQuery = () => ({
start_time: searchForm.dateRange?.[0] || undefined,
end_time: searchForm.dateRange?.[1] || undefined,
group_by: searchForm.group_by || undefined
})
const getTableData = async () => {
if (!searchForm.dateRange?.[0] || !searchForm.dateRange?.[1]) {
ElMessage.warning('请选择统计时间')
return
}
loading.value = true
try {
const summaryRes = await OperationsReportsService.getActivationSummary(buildQuery())
if (summaryRes.code === 0 && summaryRes.data) {
summary.value = summaryRes.data
} else {
summary.value = null
ElMessage.error(summaryRes.msg || '获取设备激活汇总失败')
}
} catch (error) {
console.error('获取设备激活报表失败:', error)
summary.value = null
ElMessage.error('获取设备激活报表失败')
} finally {
loading.value = false
}
}
const handleSearch = () => {
getTableData()
}
const handleReset = () => {
searchForm.dateRange = getDefaultRange()
searchForm.group_by = ''
getTableData()
}
const handleRefresh = () => {
getTableData()
}
const exportTask = computed(() => exportPolling.task.value)
const canDownload = computed(
() =>
exportTask.value?.status === ExportTaskStatus.COMPLETED && !!exportTask.value?.download_url
)
const exportStatusType = computed(() => {
const status = exportTask.value?.status
if (status === ExportTaskStatus.COMPLETED) return 'success'
if (status === ExportTaskStatus.FAILED) return 'danger'
if (status === ExportTaskStatus.CANCELED) return 'info'
return 'warning'
})
const exportPolling = useAsyncTaskPolling<ExportTaskDetail>({
storageKey: 'operations-report-active:activation',
fetchTask: async (taskId) => {
const res = await ExportTaskService.getExportTaskDetail(taskId)
if (res.code === 403) {
const error = new Error('暂无权限查看导出任务') as Error & { status?: number }
error.status = 403
throw error
}
if (res.code !== 0 || !res.data) throw new Error(res.msg || '获取导出任务详情失败')
return res.data
},
isForbidden: (error: any) => error?.status === 403 || error?.response?.status === 403
})
const handleExport = async () => {
if (!searchForm.dateRange?.[0] || !searchForm.dateRange?.[1]) {
ElMessage.warning('请选择统计时间')
return
}
exporting.value = true
try {
const res = await OperationsReportsService.exportActivationSummary({
...buildQuery(),
format: 'xlsx'
})
if (res.code !== 0 || !res.data) {
ElMessage.error(res.msg || '导出失败')
return
}
ElMessage.success(res.data.message || '导出任务已创建,请稍候')
await exportPolling.start(res.data.task_id)
} catch (error) {
console.error('导出设备激活汇总失败:', error)
ElMessage.error('导出设备激活汇总失败')
} finally {
exporting.value = false
}
}
const downloadExport = () => {
const url = exportTask.value?.download_url
if (!url) {
ElMessage.warning('当前任务暂无可用下载地址')
return
}
window.open(url, '_blank')
}
onMounted(() => {
getTableData()
})
</script>
<style lang="scss" scoped>
.operations-report-page {
display: flex;
flex-direction: column;
gap: 10px;
height: 100%;
overflow: auto;
}
.report-snapshot {
font-size: 12px;
font-weight: 400;
color: var(--el-text-color-secondary);
}
.report-export-tag {
margin-left: 12px;
}
</style>

View File

@@ -0,0 +1,115 @@
<template>
<div ref="chartRef" class="operations-trend-chart" :style="{ height: props.height }"></div>
</template>
<script setup lang="ts">
import type { EChartsOption } from 'echarts'
import { useChart } from '@/composables/useChart'
import type { OperationsTrendSeries } from '../constants'
defineOptions({ name: 'OperationsTrendChart' })
interface Props {
categories: string[]
series: OperationsTrendSeries[]
height?: string
}
const props = withDefaults(defineProps<Props>(), {
categories: () => [],
series: () => [],
height: '20rem'
})
const {
chartRef,
initChart,
getChartInstance,
isDark,
getAxisLineStyle,
getAxisLabelStyle,
getAxisTickStyle,
getSplitLineStyle
} = useChart()
const palette = ['#3b82f6', '#10b981', '#f59e0b', '#8b5cf6', '#ef4444']
const buildOptions = (): EChartsOption => {
const hasSecondary = props.series.some((item) => item.yAxisIndex === 1)
const labelStyle = getAxisLabelStyle()
return {
color: palette,
grid: {
top: 44,
right: hasSecondary ? 58 : 20,
bottom: 10,
left: 10,
containLabel: true
},
legend: {
top: 8,
itemWidth: 12,
itemHeight: 8,
textStyle: { color: labelStyle.color }
},
tooltip: {
trigger: 'axis'
},
xAxis: {
type: 'category',
boundaryGap: true,
data: props.categories,
axisTick: getAxisTickStyle(),
axisLine: getAxisLineStyle(),
axisLabel: getAxisLabelStyle()
},
yAxis: [
{
type: 'value',
axisLabel: getAxisLabelStyle(),
axisLine: getAxisLineStyle(false),
splitLine: getSplitLineStyle()
},
...(hasSecondary
? [
{
type: 'value' as const,
max: 100,
axisLabel: { ...getAxisLabelStyle(), formatter: '{value}%' },
axisLine: getAxisLineStyle(false),
splitLine: getSplitLineStyle(false)
}
]
: [])
],
series: props.series.map((item) => ({
name: item.name,
type: item.type,
yAxisIndex: item.yAxisIndex ?? 0,
smooth: true,
symbol: 'none',
barMaxWidth: 26,
connectNulls: false,
data: item.data,
areaStyle: item.areaStyle ? { opacity: 0.12 } : undefined
}))
}
}
const render = () => {
getChartInstance()?.clear()
initChart(buildOptions())
}
watch(isDark, render)
watch([() => props.categories, () => props.series], render, { deep: true })
onMounted(render)
</script>
<style lang="scss" scoped>
.operations-trend-chart {
width: calc(100% + 10px);
}
</style>

View File

@@ -0,0 +1,96 @@
import type { Option } from '@/types'
export interface OperationsMetricColumn {
key: string
label: string
kind: 'number' | 'ratio'
digits?: number
minWidth?: number
}
export interface OperationsTrendSeriesConfig {
key: string
name: string
type: 'line' | 'bar'
yAxisIndex?: 0 | 1
areaStyle?: boolean
}
export type OperationsTrendSeries = OperationsTrendSeriesConfig & { data: (number | null)[] }
export const ACTIVATION_GROUP_OPTIONS: Option[] = [
{ label: '全部', value: '' },
{ label: '设备名称', value: 'device_name' },
{ label: '设备型号', value: 'device_model' },
{ label: '制造商', value: 'manufacturer' },
{ label: '业务用户组', value: 'business_user_group' },
{ label: '代理商', value: 'agent' },
{ label: '店铺', value: 'shop' },
{ label: '业务负责人', value: 'business_owner' }
]
export const RENEWAL_GROUP_OPTIONS: Option[] = [
{ label: '全部', value: '' },
{ label: '套餐系列', value: 'package_series' },
{ label: '套餐名称', value: 'package_name' },
{ label: '业务用户组', value: 'business_user_group' },
{ label: '代理商', value: 'agent' },
{ label: '店铺', value: 'shop' },
{ label: '业务负责人', value: 'business_owner' }
]
export const GRANULARITY_OPTIONS: Option[] = [
{ label: '按日', value: 'day' },
{ label: '按月', value: 'month' }
]
export const ACTIVATION_METRIC_COLUMNS: OperationsMetricColumn[] = [
{ key: 'purchase_count', label: '采购数量', kind: 'number', minWidth: 100 },
{ key: 'activated_count', label: '累计激活数', kind: 'number', minWidth: 110 },
{ key: 'activation_rate', label: '激活率', kind: 'ratio', minWidth: 90 },
{ key: 'new_activated_count', label: '新增激活数', kind: 'number', minWidth: 110 },
{ key: 'online_count', label: '累计在网数', kind: 'number', minWidth: 110 },
{ key: 'active_user_count', label: '活跃用户数', kind: 'number', minWidth: 110 },
{ key: 'cumulative_usage_mb', label: '累计用量(MB)', kind: 'number', minWidth: 130 },
{ key: 'avg_usage_per_card_mb', label: '卡均用量(MB)', kind: 'number', minWidth: 130 }
]
export const RENEWAL_METRIC_COLUMNS: OperationsMetricColumn[] = [
{ key: 'expiring_asset_count', label: '到期资产数', kind: 'number', minWidth: 110 },
{ key: 'renewed_asset_count', label: '续费资产数', kind: 'number', minWidth: 110 },
{ key: 'renewal_rate', label: '续费率', kind: 'ratio', minWidth: 90 },
{ key: 'new_unrenewed_count', label: '新增未续费数', kind: 'number', minWidth: 120 }
]
export const ACTIVATION_TREND_SERIES: OperationsTrendSeriesConfig[] = [
{ key: 'new_activated_count', name: '新增激活数', type: 'bar' },
{ key: 'activated_count', name: '累计激活数', type: 'line', areaStyle: true },
{ key: 'activation_rate', name: '激活率', type: 'line', yAxisIndex: 1 }
]
export const RENEWAL_TREND_SERIES: OperationsTrendSeriesConfig[] = [
{ key: 'renewed_asset_count', name: '续费资产数', type: 'bar' },
{ key: 'expiring_asset_count', name: '到期资产数', type: 'line', areaStyle: true },
{ key: 'renewal_rate', name: '续费率', type: 'line', yAxisIndex: 1 }
]
export const formatMetric = (value: unknown, column: OperationsMetricColumn): string => {
if (value === null || value === undefined || value === '') return '-'
const num = Number(value)
if (Number.isNaN(num)) return String(value)
const digits = column.digits ?? 2
if (column.kind === 'ratio') {
const percent = Math.abs(num) <= 1 ? num * 100 : num
return `${percent.toFixed(digits)}%`
}
return num.toLocaleString('en-US', { maximumFractionDigits: digits })
}
export const normalizeRatio = (value: unknown): number | null => {
if (value === null || value === undefined || value === '') return null
const num = Number(value)
if (Number.isNaN(num)) return null
return Math.abs(num) <= 1 ? num * 100 : num
}

View File

@@ -0,0 +1,277 @@
<template>
<ArtTableFullScreen>
<div class="operations-report-page" id="table-full-screen">
<!-- 搜索栏 -->
<ArtSearchBar
v-model:filter="searchForm"
:items="searchFormItems"
show-expand
label-width="100px"
@reset="handleReset"
@search="handleSearch"
></ArtSearchBar>
<ElCard shadow="never" class="art-table-card">
<!-- 表格头部 -->
<ArtTableHeader
:columnList="columnOptions"
v-model:columns="columnChecks"
@refresh="handleRefresh"
>
<template #left>
<span v-if="snapshotText" class="report-snapshot">{{ snapshotText }}</span>
<ElTag v-if="exportTask" :type="exportStatusType" class="report-export-tag">
{{ exportTask.status_name || '处理中' }}
</ElTag>
<ElButton v-if="canDownload" type="success" link @click="downloadExport">
下载
</ElButton>
<ElButton type="primary" :loading="exporting" @click="handleExport">导出</ElButton>
</template>
</ArtTableHeader>
<!-- 表格 -->
<ArtTable :loading="loading" :data="tableData" :pagination="false" :marginTop="10">
<template #default>
<ElTableColumn v-for="col in columns" :key="col.prop || col.type" v-bind="col" />
</template>
</ArtTable>
</ElCard>
</div>
</ArtTableFullScreen>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { ExportTaskService, OperationsReportsService } from '@/api/modules'
import { useAsyncTaskPolling } from '@/composables/useAsyncTaskPolling'
import { useCheckedColumns } from '@/composables/useCheckedColumns'
import { ExportTaskStatus, type ExportTaskDetail } from '@/types/api'
import type { RenewalSummaryData, RenewalSummaryItem } from '@/types/api'
import type { SearchFormItem } from '@/types'
import { RENEWAL_GROUP_OPTIONS, RENEWAL_METRIC_COLUMNS, formatMetric } from '../constants'
defineOptions({ name: 'OperationsRenewalReport' })
const pad = (value: number) => String(value).padStart(2, '0')
const formatDateTimeValue = (date: Date) => {
const offset = -date.getTimezoneOffset()
const sign = offset >= 0 ? '+' : '-'
const abs = Math.abs(offset)
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(
date.getHours()
)}:${pad(date.getMinutes())}:${pad(date.getSeconds())}${sign}${pad(
Math.floor(abs / 60)
)}:${pad(abs % 60)}`
}
const getDefaultRange = () => {
const end = new Date()
const start = new Date(end.getTime() - 29 * 24 * 60 * 60 * 1000)
start.setHours(0, 0, 0, 0)
return [formatDateTimeValue(start), formatDateTimeValue(end)]
}
const searchForm = reactive({
dateRange: getDefaultRange() as string[],
group_by: ''
})
const loading = ref(false)
const exporting = ref(false)
const summary = ref<RenewalSummaryData | null>(null)
const searchFormItems: SearchFormItem[] = [
{
label: '统计时间',
prop: 'dateRange',
type: 'datetimerange',
config: {
type: 'datetimerange',
rangeSeparator: '至',
startPlaceholder: '开始时间',
endPlaceholder: '结束时间',
valueFormat: 'YYYY-MM-DDTHH:mm:ssZ'
}
},
{
label: '分组维度',
prop: 'group_by',
type: 'select',
config: { clearable: true, placeholder: '请选择分组维度' },
options: () => RENEWAL_GROUP_OPTIONS
}
]
const columnOptions = [
{ label: '分组', prop: 'group_name' },
...RENEWAL_METRIC_COLUMNS.map((col) => ({ label: col.label, prop: col.key }))
]
const { columnChecks, columns } = useCheckedColumns(() => [
{
prop: 'group_name',
label: '分组',
minWidth: 160,
fixed: 'left',
showOverflowTooltip: true,
formatter: (row: RenewalSummaryItem) => row.group_name || row.group_key || '-'
},
...RENEWAL_METRIC_COLUMNS.map((col) => ({
prop: col.key,
label: col.label,
minWidth: col.minWidth,
align: 'right' as const,
formatter: (row: RenewalSummaryItem) => formatMetric(row[col.key], col)
}))
])
const snapshotText = computed(() => {
const dates = summary.value?.snapshot_dates
return dates?.length ? `数据快照:${dates.join('、')}` : ''
})
const tableData = computed(() => {
const data = summary.value
if (!data) return []
const rows = [...(data.items || [])]
if (data.totals) {
rows.push({ ...data.totals, group_name: '合计' })
}
return rows
})
const buildQuery = () => ({
start_time: searchForm.dateRange?.[0] || undefined,
end_time: searchForm.dateRange?.[1] || undefined,
group_by: searchForm.group_by || undefined
})
const getTableData = async () => {
if (!searchForm.dateRange?.[0] || !searchForm.dateRange?.[1]) {
ElMessage.warning('请选择统计时间')
return
}
loading.value = true
try {
const summaryRes = await OperationsReportsService.getRenewalSummary(buildQuery())
if (summaryRes.code === 0 && summaryRes.data) {
summary.value = summaryRes.data
} else {
summary.value = null
ElMessage.error(summaryRes.msg || '获取套餐续费汇总失败')
}
} catch (error) {
console.error('获取套餐续费报表失败:', error)
summary.value = null
ElMessage.error('获取套餐续费报表失败')
} finally {
loading.value = false
}
}
const handleSearch = () => {
getTableData()
}
const handleReset = () => {
searchForm.dateRange = getDefaultRange()
searchForm.group_by = ''
getTableData()
}
const handleRefresh = () => {
getTableData()
}
const exportTask = computed(() => exportPolling.task.value)
const canDownload = computed(
() =>
exportTask.value?.status === ExportTaskStatus.COMPLETED && !!exportTask.value?.download_url
)
const exportStatusType = computed(() => {
const status = exportTask.value?.status
if (status === ExportTaskStatus.COMPLETED) return 'success'
if (status === ExportTaskStatus.FAILED) return 'danger'
if (status === ExportTaskStatus.CANCELED) return 'info'
return 'warning'
})
const exportPolling = useAsyncTaskPolling<ExportTaskDetail>({
storageKey: 'operations-report-active:renewal',
fetchTask: async (taskId) => {
const res = await ExportTaskService.getExportTaskDetail(taskId)
if (res.code === 403) {
const error = new Error('暂无权限查看导出任务') as Error & { status?: number }
error.status = 403
throw error
}
if (res.code !== 0 || !res.data) throw new Error(res.msg || '获取导出任务详情失败')
return res.data
},
isForbidden: (error: any) => error?.status === 403 || error?.response?.status === 403
})
const handleExport = async () => {
if (!searchForm.dateRange?.[0] || !searchForm.dateRange?.[1]) {
ElMessage.warning('请选择统计时间')
return
}
exporting.value = true
try {
const res = await OperationsReportsService.exportRenewalSummary({
...buildQuery(),
format: 'xlsx'
})
if (res.code !== 0 || !res.data) {
ElMessage.error(res.msg || '导出失败')
return
}
ElMessage.success(res.data.message || '导出任务已创建,请稍候')
await exportPolling.start(res.data.task_id)
} catch (error) {
console.error('导出套餐续费汇总失败:', error)
ElMessage.error('导出套餐续费汇总失败')
} finally {
exporting.value = false
}
}
const downloadExport = () => {
const url = exportTask.value?.download_url
if (!url) {
ElMessage.warning('当前任务暂无可用下载地址')
return
}
window.open(url, '_blank')
}
onMounted(() => {
getTableData()
})
</script>
<style lang="scss" scoped>
.operations-report-page {
display: flex;
flex-direction: column;
gap: 10px;
height: 100%;
overflow: auto;
}
.report-snapshot {
font-size: 12px;
font-weight: 400;
color: var(--el-text-color-secondary);
}
.report-export-tag {
margin-left: 12px;
}
</style>