Procházet zdrojové kódy

Merge remote-tracking branch 'origin/master'

yangyuxuan před 5 měsíci
rodič
revize
c79a06f028

+ 2 - 0
README.md

@@ -15,3 +15,5 @@ pnpm run dev
 
 ## 构建生产环境
 pnpm run build
+
+pnpm run build-only

+ 9 - 0
src/api/InformationReception/InformationReception.ts

@@ -78,4 +78,13 @@ export function getPhoneList() {
       url: '/api/info_publish/addressbook/alldepts',
       method: 'get'
   });
+}
+
+// 消息中心
+export function getUnreadMsgCount(data) {
+  return request({
+    url: "/api/info_publish/msg_center/unread_msg_count",
+    method: 'post',
+    data: data
+});
 }

+ 1 - 1
src/api/login.ts

@@ -50,7 +50,7 @@ export function callback(data): AxiosPromise<any> {
     grantType: 'social'
   };
   return request({
-    url: '/api/auth/yzy/callback',
+    url: '/auth/yzy/callback',
     headers: {
       isToken: false,
       isEncrypt: true,

+ 37 - 88
src/components/YzyCallback/index.vue

@@ -5,103 +5,52 @@
 <script setup lang="ts">
 import { ref, onMounted, nextTick } from 'vue';
 import { useRoute, useRouter } from 'vue-router';
-import { login, callback } from '@/api/login';
+import { callback, getInfo } from '@/api/login';
 import { setToken, getToken } from '@/utils/auth';
-import { LoginData } from '@/api/types';
-import { showSuccessToast, showFailToast, Loading } from "vant";
+import useUserStore from "@/store/modules/user";
 
 const route = useRoute();
-const loading = ref(true);
-
 const router = useRouter();
-const a = route.query;
-console.log('a:', a);
-/**
- * 接收Route传递的参数
- * @param {Object} route.query.
- */
-const code = route.query.code as string;
-const state = route.query.state as string;
-const source = route.query.source as string;
-// const stateJson = JSON.parse(atob(state));
-// const tenantId = (stateJson.tenantId as string) ? (stateJson.tenantId as string) : '000000';
-// const domain = stateJson.domain as string;
-debugger;     
-
-console.log('code:', code);
-
-const processResponse = async (res: any) => {
-  if (res.code !== 200) {
-    throw new Error(res.msg);
-  }
-  if (res.data !== null) {
-    setToken(res.data.access_token);
-  }
-  // showSuccessToast(res.msg);
-  setTimeout(() => {
-    location.href = res.data.redirect_url;
-  }, 2000);
-};
-
-const handleError = (error: any) => {
-  showFailToast(error.message);
-  //setTimeout(() => {
-  //  location.href = '/index';
-  //}, 2000);
-};
-
-const callbackByCode = async (data) => {
-  try {
-    const res = await callback(data);
-    await processResponse(res);
-    loading.value = false;
-  } catch (error) {
-    handleError(error);
-  }
-};
-
-const loginByCode = async (data: LoginData) => {
-  try {
-    const res = await login(data);
-    await processResponse(res);
-    loading.value = false;
-  } catch (error) {
-    handleError(error);
-  }
-};
-
-const init = async () => {
-  // 如果域名不相等 则重定向处理
-  /*
-  let host = window.location.host;
-  if (domain !== host) {
-    let urlFull = new URL(window.location.href);
-    urlFull.host = domain;
-    window.location.href = urlFull.toString();
-    return;
-  }
-
-  const data: LoginData = {
-    socialCode: code,
-    socialState: state,
-    tenantId: tenantId,
-    source: source,
-    clientId: import.meta.env.VITE_APP_CLIENT_ID,
-    grantType: 'social'
-  };
+const useUser = useUserStore();
+const loading = ref(true);
 
-  if (!getToken()) {
-    await loginByCode(data);
-  } else {
-    await callbackByCode(data);
-  }
-  */
-  await callbackByCode({code, state});
+const do_callback = () => {
+  const code = route.query.code as string;
+  const state = route.query.state as string;
+  callback({code, state}).then((res)=>{
+      loading.value = false;
+      var access_token = res.data.access_token;
+      var redirect_url = res.data.redirect_url;
+      setToken(access_token);
+      
+      console.log('redirect_url:', redirect_url);
+      setTimeout(function() {
+        getUserInfo(redirect_url)
+      }, 500);
+  })
+}
+
+const getUserInfo = (redirect_url) => {
+  getInfo().then((res)=>{
+    const roles = res.data.roles;
+    console.log('roles', roles);
+    if(roles.includes("superadmin")) {
+      useUser.setRoles("leader");
+    }
+    if(roles.includes("super_ld")) {
+      useUser.setRoles("leader");
+    }
+    if(roles.includes("super_worker")) {
+      useUser.setRoles("worker");
+    }
+    
+    router.push(redirect_url);
+  })
 };
 
 onMounted(() => {
   nextTick(() => {
-    init();
+    do_callback();
   });
 });
 </script>

+ 2 - 1
src/views/index.vue

@@ -64,13 +64,14 @@ const getUserInfo = () => {
     if(!role_is_leader.value && role_is_worker.value) {
       handleJump('WorkerIndex', 'worker');
     }
-    //
+    /*
     let redirect_url = decodeURIComponent(route.query.redirect_url as string || "");
     console.log('redirect_url:', redirect_url);
     if(redirect_url != "") {
       useUser.setRoles("worker");
       router.replace(redirect_url);
     }
+    */
   })
 }
 </script>

+ 35 - 11
src/views/leader/index.vue

@@ -87,6 +87,7 @@
 import { onClickOutside } from "@vueuse/core";
 import { ref, reactive, onMounted, onUnmounted } from "vue";
 import { getActiveEventList } from "@/api/event";
+import { getUnreadMsgCount } from "@/api/InformationReception/InformationReception";
 import noticeImg from "@/assets/images/notice.png";
 import searchImg from "@/assets/images/search.png";
 import { useRouter } from "vue-router";
@@ -226,21 +227,44 @@ const handleClickItem = item => {
   searchList.value = [];
 };
 
+// 设置定时器,刷新统计数
+const fetchInterval = process.env.NODE_ENV === 'development' ? 60000 : 3000; // 每60秒刷新一次(刷新太频繁影响调试)
+let intervalId: any | null = null;
+const startFetchingData = () => {
+  if (!intervalId) {
+    intervalId = setInterval(() => {
+      fetchData();
+    }, fetchInterval);
+  }
+};
+
+const stopFetchingData = () => {
+  if (intervalId) {
+    clearInterval(intervalId);
+    intervalId = null;
+  }
+};
+
+const fetchData = async () => {
+  getUnreadMsgCount({"msg_types": "工作审批,在线点名,事件管理"}).then((res)=>{
+    menu.value.forEach((v)=>{
+      let obj = res.data.find(item=>item.name === v.name);
+      if(obj) {
+        v.num = obj.num;
+      }
+    })
+  })
+}
+
 onMounted(() => {
   initData();
-  // rollCallData.value = {
-  //   id: '11111',
-  //   time1: '2024-10-22 12:00:00'
-  // };
-  // show.value = true;
-  //if (!timer && !!rollCallData.value.time1) {
-  //  timer = setInterval(updateTime, 1000);
-  //}
+
+  // 统计数
+  fetchData();
+  startFetchingData();
 });
 onUnmounted(() => {
-  //if (!!timer) {
-  //  clearInterval(timer);
-  //}
+  stopFetchingData();
 });
 </script>
 

+ 1 - 3
src/views/signPage/index.vue

@@ -120,9 +120,7 @@ const handleSignCancel = () => {
 }
 
 onMounted(() => {
-  if (/(micromessenger)/i.test(navigator.userAgent)) {
-    // 微信端,啥都不填写
-  } else {
+  if (/(wxworklocal)/i.test(navigator.userAgent)) {
     getSignInfo({event_id: event_id}).then((res)=> {
       const user = res.data;
       console.log('user', user);

+ 39 - 29
src/views/worker/index.vue

@@ -92,14 +92,14 @@
 
 <script lang="ts" setup>
 import { onClickOutside } from "@vueuse/core";
-import { onMounted, reactive, ref } from "vue";
+import { onMounted, onUnmounted, reactive, ref } from "vue";
 import { selectTask } from "@/api/emergencyCommandMap/JointDuty";
 import searchImg from "@/assets/images/search.png";
 import { useRouter } from "vue-router";
 import closeImg from "@/assets/images/close.png";
 import { getPointInfoComprehensiveSearch } from "@/api/globalMap";
 import OnlineRollCall from "@/components/OnlineRollCall/index.vue";
-import { InformationList } from "@/api/InformationReception/InformationReception";
+import { InformationList, getUnreadMsgCount } from "@/api/InformationReception/InformationReception";
 
 const router = useRouter();
 const noticeBarState = reactive({
@@ -185,34 +185,7 @@ const initData = async() => {
 const handleInfo = (item) => {
   router.push("/infoDetails?id=" + item.id);
 }
-/*
-const initData = async () => {
-  try {
-    const sortOrder = "desc";
-    const sortBy = "creation_time";
-    const event_code = "YJSJ0000000001";
 
-    console.log("请求任务数据:", event_code);
-    const res = await selectTask({
-      sortOrder: sortOrder,
-      sortBy: sortBy,
-      event_code: event_code
-    });
-    if (res && res.data) {
-      noticeBarState.latestMessages = res.data.slice(0, 3).map(msg => ({
-        event_title: msg.event_title,
-        event_time: msg.event_time
-      }));
-      noticeBarState.show = true;
-    } else {
-      console.error("API response data is empty or invalid");
-    }
-  } catch (error) {
-    console.error("请求任务数据失败:", error);
-    noticeBarState.show = false; // 如果请求失败,不显示通知栏
-  }
-};
-*/
 // 搜索
 const searchBoxRef = ref();
 let showSearch = ref();
@@ -274,8 +247,45 @@ const handleClickItem = item => {
   finished.value = false;
   searchList.value = [];
 };
+
+// 设置定时器,刷新统计数
+const fetchInterval = process.env.NODE_ENV === 'development' ? 60000 : 3000; // 每60秒刷新一次(刷新太频繁影响调试)
+let intervalId: any | null = null;
+const startFetchingData = () => {
+  if (!intervalId) {
+    intervalId = setInterval(() => {
+      fetchData();
+    }, fetchInterval);
+  }
+};
+
+const stopFetchingData = () => {
+  if (intervalId) {
+    clearInterval(intervalId);
+    intervalId = null;
+  }
+};
+
+const fetchData = async () => {
+  getUnreadMsgCount({"msg_types": "巡查工作,在线点名,风险防控,数据管理"}).then((res)=>{
+    menu.value.forEach((v)=>{
+      let obj = res.data.find(item=>item.name === v.name);
+      if(obj) {
+        v.num = obj.num;
+      }
+    })
+  })
+}
+
 onMounted(() => {
   initData();
+
+  // 统计数
+  fetchData();
+  startFetchingData();
+});
+onUnmounted(() => {
+  stopFetchingData();
 });
 </script>