el-plus-crud 0.1.47 → 0.1.49

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.
@@ -160,6 +160,13 @@ async function clearValid() {
160
160
  return await Promise.all(formRefs.value.map((tempRef) => tempRef.clearValid()))
161
161
  }
162
162
 
163
+ /**
164
+ * 清空表单
165
+ */
166
+ async function clear() {
167
+ return await Promise.all(formRefs.value.map((tempRef) => tempRef.clear()))
168
+ }
169
+
163
170
  /**
164
171
  * 获取数据
165
172
  */
@@ -171,7 +178,7 @@ function getData() {
171
178
  return tempData
172
179
  }
173
180
 
174
- defineExpose({ validate, getData, clearValid })
181
+ defineExpose({ validate, getData, clearValid, clear })
175
182
  </script>
176
183
  <style lang="scss">
177
184
  .el-plus-form-group {
@@ -228,7 +228,7 @@ function refreshValue() {
228
228
  divList.map((item: any, i: number) => {
229
229
  str = str.replace(item, '${' + yzList[i] + '}')
230
230
  })
231
- currentValue.value = str.replaceAll('&nbsp;', '')
231
+ currentValue.value = str.replaceAll('&nbsp;', '').replaceAll('&lt;', '<').replaceAll('&gt;', '>')
232
232
  }
233
233
 
234
234
  /**
@@ -306,6 +306,7 @@ onUnmounted(() => {
306
306
  margin-bottom: 20px;
307
307
  color: var(--el-color-danger);
308
308
  min-height: 25px;
309
+ word-break: break-all;
309
310
  }
310
311
  .title-tip {
311
312
  margin-bottom: 20px;
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <el-input style="display: flex" v-bind="attrs" v-on="onEvents" v-model="currentText" @focus="handelFocus" @blur="handelBlur" onkeypress="return event.target.value === '' || event.target.value === undefined || event.target.value?.indexOf('.') >= 0 ? /[-\d]/.test(String.fromCharCode(event.keyCode)): /[-\d\.]/.test(String.fromCharCode(event.keyCode))">
2
+ <el-input style="display: flex" v-bind="attrs" :disabled="disabled" v-on="onEvents" v-model="currentText" @focus="handelFocus" @blur="handelBlur" onkeypress="return event.target.value === '' || event.target.value === undefined || event.target.value?.indexOf('.') >= 0 ? /[-\d]/.test(String.fromCharCode(event.keyCode)): /[-\d\.]/.test(String.fromCharCode(event.keyCode))">
3
3
  <template v-for="(item, key, index) of slots" #[key] :key="index">
4
4
  <slot :name="key" />
5
5
  </template>
@@ -15,7 +15,7 @@ export default {
15
15
  }
16
16
  </script>
17
17
  <script lang="ts" setup>
18
- import { ref, watch, useAttrs, useSlots, onBeforeMount, nextTick, computed } from 'vue'
18
+ import { ref, useAttrs, useSlots, onBeforeMount, nextTick, computed, watch } from 'vue'
19
19
  import { getAttrs, getEvents } from '../mixins'
20
20
  import { ElMessage } from 'element-plus'
21
21
 
@@ -23,6 +23,7 @@ const props = defineProps<{
23
23
  modelValue?: number | null
24
24
  field: string
25
25
  desc: { [key: string]: any }
26
+ disabled?: boolean
26
27
  formData: { [key: string]: any }
27
28
  }>()
28
29
  const emits = defineEmits(['update:modelValue', 'validateThis'])
@@ -81,14 +82,17 @@ function handelBlur() {
81
82
  const numBindAttr = computed(() => {
82
83
  let min = 0
83
84
  let max = 100
85
+ let precision = 5
86
+
84
87
  let tempAttrs = props.desc?.attrs || props.desc
85
88
  if (props.desc?.attrs && typeof props.desc.attrs === 'function') {
86
89
  tempAttrs = props.desc.attrs(props.formData || {})
87
90
  }
88
91
 
89
- const { min: min_, max: max_ } = (tempAttrs || {}) as any
92
+ const { min: min_, max: max_, precision: precision_ } = (tempAttrs || {}) as any
90
93
  if (min_ !== undefined && min_ !== null && min_ !== '') min = min_
91
94
  if (max_ !== undefined && max_ !== null && max_ !== '') max = max_
95
+ if (precision_ !== undefined && precision_ !== null && precision_ !== '' && precision_ >= 2) precision = precision_
92
96
 
93
97
  // 这里判断一下,最小和最大值的大小
94
98
  if (min > max) {
@@ -96,7 +100,7 @@ const numBindAttr = computed(() => {
96
100
  } else if (max < min) {
97
101
  max = min
98
102
  }
99
- return { min, max }
103
+ return { min, max, precision }
100
104
  })
101
105
 
102
106
  // 判断一下初始值
@@ -128,20 +132,45 @@ function handelValChange(val: any, oldVal: any) {
128
132
  ElMessage.warning(`${props.desc?.label || ''}最少不能低于${numBindAttr.value.min}`)
129
133
  nextTick(() => {
130
134
  currentText.value = numBindAttr.value.min
131
- currentValue.value = +(currentText.value / 100).toFixed(4)
135
+ currentValue.value = +(currentText.value / 100).toFixed(numBindAttr.value.precision)
132
136
  change && change()
133
137
  })
134
138
  } else if (val > numBindAttr.value.max) {
135
139
  ElMessage.warning(`${props.desc?.label || ''}最多不能大于${numBindAttr.value.max}`)
136
140
  nextTick(() => {
137
141
  currentText.value = numBindAttr.value.max
138
- currentValue.value = +(currentText.value / 100).toFixed(4)
142
+ currentValue.value = +(currentText.value / 100).toFixed(numBindAttr.value.precision)
139
143
  change && change()
140
144
  })
141
145
  } else {
142
- currentValue.value = +(val / 100).toFixed(4)
146
+ if (val.indexOf('.') > 0 && val.length - val.indexOf('.') > numBindAttr.value.precision - 2) {
147
+ currentText.value = (+val).toFixed(numBindAttr.value.precision - 2)
148
+ } else {
149
+ currentText.value = val
150
+ }
151
+ currentValue.value = +(val / 100).toFixed(numBindAttr.value.precision)
143
152
  change && change()
144
153
  }
145
154
  }
146
155
  }
156
+
157
+ /**
158
+ * 清空数据
159
+ */
160
+ function clear() {
161
+ currentText.value = null
162
+ currentValue.value = null
163
+ isDoChange.value = false
164
+ }
165
+
166
+ watch(
167
+ () => props.modelValue,
168
+ (val: any) => {
169
+ if (val !== undefined && val !== null && val !== '') {
170
+ handelValChange((val * 100).toFixed(numBindAttr.value.precision - 2), null)
171
+ }
172
+ }
173
+ )
174
+
175
+ defineExpose({ clear, field: props.field })
147
176
  </script>
@@ -214,7 +214,7 @@ async function getToken(token: string | Object | Function | undefined, param?: a
214
214
  async function handelUploadSuccess(response: any, file: any) {
215
215
  if (response && Object.keys(response).length > 0) {
216
216
  // 从结果集中获取一下furl
217
- const tempUrl = getValue(defaultConf.upload?.actionMap?.objectUrlKey || [], response.request)
217
+ const tempUrl = getValue(defaultConf.upload?.actionMap?.objectUrlKey || [], response.request || response)
218
218
  if (tempUrl) file.raw.furl = tempUrl
219
219
  }
220
220
  // 获取文件上传的token以及上传路径
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "el-plus-crud",
3
3
  "description": "采用Vue3 + TS,封装的element-plus数据驱动表单、列表组件",
4
4
  "author": "K.D.Jack",
5
- "version": "0.1.47",
5
+ "version": "0.1.49",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "main": "dist/el-plus-crud.mjs",