Index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <script setup lang="ts">
  2. import { ElRow, ElCol, ElSkeleton, ElCard, ElDivider, ElLink } from 'element-plus'
  3. import { useI18n } from '@/hooks/web/useI18n'
  4. import { ref, reactive } from 'vue'
  5. import { CountTo } from '@/components/CountTo'
  6. import { formatTime } from '@/utils'
  7. import { Echart } from '@/components/Echart'
  8. import { EChartsOption } from 'echarts'
  9. import { radarOption } from './echarts-data'
  10. import { Highlight } from '@/components/Highlight'
  11. import type { WorkplaceTotal, Project, Notice, Shortcut } from './types'
  12. import { set } from 'lodash-es'
  13. import { useCache } from '@/hooks/web/useCache'
  14. import { pieOptions, barOptions, lineOptions } from './echarts-data'
  15. const { t } = useI18n()
  16. const { wsCache } = useCache()
  17. const loading = ref(true)
  18. const avatar = wsCache.get('user').user.avatar
  19. const username = wsCache.get('user').user.nickname
  20. const pieOptionsData = reactive<EChartsOption>(pieOptions) as EChartsOption
  21. // 获取统计数
  22. let totalSate = reactive<WorkplaceTotal>({
  23. project: 0,
  24. access: 0,
  25. todo: 0
  26. })
  27. const getCount = async () => {
  28. const data = {
  29. project: 40,
  30. access: 2340,
  31. todo: 10
  32. }
  33. totalSate = Object.assign(totalSate, data)
  34. }
  35. // 获取项目数
  36. let projects = reactive<Project[]>([])
  37. const getProject = async () => {
  38. const data = [
  39. {
  40. name: 'Github',
  41. icon: 'akar-icons:github-fill',
  42. message: 'workplace.introduction',
  43. personal: 'Archer',
  44. time: new Date()
  45. },
  46. {
  47. name: 'Vue',
  48. icon: 'logos:vue',
  49. message: 'workplace.introduction',
  50. personal: 'Archer',
  51. time: new Date()
  52. },
  53. {
  54. name: 'Angular',
  55. icon: 'logos:angular-icon',
  56. message: 'workplace.introduction',
  57. personal: 'Archer',
  58. time: new Date()
  59. },
  60. {
  61. name: 'React',
  62. icon: 'logos:react',
  63. message: 'workplace.introduction',
  64. personal: 'Archer',
  65. time: new Date()
  66. },
  67. {
  68. name: 'Webpack',
  69. icon: 'logos:webpack',
  70. message: 'workplace.introduction',
  71. personal: 'Archer',
  72. time: new Date()
  73. },
  74. {
  75. name: 'Vite',
  76. icon: 'vscode-icons:file-type-vite',
  77. message: 'workplace.introduction',
  78. personal: 'Archer',
  79. time: new Date()
  80. }
  81. ]
  82. projects = Object.assign(projects, data)
  83. }
  84. // 获取通知公告
  85. let notice = reactive<Notice[]>([])
  86. const getNotice = async () => {
  87. const data = [
  88. {
  89. title: '系统升级版本',
  90. type: '通知',
  91. keys: ['通知', '升级'],
  92. date: new Date()
  93. },
  94. {
  95. title: '系统凌晨维护',
  96. type: '公告',
  97. keys: ['公告', '维护'],
  98. date: new Date()
  99. },
  100. {
  101. title: '系统升级版本',
  102. type: '通知',
  103. keys: ['通知', '升级'],
  104. date: new Date()
  105. },
  106. {
  107. title: '系统凌晨维护',
  108. type: '公告',
  109. keys: ['公告', '维护'],
  110. date: new Date()
  111. }
  112. ]
  113. notice = Object.assign(notice, data)
  114. }
  115. // 获取快捷入口
  116. let shortcut = reactive<Shortcut[]>([])
  117. const getShortcut = async () => {
  118. const data = [
  119. {
  120. name: 'Github',
  121. icon: 'akar-icons:github-fill',
  122. url: 'github.io'
  123. },
  124. {
  125. name: 'Vue',
  126. icon: 'logos:vue',
  127. url: 'vuejs.org'
  128. },
  129. {
  130. name: 'Vite',
  131. icon: 'vscode-icons:file-type-vite',
  132. url: 'https://vitejs.dev/'
  133. },
  134. {
  135. name: 'Angular',
  136. icon: 'logos:angular-icon',
  137. url: 'github.io'
  138. },
  139. {
  140. name: 'React',
  141. icon: 'logos:react',
  142. url: 'github.io'
  143. },
  144. {
  145. name: 'Webpack',
  146. icon: 'logos:webpack',
  147. url: 'github.io'
  148. }
  149. ]
  150. shortcut = Object.assign(shortcut, data)
  151. }
  152. // 获取指数
  153. let radarOptionData = reactive<EChartsOption>(radarOption) as EChartsOption
  154. const getRadar = async () => {
  155. const data = [
  156. { name: 'workplace.quote', max: 65, personal: 42, team: 50 },
  157. { name: 'workplace.contribution', max: 160, personal: 30, team: 140 },
  158. { name: 'workplace.hot', max: 300, personal: 20, team: 28 },
  159. { name: 'workplace.yield', max: 130, personal: 35, team: 35 },
  160. { name: 'workplace.follow', max: 100, personal: 80, team: 90 }
  161. ]
  162. set(
  163. radarOptionData,
  164. 'radar.indicator',
  165. data.map((v) => {
  166. return {
  167. name: t(v.name),
  168. max: v.max
  169. }
  170. })
  171. )
  172. set(radarOptionData, 'series', [
  173. {
  174. name: '指数',
  175. type: 'radar',
  176. data: [
  177. {
  178. value: data.map((v) => v.personal),
  179. name: t('workplace.personal')
  180. },
  181. {
  182. value: data.map((v) => v.team),
  183. name: t('workplace.team')
  184. }
  185. ]
  186. }
  187. ])
  188. }
  189. // 用户来源
  190. const getUserAccessSource = async () => {
  191. const data = [
  192. { value: 335, name: 'analysis.directAccess' },
  193. { value: 310, name: 'analysis.mailMarketing' },
  194. { value: 234, name: 'analysis.allianceAdvertising' },
  195. { value: 135, name: 'analysis.videoAdvertising' },
  196. { value: 1548, name: 'analysis.searchEngines' }
  197. ]
  198. set(
  199. pieOptionsData,
  200. 'legend.data',
  201. data.map((v) => t(v.name))
  202. )
  203. set(pieOptionsData, 'series.data', data)
  204. }
  205. const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption
  206. // 周活跃量
  207. const getWeeklyUserActivity = async () => {
  208. const data = [
  209. { value: 13253, name: 'analysis.monday' },
  210. { value: 34235, name: 'analysis.tuesday' },
  211. { value: 26321, name: 'analysis.wednesday' },
  212. { value: 12340, name: 'analysis.thursday' },
  213. { value: 24643, name: 'analysis.friday' },
  214. { value: 1322, name: 'analysis.saturday' },
  215. { value: 1324, name: 'analysis.sunday' }
  216. ]
  217. set(
  218. barOptionsData,
  219. 'xAxis.data',
  220. data.map((v) => t(v.name))
  221. )
  222. set(barOptionsData, 'series', [
  223. {
  224. name: t('analysis.activeQuantity'),
  225. data: data.map((v) => v.value),
  226. type: 'bar'
  227. }
  228. ])
  229. }
  230. const lineOptionsData = reactive<EChartsOption>(lineOptions) as EChartsOption
  231. // 每月销售总额
  232. const getMonthlySales = async () => {
  233. const data = [
  234. { estimate: 100, actual: 120, name: 'analysis.january' },
  235. { estimate: 120, actual: 82, name: 'analysis.february' },
  236. { estimate: 161, actual: 91, name: 'analysis.march' },
  237. { estimate: 134, actual: 154, name: 'analysis.april' },
  238. { estimate: 105, actual: 162, name: 'analysis.may' },
  239. { estimate: 160, actual: 140, name: 'analysis.june' },
  240. { estimate: 165, actual: 145, name: 'analysis.july' },
  241. { estimate: 114, actual: 250, name: 'analysis.august' },
  242. { estimate: 163, actual: 134, name: 'analysis.september' },
  243. { estimate: 185, actual: 56, name: 'analysis.october' },
  244. { estimate: 118, actual: 99, name: 'analysis.november' },
  245. { estimate: 123, actual: 123, name: 'analysis.december' }
  246. ]
  247. set(
  248. lineOptionsData,
  249. 'xAxis.data',
  250. data.map((v) => t(v.name))
  251. )
  252. set(lineOptionsData, 'series', [
  253. {
  254. name: t('analysis.estimate'),
  255. smooth: true,
  256. type: 'line',
  257. data: data.map((v) => v.estimate),
  258. animationDuration: 2800,
  259. animationEasing: 'cubicInOut'
  260. },
  261. {
  262. name: t('analysis.actual'),
  263. smooth: true,
  264. type: 'line',
  265. itemStyle: {},
  266. data: data.map((v) => v.actual),
  267. animationDuration: 2800,
  268. animationEasing: 'quadraticOut'
  269. }
  270. ])
  271. }
  272. const getAllApi = async () => {
  273. await Promise.all([
  274. getCount(),
  275. getProject(),
  276. getNotice(),
  277. getShortcut(),
  278. getRadar(),
  279. getUserAccessSource(),
  280. getWeeklyUserActivity(),
  281. getMonthlySales()
  282. ])
  283. loading.value = false
  284. }
  285. getAllApi()
  286. </script>
  287. <template>
  288. <div>
  289. <el-card shadow="never">
  290. <el-skeleton :loading="loading" animated>
  291. <el-row :gutter="20" justify="space-between">
  292. <el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
  293. <div class="flex items-center">
  294. <img :src="avatar" alt="" class="w-70px h-70px rounded-[50%] mr-20px" />
  295. <div>
  296. <div class="text-20px text-700">
  297. {{ t('workplace.welcome') }} {{ username }} {{ t('workplace.happyDay') }}
  298. </div>
  299. <div class="mt-10px text-14px text-gray-500">
  300. {{ t('workplace.toady') }},20℃ - 32℃!
  301. </div>
  302. </div>
  303. </div>
  304. </el-col>
  305. <el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
  306. <div class="flex h-70px items-center justify-end <sm:mt-10px">
  307. <div class="px-8px text-right">
  308. <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.project') }}</div>
  309. <CountTo
  310. class="text-20px"
  311. :start-val="0"
  312. :end-val="totalSate.project"
  313. :duration="2600"
  314. />
  315. </div>
  316. <el-divider direction="vertical" />
  317. <div class="px-8px text-right">
  318. <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.toDo') }}</div>
  319. <CountTo
  320. class="text-20px"
  321. :start-val="0"
  322. :end-val="totalSate.todo"
  323. :duration="2600"
  324. />
  325. </div>
  326. <el-divider direction="vertical" border-style="dashed" />
  327. <div class="px-8px text-right">
  328. <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.access') }}</div>
  329. <CountTo
  330. class="text-20px"
  331. :start-val="0"
  332. :end-val="totalSate.access"
  333. :duration="2600"
  334. />
  335. </div>
  336. </div>
  337. </el-col>
  338. </el-row>
  339. </el-skeleton>
  340. </el-card>
  341. </div>
  342. <el-row class="mt-10px" :gutter="20" justify="space-between">
  343. <el-col :xl="16" :lg="16" :md="24" :sm="24" :xs="24" class="mb-20px">
  344. <el-card shadow="never">
  345. <template #header>
  346. <div class="flex justify-between">
  347. <span>{{ t('workplace.project') }}</span>
  348. <el-link type="primary" :underline="false">{{ t('workplace.more') }}</el-link>
  349. </div>
  350. </template>
  351. <el-skeleton :loading="loading" animated>
  352. <el-row>
  353. <el-col
  354. v-for="(item, index) in projects"
  355. :key="`card-${index}`"
  356. :xl="8"
  357. :lg="8"
  358. :md="12"
  359. :sm="24"
  360. :xs="24"
  361. >
  362. <el-card shadow="hover">
  363. <div class="flex items-center">
  364. <Icon :icon="item.icon" :size="25" class="mr-10px" />
  365. <span class="text-16px">{{ item.name }}</span>
  366. </div>
  367. <div class="mt-15px text-14px text-gray-400">{{ t(item.message) }}</div>
  368. <div class="mt-20px text-12px text-gray-400 flex justify-between">
  369. <span>{{ item.personal }}</span>
  370. <span>{{ formatTime(item.time, 'yyyy-MM-dd') }}</span>
  371. </div>
  372. </el-card>
  373. </el-col>
  374. </el-row>
  375. </el-skeleton>
  376. </el-card>
  377. <el-card shadow="never" class="mt-10px">
  378. <el-skeleton :loading="loading" animated>
  379. <el-row :gutter="20" justify="space-between">
  380. <el-col :xl="10" :lg="10" :md="24" :sm="24" :xs="24">
  381. <el-card shadow="hover" class="mb-20px">
  382. <el-skeleton :loading="loading" animated>
  383. <Echart :options="pieOptionsData" :height="300" />
  384. </el-skeleton>
  385. </el-card>
  386. </el-col>
  387. <el-col :xl="14" :lg="14" :md="24" :sm="24" :xs="24">
  388. <el-card shadow="hover" class="mb-20px">
  389. <el-skeleton :loading="loading" animated>
  390. <Echart :options="barOptionsData" :height="300" />
  391. </el-skeleton>
  392. </el-card>
  393. </el-col>
  394. <el-col :span="24">
  395. <el-card shadow="hover" class="mb-20px">
  396. <el-skeleton :loading="loading" animated :rows="4">
  397. <Echart :options="lineOptionsData" :height="350" />
  398. </el-skeleton>
  399. </el-card>
  400. </el-col>
  401. </el-row>
  402. </el-skeleton>
  403. </el-card>
  404. </el-col>
  405. <el-col :xl="8" :lg="8" :md="24" :sm="24" :xs="24" class="mb-20px">
  406. <el-card shadow="never">
  407. <template #header>
  408. <span>{{ t('workplace.shortcutOperation') }}</span>
  409. </template>
  410. <el-skeleton :loading="loading" animated>
  411. <el-row>
  412. <el-col v-for="item in shortcut" :key="`team-${item.name}`" :span="8" class="mb-20px">
  413. <div class="flex items-center">
  414. <Icon :icon="item.icon" class="mr-10px" />
  415. <el-link type="default" :underline="false" :href="item.url">
  416. {{ item.name }}
  417. </el-link>
  418. </div>
  419. </el-col>
  420. </el-row>
  421. </el-skeleton>
  422. </el-card>
  423. <el-card shadow="never" class="mt-10px">
  424. <template #header>
  425. <div class="flex justify-between">
  426. <span>{{ t('workplace.notice') }}</span>
  427. <el-link type="primary" :underline="false">{{ t('workplace.more') }}</el-link>
  428. </div>
  429. </template>
  430. <el-skeleton :loading="loading" animated>
  431. <div v-for="(item, index) in notice" :key="`dynamics-${index}`">
  432. <div class="flex items-center">
  433. <img :src="avatar" alt="" class="w-35px h-35px rounded-[50%] mr-20px" />
  434. <div>
  435. <div class="text-14px">
  436. <Highlight :keys="item.keys.map((v) => t(v))">
  437. {{ item.type }} : {{ item.title }}
  438. </Highlight>
  439. </div>
  440. <div class="mt-15px text-12px text-gray-400">
  441. {{ formatTime(item.date, 'yyyy-MM-dd') }}
  442. </div>
  443. </div>
  444. </div>
  445. <el-divider />
  446. </div>
  447. </el-skeleton>
  448. </el-card>
  449. <el-card shadow="never" class="mt-10px">
  450. <template #header>
  451. <span>{{ t('workplace.index') }}</span>
  452. </template>
  453. <el-skeleton :loading="loading" animated>
  454. <Echart :options="radarOptionData" :height="400" />
  455. </el-skeleton>
  456. </el-card>
  457. </el-col>
  458. </el-row>
  459. </template>