Kaynağa Gözat

feat: add HD login logic

hi-cactus! 3 yıl önce
ebeveyn
işleme
d9ff906c3f

+ 80 - 11
src/api/common.ts

@@ -13,17 +13,17 @@ import { BaseResponse } from './type';
  * - 车辆类型: zhdd_car_type
  * - 处置方案用户角色: zhdd_incident_task_role
  */
- export type DictType =
- | 'zhdd_plan_type'
- | 'zhdd_incident_type'
- | 'zhdd_incident_status'
- | 'zhdd_incident_level'
- | 'zhdd_incident_source'
- | 'zhdd_org_upload'
- | 'zhdd_resource'
- | 'zhdd_screen_type'
- | 'zhdd_car_type'
- | 'zhdd_incident_task_role';
+export type DictType =
+  | 'zhdd_plan_type'
+  | 'zhdd_incident_type'
+  | 'zhdd_incident_status'
+  | 'zhdd_incident_level'
+  | 'zhdd_incident_source'
+  | 'zhdd_org_upload'
+  | 'zhdd_resource'
+  | 'zhdd_screen_type'
+  | 'zhdd_car_type'
+  | 'zhdd_incident_task_role';
 
 export interface GlobalDict {
   dictLabel: string; // 字典标签
@@ -50,6 +50,7 @@ export interface UploadData {
 export interface UploadReponse extends BaseResponse {
   data: UploadData;
 }
+
 export const upload = (file: File) => {
   const form = new FormData();
   form.append('file', file);
@@ -61,3 +62,71 @@ export const upload = (file: File) => {
     data: form,
   });
 };
+
+export interface UserInfo {
+  userId?: string;
+  name?: string;
+  userName?: string;
+  orgName?: string;
+  deptName?: string;
+  roles?: string[];
+  accessToken: string;
+}
+
+export interface UserInfoResponse extends BaseResponse {
+  data: UserInfo;
+}
+
+export const getUserInfo = (ticket: string) =>
+  request<UserInfoResponse>('GET', {
+    url: `http://61.147.254.211:30876/tpbd-cas/user?ticket=${ticket}`,
+    headers: {
+      AppId: '3bcb760743ea456faba29a1dfb247bf4',
+    },
+  });
+
+export const NeedsReadUser = [
+  '4be8a4ea9c574734ab4acb49965b076b', //  武泽义
+  'f977a5593521478499f86dd00b2fe5d1', // 戈亚武
+  'b30f4e6d73cf49a2a99f85b1d4e5f511', // 徐健
+  '41c8d22e9bfa4009bc04eb9c6ee3c3ee', // 邵岩
+  '3436050bf856440588bf738a10510515', // 许辉
+  'e32c25131b3041c48a2889b5ccc37083', // 周卫东
+  '87a4102ce4b84b06bb5232bc2fce7135', // 宋学文
+  '1a61ecb94dda4418b32fcf862ca73f55', // 卢勇
+  '1f967f07545f43c99c9b175eb161aec8', // 李刚
+  '6b61c3e7f972467eb92ef02cd10d2777', // 韦宇
+  'a03a481e61674cd2af816db4d35042e5', // 解剑铭
+];
+
+export interface NoticeInfoParams {
+  msSource: '1';
+  msType: '2';
+  msNo: string; // 关联的处置过程 id
+}
+
+export interface NoticeInfo {
+  msTitle?: string;
+  msSynopsis?: string;
+  msText?: string;
+  msSource?: string;
+  msType?: string;
+  msTime?: string;
+  msNo?: string;
+  /** 阅读状态,0:未读,1:已读 */
+  messageReadInfoList?: { userId: string; readState: '0' | '1' }[];
+  fileList: { msAccessoryName?: string; msAccessory?: string }[];
+}
+
+export interface NoticeInfoResponse extends BaseResponse {
+  rows: NoticeInfo;
+}
+
+export const getMessage = (params: NoticeInfoParams) =>
+  request<NoticeInfoResponse>('GET', {
+    url: `http://61.147.254.211:30876/notice-info/messagepushinfo`,
+    headers: {
+      AppId: '3bcb760743ea456faba29a1dfb247bf4',
+    },
+    data: params,
+  });

+ 1 - 0
src/constants/constants.ts

@@ -1 +1,2 @@
 export const BaseMediaUrl = 'http://sqfile.xt.wenhq.top:8083';
+export const BaseLoginUrl = 'http://61.147.254.211:9999/home/#/login'

+ 5 - 0
src/layout/BaseLayout/index.scss

@@ -33,5 +33,10 @@
     flex-direction: column;
     min-height: calc(100vh);
     position: relative;
+    .el-button--small {
+      min-height: px2rem(32px * 4);
+      padding: px2rem(9px * 2) px2rem(15px * 5);
+      font-size: px2rem(12px * 4);
+    }
   }
 }

+ 18 - 0
src/router/index.ts

@@ -6,6 +6,7 @@ import {
   RouteRecordRaw,
 } from 'vue-router';
 import NProgress from 'nprogress';
+import { BaseLoginUrl } from '@/constants/constants';
 
 const BaseLayout = () =>
   import(/* webpackChunkName: "BaseLayout" */ '@/layout/BaseLayout');
@@ -57,6 +58,23 @@ router.beforeEach(() => {
   const main = useMainStore();
   main.clearReqToken();
 });
