Index.vue 12 KB

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