index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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
  18. >打开应用视为启动。完全退出或后台运行超过30s后再次进入应用,视为一次新启动。开发过程中可以通过setSessionContinueMills来自定义两次启动的间隔,默认30s</span
  19. >
  20. </p>
  21. <p><span class="highlight">启动次数占比:</span><span>某日/周/月的启动次数占所选时间段总启动次数的比例</span></p>
  22. <p>
  23. <span
  24. >按天、周或月查看数据可进行版本、渠道的交叉筛选,小时数据最多展示7天并且不支持筛选。周区间定义为周日至次周周六。按周(按月)显示时,界面上用每周的周日(每个月的第一日)来代表该周(该月)</span
  25. >
  26. </p>
  27. </div>
  28. </div>
  29. </template>
  30. </el-popover>
  31. </template>
  32. </Title>
  33. </div>
  34. <div>
  35. <el-row shadow="hover" class="ml10 mt-2">
  36. <el-form :inline="true" :model="formData" @keyup.enter="query" ref="queryRef">
  37. <el-form-item>
  38. <el-date-picker v-model="formData.time" type="daterange" start-placeholder="开始时间" end-placeholder="结束时间" />
  39. </el-form-item>
  40. <el-form-item>
  41. <el-select v-model="selectedChannelCompare" class="w-[140px]" placeholder="全部渠道">
  42. <el-option v-for="item in channelCompareOptions" :key="item.value" :label="item.label" :value="item.value" />
  43. </el-select>
  44. </el-form-item>
  45. <el-form-item>
  46. <el-select v-model="selectedChannelCompare" class="w-[140px]" placeholder="全部版本">
  47. <el-option v-for="item in channelCompareOptions" :key="item.value" :label="item.label" :value="item.value" />
  48. </el-select>
  49. </el-form-item>
  50. </el-form>
  51. </el-row>
  52. </div>
  53. </div>
  54. <div class="mt-2 el-card p-2">
  55. <div class="">
  56. <div class="flex items-center justify-between mb-2 mt-3">
  57. <div>
  58. <el-select v-model="selectedChannelCompare" class="w-[140px] ml-2" style="width: 140px" placeholder="版本对比">
  59. <el-option v-for="item in channelCompareOptions" :key="item.value" :label="item.label" :value="item.value" />
  60. </el-select>
  61. <el-button type="primary" class="ml-2">{{ t('activations.version') }}</el-button>
  62. </div>
  63. <div class="flex items-center">
  64. <el-radio-group v-model="timeGranularity" size="small">
  65. <el-radio-button label="hour">小时</el-radio-button>
  66. <el-radio-button label="day">天</el-radio-button>
  67. <el-radio-button label="week">周</el-radio-button>
  68. <el-radio-button label="month">月</el-radio-button>
  69. </el-radio-group>
  70. </div>
  71. </div>
  72. <div class="relative">
  73. <div ref="lineChartRef" style="width: 100%; height: 320px"></div>
  74. </div>
  75. </div>
  76. <!-- 明细表格 -->
  77. <div class="mt-3">
  78. <div class="flex items-center justify-between mb-2">
  79. <div class="text-base font-medium cursor-pointer select-none ml-3 items-center flex text-[#167AF0]" @click="showDetail1 = !showDetail1">
  80. {{ showDetail1 ? '收起明细数据' : '展开明细数据' }} <el-icon class="ml-2"><ArrowDown v-if="showDetail1"/> <ArrowUp v-else/> </el-icon>
  81. </div>
  82. <div>
  83. <el-button>导出</el-button>
  84. </div>
  85. </div>
  86. <el-table v-if="showDetail1" :data="pagedTableRows" border>
  87. <el-table-column prop="date" label="日期" align="center" min-width="140" />
  88. <el-table-column prop="hyyh" label="启动次数" align="center" min-width="140" />
  89. <el-table-column prop="ratio" label="启动次数(占比)" align="center" min-width="220"> </el-table-column>
  90. </el-table>
  91. <div v-if="showDetail1" class="flex justify-end mt-2">
  92. <el-pagination
  93. v-model:current-page="currentPage"
  94. v-model:page-size="pageSize"
  95. background
  96. layout="total, prev, pager, next, sizes"
  97. :total="tableRows.length"
  98. :page-sizes="[5, 10, 20]"
  99. />
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </template>
  106. <script setup lang="ts">
  107. import { ref, onMounted, watch, computed, defineAsyncComponent } from 'vue';
  108. import * as echarts from 'echarts';
  109. import { useI18n } from 'vue-i18n';
  110. const { t } = useI18n();
  111. interface TableRow {
  112. date: string;
  113. newUsers: number;
  114. ratio: string;
  115. }
  116. const formData = ref<Record<string, any>>({});
  117. const query = () => {
  118. console.log(formData.value);
  119. };
  120. const selectedChannelCompare = ref('');
  121. const channelCompareOptions = [
  122. { label: '渠道对比', value: 'compare' },
  123. { label: '渠道A', value: 'a' },
  124. { label: '渠道B', value: 'b' },
  125. ];
  126. // 图表相关
  127. const timeGranularity = ref<'hour' | 'day' | 'week' | 'month'>('week');
  128. const lineChartRef = ref<HTMLDivElement | null>(null);
  129. let chartInstance: echarts.ECharts | null = null;
  130. const lineChartData = ref<Array<{ x: string; value: number }>>([
  131. { x: '2025-07-01', value: 900 },
  132. { x: '2025-07-08', value: 1000 },
  133. { x: '2025-07-15', value: 1100 },
  134. { x: '2025-07-22', value: 1000 },
  135. { x: '2025-07-29', value: 600 },
  136. { x: '2025-08-05', value: 300 },
  137. { x: '2025-08-12', value: 250 },
  138. { x: '2025-08-19', value: 200 },
  139. { x: '2025-08-26', value: 650 },
  140. { x: '2025-09-02', value: 950 },
  141. { x: '2025-09-09', value: 900 },
  142. { x: '2025-09-16', value: 120 },
  143. ]);
  144. function initLineChart(): void {
  145. if (!lineChartRef.value) return;
  146. if (chartInstance) chartInstance.dispose();
  147. chartInstance = echarts.init(lineChartRef.value);
  148. const option: echarts.EChartsOption = {
  149. tooltip: { trigger: 'axis' },
  150. grid: { left: 40, right: 20, top: 20, bottom: 30 },
  151. xAxis: {
  152. type: 'category',
  153. data: lineChartData.value.map((d) => d.x),
  154. axisLine: { lineStyle: { color: '#e5e7eb' } },
  155. axisLabel: { color: '#6b7280' },
  156. axisTick: { alignWithLabel: true },
  157. },
  158. yAxis: {
  159. type: 'value',
  160. axisLine: { show: false },
  161. splitLine: { lineStyle: { color: '#f3f4f6' } },
  162. axisLabel: { color: '#6b7280' },
  163. },
  164. series: [
  165. {
  166. name: '新增人数',
  167. type: 'line',
  168. smooth: true,
  169. showSymbol: true,
  170. symbolSize: 6,
  171. itemStyle: { color: '#409EFF' },
  172. lineStyle: { color: '#409EFF' },
  173. data: lineChartData.value.map((d) => d.value),
  174. },
  175. ],
  176. };
  177. chartInstance.setOption(option);
  178. }
  179. onMounted(() => {
  180. initLineChart();
  181. });
  182. watch(timeGranularity, () => {
  183. // 静态页面:仅重新渲染
  184. initLineChart();
  185. });
  186. // 表格相关(静态数据)
  187. const tableRows = ref<TableRow[]>(
  188. Array.from({ length: 42 }).map((_, idx) => ({
  189. date: `2025-08-${String(11).padStart(2, '0')}`,
  190. newUsers: 727,
  191. hyyh: '115',
  192. ratio: '97.45%',
  193. }))
  194. );
  195. const currentPage = ref(1);
  196. const pageSize = ref(5);
  197. const pagedTableRows = computed(() => {
  198. const startIndex = (currentPage.value - 1) * pageSize.value;
  199. return tableRows.value.slice(startIndex, startIndex + pageSize.value);
  200. });
  201. const Title = defineAsyncComponent(() => import('/@/components/Title/index.vue'));
  202. // 展开/收起明细
  203. const showDetail1 = ref(true);
  204. </script>
  205. <style lang="scss" scoped>
  206. .highlight {
  207. color: #2196f3;
  208. }
  209. .el-form-item--default{
  210. margin-bottom: 0;
  211. }
  212. .el-form.el-form--inline .el-form-item--default.el-form-item:last-of-type, .el-form.el-form--inline .el-form-item--small.el-form-item:last-of-type{
  213. margin-bottom: 0 !important;
  214. }
  215. </style>