+router.beforeEach(async (to, from) => {
+  NProgress.start();
+
+  const main = useMainStore();
+
+  if (!to.query.ticket && !window.localStorage.getItem('Authorization')) {
+    window.location.href = BaseLoginUrl;
+    return false;
+  }
+
+  if (to.query.ticket && !window.localStorage.getItem('Authorization')) {
+    return await main.getUserInfo(to.query.ticket as string);
+  }
+
+  main.clearReqToken();
+  return true;
+});
 router.afterEach((to) => {
   NProgress.done();
   document!.title = to.meta.title

+ 36 - 0
src/store/useMainStore.ts

@@ -1,20 +1,56 @@
 import { Canceler } from 'axios';
 import { defineStore } from 'pinia';
+import {
+  getMessage,
+  getUserInfo,
+  NoticeInfo,
+  NoticeInfoParams,
+  UserInfo,
+} from '@/api/common';
+import { BaseLoginUrl } from '@/constants/constants';
 
 export interface MainStateType {
   cancelReqToken: Canceler[];
+  userInfo: Omit<UserInfo, 'accessToken'>;
 }
 
 export interface MainActionsType {
   pushReqToken(cancelToken: Canceler): void;
   clearReqToken(): void;
+  getUserInfo(ticket: string): Promise<true | undefined>;
+  getMessage(params: NoticeInfoParams): Promise<NoticeInfo | undefined>;
 }
 
 export default defineStore<'main', MainStateType, {}, MainActionsType>('main', {
   state: () => ({
     cancelReqToken: [],
+    userInfo: {},
   }),
   actions: {
+    async getMessage(params) {
+      try {
+        const { rows } = await getMessage(params);
+        return rows;
+      } catch (err) {
+        window.location.href = BaseLoginUrl;
+        console.log(err);
+      }
+    },
+    async getUserInfo(ticket) {
+      try {
+        const {
+          data: { accessToken, ...userInfo },
+        } = await getUserInfo(ticket);
+        if (accessToken) {
+          window.localStorage.setItem('Authorization', accessToken);
+        }
+        this.userInfo = userInfo;
+        return true;
+      } catch (err) {
+        window.location.href = BaseLoginUrl;
+        console.log(err);
+      }
+    },
     pushReqToken(cancelToken) {
       this.cancelReqToken.push(cancelToken);
     },

+ 25 - 2
src/utils/request.ts

@@ -2,6 +2,7 @@ import axios, { AxiosRequestConfig } from 'axios';
 import qs from 'querystring';
 import { ElMessage } from 'element-plus';
 import useMainStore from '@/store/useMainStore';
+import { BaseLoginUrl } from '@/constants/constants';
 
 const baseURL =
   process.env.NODE_ENV === 'production'
@@ -22,7 +23,29 @@ axios.interceptors.request.use((config) => {
 axios.interceptors.response.use(
   (res) => {
     if (res.status >= 200 && res.status < 300) {
-      return res.data;
+      if (res.data?.code === 200) {
+        return res.data;
+      }
+      if (res.data?.code === 401) {
+        ElMessage.error({
+          // message: `401. 没有权限访问该接口: ${res.config.url}`,
+          message: `401. 没有权限访问该接口`,
+        });
+        const main = useMainStore();
+        main.clearReqToken();
+        window.localStorage.setItem('Authorization', '');
+        window.location.href = BaseLoginUrl;
+
+        throw Error(res.statusText);
+      }
+      if (res.data?.code === 404) {
+        ElMessage.error({ message: '404. 未找到该接口!' });
+        throw Error(res.statusText);
+      }
+      if (res.data?.code >= 500) {
+        ElMessage.error({ message: res.data?.msg ?? '系统异常, 请稍后重试!' });
+        throw Error(res.statusText);
+      }
     }
     if (res.status === 401) {
       ElMessage.error({
@@ -57,7 +80,7 @@ export default function request<T>(
     headers: {
       Accept: 'application/json',
       'Content-Type': 'application/json',
-      Authorization: 'asdd',
+      Authorization: 'Bearer ' + window.localStorage.getItem('Authorization'),
       ...confifg.headers,
     },
   });

+ 1 - 0
src/views/IncidentDetail/index.scss

@@ -301,6 +301,7 @@
           overflow: hidden;
           text-overflow: ellipsis;
           white-space: nowrap;
+          padding-bottom: px2rem(20px);
           & > span {
             font-size: px2rem(18px * 2);
             font-weight: 400;

+ 8 - 5
src/views/IncidentDetail/index.tsx

@@ -23,18 +23,18 @@ export default defineComponent({
 
     const liveVideoRef = ref<HTMLElement>();
 
-    onMounted(() => {
+    onMounted(async () => {
       commonStore.getGlobalDict('zhdd_incident_type');
       commonStore.getGlobalDict('zhdd_incident_source');
       commonStore.getGlobalDict('zhdd_org_upload');
       commonStore.getGlobalDict('zhdd_incident_level');
-      if (isEmpty(store.incidentDetail)) {
-        store.getIncidentItem(route.query.id as string);
-      }
       liveVideoRef.value?.addEventListener('click', (el: MouseEvent) => {
         if (el.target && liveVideoRef.value?.contains(el.target as Node)) {
         }
       });
+      if (isEmpty(store.incidentDetail)) {
+        await store.getIncidentItem(route.query.id as string);
+      }
     });
     onUnmounted(() => {
       store.incidentDetail = {};
@@ -64,7 +64,10 @@ export default defineComponent({
           <div ref={liveVideoRef} class="live-video-container-left">
             <div class="live-video-container">
               <LiveVideoCard />
-              <div class="live-video-close" onClick={() => markerStore.livevideovisible = false} />
+              <div
+                class="live-video-close"
+                onClick={() => (markerStore.livevideovisible = false)}
+              />
             </div>
           </div>
         )}