index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div class="layout-padding">
  3. <div class="!overflow-auto px-1">
  4. <div class="el-card p-2">
  5. <div class="flex justify-between">
  6. <Title :title="t('activations.analytics')">
  7. <template #default>
  8. <el-popover class="box-item" placement="right" trigger="hover" width="250">
  9. <template #reference>
  10. <el-icon class="ml-1" style="color: #a4b8cf"><QuestionFilled /></el-icon>
  11. </template>
  12. <template #default>
  13. <div class="ant-popover-inner-content">
  14. <div class="um-page-tips-content" style="line-height: 24px">
  15. <p>
  16. <span class="highlight">活跃用户:</span>
  17. <span>启动过应用的用户(去重),启动过一次的用户即视为活跃用户,包括新用户与老用户</span>
  18. </p>
  19. <p><span class="highlight">活跃构成:</span><span>活跃用户中新增用户的占比比例</span></p>
  20. <p><span class="highlight">活跃粘度:</span><span>DAU/过去7日活跃用户,DAU/过去30日活跃用户</span></p>
  21. <p><span class="highlight">过去7日活跃用户:</span><span>过去7日(不含今日)的活跃用户数(去重)</span></p>
  22. <p><span class="highlight">过去30日活跃用户:</span><span>过去30日(不含今日)的活跃用户数(去重)</span></p>
  23. <p><span class="highlight">分时活跃用户:</span><span>活跃用户在24小时中的分布情况(每小时间去重)&ZeroWidthSpace;</span></p>
  24. <p><span class="highlight">周活跃率:</span><span>周活跃用户占截止本周累计用户的比例</span></p>
  25. <p><span class="highlight">月活跃率:</span><span>月活跃用户占截止本月累计用户的比例</span></p>
  26. <p>
  27. <span>
  28. 按天、周或月查看数据可进行版本、渠道的交叉筛选。周区间定义为周日至次周周六。按周(按月)显示时,界面上用每周的周日(每个月的第一日)来代表该周(该月)
  29. </span>
  30. </p>
  31. </div>
  32. </div>
  33. </template>
  34. </el-popover>
  35. </template>
  36. </Title>
  37. </div>
  38. <div>
  39. <el-row shadow="hover" class="ml10 mt-2">
  40. <el-form :inline="true" :model="formData" @keyup.enter="query" ref="queryRef">
  41. <el-form-item>
  42. <el-date-picker v-model="formData.time" type="daterange" start-placeholder="开始时间" end-placeholder="结束时间" />
  43. </el-form-item>
  44. <el-form-item>
  45. <el-select v-model="selectedChannelCompare" class="w-[140px]" placeholder="全部渠道">
  46. <el-option v-for="item in channelCompareOptions" :key="item.value" :label="item.label" :value="item.value" />
  47. </el-select>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-select v-model="selectedChannelCompare" class="w-[140px]" placeholder="全部版本">
  51. <el-option v-for="item in channelCompareOptions" :key="item.value" :label="item.label" :value="item.value" />
  52. </el-select>
  53. </el-form-item>
  54. </el-form>
  55. </el-row>
  56. </div>
  57. </div>
  58. <div class="mt-2 el-card p-2">
  59. <div class="">
  60. <div class="flex items-center justify-between mb-2 mt-3">
  61. <div>
  62. <el-select v-model="selectedChannelCompare" class="w-[140px] ml-2" style="width: 140px" placeholder="版本对比">
  63. <el-option v-for="item in channelCompareOptions" :key="item.value" :label="item.label" :value="item.value" />
  64. </el-select>
  65. <el-button type="primary" class="ml-2">{{ t('activations.version') }}</el-button>
  66. </div>
  67. <div class="flex items-center">
  68. <el-radio-group v-model="timeGranularity" size="small">
  69. <el-radio-button label="hour">小时</el-radio-button>
  70. <el-radio-button label="day">天</el-radio-button>
  71. <el-radio-button label="week">周</el-radio-button>
  72. <el-radio-button label="month">月</el-radio-button>
  73. </el-radio-group>
  74. </div>
  75. </div>
  76. <div class="relative">
  77. <div ref="lineChartRef" style="width: 100%; height: 320px"></div>
  78. </div>
  79. </div>
  80. <!-- 明细表格 -->
  81. <div class="mt-3">
  82. <div class="flex items-center justify-between mb-2">
  83. <div class="text-base font-medium cursor-pointer select-none" @click="showDetail1 = !showDetail1">
  84. {{ showDetail1 ? '收起明细数据' : '展开明细数据' }}
  85. </div>
  86. <div>
  87. <el-button>导出</el-button>
  88. </div>
  89. </div>
  90. <el-table v-if="showDetail1" :data="pagedTableRows" border>
  91. <el-table-column prop="date" label="日期" align="center" min-width="140" />
  92. <el-table-column prop="hyyh" label="启动次数" align="center" min-width="140" />
  93. <el-table-column prop="ratio" label="启动次数(占比)" align="center" min-width="220">
  94. </el-table-column>
  95. </el-table>
  96. <div v-if="showDetail1" class="flex justify-end mt-2">
  97. <el-pagination
  98. v-model:current-page="currentPage"
  99. v-model:page-size="pageSize"
  100. background
  101. layout="total, prev, pager, next, sizes"
  102. :total="tableRows.length"
  103. :page-sizes="[5, 10, 20]"
  104. />
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </template>
  111. <script setup lang="ts">
  112. import { ref, onMounted, watch, computed, defineAsyncComponent } from 'vue';
  113. import * as echarts from 'echarts';
  114. import { useI18n } from 'vue-i18n';
  115. const { t } = useI18n();
  116. interface TableRow {
  117. date: string;
  118. newUsers: number;
  119. ratio: string;
  120. }
  121. const formData = ref<Record<string, any>>({});
  122. const query = () => {
  123. console.log(formData.value);
  124. };
  125. const selectedChannelCompare = ref('');
  126. const channelCompareOptions = [
  127. { label: '渠道对比', value: 'compare' },
  128. { label: '渠道A', value: 'a' },
  129. { label: '渠道B', value: 'b' },
  130. ];
  131. // 图表相关
  132. const timeGranularity = ref<'hour' | 'day' | 'week' | 'month'>('week');
  133. const lineChartRef = ref<HTMLDivElement | null>(null);
  134. let chartInstance: echarts.ECharts | null = null;
  135. const lineChartData = ref<Array<{ x: string; value: number }>>([
  136. { x: '2025-07-01', value: 900 },
  137. { x: '2025-07-08', value: 1000 },
  138. { x: '2025-07-15', value: 1100 },
  139. { x: '2025-07-22', value: 1000 },
  140. { x: '2025-07-29', value: 600 },
  141. { x: '2025-08-05', value: 300 },
  142. { x: '2025-08-12', value: 250 },
  143. { x: '2025-08-19', value: 200 },
  144. { x: '2025-08-26', value: 650 },
  145. { x: '2025-09-02', value: 950 },
  146. { x: '2025-09-09', value: 900 },
  147. { x: '2025-09-16', value: 120 },
  148. ]);
  149. function initLineChart(): void {
  150. if (!lineChartRef.value) return;
  151. if (chartInstance) chartInstance.dispose();
  152. chartInstance = echarts.init(lineChartRef.value);
  153. const option: echarts.EChartsOption = {
  154. tooltip: { trigger: 'axis' },
  155. grid: { left: 40, right: 20, top: 20, bottom: 30 },
  156. xAxis: {
  157. type: 'category',
  158. data: lineChartData.value.map((d) => d.x),
  159. axisLine: { lineStyle: { color: '#e5e7eb' } },
  160. axisLabel: { color: '#6b7280' },
  161. axisTick: { alignWithLabel: true },
  162. },
  163. yAxis: {
  164. type: 'value',
  165. axisLine: { show: false },
  166. splitLine: { lineStyle: { color: '#f3f4f6' } },
  167. axisLabel: { color: '#6b7280' },
  168. },
  169. series: [
  170. {
  171. name: '新增人数',
  172. type: 'line',
  173. smooth: true,
  174. showSymbol: true,
  175. symbolSize: 6,
  176. itemStyle: { color: '#409EFF' },
  177. lineStyle: { color: '#409EFF' },
  178. data: lineChartData.value.map((d) => d.value),
  179. },
  180. ],
  181. };
  182. chartInstance.setOption(option);
  183. }
  184. onMounted(() => {
  185. initLineChart();
  186. initQualityChart();
  187. });
  188. watch(timeGranularity, () => {
  189. // 静态页面:仅重新渲染
  190. initLineChart();
  191. });
  192. // 表格相关(静态数据)
  193. const tableRows = ref<TableRow[]>(
  194. Array.from({ length: 42 }).map((_, idx) => ({
  195. date: `2025-08-${String(11).padStart(2, '0')}`,
  196. newUsers: 727,
  197. hyyh: '115',
  198. ratio: '97.45%',
  199. }))
  200. );
  201. const currentPage = ref(1);
  202. const pageSize = ref(5);
  203. const pagedTableRows = computed(() => {
  204. const startIndex = (currentPage.value - 1) * pageSize.value;
  205. return tableRows.value.slice(startIndex, startIndex + pageSize.value);
  206. });
  207. const Title = defineAsyncComponent(() => import('/@/components/Title/index.vue'));
  208. // 展开/收起明细
  209. const showDetail1 = ref(true);
  210. // 用户质量(留存率)
  211. const qualityChartRef = ref<HTMLDivElement | null>(null);
  212. let qualityChart: echarts.ECharts | null = null;
  213. const qualityXAxis = ref<string[]>([
  214. '2025-07-01',
  215. '2025-07-08',
  216. '2025-07-15',
  217. '2025-07-22',
  218. '2025-07-29',
  219. '2025-08-05',
  220. '2025-08-12',
  221. '2025-08-19',
  222. '2025-08-26',
  223. '2025-09-02',
  224. '2025-09-09',
  225. '2025-09-16',
  226. ]);
  227. const retentionSeries = ref<number[]>([20, 23, 27, 24, 22, 15, 5, 4, 16, 26, 25, 2]);
  228. const industryAvgSeries = ref<number[]>([16, 18, 20, 24, 25, 24, 16, 10, 15, 22, 21, 12]);
  229. const peerSameScaleSeries = ref<number[]>([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
  230. function initQualityChart(): void {
  231. if (!qualityChartRef.value) return;
  232. if (qualityChart) qualityChart.dispose();
  233. qualityChart = echarts.init(qualityChartRef.value);
  234. const option: echarts.EChartsOption = {
  235. tooltip: { trigger: 'axis', valueFormatter: (v) => `${v}%` },
  236. legend: { data: ['留存率', '同行业App', '同行业同规模App'] },
  237. grid: { left: 40, right: 20, top: 30, bottom: 30 },
  238. xAxis: { type: 'category', data: qualityXAxis.value },
  239. yAxis: {
  240. type: 'value',
  241. min: 0,
  242. max: 30,
  243. axisLabel: { formatter: '{value}%' },
  244. splitLine: { lineStyle: { color: '#f3f4f6' } },
  245. },
  246. series: [
  247. { name: '留存率', type: 'line', smooth: true, data: retentionSeries.value },
  248. { name: '同行业App', type: 'line', smooth: true, data: industryAvgSeries.value, color: '#f59e0b' },
  249. { name: '同行业同规模App', type: 'line', smooth: true, data: peerSameScaleSeries.value, color: '#60a5fa' },
  250. ],
  251. };
  252. qualityChart.setOption(option);
  253. }
  254. </script>
  255. <style lang="scss" scoped>
  256. .highlight {
  257. color: #2196f3;
  258. }
  259. </style>