main.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { createApp } from 'vue'
  2. import App from './App.vue'
  3. import router from './router'
  4. import store from './store'
  5. import querystring from 'querystring';
  6. import installElementPlus from './plugins/element'
  7. import jquery from 'jquery'
  8. import '@a/scss/common.scss'
  9. import '@a/font/index.scss'
  10. import '@a/js/flexible'
  11. import '@a/icon/iconfont.css'
  12. const app = createApp(App)
  13. installElementPlus(app)
  14. //使用Vue.directive()定义一个全局指令
  15. //1.参数一:指令的名称,定义时指令前面不需要写v-
  16. //2.参数二:是一个对象,该对象中有相关的操作函数
  17. //3.在调用的时候必须写v-
  18. app.directive('drag', {
  19. //1.指令绑定到元素上回立刻执行bind函数,只执行一次
  20. //2.每个函数中第一个参数永远是el,表示绑定指令的元素,el参数是原生js对象
  21. //3.通过el.focus()是无法获取焦点的,因为只有插入DOM后才生效
  22. bind: function(el) {
  23. el.style.cursor = "move"; //鼠标样式变move样式
  24. },
  25. //inserted表示一个元素,插入到DOM中会执行inserted函数,只触发一次
  26. inserted: function(el) {
  27. el.onmousedown = function(e) {
  28. console.log(121212)
  29. var distX = e.pageX - el.offsetLeft;
  30. var distY = e.pageY - el.offsetTop;
  31. console.log("元素本身的高:" + el.clientHeight + ",元素本身的宽:" + el.clientWidth)
  32. if (e.preventDefault) {
  33. e.preventDefault();
  34. } else {
  35. e.returnValue = false;
  36. }; //解决快速拖动滞后问题
  37. document.onmousemove = function(e) {
  38. // 用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
  39. let left = e.clientX - distX;
  40. let top = e.clientY - distY;
  41. if (left <= 0) {
  42. left = 5; //设置成5是为了不离边缘太近
  43. } else if (left > document.documentElement.clientWidth - el.clientWidth) {
  44. //document.documentElement.clientWidth 屏幕的可视宽度
  45. left = document.documentElement.clientWidth - el.clientWidth - 5
  46. }
  47. if (top <= 0) {
  48. top = 5;
  49. } else if (top > document.documentElement.clientHeight - el.clientHeight) {
  50. top = document.documentElement.clientHeight - el.clientHeight - 5
  51. }
  52. el.style.left = left + 'px';
  53. el.style.top = top + 'px';
  54. }
  55. document.onmouseup = function() {
  56. document.onmousemove = document.onmouseup = null;
  57. }
  58. }
  59. },
  60. //当VNode更新的时候会执行updated,可以触发多次
  61. updated: function(el) {}
  62. })
  63. import api from './http/api';
  64. import http from './http/http';
  65. import './http/axios';
  66. // 对请求方式 进行全局注册
  67. app.config.globalProperties.$axios = http;
  68. // 对后端接口 进行全局注册
  69. app.config.globalProperties.$api = api;
  70. // 类型转换
  71. app.config.globalProperties.$qs = querystring;
  72. app.use(store).use(router).use(querystring).use(http, api).mount('#app')
  73. // 大数据地图
  74. // import JMap from 'JMap'
  75. // window.vue = this;
  76. // window.jMap = null;
  77. // window.jmapQuery = null;
  78. // window.jMap = new JMap();
  79. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  80. Date.prototype.Format = function(fmt) {
  81. let o = {
  82. 'M+': this.getMonth() + 1, // 月份
  83. 'd+': this.getDate(), // 日
  84. 'h+': this.getHours(), // 小时
  85. 'm+': this.getMinutes(), // 分
  86. 's+': this.getSeconds(), // 秒
  87. 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
  88. 'S': this.getMilliseconds() // 毫秒
  89. };
  90. if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length)); }
  91. for (let k in o) {
  92. if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))); }
  93. }
  94. return fmt;
  95. };