Index.vue 14 KB

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