Sfoglia il codice sorgente

互联网权限校验

CzRger 1 anno fa
parent
commit
c60dde3d38
6 ha cambiato i file con 63 aggiunte e 5 eliminazioni
  1. 1 1
      src/App.vue
  2. 3 3
      src/api/interceptors.ts
  3. 1 1
      src/api/request.ts
  4. 1 0
      src/out/config.js
  5. 45 0
      src/views/auth.vue
  6. 12 0
      src/views/ship-test/index.vue

+ 1 - 1
src/App.vue

@@ -28,7 +28,7 @@ export default defineComponent({
     const store = useStore()
     const locale = ref(zhLocale)
     const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
-    sessionStorage.setItem('sg_token', '123')
+    localStorage.setItem('sg_token', '123')
     return {
       locale
     }

+ 3 - 3
src/api/interceptors.ts

@@ -22,7 +22,7 @@ export class Interceptors {
     this.instance.interceptors.request.use(
       (config: any) => {
         if (!config.headers.Authorization) {
-          const token = sessionStorage.getItem('ax_token');
+          const token = localStorage.getItem('ax_token');
           if (token) {
             config.headers.Authorization = token;
           } else {
@@ -41,10 +41,10 @@ export class Interceptors {
       // 请求成功
       (res: any) => {
         if (res.headers.authorization) {
-          sessionStorage.setItem('ax_token', res.headers.authorization);
+          localStorage.setItem('ax_token', res.headers.authorization);
         } else {
           if (res.data && res.data.code === 200 && res.data.token) {
-            sessionStorage.setItem('ax_token', res.data.token);
+            localStorage.setItem('ax_token', res.data.token);
           }
         }
         if (res.status === 200) {

+ 1 - 1
src/api/request.ts

@@ -218,7 +218,7 @@ export class HttpRequest {
     return new Promise((resolve, reject) => {
       let paramUrl = url
       this.axios.post(paramUrl,params,{
-        headers: { Authorization: sessionStorage.getItem('ax_token') },
+        headers: { Authorization: localStorage.getItem('ax_token') },
         responseType: "blob",
       }).then((res: Blob) => {
         let blob = new Blob([res], { type: "application/x-xlsx" });

+ 1 - 0
src/out/config.js

@@ -1,4 +1,5 @@
 window.cusConfig = {
+  internetAuth: false,
   trackSource: [
     ['TIANAO_RADAR', {
       label: '小目标雷达',

+ 45 - 0
src/views/auth.vue

@@ -0,0 +1,45 @@
+<template>
+</template>
+
+<script lang="ts">
+import {
+  defineComponent,
+  computed,
+  onMounted,
+  ref,
+  reactive,
+  watch,
+  getCurrentInstance,
+  ComponentInternalInstance,
+  toRefs,
+  nextTick
+} from 'vue'
+import {useStore} from 'vuex'
+import {useRouter, useRoute} from 'vue-router'
+import * as source from "ol/source";
+import * as layer from "ol/layer";
+import * as format from "ol/format";
+
+export default defineComponent({
+  name: '',
+  components: {},
+  setup() {
+    const store = useStore();
+    const router = useRouter();
+    const route = useRoute();
+    const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
+    const state = reactive({
+    })
+    onMounted(() => {
+      localStorage.setItem('auth', 'emmmmmm')
+      router.push('/gis')
+    })
+    return {
+      ...toRefs(state),
+    }
+  },
+})
+</script>
+
+<style scoped lang="scss">
+</style>

+ 12 - 0
src/views/ship-test/index.vue

@@ -50,6 +50,18 @@ export default defineComponent({
       state.mapFunc = func
     }
     onMounted(() => {
+      if (window.cusConfig?.internetAuth) {
+        if (!localStorage.getItem('auth')) {
+          if(navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") != -1){
+            window.location.href = "about:blank";
+            window.close();
+          }else{
+            window.opener = null;
+            window.open("", "_self");
+            window.close();
+          }
+        }
+      }
     })
     return {
       ...toRefs(state),