From a4e5f22b95b4f4e65cea7e4917f8fe9150430041 Mon Sep 17 00:00:00 2001
From: Vergil <974548713@qq.com>
Date: Mon, 24 Feb 2020 15:20:42 +0800
Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80=E6=95=B0=E5=AD=97=E9=AA=8C?=
=?UTF-8?q?=E8=AF=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AmountInputBox/AmountInputBox.js | 81 +++++
src/components/AmountInputBox/index.js | 11 +
src/main.js | 4 +
.../GroupMatching/index.vue | 8 +-
.../machiningHoursStatistics/index.vue | 325 ++++++++----------
.../OutFactoryMaintenance/index.vue | 22 +-
.../TechnologyCenter/QueryParts/index.vue | 16 +-
7 files changed, 256 insertions(+), 211 deletions(-)
create mode 100644 src/components/AmountInputBox/AmountInputBox.js
create mode 100644 src/components/AmountInputBox/index.js
diff --git a/src/components/AmountInputBox/AmountInputBox.js b/src/components/AmountInputBox/AmountInputBox.js
new file mode 100644
index 00000000..2514ead5
--- /dev/null
+++ b/src/components/AmountInputBox/AmountInputBox.js
@@ -0,0 +1,81 @@
+/**
+ * @desc 验证整数类型数字方法
+ * @param {Object} e
+ * @param {regular} reg 正则
+ * @param {Number} charcode 键盘code
+ * */
+const checkNumber = (e, reg, charcode) => {
+ if (!reg.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey) {
+ if (e.preventDefault) {
+ e.preventDefault()
+ } else {
+ e.returnValue = false
+ }
+ }
+}
+
+/**
+ * @desc 验证浮点类型小数方法(建议用text类型的表单)
+ * @param {Object} e
+ * @param {regular} reg 正则
+ * @param {Number} charcode 键盘code
+ * @param {Object} el dom对象
+ * */
+const checkFloat = (e, reg, charcode, el) => {
+ if (charcode === 46) {
+ if (el.children[0].value.includes('.')) {
+ e.preventDefault()
+ }
+ return
+ } else if (
+ !reg.test(String.fromCharCode(charcode)) &&
+ charcode > 9 &&
+ !e.ctrlKey
+ ) {
+ if (e.preventDefault) {
+ e.preventDefault()
+ } else {
+ e.returnValue = false
+ }
+ }
+}
+
+/**
+ * @author LeeYunxiang
+ * @description 限制数字输入格式 int => 正整数 , num => 自然数(正整数包括0) , float => 正数包括小数(建议用text类型的input表单)
+ * */
+export default {
+ key: 'positive',
+ func: {
+ inserted(el, bind) {
+ el.addEventListener('keypress', e => {
+ e = e || window.event
+ const charcode = typeof e.charCode === 'number' ? e.charCode : e.keyCode
+ let reg = null
+ switch (bind.value) {
+ case 'num':
+ reg = /\d/
+ checkNumber(e, reg, charcode)
+ break
+ case 'int':
+ if (el.children[0].value.length === 0) {
+ reg = /^[1-9]$/
+ } else {
+ reg = /\d/
+ }
+ checkNumber(e, reg, charcode)
+ break
+ case 'float':
+ reg = /\d/
+ checkFloat(e, reg, charcode, el)
+ break
+ case 'notZero':
+ // reg = (/^([1-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/)
+ reg = (/^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/)
+ checkFloat(e, reg, charcode, el)
+ break
+ }
+ })
+ }
+ }
+}
diff --git a/src/components/AmountInputBox/index.js b/src/components/AmountInputBox/index.js
new file mode 100644
index 00000000..75190d55
--- /dev/null
+++ b/src/components/AmountInputBox/index.js
@@ -0,0 +1,11 @@
+import AmountInputBox from './AmountInputBox.js'
+const directives = [AmountInputBox]
+export default {
+ install: Vue => {
+ if (directives.length && directives.length > 0) {
+ directives.map(item => {
+ Vue.directive(item.key, item.func)
+ })
+ }
+ }
+}
diff --git a/src/main.js b/src/main.js
index 729e3d4d..42e86a8b 100644
--- a/src/main.js
+++ b/src/main.js
@@ -22,6 +22,10 @@ import 'viewerjs/dist/viewer.css'
import VueBarcode from '@xkeshi/vue-barcode'
import Direction from 'vue-direction-key'
import elDragDialog from '@/directive/el-dragDialog'
+// 全局数字、金额输入框组件
+import directive from './components/AmountInputBox/index.js'
+Vue.use(directive)
+
Vue.use(elDragDialog)
Vue.component('barcode', VueBarcode)
Vue.use(Direction)
diff --git a/src/views/ManufacturingCenter/GroupMatching/index.vue b/src/views/ManufacturingCenter/GroupMatching/index.vue
index 28f36a16..d469982e 100644
--- a/src/views/ManufacturingCenter/GroupMatching/index.vue
+++ b/src/views/ManufacturingCenter/GroupMatching/index.vue
@@ -1,7 +1,7 @@
车间生产
@@ -77,7 +77,7 @@