index.vue 8.0 KB

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