main.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. // 全局方法挂载
  22. Vue.prototype.$echarts = echarts;
  23. Vue.prototype.getDicts = getDicts
  24. Vue.prototype.getConfigKey = getConfigKey
  25. Vue.prototype.parseTime = parseTime
  26. Vue.prototype.resetForm = resetForm
  27. Vue.prototype.addDateRange = addDateRange
  28. Vue.prototype.selectDictLabel = selectDictLabel
  29. Vue.prototype.selectDictLabels = selectDictLabels
  30. Vue.prototype.download = download
  31. Vue.prototype.handleTree = handleTree
  32. Vue.prototype.msgSuccess = function (msg) {
  33. this.$message({ showClose: true, message: msg, type: "success" });
  34. }
  35. Vue.prototype.msgError = function (msg) {
  36. this.$message({ showClose: true, message: msg, type: "error" });
  37. }
  38. Vue.prototype.msgInfo = function (msg) {
  39. this.$message.info(msg);
  40. }
  41. // 全局组件挂载
  42. Vue.component('Pagination', Pagination)
  43. Vue.component('RightToolbar', RightToolbar)
  44. Vue.use(permission)
  45. /**
  46. * If you don't want to use mock-server
  47. * you want to use MockJs for mock api
  48. * you can execute: mockXHR()
  49. *
  50. * Currently MockJs will be used in the production environment,
  51. * please remove it before going online! ! !
  52. */
  53. Vue.use(Element, {
  54. size: Cookies.get('size') || 'medium' // set element-ui default size
  55. })
  56. Vue.config.productionTip = false
  57. new Vue({
  58. el: '#app',
  59. router,
  60. store,
  61. render: h => h(App)
  62. })
  63. Vue.directive("input-limit", {
  64. bind(el, binding) {
  65. var wins_0 = /[^\d]/g //整数判断
  66. var wins_1 = /[^\d^\.]/g //小数判断
  67. var flag = true;
  68. var points = 0;
  69. var lengths = 0
  70. var remainder = 0
  71. var no_int = 0
  72. const target = el instanceof HTMLInputElement ? el : el.querySelector("input");
  73. target.addEventListener("compositionstart", e => {
  74. flag = false;
  75. });
  76. target.addEventListener("compositionend", e => {
  77. flag = true;
  78. });
  79. target.addEventListener("input", e => {
  80. setTimeout(function() {
  81. if (flag) {
  82. if (binding.value == 0) {
  83. if (wins_0.test(e.target.value)) {
  84. e.target.value = e.target.value.replace(wins_0, "");
  85. e.target.dispatchEvent(new Event("input")) //手动更新v-model值
  86. }
  87. }
  88. if (binding.value == 1) {
  89. if (wins_0.test(e.target.value.toString().replace(/\d+\.(\d*)/, '$1'))) {
  90. remainder = true
  91. }
  92. if ((e.target.value.split('.')).length - 1 > 1) {
  93. points = true
  94. }
  95. if (e.target.value.toString().split(".")[1] != undefined) {
  96. if (e.target.value.toString().split(".")[1].length > 1) {
  97. lengths = true
  98. }
  99. }
  100. if (e.target.value.toString().indexOf(".") != -1) {
  101. no_int = false
  102. } else {
  103. no_int = true
  104. }
  105. if (wins_1.test(e.target.value) || lengths || points || remainder) {
  106. if (!no_int) {
  107. e.target.value = e.target.value.replace(wins_1, "").replace('.', '$#$').replace(/\./g, '').replace(
  108. '$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').substring(0, e.target.value.indexOf(
  109. ".") + 2)
  110. } else {
  111. e.target.value = e.target.value.replace(wins_0, "")
  112. }
  113. e.target.dispatchEvent(new Event("input"))
  114. }
  115. }
  116. if (binding.value == 2) {
  117. if (wins_0.test(e.target.value.toString().replace(/\d+\.(\d*)/, '$1'))) {
  118. remainder = true
  119. }
  120. if ((e.target.value.split('.')).length - 1 > 1) {
  121. points = true
  122. }
  123. if (e.target.value.toString().split(".")[1] != undefined) {
  124. if (e.target.value.toString().split(".")[1].length > 2) {
  125. lengths = true
  126. }
  127. }
  128. if (e.target.value.toString().indexOf(".") != -1) {
  129. no_int = false
  130. } else {
  131. no_int = true
  132. }
  133. if (wins_1.test(e.target.value) || lengths || points || remainder) {
  134. if (!no_int) {
  135. e.target.value = e.target.value.replace(wins_1, "").replace('.', '$#$').replace(/\./g, '').replace(
  136. '$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').substring(0, e.target.value.indexOf(
  137. ".") + 3)
  138. } else {
  139. e.target.value = e.target.value.replace(wins_0, "")
  140. }
  141. e.target.dispatchEvent(new Event("input"))
  142. }
  143. }
  144. }
  145. }, 0)
  146. })
  147. }
  148. })