HomeView.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div id="home">
  3. <div id="Header">
  4. <div class="loginForm" v-if="isLogin">
  5. <span style="color: white">用户名:</span>
  6. <span style="color: white">{{ $store.getters.getUserName || '未登录' }}</span>
  7. <el-link type="warning" :underline="false" class="logout" @click="logout"> 退出登录</el-link>
  8. </div>
  9. <div class="loginForm" v-else>
  10. <span class="formLabel">用户名:</span>
  11. <input class="formInput" type="text" v-model="loginForm.userName" placeholder="请输入用户名"/>
  12. &nbsp;&nbsp;
  13. <span class="formLabel">密&nbsp;&nbsp;码:</span>
  14. <input class="formInput" type="password" v-model="loginForm.password" placeholder="请输入密码"/>
  15. &nbsp;&nbsp;
  16. <el-button type="warning" @click="login" size="small">登录</el-button>
  17. </div>
  18. <div class="title">
  19. <img :src="titleImg"/>
  20. </div>
  21. </div>
  22. <div id="Menu" :style="{height: contentHeight+'px'}">
  23. <div id="Tags">
  24. <el-menu
  25. :default-active="activeIndex"
  26. class="el-menu-demo"
  27. mode="horizontal"
  28. background-color="#6162f2"
  29. text-color="white"
  30. active-text-color="#ffc01c"
  31. @select="handleMenuClick"
  32. >
  33. <el-menu-item index="1" >综合展示</el-menu-item>
  34. <el-menu-item index="2" v-if="isLogin && pageShow['DTB-DATAMANAGE']">数据管理</el-menu-item>
  35. <el-menu-item index="3" v-if="isLogin && pageShow['DTB-DATAPUBLISH']">数据发布</el-menu-item>
  36. <el-menu-item index="4" v-if="isLogin && pageShow['DTB-PLUGINMANAGE']">插件管理</el-menu-item>
  37. <el-menu-item index="5" v-if="isLogin && pageShow['DTB-SYSTEMMANAGE']">系统管理</el-menu-item>
  38. </el-menu>
  39. </div>
  40. <div class="content">
  41. <!--<HomeIndex :auth="pageShow['DTB-HOMEINDEX']" v-if="activeIndex==1"/>-->
  42. <HomeIndex :auth="true" v-if="activeIndex==1"/>
  43. <DataManage v-if="activeIndex==2"/>
  44. <DataPublish v-if="activeIndex==3"/>
  45. <PluginManage v-if="activeIndex==4"/>
  46. <SystemManage v-if="activeIndex==5"/>
  47. </div>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import {defineAsyncComponent} from "vue";
  53. import loginApi from "@/api/login";
  54. import elementResizeDetectorMaker from "element-resize-detector";
  55. import titleImg from "@/assets/img/title.png"
  56. export default {
  57. name: 'homeIndex',
  58. components: {
  59. HomeIndex: defineAsyncComponent(() => import("@/components/home/HomeIndex.vue")),
  60. DataManage: defineAsyncComponent(() => import("@/components/home/DataManage.vue")),
  61. DataPublish: defineAsyncComponent(() => import("@/components/home/DataPublish.vue")),
  62. PluginManage: defineAsyncComponent(() => import("@/components/home/PluginManage.vue")),
  63. SystemManage: defineAsyncComponent(() => import("@/components/home/SystemManage.vue")),
  64. },
  65. data() {
  66. return {
  67. titleImg,
  68. activeIndex: '1',
  69. fullscreenLoading: null,
  70. contentHeight: '',
  71. isLogin: false,
  72. loginForm: {
  73. userName: '',
  74. password: '',
  75. clientId: this.$constant.serviceId,
  76. },
  77. pageShow: {
  78. "DTB-HOMEINDEX": false, // 综合展示
  79. "DTB-DATAMANAGE": false, // 数据管理
  80. "DTB-DATAPUBLISH": false, // 数据发布
  81. "DTB-PLUGINMANAGE": false, // 插件管理
  82. "DTB-SYSTEMMANAGE": false, // 系统管理
  83. }
  84. }
  85. },
  86. created() {
  87. this.$root.$.appContext.config.globalProperties.judgeLogin = this.judgeLogin;
  88. },
  89. mounted() {
  90. this.judgeLogin();
  91. },
  92. methods: {
  93. judgeLogin() {
  94. let token = this.$store.getters.getToken;
  95. this.isLogin = token && token !== '';
  96. this.activeIndex = 1;
  97. if (this.isLogin) {
  98. this.updateAuth();
  99. }
  100. },
  101. updateAuth() {
  102. let app = this;
  103. let params = {
  104. serviceId: this.$constant.serviceId,
  105. type: app.$constant.authType
  106. }
  107. let keys = Object.keys(app.pageShow);
  108. loginApi.getUserPermissions(params).then(res=>{
  109. if (res.code === 200) {
  110. res.content.forEach(item => {
  111. if (keys.indexOf(item.permissionName)>-1) {
  112. app.pageShow[item.permissionName] = true;
  113. }
  114. })
  115. }
  116. })
  117. },
  118. handleMenuClick(val) {
  119. this.activeIndex = val;
  120. },
  121. login() {
  122. let app = this;
  123. if (!app.loginForm.userName || app.loginForm.userName==='') {
  124. app.$message({message: '请输入用户名', type: 'warning'});
  125. return;
  126. } else if (!app.loginForm.password || app.loginForm.password==='') {
  127. app.$message({message: '请输入密码', type: 'warning'});
  128. return;
  129. }
  130. app.$util.loading.handleLoading(true)
  131. loginApi.userLogin(app.loginForm).then(res => {
  132. app.$store.state.token = res.message
  133. app.$store.commit('setUserInfo', res.content);
  134. app.$store.commit('setToken', res.message);
  135. app.$util.loading.handleLoading(false);
  136. app.judgeLogin()
  137. }).catch(err => {
  138. app.$util.loading.handleLoading(false);
  139. app.judgeLogin();
  140. })
  141. },
  142. logout() {
  143. this.$util.loading.handleLoading(true);
  144. this.$store.state.token = '';
  145. this.$store.state.userInfo = {};
  146. this.loginForm = {
  147. userName: '',
  148. password: '',
  149. clientId: this.$constant.serviceId,
  150. };
  151. localStorage.clear();
  152. this.$store.commit('resetState', {});
  153. this.$util.loading.handleLoading(false);
  154. this.judgeLogin();
  155. },
  156. }
  157. }
  158. </script>
  159. <style scoped>
  160. .custom-loading .circular {
  161. margin-right: 6px;
  162. width: 18px;
  163. height: 18px;
  164. animation: loading-rotate 2s linear infinite;
  165. }
  166. .custom-loading .circular .path {
  167. animation: loading-dash 1.5s ease-in-out infinite;
  168. stroke-dasharray: 90, 150;
  169. stroke-dashoffset: 0;
  170. stroke-width: 2;
  171. stroke: var(--el-button-text-color);
  172. stroke-linecap: round;
  173. }
  174. #home {
  175. width: 100%;
  176. height: 100%;
  177. min-height: 100%;
  178. }
  179. #Header {
  180. /* background-image: linear-gradient(#90e2fc, white); */
  181. background-image: url('@/assets/img/header.png');
  182. background-size: 100% 100%;
  183. height: 18%;
  184. }
  185. #Header .title {
  186. height: 100%;
  187. padding: 3.5% 0 0 10%;
  188. }
  189. #Header .title img {
  190. width: 12%;
  191. }
  192. #Header .loginForm {
  193. float: right;
  194. /*width: 30%;*/
  195. /*float: right;*/
  196. margin-top: 1%;
  197. margin-right: 3%;
  198. /*color: white;*/
  199. }
  200. .loginForm .formLabel {
  201. display: inline-block;
  202. }
  203. .loginForm .formInput {
  204. margin-right: 5px;
  205. border-color: transparent;
  206. border-radius: 3px;
  207. height: 20px;
  208. color: white;
  209. padding-left: 6px;
  210. background: rgba(255, 255, 255, 0.3);
  211. }
  212. .loginForm .formInput:hover {
  213. background-color: rgba(255, 255, 255, 0.6);
  214. }
  215. .loginForm .formInput:focus {
  216. outline: 1px solid rgba(255, 255, 255, 0.6);
  217. }
  218. .logout {
  219. color: #e1e1e1;
  220. padding: 0 15px 5px
  221. }
  222. .logout:hover {
  223. color: orange;
  224. }
  225. .formLabel {
  226. color: white;
  227. }
  228. #Menu {
  229. height: 76%;
  230. overflow: visible;
  231. }
  232. #Tags {
  233. width: 100%;
  234. }
  235. .content {
  236. width: 80%;
  237. margin: 0 auto;
  238. /*padding-top: 1%;*/
  239. height: 95%;
  240. /*overflow: visible;*/
  241. }
  242. .el-menu-demo {
  243. align-items: center;
  244. justify-content: center;
  245. }
  246. .el-menu-item {
  247. font-size: 20px;
  248. font-weight: 600;
  249. margin: 0 5% !important;
  250. }
  251. .el-menu-item:focus {
  252. background-color: #6162f2 !important;
  253. }
  254. </style>
  255. <style>
  256. .el-dialog__body {
  257. padding-top: 10px;
  258. }
  259. </style>