Преглед на файлове

feat: 增加动态设置端口号

sunxiao преди 8 месеца
родител
ревизия
b290a42cf3
променени са 3 файла, в които са добавени 91 реда и са изтрити 20 реда
  1. 34 20
      src/router/index.js
  2. 6 0
      src/utils/request.ts
  3. 51 0
      src/views/env/index.vue

+ 34 - 20
src/router/index.js

@@ -17,28 +17,42 @@ const constantRouterMap = [
   //     title: "测试建模文件"
   //   }
   // },
+
+  /** 
+   * 模版筛选使用
+   * 注释时间: 2024年08月05日15:03:02
+   * 
+   * */ 
+  // {
+  //   path: '/count1',
+  //   name: 'count1',
+  //   component: () => import('@/views/count/index1.vue'),
+  //   meta: {
+  //     title: "临时统计1"
+  //   }
+  // },
+  // {
+  //   path: '/count2',
+  //   name: 'count2',
+  //   component: () => import('@/views/count/index2.vue'),
+  //   meta: {
+  //     title: "临时统计2"
+  //   }
+  // },
+  // {
+  //   path: '/count3',
+  //   name: 'count3',
+  //   component: () => import('@/views/count/index3.vue'),
+  //   meta: {
+  //     title: "临时统计3"
+  //   }
+  // },
   {
-    path: '/count1',
-    name: 'count1',
-    component: () => import('@/views/count/index1.vue'),
-    meta: {
-      title: "临时统计1"
-    }
-  },
-  {
-    path: '/count2',
-    name: 'count2',
-    component: () => import('@/views/count/index2.vue'),
-    meta: {
-      title: "临时统计2"
-    }
-  },
-  {
-    path: '/count3',
-    name: 'count3',
-    component: () => import('@/views/count/index3.vue'),
+    path: '/env',
+    name: 'Env',
+    component: () => import('@/views/env/index.vue'),
     meta: {
-      title: "临时统计3"
+      title: "环境区分"
     }
   },
   {

+ 6 - 0
src/utils/request.ts

@@ -52,6 +52,12 @@ export class Request {
     this.instance.interceptors.request.use((config: InternalAxiosRequestConfig<Result>) => {
       const { token } = useStore.userInfo;
       
+      /**
+       * 环境区分 - 仅限于测试环境使用
+       * */
+
+      config.headers.port = localStorage.getItem("ENV");
+
       token && (config.headers.Authorization = 'Bearer ' + token);
 
       return config;

+ 51 - 0
src/views/env/index.vue

@@ -0,0 +1,51 @@
+<script setup>
+import { ref } from 'vue';
+import { NInput, NButton } from 'naive-ui';
+
+const inpVal = ref('');
+
+const handleSetEnv = () => {
+  localStorage.setItem("ENV", inpVal.value);
+  alert("ok~");
+}
+
+const handleClearEnv = () => {
+  localStorage.removeItem("ENV");
+  alert("remove~")
+}
+</script>
+
+<template>
+  <div class="env-container">
+    <ul class="env-inner">
+      <li>
+        <NInput type="text" v-model:value="inpVal"/>
+      </li>
+      <li class="space-x-[20px]">
+        <NButton type="info" @click="handleSetEnv">设置</NButton>
+        <NButton @click="handleClearEnv">清除</NButton>
+      </li>
+    </ul>
+  </div>
+</template>
+
+<style lang="scss">
+.env-container {
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  height: 100vh;
+
+  .env-inner {
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    flex-flow: column;
+    width: 300px;
+
+    .n-input__input {
+      border: 1px solid #ccc;
+    }
+  }
+}
+</style>