|
@@ -1,61 +1,67 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { useUserStoreWithOut, UserInterface } from "@/stores/modules/user"
|
|
|
-import { getAuthCode } from 'dingtalk-jsapi';
|
|
|
+import { useUserStoreWithOut, UserInterface } from "@/stores/modules/user";
|
|
|
+import { getAuthCode } from "dingtalk-jsapi";
|
|
|
import reqest from "@/utils/request";
|
|
|
-import { useDictStoreWithOut } from '@/utils/dict';
|
|
|
+import { useDictStoreWithOut } from "@/utils/dict";
|
|
|
|
|
|
const userStore = useUserStoreWithOut();
|
|
|
|
|
|
const initUserInfoHandler = async () => {
|
|
|
- const code: string = await getDDAuthCode() as string
|
|
|
- const userIdResult = await getUserIdByDD({code})
|
|
|
+ const code: string = (await getDDAuthCode()) as string;
|
|
|
+ const userIdResult = await getUserIdByDD({ code });
|
|
|
if (userIdResult && userIdResult?.data) {
|
|
|
- localStorage.setItem("ACCESS_TOKEN", userIdResult?.data.accessToken)
|
|
|
- useDictStoreWithOut()
|
|
|
- const userResult = await getUserInfoById()
|
|
|
- if (userResult && userResult?.data) {
|
|
|
- const userInfo: UserInterface = {
|
|
|
- id: userResult?.data.user.id,
|
|
|
- nickname: userResult?.data.user.nickname,
|
|
|
- signatureUrl: userResult?.data.user.signatureUrl
|
|
|
- }
|
|
|
- userStore.setUser(userInfo)
|
|
|
- localStorage.setItem("_userInfo", JSON.stringify(userInfo))
|
|
|
- }
|
|
|
+ localStorage.setItem("ACCESS_TOKEN", userIdResult?.data.accessToken);
|
|
|
+ useDictStoreWithOut();
|
|
|
+ const userResult = await getUserInfoById();
|
|
|
+ if (userResult && userResult?.data) {
|
|
|
+ const userInfo: UserInterface = {
|
|
|
+ id: userResult?.data.user.id,
|
|
|
+ nickname: userResult?.data.user.nickname,
|
|
|
+ deptId: userResult?.data.user.deptId,
|
|
|
+ deptName: userResult?.data.user.deptName,
|
|
|
+ signatureUrl: userResult?.data.user.signatureUrl,
|
|
|
+ };
|
|
|
+ userStore.setUser(userInfo);
|
|
|
+ localStorage.setItem("_userInfo", JSON.stringify(userInfo));
|
|
|
}
|
|
|
-}
|
|
|
-initUserInfoHandler()
|
|
|
+ }
|
|
|
+};
|
|
|
+initUserInfoHandler();
|
|
|
function getDDAuthCode() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- getAuthCode({
|
|
|
- corpId: 'ding65143abf9aeea2ec',
|
|
|
- success: (res: any) => {
|
|
|
- const { code } = res;
|
|
|
- if (code) {
|
|
|
- resolve(code);
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (ex: any) => {
|
|
|
- reject(ex);
|
|
|
- },
|
|
|
- complete: () => {},
|
|
|
- });
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ getAuthCode({
|
|
|
+ corpId: "ding65143abf9aeea2ec",
|
|
|
+ success: (res: any) => {
|
|
|
+ const { code } = res;
|
|
|
+ if (code) {
|
|
|
+ resolve(code);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (ex: any) => {
|
|
|
+ reject(ex);
|
|
|
+ },
|
|
|
+ complete: () => {},
|
|
|
});
|
|
|
+ });
|
|
|
}
|
|
|
interface UserIdParam {
|
|
|
- code: string
|
|
|
+ code: string;
|
|
|
}
|
|
|
const getUserIdByDD = async (data: Required<UserIdParam>) => {
|
|
|
- return reqest.post(`/app-api/system/auth/login-ding?code=${data.code}`, null, {
|
|
|
- headers: {
|
|
|
- isAuth: false
|
|
|
+ return reqest.post(
|
|
|
+ `/app-api/system/auth/login-ding?code=${data.code}`,
|
|
|
+ null,
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ isAuth: false,
|
|
|
+ },
|
|
|
}
|
|
|
- })
|
|
|
-}
|
|
|
+ );
|
|
|
+};
|
|
|
//@ts-ignore
|
|
|
const getUserInfoById = async () => {
|
|
|
- return reqest.get('/admin-api/system/auth/get-permission-info')
|
|
|
-}
|
|
|
+ return reqest.get("/admin-api/system/auth/get-permission-info");
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<template>
|