HomeView.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <script setup lang="ts">
  2. import { RouterView } from 'vue-router'
  3. import { onMounted, reactive, ref } from 'vue'
  4. import { ElMessage } from 'element-plus'
  5. import { getAllGameInfo } from '@/utils/table/table'
  6. import router from '@/router'
  7. import { getAssetsImageUrl } from '@/utils/common'
  8. import type { DropDownInfo, DropDownItem } from '@/types/dataAnalysis'
  9. import DropDownSelection from '@/components/dataAnalysis/DropDownSelection.vue'
  10. import { useCommonStore } from '@/stores/useCommon'
  11. const { selectInfo } = useCommonStore()
  12. const isCollapse = ref(false)
  13. const menuList = [
  14. {
  15. title: '数据总览',
  16. icon: 'PieChart',
  17. children: [
  18. {
  19. pathName: 'OverView',
  20. title: '工作台'
  21. }
  22. ]
  23. },
  24. {
  25. title: '信息管理',
  26. icon: 'Histogram',
  27. children: [
  28. {
  29. pathName: 'GameManageView',
  30. title: '游戏管理'
  31. },
  32. {
  33. pathName: 'PlayerManageView',
  34. title: '玩家管理'
  35. }
  36. ]
  37. },
  38. {
  39. title: '数据分析',
  40. icon: 'DataAnalysis',
  41. children: [
  42. {
  43. pathName: 'KeepView',
  44. title: '留存分析'
  45. },
  46. {
  47. pathName: 'UserTrendView',
  48. title: '用户趋势'
  49. }
  50. ]
  51. }
  52. ]
  53. const changeCollapse = () => {
  54. isCollapse.value = !isCollapse.value
  55. }
  56. // 登出
  57. const logOut = () => {
  58. ElMessage({
  59. type: 'success',
  60. message: '退出成功',
  61. duration: 1000
  62. })
  63. localStorage.removeItem('token')
  64. localStorage.removeItem('refreshToken')
  65. router.push('/login')
  66. }
  67. const iconUrl = {
  68. logo: getAssetsImageUrl('logo.svg'),
  69. defaultHead: getAssetsImageUrl('default/defaultHead.png')
  70. }
  71. // const gameSelectList = reactive<Array<DropDownItem>>([])
  72. // 游戏下拉选择框需要的数据
  73. const gameSelectInfo = reactive<DropDownInfo>({
  74. defaultSelect: '1001',
  75. title: '请选择游戏',
  76. optionsList: []
  77. })
  78. const gameinfoLoad = ref(false)
  79. /**
  80. * @description: 更新整个页面的游戏选择
  81. * @param {*} gid 游戏id
  82. * @return {*}
  83. */
  84. const changeGame = (gid: any) => {
  85. selectInfo.gid = gid
  86. }
  87. getAllGameInfo().then((data) => {
  88. if (data) {
  89. data.map((item) => {
  90. gameSelectInfo.optionsList.push({
  91. value: item.gid,
  92. label: item.gameName
  93. })
  94. })
  95. }
  96. gameinfoLoad.value = true
  97. })
  98. </script>
  99. <template>
  100. <div class="body">
  101. <div class="sideBarBox">
  102. <el-menu :router="true" :default-active="$route.name" class="sideBar" :collapse="isCollapse">
  103. <el-menu-item index="/" class="logoBox">
  104. <el-image :fit="'fill'" class="logoImg" :src="iconUrl.logo"></el-image>
  105. <template #title><span class="logoText">淳皓科技</span></template>
  106. </el-menu-item>
  107. <el-sub-menu v-for="item in menuList" :index="item.title">
  108. <template #title>
  109. <el-icon><component :is="item.icon" /></el-icon>
  110. <span class="menuTitle">{{ item.title }}</span>
  111. </template>
  112. <el-menu-item v-for="v in item.children" :index="v.pathName">{{ v.title }}</el-menu-item>
  113. </el-sub-menu>
  114. <div class="sideBarFold" @click="changeCollapse">
  115. <el-icon :size="25"><Fold /></el-icon>
  116. </div>
  117. </el-menu>
  118. </div>
  119. <div class="navBarBox">
  120. <div class="gameSelect">
  121. <el-icon class="gameIcon" :size="20">
  122. <icon-icon-park-game-three></icon-icon-park-game-three>
  123. </el-icon>
  124. <DropDownSelection
  125. :default-select="gameSelectInfo.defaultSelect"
  126. :title="gameSelectInfo.title"
  127. :options-list="gameSelectInfo.optionsList"
  128. :size="'default'"
  129. @change-select="changeGame"
  130. ></DropDownSelection>
  131. </div>
  132. <div class="headPortraitBox">
  133. <el-popover popper-class="headPopper" placement="bottom-end" trigger="click">
  134. <template #reference>
  135. <el-image class="headPortrait" :src="iconUrl.defaultHead"></el-image>
  136. </template>
  137. <div class="userTools">
  138. <span class="userToolsItem" @click="logOut">
  139. <icon-material-symbols-light-logout></icon-material-symbols-light-logout>
  140. <span> 退出登录</span>
  141. </span>
  142. </div>
  143. </el-popover>
  144. </div>
  145. </div>
  146. <div class="content">
  147. <RouterView v-if="gameinfoLoad" />
  148. </div>
  149. </div>
  150. </template>
  151. <style scoped>
  152. .body {
  153. width: 100%;
  154. display: flex;
  155. height: 100vh;
  156. }
  157. .gameSelect {
  158. position: absolute;
  159. top: 50%;
  160. transform: translateY(-50%);
  161. /* width: 10%; */
  162. height: 80%;
  163. display: flex;
  164. align-items: center;
  165. right: 10%;
  166. display: flex;
  167. align-items: center;
  168. /* background-color: lightblue; */
  169. }
  170. .gameIcon {
  171. /* box-sizing: border-box; */
  172. /* padding-right: 12px; */
  173. margin-right: 12px;
  174. }
  175. /* 设置宽度后,content无法适应宽度,只能去间接的调整内部元素的宽度 */
  176. .sideBarBox {
  177. position: relative;
  178. /* width: 12%; */
  179. z-index: 2;
  180. height: 100vh;
  181. top: 0;
  182. }
  183. .sideBar {
  184. /* width: 12vw; */
  185. height: 100vh;
  186. position: relative;
  187. overflow: scroll;
  188. }
  189. /* 设置弹出层的样式 */
  190. .el-popper > .logoText {
  191. width: 100px;
  192. font-size: 16px;
  193. /* color: red; */
  194. }
  195. /* 调整LOGO */
  196. .logoBox {
  197. display: flex;
  198. justify-content: space-between;
  199. align-items: center;
  200. }
  201. .logoImg {
  202. display: flex;
  203. align-items: center;
  204. width: 33px;
  205. /* margin-right: 20px; */
  206. /* height: 50px; */
  207. }
  208. .logoText {
  209. width: 80%;
  210. height: 100%;
  211. margin-left: 15%;
  212. display: flex;
  213. font-size: 18px;
  214. align-items: center;
  215. /* background-color: lightcoral; */
  216. }
  217. /* 主要用来调整整个menu的宽度 */
  218. .menuTitle {
  219. margin-right: 40px;
  220. }
  221. .sideBarFold {
  222. width: 5%;
  223. height: 3%;
  224. position: absolute;
  225. right: 40px;
  226. bottom: 20px;
  227. }
  228. .navBarBox {
  229. position: fixed;
  230. width: 100vw;
  231. z-index: 1;
  232. height: 7vh;
  233. top: 0;
  234. background-color: white;
  235. right: 0;
  236. border-bottom: 1px solid gainsboro;
  237. }
  238. .headPortraitBox {
  239. position: absolute;
  240. right: 3%;
  241. top: 50%;
  242. transform: translateY(-50%);
  243. }
  244. .userTools {
  245. width: 100%;
  246. height: 100%;
  247. display: flex;
  248. flex-direction: column;
  249. justify-content: space-around;
  250. align-items: center;
  251. }
  252. .userToolsItem {
  253. cursor: pointer;
  254. width: 100%;
  255. height: 4vh;
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. /* padding: 10px; */
  260. margin: 2%;
  261. }
  262. .userToolsItem > span {
  263. margin-left: 10%;
  264. }
  265. .userToolsItem:hover {
  266. background-color: #f2f3f5;
  267. }
  268. .headPortrait {
  269. cursor: pointer;
  270. width: 50px;
  271. }
  272. .content {
  273. /* flex-grow: 1; */
  274. /* position: absolute; */
  275. width: 100%;
  276. /* height: 93%; */
  277. margin-top: 7vh;
  278. overflow: scroll;
  279. background-color: #f2f3f5;
  280. right: 0vw;
  281. top: 0vh;
  282. }
  283. </style>
  284. <!-- 为了让popper-class生效,需要的单独写一份 -->
  285. <style>
  286. .headPopper {
  287. padding: 0px !important;
  288. border: 1px solid #e5e6eb;
  289. background-color: white;
  290. }
  291. </style>