index.vue 7.3 KB

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