Index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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 { ref, reactive } from 'vue'
  163. import { set } from 'lodash-es'
  164. import { EChartsOption } from 'echarts'
  165. import { ElRow, ElCol, ElSkeleton, ElCard, ElDivider, ElLink } from 'element-plus'
  166. import { formatTime } from '@/utils'
  167. import { useI18n } from '@/hooks/web/useI18n'
  168. import { useUserStore } from '@/store/modules/user'
  169. import { useWatermark } from '@/hooks/web/useWatermark'
  170. import { Echart } from '@/components/Echart'
  171. import { CountTo } from '@/components/CountTo'
  172. import { Highlight } from '@/components/Highlight'
  173. import avatarImg from '@/assets/imgs/avatar.gif'
  174. import type { WorkplaceTotal, Project, Notice, Shortcut } from './types'
  175. import { pieOptions, barOptions } from './echarts-data'
  176. const { t } = useI18n()
  177. const userStore = useUserStore()
  178. const { setWatermark } = useWatermark()
  179. const loading = ref(true)
  180. const avatar = userStore.getUser.avatar ? userStore.getUser.avatar : avatarImg
  181. const username = userStore.getUser.nickname
  182. const pieOptionsData = reactive<EChartsOption>(pieOptions) as EChartsOption
  183. // 获取统计数
  184. let totalSate = reactive<WorkplaceTotal>({
  185. project: 0,
  186. access: 0,
  187. todo: 0
  188. })
  189. const getCount = async () => {
  190. const data = {
  191. project: 40,
  192. access: 2340,
  193. todo: 10
  194. }
  195. totalSate = Object.assign(totalSate, data)
  196. }
  197. // 获取项目数
  198. let projects = reactive<Project[]>([])
  199. const getProject = async () => {
  200. const data = [
  201. {
  202. name: 'Github',
  203. icon: 'akar-icons:github-fill',
  204. message: 'workplace.introduction',
  205. personal: 'Archer',
  206. time: new Date()
  207. },
  208. {
  209. name: 'Vue',
  210. icon: 'logos:vue',
  211. message: 'workplace.introduction',
  212. personal: 'Archer',
  213. time: new Date()
  214. },
  215. {
  216. name: 'Angular',
  217. icon: 'logos:angular-icon',
  218. message: 'workplace.introduction',
  219. personal: 'Archer',
  220. time: new Date()
  221. },
  222. {
  223. name: 'React',
  224. icon: 'logos:react',
  225. message: 'workplace.introduction',
  226. personal: 'Archer',
  227. time: new Date()
  228. },
  229. {
  230. name: 'Webpack',
  231. icon: 'logos:webpack',
  232. message: 'workplace.introduction',
  233. personal: 'Archer',
  234. time: new Date()
  235. },
  236. {
  237. name: 'Vite',
  238. icon: 'vscode-icons:file-type-vite',
  239. message: 'workplace.introduction',
  240. personal: 'Archer',
  241. time: new Date()
  242. }
  243. ]
  244. projects = Object.assign(projects, data)
  245. }
  246. // 获取通知公告
  247. let notice = reactive<Notice[]>([])
  248. const getNotice = async () => {
  249. const data = [
  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. title: '系统凌晨维护',
  270. type: '公告',
  271. keys: ['公告', '维护'],
  272. date: new Date()
  273. }
  274. ]
  275. notice = Object.assign(notice, data)
  276. }
  277. // 获取快捷入口
  278. let shortcut = reactive<Shortcut[]>([])
  279. const getShortcut = async () => {
  280. const data = [
  281. {
  282. name: 'Github',
  283. icon: 'akar-icons:github-fill',
  284. url: 'github.io'
  285. },
  286. {
  287. name: 'Vue',
  288. icon: 'logos:vue',
  289. url: 'vuejs.org'
  290. },
  291. {
  292. name: 'Vite',
  293. icon: 'vscode-icons:file-type-vite',
  294. url: 'https://vitejs.dev/'
  295. },
  296. {
  297. name: 'Angular',
  298. icon: 'logos:angular-icon',
  299. url: 'github.io'
  300. },
  301. {
  302. name: 'React',
  303. icon: 'logos:react',
  304. url: 'github.io'
  305. },
  306. {
  307. name: 'Webpack',
  308. icon: 'logos:webpack',
  309. url: 'github.io'
  310. }
  311. ]
  312. shortcut = Object.assign(shortcut, data)
  313. }
  314. // 用户来源
  315. const getUserAccessSource = async () => {
  316. const data = [
  317. { value: 335, name: 'analysis.directAccess' },
  318. { value: 310, name: 'analysis.mailMarketing' },
  319. { value: 234, name: 'analysis.allianceAdvertising' },
  320. { value: 135, name: 'analysis.videoAdvertising' },
  321. { value: 1548, name: 'analysis.searchEngines' }
  322. ]
  323. set(
  324. pieOptionsData,
  325. 'legend.data',
  326. data.map((v) => t(v.name))
  327. )
  328. pieOptionsData!.series![0].data = data.map((v) => {
  329. return {
  330. name: t(v.name),
  331. value: v.value
  332. }
  333. })
  334. }
  335. const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption
  336. // 周活跃量
  337. const getWeeklyUserActivity = async () => {
  338. const data = [
  339. { value: 13253, name: 'analysis.monday' },
  340. { value: 34235, name: 'analysis.tuesday' },
  341. { value: 26321, name: 'analysis.wednesday' },
  342. { value: 12340, name: 'analysis.thursday' },
  343. { value: 24643, name: 'analysis.friday' },
  344. { value: 1322, name: 'analysis.saturday' },
  345. { value: 1324, name: 'analysis.sunday' }
  346. ]
  347. set(
  348. barOptionsData,
  349. 'xAxis.data',
  350. data.map((v) => t(v.name))
  351. )
  352. set(barOptionsData, 'series', [
  353. {
  354. name: t('analysis.activeQuantity'),
  355. data: data.map((v) => v.value),
  356. type: 'bar'
  357. }
  358. ])
  359. }
  360. const getAllApi = async () => {
  361. await Promise.all([
  362. getCount(),
  363. getProject(),
  364. getNotice(),
  365. getShortcut(),
  366. getUserAccessSource(),
  367. getWeeklyUserActivity()
  368. ])
  369. loading.value = false
  370. }
  371. getAllApi()
  372. </script>