yanghao 1 week ago
parent
commit
a25f6a03c8
2 changed files with 79 additions and 61 deletions
  1. 78 60
      src/views/index.vue
  2. 1 1
      src/views/notices/index.vue

+ 78 - 60
src/views/index.vue

@@ -311,6 +311,8 @@ import {
 } from "@/api/user";
 import { useUserStore } from "@/stores/useUserStore";
 import { getAccessToken } from "@/utils/auth";
+import { deleteUserCache } from "@hooks/useCache";
+import { manualLogoutKey, reloginCancelKey } from "@/config/axios/service";
 import banner1 from "@/assets/images/banner1.png";
 import banner2 from "@/assets/images/banner2.jpg";
 import banner3 from "@/assets/images/banner3.jpg";
@@ -369,10 +371,10 @@ const router = useRouter();
 const userStore = useUserStore();
 
 const todoPanelTitle = "待办中心";
-const newsPanelTitle = "新闻";
+const newsPanelTitle = "新闻中心";
 const noticeTabs = [
-  { key: "notice", label: "公告" },
   { key: "redHead", label: "红头文件" },
+  { key: "notice", label: "通知公告" },
 ] as const;
 
 type NoticeTabKey = (typeof noticeTabs)[number]["key"];
@@ -483,7 +485,7 @@ const nextSlide = () => {
   currentIndex.value = (currentIndex.value + 1) % slides.value.length;
 };
 
-const activeNoticeTab = ref<NoticeTabKey>("notice");
+const activeNoticeTab = ref<NoticeTabKey>("redHead");
 const noticeListMap = ref<Record<NoticeTabKey, NoticeItem[]>>({
   notice: [],
   redHead: [],
@@ -495,6 +497,27 @@ const currentNoticeList = computed(
   () => noticeListMap.value[activeNoticeTab.value] ?? [],
 );
 
+const loadHomeData = async () => {
+  await loadNoticeList(activeNoticeTab.value);
+
+  if (!userStore.getUser.username) return;
+
+  const [oaRes, newsRes] = await Promise.all([
+    getOATasks({
+      id: userStore.getUser.username,
+      pageNum: 1,
+      pageSize: 10,
+    }),
+    getNews({
+      pageNum: 1,
+      pageSize: 10,
+    }),
+  ]);
+
+  oaTasks.value = oaRes.todoList.slice(0, 3);
+  newsList.value = newsRes.list.slice(0, 3);
+};
+
 const loadNoticeList = async (tabKey: NoticeTabKey) => {
   const requestApi = tabKey === "notice" ? getNotices : getRedHeadFiles;
   const res = await requestApi({
@@ -505,7 +528,7 @@ const loadNoticeList = async (tabKey: NoticeTabKey) => {
   noticeListMap.value[tabKey] = (res?.list || []).slice(0, 3);
 };
 
-let currentTabKey = ref<NoticeTabKey>("notice");
+let currentTabKey = ref<NoticeTabKey>("redHead");
 const handleNoticeTabChange = async (tabKey: NoticeTabKey) => {
   activeNoticeTab.value = tabKey;
   currentTabKey.value = tabKey;
@@ -640,48 +663,62 @@ async function loginWithDingTalk() {
   const ddCorpId = import.meta.env.VITE_DD_CORPID;
   const ddClientId = import.meta.env.VITE_DD_CLIENTID;
 
-  if (!ddCorpId || !ddClientId) return;
-
-  dd.requestAuthCode({
-    corpId: ddCorpId,
-    clientId: ddClientId,
-    success: (res: any) => {
-      const { code } = res;
-
-      axios
-        .post(
-          import.meta.env.BASE_URL + "/admin-api/system/auth/h5SocialLogin",
-          {
-            code,
-            type: 20,
-            state: new Date().getTime(),
-          },
-          {
-            headers: {
-              "Content-Type": "application/json",
-              "tenant-id": 1,
+  if (!ddCorpId || !ddClientId) return false;
+
+  return await new Promise<boolean>((resolve) => {
+    dd.requestAuthCode({
+      corpId: ddCorpId,
+      clientId: ddClientId,
+      success: async (res: any) => {
+        try {
+          const { code } = res;
+          const response = await axios.post(
+            import.meta.env.BASE_URL + "/admin-api/system/auth/h5SocialLogin",
+            {
+              code,
+              type: 20,
+              state: new Date().getTime(),
+            },
+            {
+              headers: {
+                "Content-Type": "application/json",
+                "tenant-id": 1,
+              },
             },
-          },
-        )
-        .then((response) => {
+          );
+
+          deleteUserCache();
+          userStore.resetState();
           authUtil.setToken(response.data.data);
-          router.push({
-            path: "/login",
-          });
-        });
-    },
-    fail: (err: any) => {
-      console.log("err :>> ", err);
-    },
+          sessionStorage.removeItem(manualLogoutKey);
+          sessionStorage.removeItem(reloginCancelKey);
+          await userStore.setUserInfoAction();
+          resolve(true);
+        } catch (error) {
+          console.log("dingTalk login error :>> ", error);
+          resolve(false);
+        }
+      },
+      fail: (err: any) => {
+        console.log("err :>> ", err);
+        resolve(false);
+      },
+    });
   });
 }
 
-function dingTalkAutoLogin() {
+async function dingTalkAutoLogin() {
   const ua = window.navigator.userAgent.toLowerCase();
 
-  if (ua.includes("dingtalk") || ua.includes("dingtalkwork")) {
-    loginWithDingTalk();
+  if (
+    (ua.includes("dingtalk") || ua.includes("dingtalkwork")) &&
+    !userStore.getUser.username &&
+    !getAccessToken()
+  ) {
+    return await loginWithDingTalk();
   }
+
+  return false;
 }
 
 const getTagClass = (tag: string) => {
@@ -706,29 +743,10 @@ const getTagName = (tag: string) => {
 
 let oaTasks = ref([]);
 onMounted(async () => {
-  dingTalkAutoLogin();
   slideTimer = setInterval(nextSlide, 5000);
+  await dingTalkAutoLogin();
 
-  await loadNoticeList("notice");
-
-  if (userStore.getUser.username) {
-    try {
-      const res = await getOATasks({
-        id: userStore.getUser.username,
-        pageNum: 1,
-        pageSize: 10,
-      });
-      oaTasks.value = res.todoList.slice(0, 3);
-
-      const newList = await getNews({
-        pageNum: 1,
-        pageSize: 10,
-      });
-
-      newsList.value = newList.list.slice(0, 3);
-    } finally {
-    }
-  }
+  await loadHomeData();
 });
 
 const handleNoticeItemClick = async (notice) => {
@@ -1139,7 +1157,7 @@ onUnmounted(() => {
   align-items: center;
   justify-content: center;
   height: 25px;
-  min-width: 54px;
+  min-width: 70px;
   /* padding: 0 5px 0 10px; */
   background: #004098;
   color: #fff;

+ 1 - 1
src/views/notices/index.vue

@@ -4,7 +4,7 @@
 
     <div class="content-wrapper mt-15 max-w-[1200px] mx-auto">
       <h2 class="page-title">
-        {{ route.query.tabKey === "notice" ? "公告" : "红头文件" }}
+        {{ route.query.tabKey === "notice" ? "通知公告" : "红头文件" }}
       </h2>
 
       <!-- 新闻列表区域 - 使用 el-table -->