Index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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. pieOptionsData!.series![0].data = data.map((v) => {
  204. return {
  205. name: t(v.name),
  206. value: v.value
  207. }
  208. })
  209. }
  210. const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption
  211. // 周活跃量
  212. const getWeeklyUserActivity = async () => {
  213. const data = [
  214. { value: 13253, name: 'analysis.monday' },
  215. { value: 34235, name: 'analysis.tuesday' },
  216. { value: 26321, name: 'analysis.wednesday' },
  217. { value: 12340, name: 'analysis.thursday' },
  218. { value: 24643, name: 'analysis.friday' },
  219. { value: 1322, name: 'analysis.saturday' },
  220. { value: 1324, name: 'analysis.sunday' }
  221. ]
  222. set(
  223. barOptionsData,
  224. 'xAxis.data',
  225. data.map((v) => t(v.name))
  226. )
  227. set(barOptionsData, 'series', [
  228. {
  229. name: t('analysis.activeQuantity'),
  230. data: data.map((v) => v.value),
  231. type: 'bar'
  232. }
  233. ])
  234. }
  235. const lineOptionsData = reactive<EChartsOption>(lineOptions) as EChartsOption
  236. // 每月销售总额
  237. const getMonthlySales = async () => {
  238. const data = [
  239. { estimate: 100, actual: 120, name: 'analysis.january' },
  240. { estimate: 120, actual: 82, name: 'analysis.february' },
  241. { estimate: 161, actual: 91, name: 'analysis.march' },
  242. { estimate: 134, actual: 154, name: 'analysis.april' },
  243. { estimate: 105, actual: 162, name: 'analysis.may' },
  244. { estimate: 160, actual: 140, name: 'analysis.june' },
  245. { estimate: 165, actual: 145, name: 'analysis.july' },
  246. { estimate: 114, actual: 250, name: 'analysis.august' },
  247. { estimate: 163, actual: 134, name: 'analysis.september' },
  248. { estimate: 185, actual: 56, name: 'analysis.october' },
  249. { estimate: 118, actual: 99, name: 'analysis.november' },
  250. { estimate: 123, actual: 123, name: 'analysis.december' }
  251. ]
  252. set(
  253. lineOptionsData,
  254. 'xAxis.data',
  255. data.map((v) => t(v.name))
  256. )
  257. set(lineOptionsData, 'series', [
  258. {
  259. name: t('analysis.estimate'),
  260. smooth: true,
  261. type: 'line',
  262. data: data.map((v) => v.estimate),
  263. animationDuration: 2800,
  264. animationEasing: 'cubicInOut'
  265. },
  266. {
  267. name: t('analysis.actual'),
  268. smooth: true,
  269. type: 'line',
  270. itemStyle: {},
  271. data: data.map((v) => v.actual),
  272. animationDuration: 2800,
  273. animationEasing: 'quadraticOut'
  274. }
  275. ])
  276. }
  277. const getAllApi = async () => {
  278. await Promise.all([
  279. getCount(),
  280. getProject(),
  281. getNotice(),
  282. getShortcut(),
  283. getRadar(),
  284. getUserAccessSource(),
  285. getWeeklyUserActivity(),
  286. getMonthlySales()
  287. ])
  288. loading.value = false
  289. }
  290. getAllApi()
  291. </script>
  292. <template>
  293. <div>
  294. <el-card shadow="never">
  295. <el-skeleton :loading="loading" animated>
  296. <el-row :gutter="20" justify="space-between">
  297. <el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
  298. <div class="flex items-center">
  299. <img :src="avatar" alt="" class="w-70px h-70px rounded-[50%] mr-20px" />
  300. <div>
  301. <div class="text-20px text-700">
  302. {{ t('workplace.welcome') }} {{ username }} {{ t('workplace.happyDay') }}
  303. </div>
  304. <div class="mt-10px text-14px text-gray-500">
  305. {{ t('workplace.toady') }},20℃ - 32℃!
  306. </div>
  307. </div>
  308. </div>
  309. </el-col>
  310. <el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
  311. <div class="flex h-70px items-center justify-end <sm:mt-10px">
  312. <div class="px-8px text-right">
  313. <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.project') }}</div>
  314. <CountTo
  315. class="text-20px"
  316. :start-val="0"
  317. :end-val="totalSate.project"
  318. :duration="2600"
  319. />
  320. </div>
  321. <el-divider direction="vertical" />
  322. <div class="px-8px text-right">
  323. <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.toDo') }}</div>
  324. <CountTo
  325. class="text-20px"
  326. :start-val="0"
  327. :end-val="totalSate.todo"
  328. :duration="2600"
  329. />
  330. </div>
  331. <el-divider direction="vertical" border-style="dashed" />
  332. <div class="px-8px text-right">
  333. <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.access') }}</div>
  334. <CountTo
  335. class="text-20px"
  336. :start-val="0"
  337. :end-val="totalSate.access"
  338. :duration="2600"
  339. />
  340. </div>
  341. </div>
  342. </el-col>
  343. </el-row>
  344. </el-skeleton>
  345. </el-card>
  346. </div>
  347. <el-row class="mt-10px" :gutter="20" justify="space-between">
  348. <el-col :xl="16" :lg="16" :md="24" :sm="24" :xs="24" class="mb-20px">
  349. <el-card shadow="never">
  350. <template #header>
  351. <div class="flex justify-between">
  352. <span>{{ t('workplace.project') }}</span>
  353. <el-link type="primary" :underline="false">{{ t('workplace.more') }}</el-link>
  354. </div>
  355. </template>
  356. <el-skeleton :loading="loading" animated>
  357. <el-row>
  358. <el-col
  359. v-for="(item, index) in projects"
  360. :key="`card-${index}`"
  361. :xl="8"
  362. :lg="8"
  363. :md="12"
  364. :sm="24"
  365. :xs="24"
  366. >
  367. <el-card shadow="hover">
  368. <div class="flex items-center">
  369. <Icon :icon="item.icon" :size="25" class="mr-10px" />
  370. <span class="text-16px">{{ item.name }}</span>
  371. </div>
  372. <div class="mt-15px text-14px text-gray-400">{{ t(item.message) }}</div>
  373. <div class="mt-20px text-12px text-gray-400 flex justify-between">
  374. <span>{{ item.personal }}</span>
  375. <span>{{ formatTime(item.time, 'yyyy-MM-dd') }}</span>
  376. </div>
  377. </el-card>
  378. </el-col>
  379. </el-row>
  380. </el-skeleton>
  381. </el-card>
  382. <el-card shadow="never" class="mt-10px">
  383. <el-skeleton :loading="loading" animated>
  384. <el-row :gutter="20" justify="space-between">
  385. <el-col :xl="10" :lg="10" :md="24" :sm="24" :xs="24">
  386. <el-card shadow="hover" class="mb-20px">
  387. <el-skeleton :loading="loading" animated>
  388. <Echart :options="pieOptionsData" :height="300" />
  389. </el-skeleton>
  390. </el-card>
  391. </el-col>
  392. <el-col :xl="14" :lg="14" :md="24" :sm="24" :xs="24">
  393. <el-card shadow="hover" class="mb-20px">
  394. <el-skeleton :loading="loading" animated>
  395. <Echart :options="barOptionsData" :height="300" />
  396. </el-skeleton>
  397. </el-card>
  398. </el-col>
  399. <el-col :span="24">
  400. <el-card shadow="hover" class="mb-20px">
  401. <el-skeleton :loading="loading" animated :rows="4">
  402. <Echart :options="lineOptionsData" :height="350" />
  403. </el-skeleton>
  404. </el-card>
  405. </el-col>
  406. </el-row>
  407. </el-skeleton>
  408. </el-card>
  409. </el-col>
  410. <el-col :xl="8" :lg="8" :md="24" :sm="24" :xs="24" class="mb-20px">
  411. <el-card shadow="never">
  412. <template #header>
  413. <span>{{ t('workplace.shortcutOperation') }}</span>
  414. </template>
  415. <el-skeleton :loading="loading" animated>
  416. <el-row>
  417. <el-col v-for="item in shortcut" :key="`team-${item.name}`" :span="8" class="mb-20px">
  418. <div class="flex items-center">
  419. <Icon :icon="item.icon" class="mr-10px" />
  420. <el-link type="default" :underline="false" :href="item.url">
  421. {{ item.name }}
  422. </el-link>
  423. </div>
  424. </el-col>
  425. </el-row>
  426. </el-skeleton>
  427. </el-card>
  428. <el-card shadow="never" class="mt-10px">
  429. <template #header>
  430. <div class="flex justify-between">
  431. <span>{{ t('workplace.notice') }}</span>
  432. <el-link type="primary" :underline="false">{{ t('workplace.more') }}</el-link>
  433. </div>
  434. </template>
  435. <el-skeleton :loading="loading" animated>
  436. <div v-for="(item, index) in notice" :key="`dynamics-${index}`">
  437. <div class="flex items-center">
  438. <img :src="avatar" alt="" class="w-35px h-35px rounded-[50%] mr-20px" />
  439. <div>
  440. <div class="text-14px">
  441. <Highlight :keys="item.keys.map((v) => t(v))">
  442. {{ item.type }} : {{ item.title }}
  443. </Highlight>
  444. </div>
  445. <div class="mt-15px text-12px text-gray-400">
  446. {{ formatTime(item.date, 'yyyy-MM-dd') }}
  447. </div>
  448. </div>
  449. </div>
  450. <el-divider />
  451. </div>
  452. </el-skeleton>
  453. </el-card>
  454. <el-card shadow="never" class="mt-10px">
  455. <template #header>
  456. <span>{{ t('workplace.index') }}</span>
  457. </template>
  458. <el-skeleton :loading="loading" animated>
  459. <Echart :options="radarOptionData" :height="400" />
  460. </el-skeleton>
  461. </el-card>
  462. </el-col>
  463. </el-row>
  464. </template>