main.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import Vue from 'vue'
  2. import Cookies from 'js-cookie'
  3. import 'normalize.css/normalize.css' // a modern alternative to CSS resets
  4. import Element from 'element-ui'
  5. import './assets/styles/element-variables.scss'
  6. import '@/assets/styles/index.scss' // global css
  7. import '@/assets/styles/ruoyi.scss' // ruoyi css
  8. import App from './App'
  9. import store from './store'
  10. import router from './router'
  11. import permission from './directive/permission'
  12. import './assets/icons' // icon
  13. import './permission' // permission control
  14. import { getDicts } from "@/api/system/dict/data";
  15. import { getConfigKey } from "@/api/system/config";
  16. import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, download, handleTree } from "@/utils/ruoyi";
  17. import Pagination from "@/components/Pagination";
  18. //自定义表格工具扩展
  19. import RightToolbar from "@/components/RightToolbar"
  20. import echarts from "echarts";
  21. import '@/utils/dialog.js'
  22. import Blob from '@/excel/Blob.js'
  23. import Export2Excel from '@/excel/Export2Excel.js'
  24. // 全局方法挂载
  25. Vue.prototype.$echarts = echarts;
  26. Vue.prototype.getDicts = getDicts
  27. Vue.prototype.getConfigKey = getConfigKey
  28. Vue.prototype.parseTime = parseTime
  29. Vue.prototype.resetForm = resetForm
  30. Vue.prototype.addDateRange = addDateRange
  31. Vue.prototype.selectDictLabel = selectDictLabel
  32. Vue.prototype.selectDictLabels = selectDictLabels
  33. Vue.prototype.download = download
  34. Vue.prototype.handleTree = handleTree
  35. Vue.prototype.msgSuccess = function (msg) {
  36. this.$message({ showClose: true, message: msg, type: "success" });
  37. }
  38. Vue.prototype.msgError = function (msg) {
  39. this.$message({ showClose: true, message: msg, type: "error" });
  40. }
  41. Vue.prototype.msgInfo = function (msg) {
  42. this.$message.info(msg);
  43. }
  44. // 全局组件挂载
  45. Vue.component('Pagination', Pagination)
  46. Vue.component('RightToolbar', RightToolbar)
  47. Vue.use(permission)
  48. /**
  49. * If you don't want to use mock-server
  50. * you want to use MockJs for mock api
  51. * you can execute: mockXHR()
  52. *
  53. * Currently MockJs will be used in the production environment,
  54. * please remove it before going online! ! !
  55. */
  56. Vue.use(Element, {
  57. size: Cookies.get('size') || 'medium' // set element-ui default size
  58. })
  59. Vue.config.productionTip = false
  60. new Vue({
  61. el: '#app',
  62. router,
  63. store,
  64. render: h => h(App)
  65. })
  66. Vue.directive("dialogDrag", {
  67. bind(el, binding, vnode, oldVnode) {
  68. const dialogHeaderEl = el.querySelector(".el-dialog__header");
  69. const dragDom = el.querySelector(".el-dialog");
  70. const enlarge = el.querySelector(".enlarge");
  71. dialogHeaderEl.style.cursor = "move";
  72. // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
  73. const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);
  74. if (enlarge) {
  75. enlarge.onclick = (e) => {
  76. dragDom.style.top = "0px";
  77. dragDom.style.left = "0px";
  78. };
  79. }
  80. dialogHeaderEl.onmousedown = (e) => {
  81. // 鼠标按下,计算当前元素距离可视区的距离
  82. const disX = e.clientX - dialogHeaderEl.offsetLeft;
  83. const disY = e.clientY - dialogHeaderEl.offsetTop;
  84. // 获取到的值带px 正则匹配替换
  85. let styL, styT;
  86. // 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
  87. if (sty.left.includes("%")) {
  88. styL =
  89. +document.body.clientWidth * (+sty.left.replace(/\%/g, "") / 100);
  90. styT =
  91. +document.body.clientHeight * (+sty.top.replace(/\%/g, "") / 100);
  92. } else {
  93. styL = +sty.left.replace(/\px/g, "");
  94. styT = +sty.top.replace(/\px/g, "");
  95. }
  96. document.onmousemove = function (e) {
  97. // 通过事件委托,计算移动的距离
  98. const l = e.clientX - disX;
  99. const t = e.clientY - disY;
  100. // 移动当前元素
  101. if (t + styT >= 0) {
  102. dragDom.style.top = `${t + styT}px`;
  103. }
  104. dragDom.style.left = `${l + styL}px`;
  105. // 将此时的位置传出去
  106. // binding.value({x:e.pageX,y:e.pageY})
  107. };
  108. document.onmouseup = function (e) {
  109. document.onmousemove = null;
  110. document.onmouseup = null;
  111. };
  112. };
  113. },
  114. });
  115. Vue.directive("input-limit", {
  116. bind(el, binding) {
  117. var wins_0 = /[^\d]/g //整数判断
  118. var wins_1 = /[^\d^\.]/g //小数判断
  119. var flag = true;
  120. var points = 0;
  121. var lengths = 0
  122. var remainder = 0
  123. var no_int = 0
  124. const target = el instanceof HTMLInputElement ? el : el.querySelector("input");
  125. target.addEventListener("compositionstart", e => {
  126. flag = false;
  127. });
  128. target.addEventListener("compositionend", e => {
  129. flag = true;
  130. });
  131. target.addEventListener("input", e => {
  132. setTimeout(function() {
  133. if (flag) {
  134. if (binding.value == 0) {
  135. if (wins_0.test(e.target.value)) {
  136. e.target.value = e.target.value.replace(wins_0, "");
  137. e.target.dispatchEvent(new Event("input")) //手动更新v-model值
  138. }
  139. }
  140. if (binding.value == 1) {
  141. if (wins_0.test(e.target.value.toString().replace(/\d+\.(\d*)/, '$1'))) {
  142. remainder = true
  143. }
  144. if ((e.target.value.split('.')).length - 1 > 1) {
  145. points = true
  146. }
  147. if (e.target.value.toString().split(".")[1] != undefined) {
  148. if (e.target.value.toString().split(".")[1].length > 1) {
  149. lengths = true
  150. }
  151. }
  152. if (e.target.value.toString().indexOf(".") != -1) {
  153. no_int = false
  154. } else {
  155. no_int = true
  156. }
  157. if (wins_1.test(e.target.value) || lengths || points || remainder) {
  158. if (!no_int) {
  159. e.target.value = e.target.value.replace(wins_1, "").replace('.', '$#$').replace(/\./g, '').replace(
  160. '$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').substring(0, e.target.value.indexOf(
  161. ".") + 2)
  162. } else {
  163. e.target.value = e.target.value.replace(wins_0, "")
  164. }
  165. e.target.dispatchEvent(new Event("input"))
  166. }
  167. }
  168. if (binding.value == 2) {
  169. if (wins_0.test(e.target.value.toString().replace(/\d+\.(\d*)/, '$1'))) {
  170. remainder = true
  171. }
  172. if ((e.target.value.split('.')).length - 1 > 1) {
  173. points = true
  174. }
  175. if (e.target.value.toString().split(".")[1] != undefined) {
  176. if (e.target.value.toString().split(".")[1].length > 2) {
  177. lengths = true
  178. }
  179. }
  180. if (e.target.value.toString().indexOf(".") != -1) {
  181. no_int = false
  182. } else {
  183. no_int = true
  184. }
  185. if (wins_1.test(e.target.value) || lengths || points || remainder) {
  186. if (!no_int) {
  187. e.target.value = e.target.value.replace(wins_1, "").replace('.', '$#$').replace(/\./g, '').replace(
  188. '$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').substring(0, e.target.value.indexOf(
  189. ".") + 3)
  190. } else {
  191. e.target.value = e.target.value.replace(wins_0, "")
  192. }
  193. e.target.dispatchEvent(new Event("input"))
  194. }
  195. }
  196. }
  197. }, 0)
  198. })
  199. }
  200. })