main.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import Vue from 'vue'
  2. import Cookies from 'js-cookie'
  3. import Element from 'element-ui'
  4. import './assets/styles/element-variables.scss'
  5. import '@/assets/styles/index.scss' // global css
  6. import '@/assets/styles/ruoyi.scss' // ruoyi css
  7. import App from './App'
  8. import store from './store'
  9. import router from './router'
  10. import directive from './directive' // directive
  11. import plugins from './plugins' // plugins
  12. import { download } from '@/utils/request'
  13. import './assets/icons' // icon
  14. import './permission' // permission control
  15. import { getDicts } from "@/api/system/dict/data";
  16. import { getConfigKey } from "@/api/system/config";
  17. import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi";
  18. // 分页组件
  19. import Pagination from "@/components/Pagination";
  20. // 自定义表格工具组件
  21. import RightToolbar from "@/components/RightToolbar"
  22. // 富文本组件
  23. import Editor from "@/components/Editor"
  24. // 文件上传组件
  25. import FileUpload from "@/components/FileUpload"
  26. // 图片上传组件
  27. import ImageUpload from "@/components/ImageUpload"
  28. // 图片预览组件
  29. import ImagePreview from "@/components/ImagePreview"
  30. // 字典标签组件
  31. import DictTag from '@/components/DictTag'
  32. // 头部标签组件
  33. import VueMeta from 'vue-meta'
  34. // 字典数据组件
  35. import DictData from '@/components/DictData'
  36. import VideoPlayer from 'vue-video-player'
  37. import 'video.js/dist/video-js.css'
  38. import 'vue-video-player/src/custom-theme.css'
  39. Vue.use(VideoPlayer)
  40. // 全局方法挂载
  41. Vue.prototype.getDicts = getDicts
  42. Vue.prototype.getConfigKey = getConfigKey
  43. Vue.prototype.parseTime = parseTime
  44. Vue.prototype.resetForm = resetForm
  45. Vue.prototype.addDateRange = addDateRange
  46. Vue.prototype.selectDictLabel = selectDictLabel
  47. Vue.prototype.selectDictLabels = selectDictLabels
  48. Vue.prototype.download = download
  49. Vue.prototype.handleTree = handleTree
  50. // 全局组件挂载
  51. Vue.component('DictTag', DictTag)
  52. Vue.component('Pagination', Pagination)
  53. Vue.component('RightToolbar', RightToolbar)
  54. Vue.component('Editor', Editor)
  55. Vue.component('FileUpload', FileUpload)
  56. Vue.component('ImageUpload', ImageUpload)
  57. Vue.component('ImagePreview', ImagePreview)
  58. Vue.directive('drag', (el) => {
  59. const oDiv = el // 当前元素
  60. const minTop = oDiv.getAttribute('drag-min-top')
  61. const ifMoveSizeArea = 20
  62. oDiv.onmousedown = e => {
  63. let target = oDiv
  64. while (window.getComputedStyle(target).position !== 'absolute' && target !== document.body) {
  65. target = target.parentElement
  66. }
  67. document.onselectstart = () => {
  68. return false
  69. }
  70. if (!target.getAttribute('init_x')) {
  71. target.setAttribute('init_x', target.offsetLeft)
  72. target.setAttribute('init_y', target.offsetTop)
  73. }
  74. const initX = parseInt(target.getAttribute('init_x'))
  75. const initY = parseInt(target.getAttribute('init_y'))
  76. // 鼠标按下,计算当前元素距离可视区的距离
  77. const disX = e.clientX - target.offsetLeft
  78. const disY = e.clientY - target.offsetTop
  79. document.onmousemove = e => {
  80. // 通过事件委托,计算移动的距离
  81. // 因为浏览器里并不能直接取到并且使用clientX、clientY,所以使用事件委托在内部做完赋值
  82. const l = e.clientX - disX
  83. const t = e.clientY - disY
  84. const { marginTop: mt, marginLeft: ml } = window.getComputedStyle(target)
  85. // 计算移动当前元素的位置,并且给该元素样式中的left和top值赋值
  86. target.style.left = l - parseInt(ml) + 'px'
  87. target.style.top = (t < minTop ? minTop : t) - parseInt(mt) + 'px'
  88. // 添加对容器位置的限制
  89. const viewportWidth = window.innerWidth;
  90. const viewportHeight = window.innerHeight;
  91. const containerWidth = target.offsetWidth;
  92. const containerHeight = target.offsetHeight;
  93. let left = l - parseInt(ml);
  94. let top = (t < minTop ? minTop : t) - parseInt(mt);
  95. if (left < 0) left = 0;
  96. if (top < 0) top = 0;
  97. if (left + containerWidth > viewportWidth) left = viewportWidth - containerWidth;
  98. if (top + containerHeight > viewportHeight) top = viewportHeight - containerHeight;
  99. target.style.left = `${left}px`;
  100. target.style.top = `${top}px`;
  101. if (Math.abs(l - initX) > ifMoveSizeArea || Math.abs(t - initY) > ifMoveSizeArea) {
  102. target.setAttribute('dragged', '')
  103. } else {
  104. target.removeAttribute('dragged')
  105. }
  106. }
  107. document.onmouseup = e => {
  108. document.onmousemove = null
  109. document.onmouseup = null
  110. document.onselectstart = null
  111. }
  112. // return false不加的话可能导致黏连,拖到一个地方时div粘在鼠标上不下来,相当于onmouseup失效
  113. return false
  114. }
  115. })
  116. Vue.use(directive)
  117. Vue.use(plugins)
  118. Vue.use(VueMeta)
  119. DictData.install()
  120. /**
  121. * If you don't want to use mock-server
  122. * you want to use MockJs for mock api
  123. * you can execute: mockXHR()
  124. *
  125. * Currently MockJs will be used in the production environment,
  126. * please remove it before going online! ! !
  127. */
  128. Vue.use(Element, {
  129. size: Cookies.get('size') || 'medium' // set element-ui default size
  130. })
  131. Vue.config.productionTip = false
  132. new Vue({
  133. el: '#app',
  134. router,
  135. store,
  136. render: h => h(App)
  137. })