main.js 11 KB

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