Bläddra i källkod

跨域问题解决

wangtao 2 år sedan
förälder
incheckning
e1feddada1
2 ändrade filer med 14 tillägg och 8 borttagningar
  1. 9 4
      src/views/index.vue
  2. 5 4
      vue.config.js

+ 9 - 4
src/views/index.vue

@@ -467,7 +467,7 @@ import index2 from "./components/index/index2";
 import index3 from "./components/index/index3";
 import index5 from "./components/index/index5";
 import axios from "axios";
-axios.defaults.baseURL = "/api";
+axios.defaults.baseURL = "/YtIoT";
 // import $ from 'jquery'
 // import index6 from "./components/index/index6";
 import ui_large from "@/assets/images/status_ui_large.png"; //用户传输装置gif
@@ -601,6 +601,7 @@ export default {
             axios({
                 method: "post",
                 url: `/iot/frontpage/getCurrentObjectListByCompanyId`,
+                // url: `https://iot.usky.cn/YtIoT/iot/frontpage/getCurrentObjectListByCompanyId`,
                 params: {
                     queryJson: JSON.stringify(params),
                 },
@@ -715,6 +716,7 @@ export default {
             axios({
                 method: "post",
                 url: `/iot/frontpage/getCurrentStatus`,
+                // url: `https://iot.usky.cn/YtIoT/iot/frontpage/getCurrentStatus`,
                 params: {
                     queryJson: JSON.stringify(params),
                 },
@@ -768,12 +770,13 @@ export default {
             axios({
                 method: "post",
                 url: `/cgi-bin/demo2.cgi`,
+                // url: `https://iot.usky.cn/YtIoT/cgi-bin/demo2.cgi`,
                 data: "queryJson:" + JSON.stringify(queryQ),
                 headers: {},
             }).then((res) => {
                 if (IDX == 7) {
                     this.loadVideoFn(
-                        `http://47.103.74.123:80/hls/${code}.m3u8`,
+                        `https://iot.usky.cn/hls/${code}.m3u8`,
                         code
                     );
                 } else {
@@ -788,6 +791,7 @@ export default {
             axios({
                 method: "post",
                 url: "/cgi-bin/demo2.cgi",
+                // url: "https://iot.usky.cn/YtIoT/cgi-bin/demo2.cgi",
                 data: "queryJson:" + JSON.stringify(query),
                 headers: {},
             }).then((result) => {
@@ -797,9 +801,10 @@ export default {
                     if (data[i].DEVICE == code) {
                         if (data[i].ONAIR && !data[i].LIVEONLINE) {
                             this.loadVideoFn(
-                                `https://iot.usky.cn/hls/${code}.m3u8`,
+                                `https://iot.usky.cn/hls//${code}.m3u8`,
                                 code
                             );
+
                         } else if (!data[i].ONAIR) {
                             if (data[i].ALIVEVALUE == 3) {
                                 // this.$message.error(`设备在线,视频拉取中...`);
@@ -932,7 +937,7 @@ export default {
             let that = this;
             let num = 0;
             if ("WebSocket" in window) {
-                this.ws = new WebSocket("ws://10.21.39.1:8084/dm/alarmPush");
+                this.ws = new WebSocket("wss://10.21.39.1:8084/dm/alarmPush");
                 // console.log(this.ws)
                 this.ws.onopen = () => {
                     // console.log("websocket连接成功");

+ 5 - 4
vue.config.js

@@ -42,9 +42,10 @@ module.exports = {
                     ['^' + process.env.VUE_APP_BASE_API]: ''
                 }
             },
-            '/api': {
-                target: 'http://47.103.74.123:8080/YtIoT', //这里填入你要请求的接口的前缀
-                ws: true, //代理websocked
+            '/YtIoT': {
+                // target: 'http://47.103.74.123:8080/YtIoT', //这里填入你要请求的接口的前缀
+                target: 'https://smartpark.caih.com/YtIoT', //这里填入你要请求的接口的前缀
+                wss: true, //代理websocked
                 changeOrigin: true, //虚拟的站点需要更换origin
                 secure: true, //是否https接口,我用的http但是我变成false他打包后会报错,所以先true
                 pathRewrite: {
@@ -139,4 +140,4 @@ module.exports = {
                 }
             )
     }
-}
+}