main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import Vue from "vue";
  2. import App from "./App.vue";
  3. import router from "./router/index";
  4. import modules from "./store/index";
  5. import VueSocketIO from "vue-socket.io";
  6. import Vuex from 'vuex'
  7. import vuescroll from 'vuescroll';
  8. // 在这里设置全局配置
  9. Vue.use(vuescroll, {
  10. ops: {
  11. mode: 'native',
  12. bar: {
  13. showDelay: 500,
  14. onlyShowBarOnScroll: true,//是否只有滚动的时候才显示滚动条
  15. keepShow: false,
  16. background: '#1AB063',
  17. opacity: 0.2,
  18. hoverStyle: false,
  19. specifyBorderRadius: false,
  20. minSize: false,
  21. size: '6px',
  22. disable: false,
  23. }
  24. }, // 在这里设置全局默认配置
  25. name: 'vueScroll' // 在这里自定义组件名字,默认是vueScroll
  26. });
  27. Vue.config.productionTip = false;
  28. var strUrl=window.location.href;
  29. var strIp = "";
  30. if(strUrl.indexOf("172.16.50.4")!=-1)
  31. {
  32. strIp = "172.16.50.4:19703";
  33. }
  34. else
  35. {
  36. strIp = "47.102.97.214";
  37. }
  38. Vue.use(
  39. new VueSocketIO({
  40. debug: true,
  41. connection: "ws://" + strIp,
  42. //connection: "ws://121.42.8.157:19703",
  43. options: {
  44. transports: ["websocket", "polling"],
  45. },
  46. })
  47. );
  48. Vue.use(Vuex)
  49. const store = new Vuex.Store(modules)
  50. window.store = store;
  51. window.vm = new Vue({
  52. /*
  53. @brief
  54. 建立socket.io的监听事件
  55. @author
  56. zhuyf
  57. @date
  58. 2022/05/10 14:10
  59. */
  60. el: '#app',
  61. created: function () {
  62. // console.log('created init home page')
  63. // init()
  64. },
  65. mounted: function () {
  66. console.log("mounted init home page");
  67. this.init();
  68. },
  69. data() {
  70. return {
  71. inited: false,
  72. };
  73. },
  74. methods: {
  75. init() {
  76. // console.log('created home page by init function' + this.name)
  77. this.initService();
  78. },
  79. initService() {
  80. if (this.inited === false) {
  81. this.inited = true;
  82. // 此函数内开启监听服务器端(gis-server)传的数据
  83. // 第一个参数是命令字,第二个参数是匿名回调函数,其中回调函数的参数是服务器端传的数据内容
  84. this.sockets.subscribe("login", (data) => {
  85. console.log("receive [login] msg from server: " + data);
  86. });
  87. this.sockets.subscribe("CALL", (data) => {
  88. // console.log('receive [CALL] msg from server: ' + data)
  89. });
  90. }
  91. },
  92. },
  93. sockets: {
  94. connecting() {
  95. console.log("正在连接");
  96. },
  97. disconnect() {
  98. console.log("Socket 断开");
  99. },
  100. connect_failed() {
  101. console.log("连接失败");
  102. },
  103. connected() {
  104. console.log("socket connected");
  105. },
  106. connect() {
  107. console.log("socket connect");
  108. var start = new Date().getTime();
  109. while (new Date().getTime() - start < 500) {
  110. // 使用continue 实现;
  111. continue;
  112. }
  113. // this.$socket.emit('login', `{"cmd": "login", "data": {"name": "COLLECTOR", "password": "666666"}}`)
  114. this.$socket.emit(
  115. "USER",
  116. {
  117. cmd: "login",
  118. data: {
  119. user_name: "zjs",
  120. user_pass: "123",
  121. },
  122. },
  123. (data) => {
  124. console.log("OK, got into login-callback");
  125. console.log(JSON.stringify(data));
  126. }
  127. );
  128. console.log(this);
  129. this.init();
  130. },
  131. device_state(data) {
  132. console.log(data);
  133. },
  134. },
  135. router,
  136. store,
  137. // store,
  138. render: (h) => h(App),
  139. })
  140. // window.vm.initService();
  141. import ElementUI from "element-ui";
  142. import "element-ui/lib/theme-chalk/index.css";
  143. Vue.use(ElementUI);
  144. import axios from "axios";
  145. Vue.prototype.$axios = axios;