|
|
@@ -0,0 +1,158 @@
|
|
|
+<template>
|
|
|
+ <div class="ToOcaXdjf" v-loading="loading" element-loading-text=""></div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { mapActions } from 'vuex';
|
|
|
+import NProgress from 'nprogress';
|
|
|
+import 'nprogress/nprogress.css';
|
|
|
+import { renderWatermark } from '@/utils/util.js';
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'ToOcaXdjf',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ loading: false,
|
|
|
+ min_duration: 2000,
|
|
|
+ max_duration: 10000,
|
|
|
+ timer: null,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ console.log("this.$route.query",this.$route.query);
|
|
|
+ // 页面加载时显示一个旋转的加载图标
|
|
|
+ NProgress.start(); // 开始进度条
|
|
|
+ this.init();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapActions('oauth', ['getAccessToken']),
|
|
|
+ // 初始化
|
|
|
+ init() {
|
|
|
+ this.loading = true;
|
|
|
+ const { username, userName, usrname, usrName, sso_token } = this.$route.query;
|
|
|
+ const name = sso_token || username || usrname || usrName || userName;
|
|
|
+ console.log("name",name);
|
|
|
+ if (name) {
|
|
|
+ const encodedName = this.encodeUseName(name);
|
|
|
+ this.loginFn(encodedName);
|
|
|
+ } else {
|
|
|
+ this.$confirm('url缺少必要参数', '', {
|
|
|
+ showConfirmButton: false,
|
|
|
+ showCancelButton: false,
|
|
|
+ type: 'error',
|
|
|
+ }).catch(() => {
|
|
|
+ window.close();
|
|
|
+ });
|
|
|
+ if (this.timer) {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ this.timer = null;
|
|
|
+ }
|
|
|
+ this.timer = setTimeout(() => {
|
|
|
+ if (this.timer) {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ }
|
|
|
+ window.close();
|
|
|
+ }, this.min_duration);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 加密用户名
|
|
|
+ encodeUseName(value) {
|
|
|
+ return this.desEncrypt(value);
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * DES CBC 加密
|
|
|
+ * @param {string} text 明文
|
|
|
+ * @returns {string} 大写十六进制密文
|
|
|
+ */
|
|
|
+ desEncrypt(text) {
|
|
|
+ if (!text) return '';
|
|
|
+ // 固定密钥和 IV
|
|
|
+ const KEY = CryptoJS.enc.Utf8.parse('Passw0rd');
|
|
|
+ const IV = CryptoJS.enc.Utf8.parse('Passw0rd');
|
|
|
+ // DES/CBC/PKCS5Padding 加密
|
|
|
+ const encrypted = CryptoJS.DES.encrypt(
|
|
|
+ CryptoJS.enc.Utf8.parse(text),
|
|
|
+ KEY,
|
|
|
+ {
|
|
|
+ iv: IV,
|
|
|
+ mode: CryptoJS.mode.CBC,
|
|
|
+ padding: CryptoJS.pad.Pkcs7
|
|
|
+ }
|
|
|
+ );
|
|
|
+ // 转换为大写十六进制
|
|
|
+ return encrypted.ciphertext.toString(CryptoJS.enc.Hex).toUpperCase();
|
|
|
+ },
|
|
|
+ // 用户名登录
|
|
|
+ loginFn(encodedName) {
|
|
|
+ if (this.timer) {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ }
|
|
|
+ this.timer = setTimeout(() => {
|
|
|
+ if (this.timer) {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ }
|
|
|
+ this.$confirm('请求超时', '', {
|
|
|
+ showConfirmButton: false,
|
|
|
+ showCancelButton: false,
|
|
|
+ type: 'error',
|
|
|
+ }).catch(() => {
|
|
|
+ window.close();
|
|
|
+ });
|
|
|
+ this.timer = setTimeout(() => {
|
|
|
+ if (this.timer) {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ }
|
|
|
+ window.close();
|
|
|
+ }, this.min_duration);
|
|
|
+ }, this.max_duration);
|
|
|
+ const data = {
|
|
|
+ params: {
|
|
|
+ grantType: 'union',
|
|
|
+ username: encodedName,
|
|
|
+ },
|
|
|
+ config: { showErrorMessage: false },
|
|
|
+ };
|
|
|
+ this.getAccessToken(data).then((res) => {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ // 登录成功,初始化数据
|
|
|
+ renderWatermark();
|
|
|
+ this.$store.dispatch('initSysData');
|
|
|
+ NProgress.done();
|
|
|
+ this.loading = false;
|
|
|
+ this.redirectToFrame();
|
|
|
+ }).catch(({ code, message, data, extData }) => {
|
|
|
+ if (this.timer) {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ }
|
|
|
+ this.$confirm(message, '', {
|
|
|
+ showConfirmButton: false,
|
|
|
+ showCancelButton: false,
|
|
|
+ type: 'error',
|
|
|
+ }).catch(() => {
|
|
|
+ window.close();
|
|
|
+ });
|
|
|
+ this.timer = setTimeout(() => {
|
|
|
+ if (this.timer) {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ }
|
|
|
+ window.close();
|
|
|
+ }, this.min_duration);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 重定向路由到首页
|
|
|
+ redirectToFrame() {
|
|
|
+ window.vmrouter = this.$router;
|
|
|
+ this.$router.push({
|
|
|
+ path: this.redirect || '/',
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style lang="scss">
|
|
|
+.ToOcaXdjf {
|
|
|
+ background-color: #fff;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+}
|
|
|
+</style>
|