main.js 11 KB

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