|
|
@@ -80,6 +80,13 @@ import * as dd from 'dingtalk-jsapi'
|
|
|
import { LoginForm, QrCodeForm, RegisterForm, ForgetPasswordForm } from './components'
|
|
|
import { dingTalkLogin } from '../../api/login'
|
|
|
|
|
|
+import * as authUtil from '@/utils/auth'
|
|
|
+import { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
|
+import { usePermissionStore } from '../../store/modules/permission'
|
|
|
+
|
|
|
+import * as LoginApi from '@/api/login'
|
|
|
+import { ElLoading } from 'element-plus'
|
|
|
+
|
|
|
defineOptions({ name: 'Login' })
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
@@ -87,34 +94,79 @@ const appStore = useAppStore()
|
|
|
const { getPrefixCls } = useDesign()
|
|
|
const prefixCls = getPrefixCls('login')
|
|
|
|
|
|
-function loginWithDingTalk() {
|
|
|
+const loading = ref<any>(null)
|
|
|
+
|
|
|
+const redirect = ref<string>('')
|
|
|
+
|
|
|
+const router = useRouter()
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => router.currentRoute.value,
|
|
|
+ (route: RouteLocationNormalizedLoaded) => {
|
|
|
+ redirect.value = route?.query?.redirect as string
|
|
|
+ },
|
|
|
+ {
|
|
|
+ immediate: true
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+const getTenantId = async () => {
|
|
|
+ if (import.meta.env.VITE_APP_TENANT_ENABLE === 'true') {
|
|
|
+ const res = await LoginApi.getTenantIdByName('芋道源码')
|
|
|
+ debugger
|
|
|
+ authUtil.setTenantId(res)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const permissionStore = usePermissionStore()
|
|
|
+
|
|
|
+async function loginWithDingTalk() {
|
|
|
const ddCorpId = import.meta.env.VITE_DD_CORPID
|
|
|
const ddClientId = import.meta.env.VITE_DD_CLIENTID
|
|
|
|
|
|
if (!ddCorpId || !ddClientId) return
|
|
|
|
|
|
+ await getTenantId()
|
|
|
+
|
|
|
dd.requestAuthCode({
|
|
|
corpId: ddCorpId,
|
|
|
clientId: ddClientId,
|
|
|
success: (res: any) => {
|
|
|
const { code } = res
|
|
|
-
|
|
|
- dingTalkLogin({ code, type: 10, state: new Date().getTime() }).then((res) => {
|
|
|
+ dingTalkLogin({ code, type: 10, state: new Date().getTime() }).then(async (res) => {
|
|
|
console.log('res :>> ', res)
|
|
|
+ loading.value = ElLoading.service({
|
|
|
+ lock: true,
|
|
|
+ text: '正在加载系统中...',
|
|
|
+ background: 'rgba(0, 0, 0, 0.7)'
|
|
|
+ })
|
|
|
+
|
|
|
+ // authUtil.removeLoginForm()
|
|
|
+
|
|
|
+ authUtil.setToken(res)
|
|
|
+
|
|
|
+ if (!redirect.value) {
|
|
|
+ redirect.value = '/'
|
|
|
+ }
|
|
|
+ if (redirect.value.indexOf('sso') !== -1) {
|
|
|
+ window.location.href = window.location.href.replace('/login?redirect=', '')
|
|
|
+ } else {
|
|
|
+ router.push({ path: redirect.value || permissionStore.addRouters[0].path }).then(() => {
|
|
|
+ loading.value.close()
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
fail: (err: any) => {
|
|
|
console.log('err :>> ', err)
|
|
|
+ },
|
|
|
+ complete: () => {
|
|
|
+ console.log('11 :>> ', 11)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
function dingTalkAutoLogin() {
|
|
|
- const url = window.location.href
|
|
|
-
|
|
|
- console.log('url :>> ', url)
|
|
|
- if (!url.includes('/deepoli')) return
|
|
|
-
|
|
|
const ua = window.navigator.userAgent.toLowerCase()
|
|
|
|
|
|
console.log('ua :>> ', ua)
|