main.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import Vue from 'vue'
  2. import 'normalize.css/normalize.css' // a modern alternative to CSS resets
  3. import EleForm from 'vue-ele-form'
  4. import Element from 'element-ui'
  5. import EleFormUploadFile from 'vue-ele-form-upload-file'
  6. import EleFormImageUploader from 'vue-ele-form-image-uploader'
  7. import EleFormBmap from 'vue-ele-form-bmap'
  8. import EleFormGallery from 'vue-ele-form-gallery'
  9. import EleFormDynamic from 'vue-ele-form-dynamic'
  10. // 自定义区域级联
  11. import EleFormRegional from "@/components/Cascader/regional-cascader.vue"
  12. import 'element-ui/lib/theme-chalk/index.css'
  13. import './styles/element-variables.scss'
  14. // import enLang from 'element-ui/lib/locale/lang/en'// 如果使用中文语言包请默认支持,无需额外引入,请删除该依赖
  15. import '@/styles/index.scss' // global css
  16. import '@/rl_icons/iconfont.css'
  17. import App from './App'
  18. import store from './store'
  19. import router from './router'
  20. import './icons' // icon
  21. import '@/assets/icon/iconfont.css'
  22. import './permission' // permission control
  23. import './utils/error-log' // error log
  24. import request from '@/utils/request'
  25. import '@/utils/dialogdrag'//dialog 拖拽指令 v-dialogDrag 放入el-dialog中即可
  26. import * as filters from './filters' // global filters
  27. import VueHighlightJS from 'vue-highlight.js'
  28. var appConfig = require('../static/app_config.json')
  29. import echarts from 'echarts'
  30. import VueSocketIO from 'vue-socket.io'
  31. import SocketIO from "socket.io-client"
  32. /*
  33. 地图相关
  34. start
  35. */
  36. import VueAMap from 'vue-amap';
  37. // ,'AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'
  38. Vue.use(VueAMap);
  39. VueAMap.initAMapApiLoader({
  40. key: '8af92d391127d03d83fc52e7f0efea08',
  41. plugin: ['AMap.Geolocation','AMap.Scale','AMap.OverView', 'AMap.ToolBar','AMap.MassMarks',
  42. 'AMap.MapType','AMap.MarkerClusterer','AMap.Geocoder', 'AMap.Heatmap', 'AMap.OverlayGroup'
  43. ],
  44. v: '1.4.15',
  45. uiVersion: '1.1'
  46. });
  47. import BaiduMap from 'vue-baidu-map'
  48. Vue.use(BaiduMap, {
  49. // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  50. ak: '2Gk7v8Gcb6PkgDZytoqsfdxuTGrQgfgB',//'LDeyoWgKV2mO1b3MRkTlyzGcNjFUycLL'
  51. })
  52. const socketOptions = {
  53. autoConnect: false,
  54. //path: '/socket.io/',
  55. path: '/',
  56. transports: ['websocket']
  57. }
  58. Vue.directive('loadmore', {
  59. bind(el, binding) {
  60. const selectWrap = el.querySelector('.el-table__body-wrapper');
  61. selectWrap.addEventListener('scroll', function () {
  62. // console.log(this.scrollHeight, this.scrollTop, this.clientHeight)
  63. if (this.scrollHeight - this.scrollTop <= this.clientHeight) {
  64. binding.value();
  65. }
  66. })
  67. }
  68. })
  69. // 除数,被除数, 保留的小数点后的位数
  70. Vue.prototype.NumberDiv = function (arg1,arg2,digit){
  71. var t1=0,t2=0,r1,r2;
  72. if(!arg2){
  73. return Number(0);
  74. }
  75. if(arg1 == arg2){
  76. return Number(1);
  77. }
  78. // console.log(arg1,arg2)
  79. try{t1=arg1.toString().split(".")[1].length}catch(e){}
  80. try{t2=arg2.toString().split(".")[1].length}catch(e){}
  81. r1=Number(arg1.toString().replace(".",""))
  82. r2=Number(arg2.toString().replace(".",""))
  83. //获取小数点后的计算值
  84. var result= ((r1/r2)*Math.pow(10,t2-t1)).toString()
  85. var result2=result.split(".")[1];
  86. if(result2!=undefined){
  87. result2 = result2.substring(0, digit > result2.length ? result2.length : digit);
  88. }
  89. if(result==0){
  90. return Number(result);
  91. }else{
  92. return Number(result.split(".")[0] + "." + result2);
  93. }
  94. }
  95. Vue.prototype.NumberMul = function(arg1, arg2) {
  96. var m = 0;
  97. var s1 = arg1.toString();
  98. var s2 = arg2.toString();
  99. try {
  100. m += s1.split(".")[1].length;
  101. } catch (e) {}
  102. try {
  103. m += s2.split(".")[1].length;
  104. } catch (e) {}
  105. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
  106. }
  107. // import elTableInfiniteScroll from 'el-table-infinite-scroll';
  108. // Vue.use(elTableInfiniteScroll);
  109. /*
  110. 地图相关
  111. end
  112. */
  113. // Vue.use(
  114. // new VueSocketIO({
  115. // debug: true,
  116. // connection: SocketIO(appConfig.websocketUrl, socketOptions),
  117. // store,
  118. // })
  119. // )
  120. // Vue.use(new VueSocketIO({
  121. // debug: true,
  122. // connection: 'ws://192.168.1.60:60002',
  123. // store,
  124. // options: { path: "/socket.io/" } //Optional options
  125. // }))
  126. /**
  127. * If you don't want to use mock-server
  128. * you want to use MockJs for mock api
  129. * you can execute: mockXHR()
  130. *
  131. * Currently MockJs will be used in the production environment,
  132. * please remove it before going online ! ! !
  133. */
  134. // if (process.env.NODE_ENV === 'production') {
  135. // const { mockXHR } = require('../mock')
  136. // mockXHR()
  137. // }
  138. Vue.component("file-upload", EleFormUploadFile)
  139. Vue.component('image-upload', EleFormImageUploader)
  140. Vue.component("bmap", EleFormBmap)
  141. Vue.component("gallery", EleFormGallery)
  142. Vue.component('dynamic', EleFormDynamic)
  143. Vue.component('regional-cascader', EleFormRegional)
  144. Vue.use(Element, {
  145. size: 'small', // set element-ui default size
  146. // locale: enLang // 如果使用中文,无需设置,请删除
  147. // 专门设置全局的 dynamic 属性
  148. // 属性参考: https://github.com/dream2023/ele-dynamic 或者 下面的属性说明
  149. dynamic: {
  150. delimiter: '/' // 所有的 dynamic 都会有 delimiter = '/' 的属性值
  151. }
  152. })
  153. Vue.use(VueHighlightJS)
  154. Vue.use(EleForm)
  155. // register global utility filters
  156. Object.keys(filters).forEach(key => {
  157. Vue.filter(key, filters[key])
  158. })
  159. Vue.config.productionTip = false
  160. Vue.prototype.$http = request
  161. Vue.prototype.$appConfig = appConfig
  162. Vue.prototype.$echarts = echarts
  163. new Vue({
  164. sockets: {
  165. connecting() {
  166. console.log('正在连接')
  167. },
  168. disconnect() {
  169. console.log("Socket 断开");
  170. },
  171. connect_failed() {
  172. cosnole.log('连接失败')
  173. },
  174. connect() {
  175. console.log('socket connected')
  176. },
  177. message(data) {
  178. this.$notify({
  179. title: '新消息',
  180. message: data,
  181. type: 'warning',
  182. duration:10000
  183. });
  184. console.log("data", data);//接收的消息
  185. },
  186. alarm_notify: data => {
  187. if (typeof data == 'string') {
  188. // console.log('alarm_notify data ', data)
  189. }
  190. if (typeof data == 'object') {
  191. // console.log('alarm_notify data ', data)
  192. Element.Notification({
  193. title: data.title,
  194. message: data.content,
  195. type: 'warning',
  196. position: 'bottom-right'
  197. });
  198. }
  199. }
  200. },
  201. el: '#app',
  202. router,
  203. store,
  204. render: h => h(App)
  205. })