main.js 11 KB

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