Index2.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <el-row :class="prefixCls" :gutter="20" justify="space-between">
  3. <el-col :lg="6" :md="12" :sm="12" :xl="6" :xs="24">
  4. <el-card class="mb-20px" shadow="hover">
  5. <el-skeleton :loading="loading" :rows="2" animated>
  6. <template #default>
  7. <div :class="`${prefixCls}__item flex justify-between`">
  8. <div>
  9. <div
  10. :class="`${prefixCls}__item--icon ${prefixCls}__item--peoples p-16px inline-block rounded-6px`"
  11. >
  12. <Icon :size="40" icon="svg-icon:peoples" />
  13. </div>
  14. </div>
  15. <div class="flex flex-col justify-between">
  16. <div :class="`${prefixCls}__item--text text-16px text-gray-500 text-right`"
  17. >{{ t('analysis.newUser') }}
  18. </div>
  19. <CountTo
  20. :duration="2600"
  21. :end-val="102400"
  22. :start-val="0"
  23. class="text-right text-20px font-700"
  24. />
  25. </div>
  26. </div>
  27. </template>
  28. </el-skeleton>
  29. </el-card>
  30. </el-col>
  31. <el-col :lg="6" :md="12" :sm="12" :xl="6" :xs="24">
  32. <el-card class="mb-20px" shadow="hover">
  33. <el-skeleton :loading="loading" :rows="2" animated>
  34. <template #default>
  35. <div :class="`${prefixCls}__item flex justify-between`">
  36. <div>
  37. <div
  38. :class="`${prefixCls}__item--icon ${prefixCls}__item--message p-16px inline-block rounded-6px`"
  39. >
  40. <Icon :size="40" icon="svg-icon:message" />
  41. </div>
  42. </div>
  43. <div class="flex flex-col justify-between">
  44. <div :class="`${prefixCls}__item--text text-16px text-gray-500 text-right`"
  45. >{{ t('analysis.unreadInformation') }}
  46. </div>
  47. <CountTo
  48. :duration="2600"
  49. :end-val="81212"
  50. :start-val="0"
  51. class="text-right text-20px font-700"
  52. />
  53. </div>
  54. </div>
  55. </template>
  56. </el-skeleton>
  57. </el-card>
  58. </el-col>
  59. <el-col :lg="6" :md="12" :sm="12" :xl="6" :xs="24">
  60. <el-card class="mb-20px" shadow="hover">
  61. <el-skeleton :loading="loading" :rows="2" animated>
  62. <template #default>
  63. <div :class="`${prefixCls}__item flex justify-between`">
  64. <div>
  65. <div
  66. :class="`${prefixCls}__item--icon ${prefixCls}__item--money p-16px inline-block rounded-6px`"
  67. >
  68. <Icon :size="40" icon="svg-icon:money" />
  69. </div>
  70. </div>
  71. <div class="flex flex-col justify-between">
  72. <div :class="`${prefixCls}__item--text text-16px text-gray-500 text-right`"
  73. >{{ t('analysis.transactionAmount') }}
  74. </div>
  75. <CountTo
  76. :duration="2600"
  77. :end-val="9280"
  78. :start-val="0"
  79. class="text-right text-20px font-700"
  80. />
  81. </div>
  82. </div>
  83. </template>
  84. </el-skeleton>
  85. </el-card>
  86. </el-col>
  87. <el-col :lg="6" :md="12" :sm="12" :xl="6" :xs="24">
  88. <el-card class="mb-20px" shadow="hover">
  89. <el-skeleton :loading="loading" :rows="2" animated>
  90. <template #default>
  91. <div :class="`${prefixCls}__item flex justify-between`">
  92. <div>
  93. <div
  94. :class="`${prefixCls}__item--icon ${prefixCls}__item--shopping p-16px inline-block rounded-6px`"
  95. >
  96. <Icon :size="40" icon="svg-icon:shopping" />
  97. </div>
  98. </div>
  99. <div class="flex flex-col justify-between">
  100. <div :class="`${prefixCls}__item--text text-16px text-gray-500 text-right`"
  101. >{{ t('analysis.totalShopping') }}
  102. </div>
  103. <CountTo
  104. :duration="2600"
  105. :end-val="13600"
  106. :start-val="0"
  107. class="text-right text-20px font-700"
  108. />
  109. </div>
  110. </div>
  111. </template>
  112. </el-skeleton>
  113. </el-card>
  114. </el-col>
  115. </el-row>
  116. <el-row :gutter="20" justify="space-between">
  117. <el-col :lg="10" :md="24" :sm="24" :xl="10" :xs="24">
  118. <el-card class="mb-20px" shadow="hover">
  119. <el-skeleton :loading="loading" animated>
  120. <Echart :height="300" :options="pieOptionsData" />
  121. </el-skeleton>
  122. </el-card>
  123. </el-col>
  124. <el-col :lg="14" :md="24" :sm="24" :xl="14" :xs="24">
  125. <el-card class="mb-20px" shadow="hover">
  126. <el-skeleton :loading="loading" animated>
  127. <Echart :height="300" :options="barOptionsData" />
  128. </el-skeleton>
  129. </el-card>
  130. </el-col>
  131. <el-col :span="24">
  132. <el-card class="mb-20px" shadow="hover">
  133. <el-skeleton :loading="loading" :rows="4" animated>
  134. <Echart :height="350" :options="lineOptionsData" />
  135. </el-skeleton>
  136. </el-card>
  137. </el-col>
  138. </el-row>
  139. </template>
  140. <script lang="ts" setup>
  141. import { set } from 'lodash-es'
  142. import { EChartsOption } from 'echarts'
  143. import { useDesign } from '@/hooks/web/useDesign'
  144. import type { AnalysisTotalTypes } from './types'
  145. import { barOptions, lineOptions, pieOptions } from './echarts-data'
  146. defineOptions({ name: 'Home2' })
  147. const { t } = useI18n()
  148. const loading = ref(true)
  149. const { getPrefixCls } = useDesign()
  150. const prefixCls = getPrefixCls('panel')
  151. const pieOptionsData = reactive<EChartsOption>(pieOptions) as EChartsOption
  152. let totalState = reactive<AnalysisTotalTypes>({
  153. users: 0,
  154. messages: 0,
  155. moneys: 0,
  156. shoppings: 0
  157. })
  158. const getCount = async () => {
  159. const data = {
  160. users: 102400,
  161. messages: 81212,
  162. moneys: 9280,
  163. shoppings: 13600
  164. }
  165. totalState = Object.assign(totalState, data)
  166. }
  167. // 用户来源
  168. const getUserAccessSource = async () => {
  169. const data = [
  170. { value: 335, name: 'analysis.directAccess' },
  171. { value: 310, name: 'analysis.mailMarketing' },
  172. { value: 234, name: 'analysis.allianceAdvertising' },
  173. { value: 135, name: 'analysis.videoAdvertising' },
  174. { value: 1548, name: 'analysis.searchEngines' }
  175. ]
  176. set(
  177. pieOptionsData,
  178. 'legend.data',
  179. data.map((v) => t(v.name))
  180. )
  181. set(pieOptionsData, 'series.data', data)
  182. }
  183. const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption
  184. // 周活跃量
  185. const getWeeklyUserActivity = async () => {
  186. const data = [
  187. { value: 13253, name: 'analysis.monday' },
  188. { value: 34235, name: 'analysis.tuesday' },
  189. { value: 26321, name: 'analysis.wednesday' },
  190. { value: 12340, name: 'analysis.thursday' },
  191. { value: 24643, name: 'analysis.friday' },
  192. { value: 1322, name: 'analysis.saturday' },
  193. { value: 1324, name: 'analysis.sunday' }
  194. ]
  195. set(
  196. barOptionsData,
  197. 'xAxis.data',
  198. data.map((v) => t(v.name))
  199. )
  200. set(barOptionsData, 'series', [
  201. {
  202. name: t('analysis.activeQuantity'),
  203. data: data.map((v) => v.value),
  204. type: 'bar'
  205. }
  206. ])
  207. }
  208. const lineOptionsData = reactive<EChartsOption>(lineOptions) as EChartsOption
  209. // 每月销售总额
  210. const getMonthlySales = async () => {
  211. const data = [
  212. { estimate: 100, actual: 120, name: 'analysis.january' },
  213. { estimate: 120, actual: 82, name: 'analysis.february' },
  214. { estimate: 161, actual: 91, name: 'analysis.march' },
  215. { estimate: 134, actual: 154, name: 'analysis.april' },
  216. { estimate: 105, actual: 162, name: 'analysis.may' },
  217. { estimate: 160, actual: 140, name: 'analysis.june' },
  218. { estimate: 165, actual: 145, name: 'analysis.july' },
  219. { estimate: 114, actual: 250, name: 'analysis.august' },
  220. { estimate: 163, actual: 134, name: 'analysis.september' },
  221. { estimate: 185, actual: 56, name: 'analysis.october' },
  222. { estimate: 118, actual: 99, name: 'analysis.november' },
  223. { estimate: 123, actual: 123, name: 'analysis.december' }
  224. ]
  225. set(
  226. lineOptionsData,
  227. 'xAxis.data',
  228. data.map((v) => t(v.name))
  229. )
  230. set(lineOptionsData, 'series', [
  231. {
  232. name: t('analysis.estimate'),
  233. smooth: true,
  234. type: 'line',
  235. data: data.map((v) => v.estimate),
  236. animationDuration: 2800,
  237. animationEasing: 'cubicInOut'
  238. },
  239. {
  240. name: t('analysis.actual'),
  241. smooth: true,
  242. type: 'line',
  243. itemStyle: {},
  244. data: data.map((v) => v.actual),
  245. animationDuration: 2800,
  246. animationEasing: 'quadraticOut'
  247. }
  248. ])
  249. }
  250. const getAllApi = async () => {
  251. await Promise.all([getCount(), getUserAccessSource(), getWeeklyUserActivity(), getMonthlySales()])
  252. loading.value = false
  253. }
  254. getAllApi()
  255. </script>
  256. <style lang="scss" scoped>
  257. $prefix-cls: #{$namespace}-panel;
  258. .#{$prefix-cls} {
  259. &__item {
  260. &--peoples {
  261. color: #40c9c6;
  262. }
  263. &--message {
  264. color: #36a3f7;
  265. }
  266. &--money {
  267. color: #f4516c;
  268. }
  269. &--shopping {
  270. color: #34bfa3;
  271. }
  272. &:hover {
  273. :deep(.#{$namespace}-icon) {
  274. color: #fff !important;
  275. }
  276. .#{$prefix-cls}__item--icon {
  277. transition: all 0.38s ease-out;
  278. }
  279. .#{$prefix-cls}__item--peoples {
  280. background: #40c9c6;
  281. }
  282. .#{$prefix-cls}__item--message {
  283. background: #36a3f7;
  284. }
  285. .#{$prefix-cls}__item--money {
  286. background: #f4516c;
  287. }
  288. .#{$prefix-cls}__item--shopping {
  289. background: #34bfa3;
  290. }
  291. }
  292. }
  293. }
  294. </style>