index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <div class="app-container home">
  3. <!-- <el-divider /> -->
  4. <el-row :gutter="12">
  5. <el-col :span="24">
  6. <div class="dashboard-title">数据看板</div>
  7. </el-col>
  8. <el-col :span="24">
  9. <div class="stat-grid">
  10. <el-card shadow="hover" class="stat-card">
  11. <div class="stat-label">商品总数</div>
  12. <div class="stat-value">{{ metrics.productTotal }}</div>
  13. </el-card>
  14. <el-card shadow="hover" class="stat-card">
  15. <div class="stat-label">自营商品</div>
  16. <div class="stat-value">{{ metrics.productSelf }}</div>
  17. </el-card>
  18. <el-card shadow="hover" class="stat-card">
  19. <div class="stat-label">上架商品</div>
  20. <div class="stat-value">{{ metrics.productOnSale }}</div>
  21. </el-card>
  22. <el-card shadow="hover" class="stat-card">
  23. <div class="stat-label">下架商品</div>
  24. <div class="stat-value">{{ metrics.productOffSale }}</div>
  25. </el-card>
  26. <el-card shadow="hover" class="stat-card">
  27. <div class="stat-label">停售商品</div>
  28. <div class="stat-value">{{ metrics.productStopSale }}</div>
  29. </el-card>
  30. <el-card shadow="hover" class="stat-card">
  31. <div class="stat-label">精选商品</div>
  32. <div class="stat-value">{{ metrics.productFeatured }}</div>
  33. </el-card>
  34. <el-card shadow="hover" class="stat-card">
  35. <div class="stat-label">商品总池</div>
  36. <div class="stat-value">{{ metrics.poolTotal }}</div>
  37. </el-card>
  38. <el-card shadow="hover" class="stat-card">
  39. <div class="stat-label">精选商品池</div>
  40. <div class="stat-value">{{ metrics.poolFeatured }}</div>
  41. </el-card>
  42. <el-card shadow="hover" class="stat-card">
  43. <div class="stat-label">方案数量</div>
  44. <div class="stat-value">{{ metrics.programTotal }}</div>
  45. </el-card>
  46. <el-card shadow="hover" class="stat-card">
  47. <div class="stat-label">今日方案新增</div>
  48. <div class="stat-value">{{ metrics.programTodayNew }}</div>
  49. </el-card>
  50. </div>
  51. </el-col>
  52. <el-col :span="12" class="card-box">
  53. <el-card shadow="hover" class="chart-card">
  54. <template #header>
  55. <span>商品状态分布</span>
  56. </template>
  57. <div ref="productStatusChartRef" class="chart" />
  58. </el-card>
  59. </el-col>
  60. <el-col :span="12" class="card-box">
  61. <el-card shadow="hover" class="chart-card">
  62. <template #header>
  63. <span>精选/停售/默认</span>
  64. </template>
  65. <div ref="productTypeChartRef" class="chart" />
  66. </el-card>
  67. </el-col>
  68. </el-row>
  69. </div>
  70. </template>
  71. <script setup name="Index" lang="ts">
  72. import * as echarts from 'echarts';
  73. import { getProductStatusCount, listBase } from '@/api/product/base';
  74. import { listProgram } from '@/api/product/program';
  75. import { listPool } from '@/api/product/pool/index';
  76. const productStatusChartRef = ref();
  77. const productTypeChartRef = ref();
  78. let productStatusChartInstance: echarts.ECharts | undefined;
  79. let productTypeChartInstance: echarts.ECharts | undefined;
  80. const metrics = reactive({
  81. productTotal: 0,
  82. productSelf: 0,
  83. productOnSale: 0,
  84. productOffSale: 0,
  85. productStopSale: 0,
  86. productFeatured: 0,
  87. poolTotal: 0,
  88. poolFeatured: 0,
  89. programTotal: 0,
  90. programTodayNew: 0
  91. });
  92. const safeTotal = (res: any): number => {
  93. const total = res?.total;
  94. return typeof total === 'number' ? total : 0;
  95. };
  96. const getTodayRange = () => {
  97. const now = new Date();
  98. const start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
  99. const end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59);
  100. const fmt = (d: Date) => {
  101. const pad = (n: number) => `${n}`.padStart(2, '0');
  102. return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
  103. };
  104. return { beginTime: fmt(start), endTime: fmt(end) };
  105. };
  106. const renderProductStatusChart = () => {
  107. if (!productStatusChartRef.value) return;
  108. if (!productStatusChartInstance) {
  109. productStatusChartInstance = echarts.init(productStatusChartRef.value, 'macarons');
  110. }
  111. productStatusChartInstance.setOption({
  112. tooltip: { trigger: 'item' },
  113. legend: { bottom: 0 },
  114. series: [
  115. {
  116. name: '商品状态',
  117. type: 'pie',
  118. radius: ['45%', '70%'],
  119. avoidLabelOverlap: true,
  120. itemStyle: { borderRadius: 8, borderColor: '#fff', borderWidth: 2 },
  121. label: { show: false },
  122. emphasis: { label: { show: true, fontSize: 14, fontWeight: 'bold' } },
  123. labelLine: { show: false },
  124. data: [
  125. { value: metrics.productOnSale, name: '上架' },
  126. { value: metrics.productOffSale, name: '下架' }
  127. ]
  128. }
  129. ]
  130. });
  131. };
  132. const renderProductTypeChart = () => {
  133. if (!productTypeChartRef.value) return;
  134. if (!productTypeChartInstance) {
  135. productTypeChartInstance = echarts.init(productTypeChartRef.value, 'macarons');
  136. }
  137. const defaultCount = Math.max(metrics.productTotal - metrics.productFeatured - metrics.productStopSale, 0);
  138. productTypeChartInstance.setOption({
  139. tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
  140. grid: { left: 12, right: 12, top: 20, bottom: 20, containLabel: true },
  141. xAxis: { type: 'category', data: ['默认', '精选', '停售'] },
  142. yAxis: { type: 'value' },
  143. series: [
  144. {
  145. name: '数量',
  146. type: 'bar',
  147. barWidth: 36,
  148. itemStyle: { borderRadius: [8, 8, 0, 0] },
  149. data: [defaultCount, metrics.productFeatured, metrics.productStopSale]
  150. }
  151. ]
  152. });
  153. };
  154. const refreshMetrics = async () => {
  155. const statusRes = await getProductStatusCount();
  156. metrics.productTotal = statusRes.data?.total ?? 0;
  157. metrics.productOnSale = statusRes.data?.onSale ?? 0;
  158. metrics.productOffSale = statusRes.data?.offSale ?? 0;
  159. const [selfRes, featuredRes, stopSaleRes] = await Promise.all([
  160. listBase({ pageNum: 1, pageSize: 1, isSelf: 1 } as any),
  161. listBase({ pageNum: 1, pageSize: 1, productCategory: 2 } as any),
  162. listBase({ pageNum: 1, pageSize: 1, productCategory: 3 } as any)
  163. ]);
  164. metrics.productSelf = safeTotal(selfRes);
  165. metrics.productFeatured = safeTotal(featuredRes);
  166. metrics.productStopSale = safeTotal(stopSaleRes);
  167. const [poolTotalRes, poolFeaturedRes] = await Promise.all([
  168. listPool({ pageNum: 1, pageSize: 1 } as any),
  169. listPool({ pageNum: 1, pageSize: 1, type: 1 } as any)
  170. ]);
  171. metrics.poolTotal = safeTotal(poolTotalRes);
  172. metrics.poolFeatured = safeTotal(poolFeaturedRes);
  173. const programTotalRes = await listProgram({ pageNum: 1, pageSize: 1 } as any);
  174. metrics.programTotal = safeTotal(programTotalRes);
  175. const { beginTime, endTime } = getTodayRange();
  176. const programTodayRes = await listProgram({ pageNum: 1, pageSize: 1, params: { beginTime, endTime } } as any);
  177. metrics.programTodayNew = safeTotal(programTodayRes);
  178. renderProductStatusChart();
  179. renderProductTypeChart();
  180. };
  181. const onResize = () => {
  182. productStatusChartInstance?.resize();
  183. productTypeChartInstance?.resize();
  184. };
  185. onMounted(async () => {
  186. await refreshMetrics();
  187. window.addEventListener('resize', onResize);
  188. });
  189. onBeforeUnmount(() => {
  190. window.removeEventListener('resize', onResize);
  191. productStatusChartInstance?.dispose();
  192. productTypeChartInstance?.dispose();
  193. productStatusChartInstance = undefined;
  194. productTypeChartInstance = undefined;
  195. });
  196. </script>
  197. <style lang="scss" scoped>
  198. .home {
  199. blockquote {
  200. padding: 10px 20px;
  201. margin: 0 0 20px;
  202. font-size: 17.5px;
  203. border-left: 5px solid #eee;
  204. }
  205. hr {
  206. margin-top: 20px;
  207. margin-bottom: 20px;
  208. border: 0;
  209. border-top: 1px solid #eee;
  210. }
  211. .col-item {
  212. margin-bottom: 20px;
  213. }
  214. .dashboard-title {
  215. font-size: 18px;
  216. font-weight: 600;
  217. color: #1f2937;
  218. padding: 4px 2px 10px;
  219. }
  220. .stat-grid {
  221. display: grid;
  222. grid-template-columns: repeat(4, minmax(0, 1fr));
  223. gap: 12px;
  224. }
  225. .stat-card {
  226. border-radius: 12px;
  227. background: linear-gradient(135deg, #ffffff 0%, #f7fbff 100%);
  228. }
  229. .stat-label {
  230. font-size: 13px;
  231. color: #6b7280;
  232. margin-bottom: 8px;
  233. }
  234. .stat-value {
  235. font-size: 28px;
  236. font-weight: 700;
  237. color: #111827;
  238. letter-spacing: 0.5px;
  239. }
  240. .chart-card {
  241. border-radius: 12px;
  242. }
  243. .chart {
  244. height: 360px;
  245. }
  246. ul {
  247. padding: 0;
  248. margin: 0;
  249. }
  250. font-family: 'open sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  251. font-size: 13px;
  252. color: #676a6c;
  253. overflow-x: hidden;
  254. ul {
  255. list-style-type: none;
  256. }
  257. h4 {
  258. margin-top: 0px;
  259. }
  260. h2 {
  261. margin-top: 10px;
  262. font-size: 26px;
  263. font-weight: 100;
  264. }
  265. p {
  266. margin-top: 10px;
  267. b {
  268. font-weight: 700;
  269. }
  270. }
  271. .update-log {
  272. ol {
  273. display: block;
  274. list-style-type: decimal;
  275. margin-block-start: 1em;
  276. margin-block-end: 1em;
  277. margin-inline-start: 0;
  278. margin-inline-end: 0;
  279. padding-inline-start: 40px;
  280. }
  281. }
  282. .index-style {
  283. font-size: 48px;
  284. font-weight: bold;
  285. letter-spacing: 15px;
  286. display: flex;
  287. justify-content: center;
  288. align-items: center;
  289. height: 300px;
  290. background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  291. border-radius: 10px;
  292. box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
  293. .typewriter-container {
  294. display: flex;
  295. }
  296. .typewriter-char {
  297. opacity: 0;
  298. transform: translateY(20px) rotate(-5deg);
  299. animation:
  300. typewriter-animation 0.8s ease forwards,
  301. pulse 2s ease-in-out infinite 1s;
  302. color: #2d8cf0;
  303. text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
  304. transition: color 0.3s ease;
  305. &:hover {
  306. color: #f06292;
  307. transform: scale(1.1);
  308. animation-play-state: paused;
  309. }
  310. }
  311. }
  312. @keyframes typewriter-animation {
  313. 0% {
  314. opacity: 0;
  315. transform: translateY(20px) rotate(-5deg);
  316. }
  317. 50% {
  318. opacity: 0.5;
  319. transform: translateY(10px) rotate(-2deg);
  320. }
  321. 100% {
  322. opacity: 1;
  323. transform: translateY(0) rotate(0deg);
  324. }
  325. }
  326. @keyframes pulse {
  327. 0% {
  328. text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
  329. transform: scale(1);
  330. }
  331. 50% {
  332. text-shadow:
  333. 0 0 15px rgba(45, 140, 240, 0.8),
  334. 0 0 30px rgba(45, 140, 240, 0.4);
  335. transform: scale(1.05);
  336. }
  337. 100% {
  338. text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
  339. transform: scale(1);
  340. }
  341. }
  342. @media (max-width: 1200px) {
  343. .stat-grid {
  344. grid-template-columns: repeat(2, minmax(0, 1fr));
  345. }
  346. }
  347. }
  348. </style>