index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div class="app-container home">
  3. <!-- <el-divider /> -->
  4. <el-row :gutter="12" class="stat-row">
  5. <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6">
  6. <el-card shadow="hover" class="stat-card stat-card--blue">
  7. <div class="stat-title">商品总数</div>
  8. <div class="stat-value">{{ stats.totalGoods }}</div>
  9. </el-card>
  10. </el-col>
  11. <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6">
  12. <el-card shadow="hover" class="stat-card stat-card--orange">
  13. <div class="stat-title">停售商品</div>
  14. <div class="stat-value">{{ stats.stoppedGoods }}</div>
  15. </el-card>
  16. </el-col>
  17. <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6">
  18. <el-card shadow="hover" class="stat-card stat-card--purple">
  19. <div class="stat-title">上下架申请</div>
  20. <div class="stat-value">{{ stats.shelfApply }}</div>
  21. </el-card>
  22. </el-col>
  23. <el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6">
  24. <el-card shadow="hover" class="stat-card stat-card--green">
  25. <div class="stat-title">新鲜闪购</div>
  26. <div class="stat-value">{{ stats.flashSale }}</div>
  27. </el-card>
  28. </el-col>
  29. </el-row>
  30. <el-row :gutter="12" class="chart-row">
  31. <el-col :xs="24" :sm="24" :md="14" :lg="14" :xl="14">
  32. <el-card shadow="hover">
  33. <template #header>
  34. <span>商品状态统计</span>
  35. </template>
  36. <div ref="goodsStatusRef" class="chart" />
  37. </el-card>
  38. </el-col>
  39. <el-col :xs="24" :sm="24" :md="10" :lg="10" :xl="10">
  40. <el-card shadow="hover">
  41. <template #header>
  42. <span>新鲜好物分布</span>
  43. </template>
  44. <div ref="freshPieRef" class="chart" />
  45. </el-card>
  46. </el-col>
  47. </el-row>
  48. <el-row :gutter="12" class="info-row">
  49. <el-col :xs="24" :sm="24" :md="14" :lg="14" :xl="14">
  50. <el-card shadow="hover">
  51. <template #header>
  52. <span>新鲜闪购TOP5</span>
  53. </template>
  54. <div class="top-list">
  55. <div v-for="(item, idx) in freshTop" :key="idx" class="top-item">
  56. <div class="top-left">
  57. <span class="top-rank">{{ idx + 1 }}</span>
  58. <span class="top-name">{{ item.name }}</span>
  59. </div>
  60. <div class="top-right">{{ item.count }}件</div>
  61. </div>
  62. </div>
  63. </el-card>
  64. </el-col>
  65. <el-col :xs="24" :sm="24" :md="10" :lg="10" :xl="10">
  66. <el-card shadow="hover">
  67. <template #header>
  68. <span>待处理</span>
  69. </template>
  70. <div class="todo-box">
  71. <div class="todo-item">
  72. <span class="todo-label">商品审核</span>
  73. <span class="todo-value">{{ pending.review }}</span>
  74. </div>
  75. <div class="todo-item">
  76. <span class="todo-label">上下架申请</span>
  77. <span class="todo-value">{{ pending.shelfApply }}</span>
  78. </div>
  79. <div class="todo-item">
  80. <span class="todo-label">停售复核</span>
  81. <span class="todo-value">{{ pending.stopCheck }}</span>
  82. </div>
  83. </div>
  84. </el-card>
  85. </el-col>
  86. </el-row>
  87. </div>
  88. </template>
  89. <script setup name="Index" lang="ts">
  90. import * as echarts from 'echarts';
  91. const goodsStatusRef = ref();
  92. const freshPieRef = ref();
  93. let goodsStatusChart: echarts.ECharts | null = null;
  94. let freshPieChart: echarts.ECharts | null = null;
  95. const stats = reactive({
  96. totalGoods: 0,
  97. stoppedGoods: 0,
  98. shelfApply: 0,
  99. flashSale: 0
  100. });
  101. const freshTop = ref([
  102. { name: '精品草莓(500g)', count: 12 },
  103. { name: '云南小番茄(1kg)', count: 10 },
  104. { name: '原切牛排(2片)', count: 8 },
  105. { name: '高山生菜(2颗)', count: 7 },
  106. { name: '鲜活基围虾(500g)', count: 6 }
  107. ]);
  108. const pending = reactive({
  109. review: 5,
  110. shelfApply: 12,
  111. stopCheck: 3
  112. });
  113. const renderCharts = () => {
  114. stats.totalGoods = 1280;
  115. stats.stoppedGoods = 36;
  116. stats.shelfApply = 12;
  117. stats.flashSale = 58;
  118. const goodsStatus = [
  119. { name: '商品总数', value: stats.totalGoods },
  120. { name: '停售商品', value: stats.stoppedGoods },
  121. { name: '上下架申请', value: stats.shelfApply },
  122. { name: '新鲜闪购', value: stats.flashSale }
  123. ];
  124. if (goodsStatusRef.value) {
  125. goodsStatusChart?.dispose();
  126. goodsStatusChart = echarts.init(goodsStatusRef.value, 'macarons');
  127. goodsStatusChart.setOption({
  128. tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
  129. grid: { left: 20, right: 20, bottom: 20, top: 20, containLabel: true },
  130. xAxis: { type: 'category', data: goodsStatus.map((i) => i.name), axisLabel: { interval: 0 } },
  131. yAxis: { type: 'value' },
  132. series: [{ type: 'bar', data: goodsStatus.map((i) => i.value), barMaxWidth: 40 }]
  133. });
  134. }
  135. const freshGoods = [
  136. { name: '果蔬生鲜', value: 18 },
  137. { name: '零食饮料', value: 14 },
  138. { name: '粮油调味', value: 9 },
  139. { name: '日用百货', value: 11 },
  140. { name: '乳品烘焙', value: 6 }
  141. ];
  142. if (freshPieRef.value) {
  143. freshPieChart?.dispose();
  144. freshPieChart = echarts.init(freshPieRef.value, 'macarons');
  145. freshPieChart.setOption({
  146. tooltip: { trigger: 'item', formatter: '{b}: {c} ({d}%)' },
  147. legend: { top: 'bottom' },
  148. series: [
  149. {
  150. type: 'pie',
  151. radius: ['38%', '72%'],
  152. center: ['50%', '45%'],
  153. label: { show: true, formatter: '{b}' },
  154. data: freshGoods
  155. }
  156. ]
  157. });
  158. }
  159. };
  160. const resizeCharts = () => {
  161. goodsStatusChart?.resize();
  162. freshPieChart?.resize();
  163. };
  164. onMounted(() => {
  165. renderCharts();
  166. window.addEventListener('resize', resizeCharts);
  167. });
  168. onBeforeUnmount(() => {
  169. window.removeEventListener('resize', resizeCharts);
  170. goodsStatusChart?.dispose();
  171. goodsStatusChart = null;
  172. freshPieChart?.dispose();
  173. freshPieChart = null;
  174. });
  175. </script>
  176. <style lang="scss" scoped>
  177. .home {
  178. blockquote {
  179. padding: 10px 20px;
  180. margin: 0 0 20px;
  181. font-size: 17.5px;
  182. border-left: 5px solid #eee;
  183. }
  184. hr {
  185. margin-top: 20px;
  186. margin-bottom: 20px;
  187. border: 0;
  188. border-top: 1px solid #eee;
  189. }
  190. .col-item {
  191. margin-bottom: 20px;
  192. }
  193. ul {
  194. padding: 0;
  195. margin: 0;
  196. }
  197. font-family: 'open sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  198. font-size: 13px;
  199. color: #676a6c;
  200. overflow-x: hidden;
  201. ul {
  202. list-style-type: none;
  203. }
  204. h4 {
  205. margin-top: 0px;
  206. }
  207. h2 {
  208. margin-top: 10px;
  209. font-size: 26px;
  210. font-weight: 100;
  211. }
  212. p {
  213. margin-top: 10px;
  214. b {
  215. font-weight: 700;
  216. }
  217. }
  218. .chart-row {
  219. margin-top: 12px;
  220. }
  221. .info-row {
  222. margin-top: 12px;
  223. }
  224. .stat-row {
  225. margin-bottom: 12px;
  226. }
  227. .stat-card {
  228. height: 92px;
  229. border-radius: 10px;
  230. overflow: hidden;
  231. color: #fff;
  232. }
  233. .stat-title {
  234. font-size: 14px;
  235. opacity: 0.9;
  236. }
  237. .stat-value {
  238. font-size: 26px;
  239. font-weight: 600;
  240. margin-top: 6px;
  241. }
  242. .stat-card--blue {
  243. background: linear-gradient(135deg, #2d8cf0 0%, #57a3f3 100%);
  244. }
  245. .stat-card--orange {
  246. background: linear-gradient(135deg, #ff9900 0%, #ffb347 100%);
  247. }
  248. .stat-card--purple {
  249. background: linear-gradient(135deg, #7c5cff 0%, #a491ff 100%);
  250. }
  251. .stat-card--green {
  252. background: linear-gradient(135deg, #19be6b 0%, #47cb89 100%);
  253. }
  254. .chart {
  255. height: 320px;
  256. width: 100%;
  257. }
  258. .top-list {
  259. display: flex;
  260. flex-direction: column;
  261. gap: 10px;
  262. }
  263. .top-item {
  264. display: flex;
  265. align-items: center;
  266. justify-content: space-between;
  267. }
  268. .top-left {
  269. display: flex;
  270. align-items: center;
  271. gap: 10px;
  272. min-width: 0;
  273. }
  274. .top-rank {
  275. display: inline-flex;
  276. align-items: center;
  277. justify-content: center;
  278. width: 22px;
  279. height: 22px;
  280. border-radius: 6px;
  281. background: rgba(45, 140, 240, 0.12);
  282. color: #2d8cf0;
  283. font-size: 12px;
  284. flex: 0 0 auto;
  285. }
  286. .top-name {
  287. color: #303133;
  288. white-space: nowrap;
  289. overflow: hidden;
  290. text-overflow: ellipsis;
  291. }
  292. .top-right {
  293. color: #606266;
  294. flex: 0 0 auto;
  295. }
  296. .todo-box {
  297. display: flex;
  298. flex-direction: column;
  299. gap: 10px;
  300. }
  301. .todo-item {
  302. display: flex;
  303. align-items: center;
  304. justify-content: space-between;
  305. }
  306. .todo-label {
  307. color: #606266;
  308. }
  309. .todo-value {
  310. font-weight: 600;
  311. color: #303133;
  312. }
  313. .update-log {
  314. ol {
  315. display: block;
  316. list-style-type: decimal;
  317. margin-block-start: 1em;
  318. margin-block-end: 1em;
  319. margin-inline-start: 0;
  320. margin-inline-end: 0;
  321. padding-inline-start: 40px;
  322. }
  323. }
  324. }
  325. </style>