Browse Source

数据请求地址可配置

huliu 1 year ago
parent
commit
d225410820
7 changed files with 35 additions and 15 deletions
  1. BIN
      dist.zip
  2. 1 0
      index.html
  3. 1 3
      src/components/left.vue
  4. 7 0
      src/config.js
  5. 11 5
      src/request/api.js
  6. 14 7
      src/request/http.js
  7. 1 0
      vite.config.js

BIN
dist.zip


+ 1 - 0
index.html

@@ -6,6 +6,7 @@
6 6
   <link rel="icon" href="/favicon.ico" />
7 7
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8 8
   <script src="/src/assets/js/leaderline.js"></script>
9
+  <script src="/src/config.js"></script>
9 10
   <title>元宇宙 App</title>
10 11
   <style>
11 12
     * {

+ 1 - 3
src/components/left.vue

@@ -49,9 +49,7 @@
49 49
                     </ul>
50 50
                     <div ref="testMain" style="height: 310px;overflow: hidden;">
51 51
                         <ul v-for="item in classRoom" @mouseenter="testMove" @mouseleave="testMend">
52
-                            <li>
53
-                                {{ item.class }}
54
-                            </li>
52
+                            <li> {{ item.class }} </li>
55 53
                             <li>{{ item.status }}</li>
56 54
                             <li>{{ item.people }}</li>
57 55
                             <li>{{ item.percentage }}</li>

+ 7 - 0
src/config.js

@@ -0,0 +1,7 @@
1
+window.g = {
2
+    // 获取数据请求地址
3
+    BASE_API: "http://192.168.4.219:12397/ioc-server",
4
+
5
+
6
+
7
+};

+ 11 - 5
src/request/api.js

@@ -1,11 +1,17 @@
1
-import { get, post } from './http'
2 1
 
2
+import { service } from './http'
3 3
 
4
-export const testApi = p => post(`https://test.lqkj.top/wsngt-server/system/sysuser/bind/ticket?userCode${p}`)
5 4
 
6
-export const getClass = () => get("http://192.168.4.219:12397/ioc-server/wisdomClass/classroomStatistic")
5
+// export const getClass = () => get("http://192.168.4.219:12397/ioc-server/wisdomClass/classroomStatistic")
7 6
 
8
-export const getDevice = () => get("http://192.168.4.219:12397/ioc-server/wisdomClass/deviceStatistic")
9 7
 
8
+export const getClass = () => service.get("/wisdomClass/classroomStatistic")
10 9
 
11
-export const getClassDetail = (deviceCode) => get(`http://192.168.4.219:12397/ioc-server/wisdomClass/deviceDetail/${deviceCode}`)
10
+
11
+
12
+
13
+
14
+export const getDevice = () => service.get("/wisdomClass/deviceStatistic")
15
+
16
+
17
+export const getClassDetail = (deviceCode) => service.get(`/wisdomClass/deviceDetail/${deviceCode}`)

+ 14 - 7
src/request/http.js

@@ -1,11 +1,19 @@
1 1
 import axios from 'axios'
2 2
 import { ElMessage } from 'element-plus';
3 3
 
4
-// 请求超时时间
5
-axios.defaults.timeout = 10000
4
+
5
+export const service = axios.create({
6
+    baseURL: window.g.BASE_API,
7
+    // withCredentials: true, // 跨域请求时发送 cookies
8
+    timeout: 10000
9
+
10
+})
11
+
12
+
13
+
6 14
 
7 15
 // 请求拦截器
8
-axios.interceptors.request.use(
16
+service.interceptors.request.use(
9 17
     config => {
10 18
         // const token = session.get('Token');
11 19
         // token && (config.headers.Authorization = token);
@@ -20,7 +28,7 @@ axios.interceptors.request.use(
20 28
 )
21 29
 // 响应请求拦截器
22 30
 
23
-axios.interceptors.response.use(
31
+service.interceptors.response.use(
24 32
     response => {
25 33
         // console.log("response", response)
26 34
         if (response.status === 200) {
@@ -51,7 +59,7 @@ axios.interceptors.response.use(
51 59
 
52 60
 export function get(url, params) {
53 61
     return new Promise((resolve, reject) => {
54
-        axios.get(url, {
62
+        service.get(url, {
55 63
             params
56 64
         }).then(res => {
57 65
             resolve(res)
@@ -62,9 +70,8 @@ export function get(url, params) {
62 70
 }
63 71
 
64 72
 export function post(url, params) {
65
-
66 73
     return new Promise((resolve, reject) => {
67
-        axios.post(url, {
74
+        service.post(url, {
68 75
             data: params
69 76
         }).then(res => {
70 77
             resolve(res)

+ 1 - 0
vite.config.js

@@ -6,6 +6,7 @@ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
6 6
 import postCssPxToRem from "postcss-pxtorem";
7 7
 
8 8
 export default defineConfig({
9
+  base: './',//相对路径
9 10
   plugins: [
10 11
     vue(),
11 12
     Components({