index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="login-container flex-row">
  3. <div class="part" v-if="userInfo.avatarUrl">
  4. <div class="user">
  5. <img :src="userInfo.avatarUrl" alt="" class="avatar">
  6. <div class="name">{{ userInfo.nickname }}</div>
  7. <div class="info">登录成功即可绑定</div>
  8. </div>
  9. <Account from="sso" :ssoInfo="userInfo" />
  10. </div>
  11. </div>
  12. </template>
  13. <script lang="ts">
  14. import { computed, defineComponent, getCurrentInstance, ref } from 'vue';
  15. import { useRoute, useRouter } from 'vue-router';
  16. import { useStore } from '/@/store/index';
  17. import dayjs from 'dayjs';
  18. import api from '/@/api/system';
  19. import { Session, Local } from '/@/utils/storage';
  20. import { initFrontEndControlRoutes } from '/@/router/frontEnd';
  21. import { initBackEndControlRoutes } from '/@/router/backEnd';
  22. import { ElMessage } from 'element-plus';
  23. import { setToken } from "/@/utils/auth";
  24. import Account from '/@/views/login/component/account.vue';
  25. // 定义接口来定义对象的类型
  26. interface LoginState {
  27. tabsActiveName: string;
  28. isScan: boolean;
  29. }
  30. export default defineComponent({
  31. components: {
  32. Account
  33. },
  34. data: function () {
  35. return {
  36. dayjs,
  37. sysinfo: {
  38. buildVersion: '',
  39. systemName: '',
  40. buildTime: '',
  41. systemCopyright: '',
  42. systemLogo: '',
  43. systemLoginPIC: '',
  44. },
  45. };
  46. },
  47. mounted() {
  48. this.sysinfo = JSON.parse(localStorage.sysinfo || '{}');
  49. },
  50. setup() {
  51. const route = useRoute()
  52. const router = useRouter();
  53. const store = useStore();
  54. const { proxy } = getCurrentInstance() as any;
  55. const userInfo = ref<any>({})
  56. api.sso.callback(route.query).then(async (res: any) => {
  57. if (!res.loginUser) {
  58. userInfo.value = res.oauthUser
  59. return
  60. }
  61. setToken(res.loginUser.token);
  62. localStorage.setItem('token', res.loginUser.token);
  63. const userInfos = res.loginUser;
  64. userInfos.avatar = proxy.getUpFileUrl(userInfos.avatar);
  65. // 存储 token 到浏览器缓存
  66. Local.set('userInfo', userInfos);
  67. // 存储用户信息到浏览器缓存
  68. Session.set('userInfo', userInfos);
  69. // 获取权限配置,上传文件类型等
  70. const [columnRes, buttonRes, uploadFileRes] = await Promise.all([api.getInfoByKey('sys.column.switch'), api.getInfoByKey('sys.button.switch'), api.getInfoByKey('sys.uploadFile.way')])
  71. const isSecurityControlEnabled = sessionStorage.isSecurityControlEnabled || null
  72. localStorage.setItem('btnNoAuth', (isSecurityControlEnabled && Number(buttonRes?.data?.configValue)) ? '' : '1');
  73. localStorage.setItem('colNoAuth', (isSecurityControlEnabled && Number(columnRes?.data?.configValue)) ? '' : '1');
  74. localStorage.setItem('uploadFileWay', uploadFileRes?.data?.configValue || '0');
  75. await store.dispatch('userInfos/setUserInfos', userInfos);
  76. currentUser();
  77. })
  78. // 获取登录用户信息
  79. const currentUser = async () => {
  80. api.login.currentUser().then(async (res: any) => {
  81. localStorage.setItem('userId', res.Info.id);
  82. // 设置用户菜单
  83. Session.set('userMenu', res.Data || []);
  84. store.dispatch('requestOldRoutes/setBackEndControlRoutes', res || []);
  85. if (!store.state.themeConfig.themeConfig.isRequestRoutes) {
  86. // 前端控制路由,2、请注意执行顺序
  87. await initFrontEndControlRoutes();
  88. signInSuccess();
  89. } else {
  90. // 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
  91. // 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
  92. await initBackEndControlRoutes();
  93. // 执行完 initBackEndControlRoutes,再执行 signInSuccess
  94. signInSuccess();
  95. }
  96. });
  97. // // 设置按钮权限
  98. // Session.set('permissions', res.data.permissions);
  99. // // 1、请注意执行顺序(存储用户信息到vuex)
  100. // await store.dispatch('userInfos/setPermissions', res.data.permissions);
  101. };
  102. // 登录成功后的跳转
  103. const signInSuccess = () => {
  104. // 修改首页重定向的地址,从后台配置中获取首页的地址并在登录之后和刷新页面时进行修改
  105. const sysinfo = JSON.parse(localStorage.sysinfo || '{}');
  106. const homePage = router.getRoutes().find((item) => item.path === '/');
  107. homePage && (homePage.redirect = sysinfo.systemHomePageRoute || '/home');
  108. if (route.query?.redirect) {
  109. router.push({
  110. path: route.query?.redirect as string,
  111. query: route.query.params ? (Object.keys(route.query?.params as string).length > 0 ? JSON.parse(route.query?.params as string) : '') : '',
  112. });
  113. } else {
  114. router.push('/');
  115. }
  116. // 登录成功提示
  117. ElMessage.success('登录成功');
  118. };
  119. return {
  120. userInfo
  121. };
  122. },
  123. });
  124. </script>
  125. <style scoped lang="scss">
  126. .user {
  127. text-align: center;
  128. .avatar {
  129. width: 80px;
  130. height: 80px;
  131. border-radius: 50%;
  132. }
  133. .name {
  134. font-size: 20px;
  135. font-weight: 500;
  136. text-align: center;
  137. font-size: #999;
  138. }
  139. .info {
  140. font-size: 16px;
  141. text-align: center;
  142. color: #f40;
  143. }
  144. }
  145. html[data-theme='dark'] {
  146. .login-container {
  147. background: #293146;
  148. }
  149. .left {
  150. background-image: url(/@/assets/login-bg-dark.svg);
  151. }
  152. .title {
  153. color: #aaa;
  154. }
  155. }
  156. .flex {
  157. display: flex;
  158. align-items: center;
  159. }
  160. .text {
  161. color: #fff;
  162. }
  163. .switch {
  164. position: fixed;
  165. right: 20px;
  166. top: 20px;
  167. }
  168. .login-container {
  169. width: 100vw;
  170. height: 100vh;
  171. position: relative;
  172. background: #fff;
  173. .title {
  174. font-size: 30px;
  175. color: #333;
  176. font-weight: bold;
  177. letter-spacing: 20px;
  178. }
  179. .logo {
  180. font-size: 30px;
  181. color: #fff;
  182. .logoimg {
  183. height: 50px;
  184. display: block;
  185. margin-right: 12px;
  186. }
  187. }
  188. .img {
  189. width: 50%;
  190. display: block;
  191. margin: 15vh 0;
  192. }
  193. .part {
  194. flex: 1;
  195. display: flex;
  196. flex-flow: column nowrap;
  197. justify-content: center;
  198. align-items: center;
  199. }
  200. .left {
  201. height: 100vh;
  202. background-image: url(/@/assets/login-bg.svg);
  203. background-repeat: no-repeat;
  204. background-size: auto 100%;
  205. background-position: right center;
  206. align-items: flex-start;
  207. padding-left: 8%;
  208. }
  209. .login-icon-group {
  210. width: 100%;
  211. height: 100%;
  212. position: relative;
  213. .login-icon-group-title {
  214. display: flex;
  215. align-items: center;
  216. justify-content: center;
  217. margin: 12px 0;
  218. img {
  219. width: auto;
  220. height: 40px;
  221. }
  222. &-text {
  223. padding-left: 20px;
  224. color: var(--el-color-primary);
  225. }
  226. }
  227. &-icon {
  228. width: 60%;
  229. height: 70%;
  230. position: absolute;
  231. left: 0;
  232. bottom: 0;
  233. }
  234. }
  235. .login-content-out {
  236. width: 100%;
  237. height: 100%;
  238. padding-top: calc(50vh - 227px);
  239. }
  240. .login-content {
  241. width: 500px;
  242. padding: 20px;
  243. margin-left: calc(50% - 500px);
  244. background-color: rgba(255, 255, 255, 0.8);
  245. border: 5px solid var(--el-color-primary-light-8);
  246. border-radius: 5px;
  247. overflow: hidden;
  248. z-index: 1;
  249. position: relative;
  250. .login-content-main {
  251. margin: 0 auto;
  252. width: 80%;
  253. .login-content-title {
  254. color: var(--el-text-color-primary);
  255. font-weight: 500;
  256. font-size: 22px;
  257. text-align: center;
  258. letter-spacing: 4px;
  259. margin: 15px 0 30px;
  260. white-space: nowrap;
  261. z-index: 5;
  262. position: relative;
  263. transition: all 0.3s ease;
  264. }
  265. }
  266. .login-content-main-sacn {
  267. position: absolute;
  268. top: 0;
  269. right: 0;
  270. width: 50px;
  271. height: 50px;
  272. overflow: hidden;
  273. cursor: pointer;
  274. transition: all ease 0.3s;
  275. color: var(--el-text-color-primary);
  276. &-delta {
  277. position: absolute;
  278. width: 35px;
  279. height: 70px;
  280. z-index: 2;
  281. top: 2px;
  282. right: 21px;
  283. background: var(--el-color-white);
  284. transform: rotate(-45deg);
  285. }
  286. &:hover {
  287. opacity: 1;
  288. transition: all ease 0.3s;
  289. color: var(--el-color-primary) !important;
  290. }
  291. i {
  292. width: 47px;
  293. height: 50px;
  294. display: inline-block;
  295. font-size: 48px;
  296. position: absolute;
  297. right: 2px;
  298. top: -1px;
  299. }
  300. }
  301. }
  302. .login-footer {
  303. position: absolute;
  304. bottom: 5px;
  305. width: 100%;
  306. &-content {
  307. width: 100%;
  308. display: flex;
  309. &-warp {
  310. margin: auto;
  311. color: #e0e3e9;
  312. text-align: center;
  313. animation: error-num 1s ease-in-out;
  314. }
  315. }
  316. }
  317. }
  318. </style>