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