Index2.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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-20px font-700 text-right"
  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-20px font-700 text-right"
  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-20px font-700 text-right"
  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-20px font-700 text-right"
  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" name="Home2" 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. const { t } = useI18n()
  147. const loading = ref(true)
  148. const { getPrefixCls } = useDesign()
  149. const prefixCls = getPrefixCls('panel')
  150. const pieOptionsData = reactive<EChartsOption>(pieOptions) as EChartsOption
  151. let totalState = reactive<AnalysisTotalTypes>({
  152. users: 0,
  153. messages: 0,
  154. moneys: 0,
  155. shoppings: 0
  156. })
  157. const getCount = async () => {
  158. const data = {
  159. users: 102400,
  160. messages: 81212,
  161. moneys: 9280,
  162. shoppings: 13600
  163. }
  164. totalState = Object.assign(totalState, data)
  165. }
  166. // 用户来源
  167. const getUserAccessSource = async () => {
  168. const data = [
  169. { value: 335, name: 'analysis.directAccess' },
  170. { value: 310, name: 'analysis.mailMarketing' },
  171. { value: 234, name: 'analysis.allianceAdvertising' },
  172. { value: 135, name: 'analysis.videoAdvertising' },
  173. { value: 1548, name: 'analysis.searchEngines' }
  174. ]
  175. set(
  176. pieOptionsData,
  177. 'legend.data',
  178. data.map((v) => t(v.name))
  179. )
  180. set(pieOptionsData, 'series.data', data)
  181. }
  182. const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption
  183. // 周活跃量
  184. const getWeeklyUserActivity = async () => {
  185. const data = [
  186. { value: 13253, name: 'analysis.monday' },
  187. { value: 34235, name: 'analysis.tuesday' },
  188. { value: 26321, name: 'analysis.wednesday' },
  189. { value: 12340, name: 'analysis.thursday' },
  190. { value: 24643, name: 'analysis.friday' },
  191. { value: 1322, name: 'analysis.saturday' },
  192. { value: 1324, name: 'analysis.sunday' }
  193. ]
  194. set(
  195. barOptionsData,
  196. 'xAxis.data',
  197. data.map((v) => t(v.name))
  198. )
  199. set(barOptionsData, 'series', [
  200. {
  201. name: t('analysis.activeQuantity'),
  202. data: data.map((v) => v.value),
  203. type: 'bar'
  204. }
  205. ])
  206. }
  207. const lineOptionsData = reactive<EChartsOption>(lineOptions) as EChartsOption
  208. // 每月销售总额
  209. const getMonthlySales = async () => {
  210. const data = [
  211. { estimate: 100, actual: 120, name: 'analysis.january' },
  212. { estimate: 120, actual: 82, name: 'analysis.february' },
  213. { estimate: 161, actual: 91, name: 'analysis.march' },
  214. { estimate: 134, actual: 154, name: 'analysis.april' },
  215. { estimate: 105, actual: 162, name: 'analysis.may' },
  216. { estimate: 160, actual: 140, name: 'analysis.june' },
  217. { estimate: 165, actual: 145, name: 'analysis.july' },
  218. { estimate: 114, actual: 250, name: 'analysis.august' },
  219. { estimate: 163, actual: 134, name: 'analysis.september' },
  220. { estimate: 185, actual: 56, name: 'analysis.october' },
  221. { estimate: 118, actual: 99, name: 'analysis.november' },
  222. { estimate: 123, actual: 123, name: 'analysis.december' }
  223. ]
  224. set(
  225. lineOptionsData,
  226. 'xAxis.data',
  227. data.map((v) => t(v.name))
  228. )
  229. set(lineOptionsData, 'series', [
  230. {
  231. name: t('analysis.estimate'),
  232. smooth: true,
  233. type: 'line',
  234. data: data.map((v) => v.estimate),
  235. animationDuration: 2800,
  236. animationEasing: 'cubicInOut'
  237. },
  238. {
  239. name: t('analysis.actual'),
  240. smooth: true,
  241. type: 'line',
  242. itemStyle: {},
  243. data: data.map((v) => v.actual),
  244. animationDuration: 2800,
  245. animationEasing: 'quadraticOut'
  246. }
  247. ])
  248. }
  249. const getAllApi = async () => {
  250. await Promise.all([getCount(), getUserAccessSource(), getWeeklyUserActivity(), getMonthlySales()])
  251. loading.value = false
  252. }
  253. getAllApi()
  254. </script>
  255. <style lang="scss" scoped>
  256. $prefix-cls: #{$namespace}-panel;
  257. .#{$prefix-cls} {
  258. &__item {
  259. &--peoples {
  260. color: #40c9c6;
  261. }
  262. &--message {
  263. color: #36a3f7;
  264. }
  265. &--money {
  266. color: #f4516c;
  267. }
  268. &--shopping {
  269. color: #34bfa3;
  270. }
  271. &:hover {
  272. :deep(.#{$namespace}-icon) {
  273. color: #fff !important;
  274. }
  275. .#{$prefix-cls}__item--icon {
  276. transition: all 0.38s ease-out;
  277. }
  278. .#{$prefix-cls}__item--peoples {
  279. background: #40c9c6;
  280. }
  281. .#{$prefix-cls}__item--message {
  282. background: #36a3f7;
  283. }
  284. .#{$prefix-cls}__item--money {
  285. background: #f4516c;
  286. }
  287. .#{$prefix-cls}__item--shopping {
  288. background: #34bfa3;
  289. }
  290. }
  291. }
  292. }
  293. </style>