|
@@ -1,16 +1,63 @@
|
|
|
<script setup lang="ts">
|
|
|
-dd.getAuthCode({
|
|
|
- corpId: 'ding12345xxx',
|
|
|
- success: (res) => {
|
|
|
- const { authCode } = res;
|
|
|
- if (authCode) {
|
|
|
- // 授权成功
|
|
|
- console.log(authCode);
|
|
|
- }
|
|
|
- },
|
|
|
- fail: () => {},
|
|
|
- complete: () => {},
|
|
|
-});
|
|
|
+import { getAuthCode } from 'dingtalk-jsapi';
|
|
|
+import { getUrlParams } from "@/utils/common";
|
|
|
+import reqest from "@/utils/request";
|
|
|
+
|
|
|
+const socialAuthRedirect = (type: number, redirectUri: string) => {
|
|
|
+ return reqest.get('/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri)
|
|
|
+}
|
|
|
+const initUserInfoHandler = async (type: number) => {
|
|
|
+ const redirectUri:string ='http://10.10.10.7:48080/admin-api/system/auth/social-login?type=' + type
|
|
|
+ const res = await socialAuthRedirect(type, encodeURIComponent(redirectUri))
|
|
|
+ if (res && res.data) {
|
|
|
+ const map = getUrlParams(res.data);
|
|
|
+ const state: string = map?.get("state") as string
|
|
|
+ const code: string = await getDDAuthCode() as string
|
|
|
+ const userIdResult = await getUserIdByDD({
|
|
|
+ type,
|
|
|
+ code,
|
|
|
+ state
|
|
|
+ })
|
|
|
+ if (userIdResult && userIdResult.data) {
|
|
|
+ getUserInfoById(userIdResult.data)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+initUserInfoHandler(20)
|
|
|
+function getDDAuthCode() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ getAuthCode({
|
|
|
+ corpId: 'ding65143abf9aeea2ec',
|
|
|
+ success: (res) => {
|
|
|
+ const { authCode } = res;
|
|
|
+ if (authCode) {
|
|
|
+ resolve(authCode);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (ex: any) => {
|
|
|
+ reject(ex);
|
|
|
+ },
|
|
|
+ complete: () => {},
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+interface UserIdParam {
|
|
|
+ type: number
|
|
|
+ code: string
|
|
|
+ state: string
|
|
|
+}
|
|
|
+const getUserIdByDD = async (data: Required<UserIdParam>) => {
|
|
|
+ return reqest.post({
|
|
|
+ url: '/system/auth/social-login',
|
|
|
+ data: data
|
|
|
+ })
|
|
|
+}
|
|
|
+const getUserInfoById = async (idStr: Required<string>) => {
|
|
|
+ return reqest.get({
|
|
|
+ url: '/system/user/get',
|
|
|
+ params: {id: idStr}
|
|
|
+ })
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|