eventData.vue 11 KB

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