eventData.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="layout-padding">
  3. <div class="!overflow-auto pl-1">
  4. <!-- 顶部控制区域 -->
  5. <div class="mb-2 el-card p-9">
  6. <div class="flex items-center mb-4">
  7. <Title title="自定义事件" />
  8. </div>
  9. <div class="flex items-center justify-between space-x-4">
  10. <div class="flex items-center">
  11. <FilterSelect v-model="formData.version" type="version" class="!w-[180px]" />
  12. </div>
  13. <div class="flex items-center ml-2">
  14. <FilterSelect v-model="formData.version" type="version" class="!w-[180px] ml-2" />
  15. <FilterSelect v-model="formData.channel" type="channel" class="!w-[180px] ml-2" />
  16. <el-date-picker v-model="formData.time" class="w-[200px] ml-2" type="daterange" start-placeholder="开始时间" end-placeholder="结束时间" />
  17. </div>
  18. </div>
  19. </div>
  20. <div class="el-card p-9 mt-2">
  21. <div class="flex justify-between items-center mb-2">
  22. <Title left-line title="事件统计">
  23. <template #default>
  24. <el-popover class="box-item" placement="right" trigger="hover" width="600">
  25. <template #reference>
  26. <el-icon class="ml-1" style="color: #a4b8cf"><QuestionFilled /></el-icon>
  27. </template>
  28. <template #default>
  29. <div class="ant-popover-inner-content">
  30. <div class="um-page-tips-content" style="line-height: 24px">
  31. <p><span class="highlight">事件消息数:</span><span>事件被触发的次数</span></p>
  32. <p><span class="highlight">消息数/启动次数:</span><span>平均每次启动被触发的次数</span></p>
  33. <p><span class="highlight">独立用户数:</span><span>每日触发事件的独立用户数(以设备为判断标准)</span></p>
  34. <p><span class="highlight">持续时长:</span><span>事件持续的时间长度</span></p>
  35. </div>
  36. </div>
  37. </template>
  38. </el-popover>
  39. </template>
  40. </Title>
  41. </div>
  42. <div class="flex justify-between items-center mb-2">
  43. <div class="flex items-center">
  44. <FilterSelect v-model="formData.version" type="version" class="!w-[140px]" />
  45. <el-button type="primary" class="ml-2">行业均值</el-button>
  46. </div>
  47. <el-radio-group v-model="timeGranularity">
  48. <el-radio-button label="day">消息数量</el-radio-button>
  49. <el-radio-button label="week">消息数/启动次数</el-radio-button>
  50. <el-radio-button label="month">独立用户数</el-radio-button>
  51. <el-radio-button label="xxsc">消息时长</el-radio-button>
  52. </el-radio-group>
  53. </div>
  54. <div class="relative">
  55. <div ref="lineChartRef" style="width: 100%; height: 320px"></div>
  56. </div>
  57. </div>
  58. <div class="el-card p-9 mt-2">
  59. <!-- 明细表格 -->
  60. <Title left-line title="事件统计明细" />
  61. <div class="mt-4">
  62. <el-table :data="pagedTableRows" border>
  63. <el-table-column prop="date" label="日期" align="center" min-width="140" />
  64. <el-table-column prop="hyyh" label="消息数量" ali gn="center" min-width="140" />
  65. <el-table-column prop="hyyh" label="消息数/启动次数" align="center" sortable min-width="140" />
  66. <el-table-column prop="hyyh" label="独立用户数" align="center" sortable min-width="140" />
  67. <el-table-column prop="hyyh" label="消息时长" align="center" sortable min-width="140" />
  68. </el-table>
  69. <div class="flex justify-end mt-2">
  70. <el-pagination
  71. v-model:current-page="currentPage"
  72. v-model:page-size="pageSize"
  73. background
  74. layout="total, prev, pager, next, sizes"
  75. :total="tableRows.length"
  76. :page-sizes="[5, 10, 20]"
  77. />
  78. </div>
  79. </div>
  80. <!-- 趋势图表区域 -->
  81. <div v-if="showTrendChart" class="mt-4">
  82. <div class="flex justify-between items-center mb-4">
  83. <h3 class="text-lg font-medium">趋势分析</h3>
  84. <el-button type="primary" link @click="showTrendChart = false">
  85. <el-icon><Close /></el-icon>
  86. 关闭
  87. </el-button>
  88. </div>
  89. <trend :data="trendData" series-name="消息数量" height="320px" :smooth="true" :area="false" :y-max="1200" />
  90. </div>
  91. <!-- 选择模块 -->
  92. <div v-if="!showTrendChart" class="flex justify-between items-center mt-4">
  93. <div class="flex items-center">
  94. <FilterSelect v-model="formData.version" type="version" class="!w-[180px]" />
  95. <el-popover class="box-item" placement="right" trigger="hover" width="600">
  96. <template #reference>
  97. <el-icon class="ml-1" style="color: #a4b8cf"><QuestionFilled /></el-icon>
  98. </template>
  99. <template #default>
  100. <div class="ant-popover-inner-content">
  101. <div class="um-page-tips-content" style="line-height: 24px">
  102. <p><span>您可以为事件设置参数,丰富自定义统计的内容,每个事件至多同时传100个参数,每个参数至多有1000个取值。</span></p>
  103. </div>
  104. </div>
  105. </template>
  106. </el-popover>
  107. </div>
  108. <div class="flex items-center">
  109. <el-radio-group v-model="timeGranularity">
  110. <el-radio-button label="day">次数分布</el-radio-button>
  111. <el-radio-button label="week">时长分布</el-radio-button>
  112. </el-radio-group>
  113. <el-button class="ml-2" type="primary" link>导出</el-button>
  114. </div>
  115. </div>
  116. <div v-if="!showTrendChart" class="mt-2">
  117. <el-table :data="pagedTableRows" border>
  118. <el-table-column prop="date" label="参数值" align="center" min-width="140" />
  119. <el-table-column prop="hyyh" label="消息数量" ali gn="center" min-width="140" />
  120. <el-table-column prop="hyyh" label="占比" align="center" sortable min-width="140" />
  121. <el-table-column fixed="right" label="趋势" align="center" min-width="140">
  122. <template #default>
  123. <el-button type="primary" link @click="showTrendChart = true">趋势</el-button>
  124. </template>
  125. </el-table-column>
  126. </el-table>
  127. <div class="flex justify-end mt-2">
  128. <el-pagination
  129. v-model:current-page="currentPage"
  130. v-model:page-size="pageSize"
  131. background
  132. layout="total, prev, pager, next, sizes"
  133. :total="tableRows.length"
  134. :page-sizes="[5, 10, 20]"
  135. />
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. </template>
  142. <script setup lang="ts">
  143. import { ref, onMounted, watch, computed, defineAsyncComponent, onBeforeUnmount } from 'vue';
  144. import * as echarts from 'echarts';
  145. import { Close } from '@element-plus/icons-vue';
  146. const Title = defineAsyncComponent(() => import('/@/components/Title/index.vue'));
  147. const Trend = defineAsyncComponent(() => import('./component/trend.vue'));
  148. const FilterSelect = defineAsyncComponent(() => import('/@/components/common/filter-select.vue'));
  149. interface TableRow {
  150. date: string;
  151. newUsers: number;
  152. ratio: string;
  153. }
  154. const formData = ref<Record<string, any>>({
  155. version: '',
  156. channel: '',
  157. time: '',
  158. });
  159. const channelCompareOptions: Array<{label: string; value: string}> = [];
  160. // 图表相关
  161. const timeGranularity = ref<'hour' | 'day' | 'week' | 'month'>('week');
  162. const lineChartRef = ref<HTMLDivElement | null>(null);
  163. let chartInstance: echarts.ECharts | null = null;
  164. const lineChartData = ref<Array<{ x: string; value: number }>>([
  165. { x: '2025-07-01', value: 900 },
  166. { x: '2025-07-08', value: 1000 },
  167. { x: '2025-07-15', value: 1100 },
  168. { x: '2025-07-22', value: 1000 },
  169. { x: '2025-07-29', value: 600 },
  170. { x: '2025-08-05', value: 300 },
  171. { x: '2025-08-12', value: 250 },
  172. { x: '2025-08-19', value: 200 },
  173. { x: '2025-08-26', value: 650 },
  174. { x: '2025-09-02', value: 950 },
  175. { x: '2025-09-09', value: 900 },
  176. { x: '2025-09-16', value: 120 },
  177. ]);
  178. function initLineChart(): void {
  179. if (!lineChartRef.value) return;
  180. if (chartInstance) chartInstance.dispose();
  181. chartInstance = echarts.init(lineChartRef.value);
  182. const option: echarts.EChartsOption = {
  183. tooltip: { trigger: 'axis' },
  184. grid: { left: 40, right: 20, top: 20, bottom: 30 },
  185. xAxis: {
  186. type: 'category',
  187. data: lineChartData.value.map((d) => d.x),
  188. axisLine: { lineStyle: { color: '#e5e7eb' } },
  189. axisLabel: { color: '#6b7280' },
  190. axisTick: { alignWithLabel: true },
  191. },
  192. yAxis: {
  193. type: 'value',
  194. axisLine: { show: false },
  195. splitLine: { lineStyle: { color: '#f3f4f6' } },
  196. axisLabel: { color: '#6b7280' },
  197. },
  198. series: [
  199. {
  200. name: '新增人数',
  201. type: 'line',
  202. smooth: true,
  203. showSymbol: true,
  204. symbolSize: 6,
  205. itemStyle: { color: '#409EFF' },
  206. lineStyle: { color: '#409EFF' },
  207. data: lineChartData.value.map((d) => d.value),
  208. },
  209. ],
  210. };
  211. chartInstance.setOption(option);
  212. }
  213. onMounted(() => {
  214. initLineChart();
  215. });
  216. watch(timeGranularity, () => {
  217. // 静态页面:仅重新渲染
  218. initLineChart();
  219. });
  220. // 表格相关(静态数据)
  221. const tableRows = ref<TableRow[]>(
  222. Array.from({ length: 42 }).map((_, idx) => ({
  223. date: `2025-08-${String(11).padStart(2, '0')}`,
  224. newUsers: 727,
  225. hyyh: '123' + idx,
  226. ratio: '97.45%',
  227. }))
  228. );
  229. const currentPage = ref(1);
  230. const pageSize = ref(5);
  231. const pagedTableRows = computed(() => {
  232. const startIndex = (currentPage.value - 1) * pageSize.value;
  233. return tableRows.value.slice(startIndex, startIndex + pageSize.value);
  234. });
  235. // 趋势图表相关
  236. const showTrendChart = ref(false);
  237. const trendData = ref([
  238. { date: '2025-07-30', value: 860 },
  239. { date: '2025-07-30', value: 1100 },
  240. { date: '2025-07-30', value: 1000 },
  241. { date: '2025-07-30', value: 920 },
  242. { date: '2025-07-30', value: 600 },
  243. { date: '2025-07-30', value: 250 },
  244. { date: '2025-07-30', value: 200 },
  245. { date: '2025-07-30', value: 620 },
  246. { date: '2025-07-30', value: 1050 },
  247. { date: '2025-07-30', value: 1000 },
  248. { date: '2025-07-30', value: 70 },
  249. ]);
  250. </script>
  251. <style lang="scss" scoped>
  252. .el-card {
  253. background: white;
  254. border-radius: 8px;
  255. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  256. }
  257. :deep(.el-tabs__item.is-top.is-active) {
  258. color: #167af0;
  259. background-color: #e8f2fe;
  260. }
  261. .el-radio-button__inner {
  262. border-radius: 4px;
  263. }
  264. .el-radio-button:first-child .el-radio-button__inner {
  265. border-radius: 4px 0 0 4px;
  266. }
  267. .el-radio-button:last-child .el-radio-button__inner {
  268. border-radius: 0 4px 4px 0;
  269. }
  270. </style>