n20-common-lib 2.22.17 → 2.22.19

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n20-common-lib",
3
- "version": "2.22.17",
3
+ "version": "2.22.19",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -1,16 +1,16 @@
1
1
  <template>
2
2
  <div
3
3
  class="w-100p flex-box"
4
- style="
5
- flex-wrap: wrap;
6
- display: grid;
7
- grid-template-columns: repeat(2, 1fr);
8
- gap: 16px;
9
- padding: 0;
10
- overflow-x: hidden;
11
- "
4
+ :style="{
5
+ display: 'grid',
6
+ flexWrap: 'wrap',
7
+ gridTemplateColumns: `repeat(${columns}, 1fr)`,
8
+ gap: '16px',
9
+ padding: '0',
10
+ overflowX: 'hidden'
11
+ }"
12
12
  >
13
- <div v-for="(item, i) in otherAttData" :key="i" class="flex-box flex-v" style="width: 100%; padding: 0 20px">
13
+ <div v-for="(item, i) in otherAttData" :key="i" class="flex-box" style="width: 100%; padding: 0 20px">
14
14
  <el-form-item
15
15
  class="m-r-ss m-b-s"
16
16
  :label-width="labelWidth"
@@ -20,12 +20,7 @@
20
20
  <span slot="label">
21
21
  <span
22
22
  v-title="item.cfgName"
23
- style="
24
- display: inline-block;
25
- white-space: nowrap;
26
- overflow: hidden;
27
- text-overflow: ellipsis;
28
- "
23
+ style="display: inline-block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis"
29
24
  :style="{ maxWidth: labelWidth }"
30
25
  >
31
26
  <span v-if="required" style="color: red">*</span>
@@ -93,13 +88,13 @@
93
88
  v-model="item.cfgVal"
94
89
  :type="'textarea'"
95
90
  placeholder="请输入"
96
- class="w-100p m-r-ss m-b-s flex-1"
91
+ class="w-100p m-r-s m-b-s flex-1"
97
92
  clearable
98
93
  />
99
94
  <el-input
100
95
  v-if="item.cfgHasRemark === '1' && !['11', '12'].includes(item.cfgType)"
101
96
  v-model="item.cfgRemark"
102
- class="w-100p m-r-ss m-b-s flex-1"
97
+ class="w-100p m-r-lg m-b-s flex-1"
103
98
  placeholder="请输入备注"
104
99
  />
105
100
  </div>
@@ -118,6 +113,10 @@ export default {
118
113
  type: [String, Number],
119
114
  default: ''
120
115
  },
