Index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <div>
  3. <el-card shadow="never">
  4. <el-skeleton :loading="loading" animated>
  5. <el-row :gutter="20" justify="space-between">
  6. <el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
  7. <div class="flex items-center">
  8. <img :src="avatar" alt="" class="w-70px h-70px rounded-[50%] mr-20px" />
  9. <div>
  10. <div class="text-20px text-700">
  11. {{ t('workplace.welcome') }} {{ username }} {{ t('workplace.happyDay') }}
  12. </div>
  13. <div class="mt-10px text-14px text-gray-500">
  14. {{ t('workplace.toady') }},20℃ - 32℃!
  15. </div>
  16. </div>
  17. </div>
  18. </el-col>
  19. <el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
  20. <div class="flex h-70px items-center justify-end <sm:mt-10px">
  21. <div class="px-8px text-right">
  22. <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.project') }}</div>
  23. <CountTo
  24. class="text-20px"
  25. :start-val="0"
  26. :end-val="totalSate.project"
  27. :duration="2600"
  28. />
  29. </div>
  30. <el-divider direction="vertical" />
  31. <div class="px-8px text-right">
  32. <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.toDo') }}</div>
  33. <CountTo
  34. class="text-20px"
  35. :start-val="0"
  36. :end-val="totalSate.todo"
  37. :duration="2600"
  38. />
  39. </div>
  40. <el-divider direction="vertical" border-style="dashed" />
  41. <div class="px-8px text-right">
  42. <div class="text-14px text-gray-400 mb-20px">{{ t('workplace.access') }}</div>
  43. <CountTo
  44. class="text-20px"
  45. :start-val="0"
  46. :end-val="totalSate.access"
  47. :duration="2600"
  48. />
  49. </div>
  50. </div>
  51. </el-col>
  52. </el-row>
  53. </el-skeleton>
  54. </el-card>
  55. </div>
  56. <el-row class="mt-5px" :gutter="20" justify="space-between">
  57. <el-col :xl="16" :lg="16" :md="24" :sm="24" :xs="24" class="mb-10px">
  58. <el-card shadow="never">
  59. <template #header>
  60. <div class="flex justify-between h-3">
  61. <span>{{ t('workplace.project') }}</span>
  62. <el-link type="primary" :underline="false">{{ t('action.more') }}</el-link>
  63. </div>
  64. </template>
  65. <el-skeleton :loading="loading" animated>
  66. <el-row>
  67. <el-col
  68. v-for="(item, index) in projects"
  69. :key="`card-${index}`"
  70. :xl="8"
  71. :lg="8"
  72. :md="8"
  73. :sm="24"
  74. :xs="24"
  75. >
  76. <el-card shadow="hover">
  77. <div class="flex items-center">
  78. <Icon :icon="item.icon" :size="25" class="mr-10px" />
  79. <span class="text-16px">{{ item.name }}</span>
  80. </div>
  81. <div class="mt-15px text-14px text-gray-400">{{ t(item.message) }}</div>
  82. <div class="mt-20px text-12px text-gray-400 flex justify-between">
  83. <span>{{ item.personal }}</span>
  84. <span>{{ formatTime(item.time, 'yyyy-MM-dd') }}</span>
  85. </div>
  86. </el-card>
  87. </el-col>
  88. </el-row>
  89. </el-skeleton>
  90. </el-card>
  91. <el-card shadow="never" class="mt-5px">
  92. <el-skeleton :loading="loading" animated>
  93. <el-row :gutter="20" justify="space-between">
  94. <el-col :xl="10" :lg="10" :md="24" :sm="24" :xs="24">
  95. <el-card shadow="hover" class="mb-10px">
  96. <el-skeleton :loading="loading" animated>
  97. <Echart :options="pieOptionsData" :height="280" />
  98. </el-skeleton>
  99. </el-card>
  100. </el-col>
  101. <el-col :xl="14" :lg="14" :md="24" :sm="24" :xs="24">
  102. <el-card shadow="hover" class="mb-10px">
  103. <el-skeleton :loading="loading" animated>
  104. <Echart :options="barOptionsData" :height="280" />
  105. </el-skeleton>
  106. </el-card>
  107. </el-col>
  108. </el-row>
  109. </el-skeleton>
  110. </el-card>
  111. </el-col>
  112. <el-col :xl="8" :lg="8" :md="24" :sm="24" :xs="24" class="mb-10px">
  113. <el-card shadow="never">
  114. <template #header>
  115. <div class="flex justify-between h-3">
  116. <span>{{ t('workplace.shortcutOperation') }}</span>
  117. </div>
  118. </template>
  119. <el-skeleton :loading="loading" animated>
  120. <el-row>
  121. <el-col v-for="item in shortcut" :key="`team-${item.name}`" :span="8" class="mb-10px">
  122. <div class="flex items-center">
  123. <Icon :icon="item.icon" class="mr-10px" />
  124. <el-link type="default" :underline="false" @click="setWatermark(item.name)">
  125. {{ item.name }}
  126. </el-link>
  127. </div>
  128. </el-col>
  129. </el-row>
  130. </el-skeleton>
  131. </el-card>
  132. <el-card shadow="never" class="mt-10px">
  133. <template #header>
  134. <div class="flex justify-between h-3">
  135. <span>{{ t('workplace.notice') }}</span>
  136. <el-link type="primary" :underline="false">{{ t('action.more') }}</el-link>
  137. </div>
  138. </template>
  139. <el-skeleton :loading="loading" animated>
  140. <div v-for="(item, index) in notice" :key="`dynamics-${index}`">
  141. <div class="flex items-center">
  142. <img :src="avatar" alt="" class="w-35px h-35px rounded-[50%] mr-20px" />
  143. <div>
  144. <div class="text-14px">
  145. <Highlight :keys="item.keys.map((v) => t(v))">
  146. {{ item.type }} : {{ item.title }}
  147. </Highlight>
  148. </div>
  149. <div class="mt-15px text-12px text-gray-400">
  150. {{ formatTime(item.date, 'yyyy-MM-dd') }}
  151. </div>
  152. </div>
  153. </div>
  154. <el-divider />
  155. </div>
  156. </el-skeleton>
  157. </el-card>
  158. </el-col>
  159. </el-row>
  160. </template>
  161. <script setup lang="ts" name="Home">
  162. import { set } from 'lodash-es'
  163. import { EChartsOption } from 'echarts'
  164. import { formatTime } from '@/utils'
  165. import { useUserStore } from '@/store/modules/user'
  166. import { useWatermark } from '@/hooks/web/useWatermark'
  167. import avatarImg from '@/assets/imgs/avatar.gif'
  168. import type { WorkplaceTotal, Project, Notice, Shortcut } from './types'
  169. import { pieOptions, barOptions } from './echarts-data'
  170. const { t } = useI18n()
  171. const userStore = useUserStore()
  172. const { setWatermark } = useWatermark()
  173. const loading = ref(true)
  174. const avatar = userStore.getUser.avatar ? userStore.getUser.avatar : avatarImg
  175. const username = userStore.getUser.nickname
  176. const pieOptionsData = reactive<EChartsOption>(pieOptions) as EChartsOption
  177. // 获取统计数
  178. let totalSate = reactive<WorkplaceTotal>({
  179. project: 0,
  180. access: 0,
  181. todo: 0
  182. })
  183. const getCount = async () => {
  184. const data = {
  185. project: 40,
  186. access: 2340,
  187. todo: 10
  188. }
  189. totalSate = Object.assign(totalSate, data)
  190. }
  191. // 获取项目数
  192. let projects = reactive<Project[]>([])
  193. const getProject = async () => {
  194. const data = [
  195. {
  196. name: 'Github',
  197. icon: 'akar-icons:github-fill',
  198. message: 'workplace.introduction',
  199. personal: 'Archer',
  200. time: new Date()
  201. },
  202. {
  203. name: 'Vue',
  204. icon: 'logos:vue',
  205. message: 'workplace.introduction',
  206. personal: 'Archer',
  207. time: new Date()
  208. },
  209. {
  210. name: 'Angular',
  211. icon: 'logos:angular-icon',
  212. message: 'workplace.introduction',
  213. personal: 'Archer',
  214. time: new Date()
  215. },
  216. {
  217. name: 'React',
  218. icon: 'logos:react',
  219. message: 'workplace.introduction',
  220. personal: 'Archer',
  221. time: new Date()
  222. },
  223. {
  224. name: 'Webpack',
  225. icon: 'logos:webpack',
  226. message: 'workplace.introduction',
  227. personal: 'Archer',
  228. time: new Date()
  229. },
  230. {
  231. name: 'Vite',
  232. icon: 'vscode-icons:file-type-vite',
  233. message: 'workplace.introduction',
  234. personal: 'Archer',
  235. time: new Date()
  236. }
  237. ]
  238. projects = Object.assign(projects, data)
  239. }
  240. // 获取通知公告
  241. let notice = reactive<Notice[]>([])
  242. const getNotice = async () => {
  243. const data = [
  244. {
  245. title: '系统升级版本',
  246. type: '通知',
  247. keys: ['通知', '升级'],
  248. date: new Date()
  249. },
  250. {
  251. title: '系统凌晨维护',
  252. type: '公告',
  253. keys: ['公告', '维护'],
  254. date: new Date()
  255. },
  256. {
  257. title: '系统升级版本',
  258. type: '通知',
  259. keys: ['通知', '升级'],
  260. date: new Date()
  261. },
  262. {
  263. title: '系统凌晨维护',
  264. type: '公告',
  265. keys: ['公告', '维护'],
  266. date: new Date()
  267. }
  268. ]
  269. notice = Object.assign(notice, data)
  270. }
  271. // 获取快捷入口
  272. let shortcut = reactive<Shortcut[]>([])
  273. const getShortcut = async () => {
  274. const data = [
  275. {
  276. name: 'Github',
  277. icon: 'akar-icons:github-fill',
  278. url: 'github.io'
  279. },
  280. {
  281. name: 'Vue',
  282. icon: 'logos:vue',
  283. url: 'vuejs.org'
  284. },
  285. {
  286. name: 'Vite',
  287. icon: 'vscode-icons:file-type-vite',
  288. url: 'https://vitejs.dev/'
  289. },
  290. {
  291. name: 'Angular',
  292. icon: 'logos:angular-icon',
  293. url: 'github.io'
  294. },
  295. {
  296. name: 'React',
  297. icon: 'logos:react',
  298. url: 'github.io'
  299. },
  300. {
  301. name: 'Webpack',
  302. icon: 'logos:webpack',
  303. url: 'github.io'
  304. }
  305. ]
  306. shortcut = Object.assign(shortcut, data)
  307. }
  308. // 用户来源
  309. const getUserAccessSource = async () => {
  310. const data = [
  311. { value: 335, name: 'analysis.directAccess' },
  312. { value: 310, name: 'analysis.mailMarketing' },
  313. { value: 234, name: 'analysis.allianceAdvertising' },
  314. { value: 135, name: 'analysis.videoAdvertising' },
  315. { value: 1548, name: 'analysis.searchEngines' }
  316. ]
  317. set(
  318. pieOptionsData,
  319. 'legend.data',
  320. data.map((v) => t(v.name))
  321. )
  322. pieOptionsData!.series![0].data = data.map((v) => {
  323. return {
  324. name: t(v.name),
  325. value: v.value
  326. }
  327. })
  328. }
  329. const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption
  330. // 周活跃量
  331. const getWeeklyUserActivity = async () => {
  332. const data = [
  333. { value: 13253, name: 'analysis.monday' },
  334. { value: 34235, name: 'analysis.tuesday' },
  335. { value: 26321, name: 'analysis.wednesday' },
  336. { value: 12340, name: 'analysis.thursday' },
  337. { value: 24643, name: 'analysis.friday' },
  338. { value: 1322, name: 'analysis.saturday' },
  339. { value: 1324, name: 'analysis.sunday' }
  340. ]
  341. set(
  342. barOptionsData,
  343. 'xAxis.data',
  344. data.map((v) => t(v.name))
  345. )
  346. set(barOptionsData, 'series', [
  347. {
  348. name: t('analysis.activeQuantity'),
  349. data: data.map((v) => v.value),
  350. type: 'bar'
  351. }
  352. ])
  353. }
  354. const getAllApi = async () => {
  355. await Promise.all([
  356. getCount(),
  357. getProject(),
  358. getNotice(),
  359. getShortcut(),
  360. getUserAccessSource(),
  361. getWeeklyUserActivity()
  362. ])
  363. loading.value = false
  364. }
  365. getAllApi()
  366. </script>