Index.vue 12 KB

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