main.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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("input-limit", {
  67. bind(el, binding) {
  68. var wins_0 = /[^\d]/g //整数判断
  69. var wins_1 = /[^\d^\.]/g //小数判断
  70. var flag = true;
  71. var points = 0;
  72. var lengths = 0
  73. var remainder = 0
  74. var no_int = 0
  75. const target = el instanceof HTMLInputElement ? el : el.querySelector("input");
  76. target.addEventListener("compositionstart", e => {
  77. flag = false;
  78. });
  79. target.addEventListener("compositionend", e => {
  80. flag = true;
  81. });
  82. target.addEventListener("input", e => {
  83. setTimeout(function() {
  84. if (flag) {
  85. if (binding.value == 0) {
  86. if (wins_0.test(e.target.value)) {
  87. e.target.value = e.target.value.replace(wins_0, "");
  88. e.target.dispatchEvent(new Event("input")) //手动更新v-model值
  89. }
  90. }
  91. if (binding.value == 1) {
  92. if (wins_0.test(e.target.value.toString().replace(/\d+\.(\d*)/, '$1'))) {
  93. remainder = true
  94. }
  95. if ((e.target.value.split('.')).length - 1 > 1) {
  96. points = true
  97. }
  98. if (e.target.value.toString().split(".")[1] != undefined) {
  99. if (e.target.value.toString().split(".")[1].length > 1) {
  100. lengths = true
  101. }
  102. }
  103. if (e.target.value.toString().indexOf(".") != -1) {
  104. no_int = false
  105. } else {
  106. no_int = true
  107. }
  108. if (wins_1.test(e.target.value) || lengths || points || remainder) {
  109. if (!no_int) {
  110. e.target.value = e.target.value.replace(wins_1, "").replace('.', '$#$').replace(/\./g, '').replace(
  111. '$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').substring(0, e.target.value.indexOf(
  112. ".") + 2)
  113. } else {
  114. e.target.value = e.target.value.replace(wins_0, "")
  115. }
  116. e.target.dispatchEvent(new Event("input"))
  117. }
  118. }
  119. if (binding.value == 2) {
  120. if (wins_0.test(e.target.value.toString().replace(/\d+\.(\d*)/, '$1'))) {
  121. remainder = true
  122. }
  123. if ((e.target.value.split('.')).length - 1 > 1) {
  124. points = true
  125. }
  126. if (e.target.value.toString().split(".")[1] != undefined) {
  127. if (e.target.value.toString().split(".")[1].length > 2) {
  128. lengths = true
  129. }
  130. }
  131. if (e.target.value.toString().indexOf(".") != -1) {
  132. no_int = false
  133. } else {
  134. no_int = true
  135. }
  136. if (wins_1.test(e.target.value) || lengths || points || remainder) {
  137. if (!no_int) {
  138. e.target.value = e.target.value.replace(wins_1, "").replace('.', '$#$').replace(/\./g, '').replace(
  139. '$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').substring(0, e.target.value.indexOf(
  140. ".") + 3)
  141. } else {
  142. e.target.value = e.target.value.replace(wins_0, "")
  143. }
  144. e.target.dispatchEvent(new Event("input"))
  145. }
  146. }
  147. }
  148. }, 0)
  149. })
  150. }
  151. })