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