main.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 Print from '@/components/plugs/print'
  23. Vue.use(Print) // 注册
  24. import Blob from '@/excel/Blob.js'
  25. import Export2Excel from '@/excel/Export2Excel.js'
  26. // 全局方法挂载
  27. Vue.prototype.$echarts = echarts;
  28. Vue.prototype.getDicts = getDicts
  29. Vue.prototype.getConfigKey = getConfigKey
  30. Vue.prototype.parseTime = parseTime
  31. Vue.prototype.resetForm = resetForm
  32. Vue.prototype.addDateRange = addDateRange
  33. Vue.prototype.selectDictLabel = selectDictLabel
  34. Vue.prototype.selectDictLabels = selectDictLabels
  35. Vue.prototype.download = download
  36. Vue.prototype.handleTree = handleTree
  37. Vue.prototype.msgSuccess = function (msg) {
  38. this.$message({ showClose: true, message: msg, type: "success" });
  39. }
  40. Vue.prototype.msgError = function (msg) {
  41. this.$message({ showClose: true, message: msg, type: "error" });
  42. }
  43. Vue.prototype.msgInfo = function (msg) {
  44. this.$message.info(msg);
  45. }
  46. // 全局组件挂载
  47. Vue.component('Pagination', Pagination)
  48. Vue.component('RightToolbar', RightToolbar)
  49. Vue.use(permission)
  50. /**
  51. * If you don't want to use mock-server
  52. * you want to use MockJs for mock api
  53. * you can execute: mockXHR()
  54. *
  55. * Currently MockJs will be used in the production environment,
  56. * please remove it before going online! ! !
  57. */
  58. Vue.use(Element, {
  59. size: Cookies.get('size') || 'medium' // set element-ui default size
  60. })
  61. Vue.config.productionTip = false
  62. new Vue({
  63. el: '#app',
  64. router,
  65. store,
  66. render: h => h(App)
  67. })
  68. Vue.directive("dialogDrag", {
  69. bind(el, binding, vnode, oldVnode) {
  70. const dialogHeaderEl = el.querySelector(".el-dialog__header");
  71. const dragDom = el.querySelector(".el-dialog");
  72. const enlarge = el.querySelector(".enlarge");
  73. dialogHeaderEl.style.cursor = "move";
  74. // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
  75. const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);
  76. if (enlarge) {
  77. enlarge.onclick = (e) => {
  78. dragDom.style.top = "0px";
  79. dragDom.style.left = "0px";
  80. };
  81. }
  82. dialogHeaderEl.onmousedown = (e) => {
  83. // 鼠标按下,计算当前元素距离可视区的距离
  84. const disX = e.clientX - dialogHeaderEl.offsetLeft;
  85. const disY = e.clientY - dialogHeaderEl.offsetTop;
  86. // 获取到的值带px 正则匹配替换
  87. let styL, styT;
  88. // 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
  89. if (sty.left.includes("%")) {
  90. styL =
  91. +document.body.clientWidth * (+sty.left.replace(/\%/g, "") / 100);
  92. styT =
  93. +document.body.clientHeight * (+sty.top.replace(/\%/g, "") / 100);
  94. } else {
  95. styL = +sty.left.replace(/\px/g, "");
  96. styT = +sty.top.replace(/\px/g, "");
  97. }
  98. document.onmousemove = function (e) {
  99. // 通过事件委托,计算移动的距离
  100. const l = e.clientX - disX;
  101. const t = e.clientY - disY;
  102. // 移动当前元素
  103. if (t + styT >= 0) {
  104. dragDom.style.top = `${t + styT}px`;
  105. }
  106. dragDom.style.left = `${l + styL}px`;
  107. // 将此时的位置传出去
  108. // binding.value({x:e.pageX,y:e.pageY})
  109. };
  110. document.onmouseup = function (e) {
  111. document.onmousemove = null;
  112. document.onmouseup = null;
  113. };
  114. };
  115. },
  116. });
  117. Vue.directive("input-limit", {
  118. bind(el, binding) {
  119. var wins_0 = /[^\d]/g //整数判断
  120. var wins_1 = /[^\d^\.]/g //小数判断
  121. var flag = true;
  122. var points = 0;
  123. var lengths = 0
  124. var remainder = 0
  125. var no_int = 0
  126. const target = el instanceof HTMLInputElement ? el : el.querySelector("input");
  127. target.addEventListener("compositionstart", e => {
  128. flag = false;
  129. });
  130. target.addEventListener("compositionend", e => {
  131. flag = true;
  132. });
  133. target.addEventListener("input", e => {
  134. setTimeout(function() {
  135. if (flag) {
  136. if (binding.value == 0) {
  137. if (wins_0.test(e.target.value)) {
  138. e.target.value = e.target.value.replace(wins_0, "");
  139. e.target.dispatchEvent(new Event("input")) //手动更新v-model值
  140. }
  141. }
  142. if (binding.value == 1) {
  143. if (wins_0.test(e.target.value.toString().replace(/\d+\.(\d*)/, '$1'))) {
  144. remainder = true
  145. }
  146. if ((e.target.value.split('.')).length - 1 > 1) {
  147. points = true
  148. }
  149. if (e.target.value.toString().split(".")[1] != undefined) {
  150. if (e.target.value.toString().split(".")[1].length > 1) {
  151. lengths = true
  152. }
  153. }
  154. if (e.target.value.toString().indexOf(".") != -1) {
  155. no_int = false
  156. } else {
  157. no_int = true
  158. }
  159. if (wins_1.test(e.target.value) || lengths || points || remainder) {
  160. if (!no_int) {
  161. e.target.value = e.target.value.replace(wins_1, "").replace('.', '$#$').replace(/\./g, '').replace(
  162. '$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').substring(0, e.target.value.indexOf(
  163. ".") + 2)
  164. } else {
  165. e.target.value = e.target.value.replace(wins_0, "")
  166. }
  167. e.target.dispatchEvent(new Event("input"))
  168. }
  169. }
  170. if (binding.value == 2) {
  171. if (wins_0.test(e.target.value.toString().replace(/\d+\.(\d*)/, '$1'))) {
  172. remainder = true
  173. }
  174. if ((e.target.value.split('.')).length - 1 > 1) {
  175. points = true
  176. }
  177. if (e.target.value.toString().split(".")[1] != undefined) {
  178. if (e.target.value.toString().split(".")[1].length > 2) {
  179. lengths = true
  180. }
  181. }
  182. if (e.target.value.toString().indexOf(".") != -1) {
  183. no_int = false
  184. } else {
  185. no_int = true
  186. }
  187. if (wins_1.test(e.target.value) || lengths || points || remainder) {
  188. if (!no_int) {
  189. e.target.value = e.target.value.replace(wins_1, "").replace('.', '$#$').replace(/\./g, '').replace(
  190. '$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').substring(0, e.target.value.indexOf(
  191. ".") + 3)
  192. } else {
  193. e.target.value = e.target.value.replace(wins_0, "")
  194. }
  195. e.target.dispatchEvent(new Event("input"))
  196. }
  197. }
  198. if (binding.value == 4) {
  199. if (wins_0.test(e.target.value.toString().replace(/\d+\.(\d*)/, '$1'))) {
  200. remainder = true
  201. }
  202. if ((e.target.value.split('.')).length - 1 > 1) {
  203. points = true
  204. }
  205. if (e.target.value.toString().split(".")[1] != undefined) {
  206. if (e.target.value.toString().split(".")[1].length > 4) {
  207. lengths = true
  208. }
  209. }
  210. if (e.target.value.toString().indexOf(".") != -1) {
  211. no_int = false
  212. } else {
  213. no_int = true
  214. }
  215. if (wins_1.test(e.target.value) || lengths || points || remainder) {
  216. if (!no_int) {
  217. e.target.value = e.target.value.replace(wins_1, "").replace('.', '$#$').replace(/\./g, '').replace(
  218. '$#$', '.').substring(0, e.target.value.indexOf(
  219. ".") + 5)
  220. } else {
  221. e.target.value = e.target.value.replace(wins_0, "")
  222. }
  223. e.target.dispatchEvent(new Event("input"))
  224. }
  225. }
  226. }
  227. }, 0)
  228. })
  229. }
  230. })
  231. Vue.directive('Alphabet', {
  232. inserted: function (el) {
  233. const input = el.querySelector('.el-input__inner');
  234. input.onkeyup = function (e) {
  235. input.value = input.value.replace(/[^A-Za-z0-9]/g,'')
  236. }
  237. input.onblur = function (e) {
  238. input.value = input.value.replace(/[^A-Za-z0-9]/g,'')
  239. }
  240. }
  241. });
  242. Vue.directive('Space', {
  243. inserted: function (el) {
  244. const input = el.querySelector('.el-input__inner');
  245. input.onkeyup = function (e) {
  246. input.value = input.value.replace(/\s+/g,'')
  247. }
  248. input.onblur = function (e) {
  249. input.value = input.value.replace(/\s+/g,'')
  250. }
  251. }
  252. });