116
+ columns: {
117
+ type: Number,
118
+ default: 1
119
+ },
121
120
  form: {
122
121
  type: Object,
123
122
  default: () => ({})
@@ -44,6 +44,7 @@
44
44
  :other-att-data-a="otherAttDataA"
45
45
  :proc-inst-id="procInstId || this.$route.query.processInstanceId"
46
46
  :required="true"
47
+ :columns="columns"
47
48
  :label-width="labelWidth"
48
49
  />
49
50
  </div>
@@ -74,6 +75,10 @@ export default {
74
75
  type: String,
75
76
  default: '12em'
76
77
  },
78
+ columns: {
79
+ type: Number,
80
+ default: 1
81
+ },
77
82
  afterGetConf: {
78
83
  type: Function,
79
84
  default: undefined
@@ -0,0 +1,112 @@
1
+ # InputNumber 数字输入框组件
2
+
3
+ 数字输入框组件,支持金额、比率、纯数字三种类型,提供千分位格式化、小数位控制等功能。
4
+
5
+ ## 基础用法
6
+
7
+ ```vue
8
+ <template>
9
+ <!-- 金额类型(默认) -->
10
+ <InputNumber v-model="money" type="money" />
11
+
12
+ <!-- 比率类型 -->
13
+ <InputNumber v-model="rate" type="rate" />
14
+
15
+ <!-- 纯数字类型 -->
16
+ <InputNumber v-model="num" type="number" />
17
+ </template>
18
+ ```
19
+
20
+ ## 属性说明
21
+
22
+ | 属性名 | 类型 | 默认值 | 说明 |
23
+ | ------------ | ------------- | ----------------- | --------------------------------- |
24
+ | value | Number/String | undefined | 绑定值 |
25
+ | type | String | 'money' | 输入框类型,可选值:'money'、'rate'、'number' |
26
+ | maxlength | Number | 16 | 最大输入长度 |
27
+ | min | Number | -9999999999999.99 | 最小值限制 |
28
+ | max | Number | 9999999999999.99 | 最大值限制 |
29
+ | step | Number | 1 | 步进值,按上下箭头时的增减幅度 |
30
+ | stepStrictly | Boolean | false | 是否严格按步进值递增/递减 |
31
+ | disabled | Boolean | undefined | 是否禁用 |
32
+ | isClearable | Boolean | false | 是否可清空 |
33
+ | placeholder | String | '请输入' | 占位提示文本 |
34
+ | dNum | Number | undefined | 小数位数,优先级低于format |
35
+ | format | String | undefined | 格式化字符串,如'0.00'表示保留2位小数 |
36
+ | suffix | String | '%' | 后缀文本,仅在type='rate'时有效 |
37
+ | rangeAuto | Boolean | false | 是否自动处理范围值 |
38
+
39
+ ## 类型说明
40
+
41
+ ### money(金额类型)
42
+
43
+ - **默认值**:保留2位小数
44
+ - **千分位格式化**:启用(如:1,234.56)
45
+ - **适用场景**:金额、价格等需要千分位展示的数值
46
+
47
+ ### rate(比率类型)
48
+
49
+ - **默认值**:保留4位小数
50
+ - **千分位格式化**:启用
51
+ - **后缀**:默认显示%符号
52
+ - **适用场景**:利率、比率等百分比数值
53
+
54
+ ### number(纯数字类型)
55
+
56
+ - **默认值**:保留2位小数(可通过dNum或format属性自定义)
57
+ - **千分位格式化**:禁用
58
+ - **适用场景**:普通数值输入,如数量、计数等不需要千分位格式化的场景
59
+ - **特点**:与money类型相比,唯一的区别是不显示千分位逗号分隔符
60
+
61
+ ## 事件
62
+
63
+ | 事件名 | 说明 | 回调参数 |
64
+ | ------ | ----------- | ---- |
65
+ | input | 值改变时触发 | 当前值 |
66
+ | change | 值改变且失去焦点时触发 | 当前值 |
67
+ | blur | 失去焦点时触发 | - |
68
+ | clear | 清空时触发 | - |
69
+
70
+ ## 方法
71
+
72
+ | 方法名 | 说明 |
73
+ | ----- | -------- |
74
+ | focus | 使输入框获得焦点 |
75
+
76
+ ## 使用示例
77
+
78
+ ### 金额输入
79
+
80
+ ```vue
81
+ <InputNumber v-model="amount" type="money" :min="0" :max="1000000" />
82
+ ```
83
+
84
+ ### 比率输入
85
+
86
+ ```vue
87
+ <InputNumber v-model="interestRate" type="rate" suffix="%" />
88
+ ```
89
+
90
+ ### 纯数字输入(无千分位)
91
+
92
+ ```vue
93
+ <InputNumber v-model="quantity" type="number" :step="1" :min="0" />
94
+ ```
95
+
96
+ ### 自定义小数位
97
+
98
+ ```vue
99
+ <!-- 使用dNum属性 -->
100
+ <InputNumber v-model="value" type="money" :dNum="4" />
101
+
102
+ <!-- 使用format属性(优先级更高) -->
103
+ <InputNumber v-model="value" type="money" format="0.0000" />
104
+ ```
105
+
106
+ ### 步进控制
107
+
108
+ ```vue
109
+ <!-- 启用步进严格模式 -->
110
+ <InputNumber v-model="value" type="number" :step="0.5" :stepStrictly="true" />
111
+ ```
112
+
@@ -43,11 +43,17 @@ export default {
43
43
  type: [Number, String],
44
44
  default: undefined
45
45
  },
46
+ /**
47
+ * 输入框类型
48
+ * - money: 金额类型,默认保留2位小数,启用千分位格式化
49
+ * - rate: 比率类型,默认保留4位小数,显示%后缀
50
+ * - number: 纯数字类型,不启用千分位格式化
51
+ */
46
52
  type: {
47
53
  type: String,
48
54
  default: 'money',
49
55
  validator(v) {
50
- return ['money', 'rate'].includes(v)
56
+ return ['money', 'rate', 'number'].includes(v)
51
57
  }
52
58
  },
53
59
  maxlength: {
@@ -122,6 +128,12 @@ export default {
122
128
  return $lc('请输入')
123
129
  }
124
130
  },
131
+ /**
132
+ * 计算小数位数
133
+ * - 优先使用format属性解析
134
+ * - 其次使用dNum属性
135
+ * - 根据type类型设置默认值:rate=4, money=2, number=2
136
+ */
125
137
  fNum() {
126
138
  if (this.format) {
127
139
  let i_f = this.format.indexOf('.')
@@ -133,7 +145,8 @@ export default {
133
145
  if (this.type === 'rate') {
134
146
  return 4
135
147
  }
136
- if (this.type === 'money') {
148
+ // number类型不限制小数位,默认返回2
149
+ if (this.type === 'money' || this.type === 'number') {
137
150
  return 2
138
151
  }
139
152
  return 2
@@ -142,6 +155,24 @@ export default {
142
155
  watch: {
143
156
  value: {
144
157
  handler(val) {
158
+ // number类型不启用千分位格式化,但应用小数位限制
159
+ if (this.type === 'number') {
160
+ if (val === undefined || val === null) {
161
+ this.valueStr = ''
162
+ } else if (this.rangeAuto) {
163
+ // rangeAuto模式下,仅当小数位不足时补零
164
+ let nF = N.toString(val).split('.')[1] || ''
165
+ if (nF.length < this.fNum) {
166
+ this.valueStr = N.subFixed(val, this.fNum)
167
+ } else {
168
+ this.valueStr = N.toString(val)
169
+ }
170
+ } else {
171
+ // 非rangeAuto模式,强制应用小数位
172
+ this.valueStr = N.subFixed(val, this.fNum)
173
+ }
174
+ return
175
+ }
145
176
  if (this.rangeAuto) {
146
177
  if (val || val === 0) {
147
178
  let nF = N.toString(val).split('.')[1] || ''
@@ -161,7 +192,10 @@ export default {
161
192
  focusFn() {
162
193
  this.isFocus = true
163
194
  if (!this.disabled && this.valueStr) {
164
- this.valueStr = this.valueStr.replace(/,/g, '')
195
+ // number类型不处理千分位(因为根本没有千分位)
196
+ if (this.type !== 'number') {
197
+ this.valueStr = this.valueStr.replace(/,/g, '')
198
+ }
165
199
  this.preValue = this.valueStr
166
200
  }
167
201
  },
@@ -186,8 +220,10 @@ export default {
186
220
  val = this.max
187
221
  }
188
222
  if (this.rangeAuto) {
223
+ // rangeAuto模式下,直接转换为字符串,不固定小数位
189
224
  this.valueStr = N.toString(val)
190
225
  } else {
226
+ // 应用小数位限制(number类型默认2位)
191
227
  this.valueStr = N.subFixed(val, this.fNum)
192
228
  }
193
229
  }
@@ -220,14 +256,30 @@ export default {
220
256
  }
221
257
 
222
258
  let nStr
223
- if (this.rangeAuto) {
259
+ // number类型不启用千分位格式化,但应用小数位限制
260
+ if (this.type === 'number') {
261
+ if (this.stepStrictly) {
262
+ let stepCount = val / this.step
263
+ if (val % this.step !== 0) {
264
+ val = Math.round(stepCount) * this.step
265
+ }
266
+ }
267
+ if (val < this.min) {
268
+ val = this.min
269
+ } else if (val > this.max) {
270
+ val = this.max
271
+ }
272
+ // 应用小数位限制(默认2位)
273
+ nStr = N.subFixed(val, this.fNum)
274
+ this.valueStr = nStr
275
+ } else if (this.rangeAuto) {
224
276
  nStr = N.toString(val)
225
277
  this.valueStr = N.addThousands(valStr)
226
278
  } else {
227
279
  if (this.stepStrictly) {
228
- let N = val / this.step
280
+ let stepCount = val / this.step
229
281
  if (val % this.step !== 0) {
230
- val = Math.round(N) * this.step
282
+ val = Math.round(stepCount) * this.step
231
283
  }
232
284
  }
233
285
  if (val < this.min) {