Index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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="mr-20px h-70px w-70px rounded-[50%]" />
  9. <div>
  10. <div class="text-20px">
  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="h-70px flex items-center justify-end lt-sm:mt-10px">
  21. <div class="px-8px text-right">
  22. <div class="mb-20px text-14px text-gray-400">{{ 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="mb-20px text-14px text-gray-400">{{ 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="mb-20px text-14px text-gray-400">{{ 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="h-3 flex justify-between">
  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 flex justify-between text-12px text-gray-400">
  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="h-3 flex justify-between">
  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="h-3 flex justify-between">
  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="mr-20px h-35px w-35px rounded-[50%]" />
  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 lang="ts" setup>
  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. defineOptions({ name: 'Home' })
  171. const { t } = useI18n()
  172. const userStore = useUserStore()
  173. const { setWatermark } = useWatermark()
  174. const loading = ref(true)
  175. const avatar = userStore.getUser.avatar ? userStore.getUser.avatar : avatarImg
  176. const username = userStore.getUser.nickname
  177. const pieOptionsData = reactive<EChartsOption>(pieOptions) as EChartsOption
  178. // 获取统计数
  179. let totalSate = reactive<WorkplaceTotal>({
  180. project: 0,
  181. access: 0,
  182. todo: 0
  183. })
  184. const getCount = async () => {
  185. const data = {
  186. project: 40,
  187. access: 2340,
  188. todo: 10
  189. }
  190. totalSate = Object.assign(totalSate, data)
  191. }
  192. // 获取项目数
  193. let projects = reactive<Project[]>([])
  194. const getProject = async () => {
  195. const data = [
  196. {
  197. name: 'Github',
  198. icon: 'akar-icons:github-fill',
  199. message: 'workplace.introduction',
  200. personal: 'Archer',
  201. time: new Date()
  202. },
  203. {
  204. name: 'Vue',
  205. icon: 'logos:vue',
  206. message: 'workplace.introduction',
  207. personal: 'Archer',
  208. time: new Date()
  209. },
  210. {
  211. name: 'Angular',
  212. icon: 'logos:angular-icon',
  213. message: 'workplace.introduction',
  214. personal: 'Archer',
  215. time: new Date()
  216. },
  217. {
  218. name: 'React',
  219. icon: 'logos:react',
  220. message: 'workplace.introduction',
  221. personal: 'Archer',
  222. time: new Date()
  223. },
  224. {
  225. name: 'Webpack',
  226. icon: 'logos:webpack',
  227. message: 'workplace.introduction',
  228. personal: 'Archer',
  229. time: new Date()
  230. },
  231. {
  232. name: 'Vite',
  233. icon: 'vscode-icons:file-type-vite',
  234. message: 'workplace.introduction',
  235. personal: 'Archer',
  236. time: new Date()
  237. }
  238. ]
  239. projects = Object.assign(projects, data)
  240. }
  241. // 获取通知公告
  242. let notice = reactive<Notice[]>([])
  243. const getNotice = async () => {
  244. const data = [
  245. {
  246. title: '系统升级版本',
  247. type: '通知',
  248. keys: ['通知', '升级'],
  249. date: new Date()
  250. },
  251. {
  252. title: '系统凌晨维护',
  253. type: '公告',
  254. keys: ['公告', '维护'],
  255. date: new Date()
  256. },
  257. {
  258. title: '系统升级版本',
  259. type: '通知',
  260. keys: ['通知', '升级'],
  261. date: new Date()
  262. },
  263. {
  264. title: '系统凌晨维护',
  265. type: '公告',
  266. keys: ['公告', '维护'],
  267. date: new Date()
  268. }
  269. ]
  270. notice = Object.assign(notice, data)
  271. }
  272. // 获取快捷入口
  273. let shortcut = reactive<Shortcut[]>([])
  274. const getShortcut = async () => {
  275. const data = [
  276. {
  277. name: 'Github',
  278. icon: 'akar-icons:github-fill',
  279. url: 'github.io'
  280. },
  281. {
  282. name: 'Vue',
  283. icon: 'logos:vue',
  284. url: 'vuejs.org'
  285. },
  286. {
  287. name: 'Vite',
  288. icon: 'vscode-icons:file-type-vite',
  289. url: 'https://vitejs.dev/'
  290. },
  291. {
  292. name: 'Angular',
  293. icon: 'logos:angular-icon',
  294. url: 'github.io'
  295. },
  296. {
  297. name: 'React',
  298. icon: 'logos:react',
  299. url: 'github.io'
  300. },
  301. {
  302. name: 'Webpack',
  303. icon: 'logos:webpack',
  304. url: 'github.io'
  305. }
  306. ]
  307. shortcut = Object.assign(shortcut, data)
  308. }
  309. // 用户来源
  310. const getUserAccessSource = async () => {
  311. const data = [
  312. { value: 335, name: 'analysis.directAccess' },
  313. { value: 310, name: 'analysis.mailMarketing' },
  314. { value: 234, name: 'analysis.allianceAdvertising' },
  315. { value: 135, name: 'analysis.videoAdvertising' },
  316. { value: 1548, name: 'analysis.searchEngines' }
  317. ]
  318. set(
  319. pieOptionsData,
  320. 'legend.data',
  321. data.map((v) => t(v.name))
  322. )
  323. pieOptionsData!.series![0].data = data.map((v) => {
  324. return {
  325. name: t(v.name),
  326. value: v.value
  327. }
  328. })
  329. }
  330. const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption
  331. // 周活跃量
  332. const getWeeklyUserActivity = async () => {
  333. const data = [
  334. { value: 13253, name: 'analysis.monday' },
  335. { value: 34235, name: 'analysis.tuesday' },
  336. { value: 26321, name: 'analysis.wednesday' },
  337. { value: 12340, name: 'analysis.thursday' },
  338. { value: 24643, name: 'analysis.friday' },
  339. { value: 1322, name: 'analysis.saturday' },
  340. { value: 1324, name: 'analysis.sunday' }
  341. ]
  342. set(
  343. barOptionsData,
  344. 'xAxis.data',
  345. data.map((v) => t(v.name))
  346. )
  347. set(barOptionsData, 'series', [
  348. {
  349. name: t('analysis.activeQuantity'),
  350. data: data.map((v) => v.value),
  351. type: 'bar'
  352. }
  353. ])
  354. }
  355. const getAllApi = async () => {
  356. await Promise.all([
  357. getCount(),
  358. getProject(),
  359. getNotice(),
  360. getShortcut(),
  361. getUserAccessSource(),
  362. getWeeklyUserActivity()
  363. ])
  364. loading.value = false
  365. }
  366. getAllApi()
  367. </script>