el-plus-crud 0.0.78 → 0.0.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,7 +45,7 @@ import * as validates from './util/validate'
45
45
  import { typeList } from './components/index'
46
46
  import ElPlusFormBtn from './components/ElPlusFormBtn.vue'
47
47
  import { cloneDeep } from 'lodash'
48
- import { ICRUDConfig, IFormBack, IFormDescItem } from 'types'
48
+ import { ICRUDConfig, IFormBack, IFormDesc, IFormDescItem } from 'types'
49
49
 
50
50
  // IFormProps定义
51
51
  export interface IFormProps {
@@ -227,7 +227,7 @@ const computedRules = computed(() => {
227
227
  tempRules[field].push(item)
228
228
  })
229
229
  }
230
- } else if (props.formDesc[field].required || props.formDesc[field].require) {
230
+ } else if (props.formDesc[field].required) {
231
231
  // 如果直接指定 required || require,手动添加校验信息
232
232
  //
233
233
  let rules = 'notAllBlank'
@@ -1,149 +1,152 @@
1
- <template>
2
- <el-input-number v-if="isInit" class="ElPlusFormNumber-panel" v-bind="attrs" v-on="onEvents" v-model="currentValue" :disabled="disabled" @focus="handelFocus" @blur="handelBlur" onkeypress="return( /[\d\.]/.test(String.fromCharCode(event.keyCode)))" />
3
- </template>
4
- <script lang="ts">
5
- export default {
6
- name: 'ElPlusFormNumber',
7
- inheritAttrs: false,
8
- typeName: 'number',
9
- customOptions: {}
10
- }
11
- </script>
12
- <script lang="ts" setup>
13
- import { ref, computed, useAttrs, onBeforeMount, nextTick, inject } from 'vue'
14
- import { getAttrs, getEvents } from '../mixins'
15
- import { ElMessage } from 'element-plus'
16
- import { ICRUDConfig } from 'types'
17
-
18
- const defaultConf = inject('defaultConf') as ICRUDConfig
19
-
20
- const props = defineProps<{
21
- modelValue?: number | null
22
- field: string
23
- loading?: boolean
24
- desc: { [key: string]: any }
25
- formData: { [key: string]: any }
26
- rowIndex?: number
27
- disabled?: boolean
28
- }>()
29
-
30
- const emits = defineEmits(['update:modelValue', 'validateThis'])
31
- const currentValue = ref(props.modelValue)
32
- emits('update:modelValue', currentValue)
33
- const attrs = ref({} as any)
34
- const isInit = ref(false)
35
- const onEvents = ref(getEvents(props))
36
-
37
- const isDoChange = ref(false)
38
-
39
- onBeforeMount(async () => {
40
- attrs.value = await getAttrs(props, { ...defaultConf.form?.leng.nbinput, ...useAttrs() })
41
- delete attrs.value.min
42
- delete attrs.value.max
43
- isInit.value = true
44
- })
45
-
46
- /**
47
- * 获取焦点
48
- */
49
- function handelFocus() {
50
- isDoChange.value = false
51
- }
52
-
53
- /**
54
- * 处理失去焦点
55
- * @param event
56
- */
57
- function handelBlur() {
58
- if (!isDoChange.value) {
59
- if (!currentValue.value) {
60
- nextTick(() => {
61
- currentValue.value = props.desc?.required ? numBindAttr.value.min : 0
62
- if (!props.desc?.required) {
63
- // 查看了源码,这里需要二次赋不一样的值,这里才会真正重新渲染
64
- nextTick(() => {
65
- currentValue.value = null
66
- })
67
- }
68
- })
69
- } else {
70
- handelValChange(currentValue.value, 0)
71
- }
72
- }
73
- nextTick(() => {
74
- emits('validateThis')
75
- })
76
- }
77
-
78
- /**
79
- * 绑定属性
80
- */
81
- const numBindAttr = computed(() => {
82
- let numAttrs = props.desc.attrs || defaultConf.form?.leng.nbinput
83
- if (typeof props.desc.attrs === 'function') {
84
- numAttrs = props.desc.attrs(props.formData)
85
- }
86
- // 这里判断一下,最小和最大值的大小
87
- if (numAttrs.min > numAttrs.max) {
88
- numAttrs.min = numAttrs.max
89
- } else if (numAttrs.max < numAttrs.min) {
90
- numAttrs.max = numAttrs.min
91
- }
92
- return numAttrs
93
- })
94
-
95
- // 判断一下初始值
96
- if (currentValue.value !== undefined && currentValue.value !== null) {
97
- if (currentValue.value < numBindAttr.value.min) {
98
- currentValue.value = numBindAttr.value.min
99
- } else if (currentValue.value > numBindAttr.value.max) {
100
- currentValue.value = numBindAttr.value.max
101
- }
102
- }
103
-
104
- const change = onEvents.value.change
105
- if (change) {
106
- onEvents.value.change = (val: any, oldVal: any) => {
107
- handelValChange(val, oldVal)
108
- }
109
- } else {
110
- onEvents.value.change = handelValChange
111
- }
112
-
113
- /**
114
- * 监听值改变
115
- * @param val
116
- */
117
- function handelValChange(val: any, oldVal: any) {
118
- isDoChange.value = true
119
- if (val !== oldVal) {
120
- if (val < numBindAttr.value.min) {
121
- ElMessage.warning(`${props.desc?.label || ''}最少不能低于${numBindAttr.value.min}`)
122
- nextTick(() => {
123
- currentValue.value = numBindAttr.value.min
124
- })
125
- } else if (val > numBindAttr.value.max) {
126
- ElMessage.warning(`${props.desc?.label || ''}最多不能大于${numBindAttr.value.max}`)
127
- nextTick(() => {
128
- currentValue.value = numBindAttr.value.max
129
- change && change()
130
- })
131
- } else {
132
- change && change()
133
- }
134
- }
135
- }
136
- </script>
137
- <style lang="scss" scoped>
138
- .ElPlusFormNumber-panel {
139
- width: 100% !important;
140
- max-width: 100%;
141
- :deep(.el-input__wrapper) {
142
- // padding-left: 11px !important;
143
- input {
144
- text-align: left !important;
145
- }
146
- }
147
- }
148
- </style>
149
- types
1
+ <template>
2
+ <el-input-number v-if="isInit" class="ElPlusFormNumber-panel" v-bind="attrs" v-on="onEvents" v-model="currentValue" :disabled="disabled" @focus="handelFocus" @blur="handelBlur" onkeypress="return( /[\d\.]/.test(String.fromCharCode(event.keyCode)))" />
3
+ </template>
4
+ <script lang="ts">
5
+ export default {
6
+ name: 'ElPlusFormNumber',
7
+ inheritAttrs: false,
8
+ typeName: 'number',
9
+ customOptions: {}
10
+ }
11
+ </script>
12
+ <script lang="ts" setup>
13
+ import { ref, computed, useAttrs, onBeforeMount, nextTick, inject } from 'vue'
14
+ import { getAttrs, getEvents } from '../mixins'
15
+ import { ElMessage } from 'element-plus'
16
+ import { ICRUDConfig } from 'types'
17
+
18
+ const defaultConf = inject('defaultConf') as ICRUDConfig
19
+
20
+ const props = defineProps<{
21
+ modelValue?: number | null
22
+ field: string
23
+ loading?: boolean
24
+ desc: { [key: string]: any }
25
+ formData: { [key: string]: any }
26
+ rowIndex?: number
27
+ disabled?: boolean
28
+ }>()
29
+
30
+ const emits = defineEmits(['update:modelValue', 'validateThis'])
31
+ const currentValue = ref(props.modelValue)
32
+ emits('update:modelValue', currentValue)
33
+ const attrs = ref({} as any)
34
+ const isInit = ref(false)
35
+ const onEvents = ref(getEvents(props))
36
+
37
+ const isDoChange = ref(false)
38
+
39
+ onBeforeMount(async () => {
40
+ attrs.value = await getAttrs(props, { ...defaultConf.form?.leng.nbinput, ...useAttrs() })
41
+ delete attrs.value.min
42
+ delete attrs.value.max
43
+ isInit.value = true
44
+ })
45
+
46
+ /**
47
+ * 获取焦点
48
+ */
49
+ function handelFocus() {
50
+ isDoChange.value = false
51
+ }
52
+
53
+ /**
54
+ * 处理失去焦点
55
+ * @param event
56
+ */
57
+ function handelBlur() {
58
+ console.log('currentValue', currentValue.value)
59
+
60
+ if (!isDoChange.value) {
61
+ if (currentValue.value !== 0 && !currentValue.value) {
62
+ nextTick(() => {
63
+ currentValue.value = props.desc?.required ? numBindAttr.value.min : 0
64
+ if (currentValue.value === 0) {
65
+ // 查看了源码,这里需要二次赋不一样的值,这里才会真正重新渲染
66
+ nextTick(() => {
67
+ currentValue.value = null
68
+ change && change()
69
+ })
70
+ }
71
+ })
72
+ } else {
73
+ handelValChange(currentValue.value, 0)
74
+ }
75
+ }
76
+ nextTick(() => {
77
+ emits('validateThis')
78
+ })
79
+ }
80
+
81
+ /**
82
+ * 绑定属性
83
+ */
84
+ const numBindAttr = computed(() => {
85
+ let numAttrs = props.desc.attrs || defaultConf.form?.leng.nbinput
86
+ if (typeof props.desc.attrs === 'function') {
87
+ numAttrs = props.desc.attrs(props.formData)
88
+ }
89
+ // 这里判断一下,最小和最大值的大小
90
+ if (numAttrs.min > numAttrs.max) {
91
+ numAttrs.min = numAttrs.max
92
+ } else if (numAttrs.max < numAttrs.min) {
93
+ numAttrs.max = numAttrs.min
94
+ }
95
+ return numAttrs
96
+ })
97
+
98
+ // 判断一下初始值
99
+ if (currentValue.value !== undefined && currentValue.value !== null) {
100
+ if (currentValue.value < numBindAttr.value.min) {
101
+ currentValue.value = numBindAttr.value.min
102
+ } else if (currentValue.value > numBindAttr.value.max) {
103
+ currentValue.value = numBindAttr.value.max
104
+ }
105
+ }
106
+
107
+ const change = onEvents.value.change
108
+ if (change) {
109
+ onEvents.value.change = (val: any, oldVal: any) => {
110
+ handelValChange(val, oldVal)
111
+ }
112
+ } else {
113
+ onEvents.value.change = handelValChange
114
+ }
115
+
116
+ /**
117
+ * 监听值改变
118
+ * @param val
119
+ */
120
+ function handelValChange(val: any, oldVal: any) {
121
+ isDoChange.value = true
122
+ if (val !== oldVal) {
123
+ if (val < numBindAttr.value.min) {
124
+ ElMessage.warning(`${props.desc?.label || ''}最少不能低于${numBindAttr.value.min}`)
125
+ nextTick(() => {
126
+ currentValue.value = numBindAttr.value.min
127
+ change && change()
128
+ })
129
+ } else if (val > numBindAttr.value.max) {
130
+ ElMessage.warning(`${props.desc?.label || ''}最多不能大于${numBindAttr.value.max}`)
131
+ nextTick(() => {
132
+ currentValue.value = numBindAttr.value.max
133
+ change && change()
134
+ })
135
+ } else {
136
+ change && change()
137
+ }
138
+ }
139
+ }
140
+ </script>
141
+ <style lang="scss" scoped>
142
+ .ElPlusFormNumber-panel {
143
+ width: 100% !important;
144
+ max-width: 100%;
145
+ :deep(.el-input__wrapper) {
146
+ // padding-left: 11px !important;
147
+ input {
148
+ text-align: left !important;
149
+ }
150
+ }
151
+ }
152
+ </style>