n20-common-lib 2.22.74 → 2.22.76

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.74",
3
+ "version": "2.22.76",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -57,13 +57,17 @@ export default {
57
57
  }
58
58
  },
59
59
  computed: {
60
+ isChinaUrban() {
61
+ return this.isUrban && this.countryId === 'CHN'
62
+ },
60
63
  propsAs() {
61
64
  let _prop = {
62
65
  value: 'regionNo',
63
66
  label: 'regionName',
64
67
  children: 'children',
65
68
  expandTrigger: 'hover',
66
- checkStrictly: !this.isUrban
69
+ // 保留二级城市的子节点后,允许独立选择二级城市和三级地区。
70
+ checkStrictly: this.isChinaUrban || !this.isUrban
67
71
  }
68
72
  return Object.assign(_prop, this.props)
69
73
  },
@@ -75,17 +79,17 @@ export default {
75
79
  },
76
80
  streetKey() {
77
81
  return this.countryId === 'CHN' ? '_china_street_tree_' : `_${this.countryId}_street_tree_`
82
+ },
83
+ cacheKey() {
84
+ // 按当前模式检查缓存,避免普通地区缓存存在时误用尚未加载的城市缓存。
85
+ return this.isUrban ? this.urbanKey : this.isStreet ? this.streetKey : this.areaKey
78
86
  }
79
87
  },
80
88
  mounted() {
81
- if (!window[this.areaKey]) {
89
+ if (!window[this.cacheKey]) {
82
90
  this.getAreaTree()
83
91
  } else {
84
- this.areaTree = this.isUrban
85
- ? window[this.urbanKey]
86
- : this.isStreet
87
- ? window[this.streetKey]
88
- : window[this.areaKey]
92
+ this.areaTree = window[this.cacheKey]
89
93
  }
90
94
  },
91
95
  methods: {
@@ -100,7 +104,7 @@ export default {
100
104
  if (data) {
101
105
  let result = JSON.parse(JSON.stringify(data))
102
106
  if (this.isUrban) {
103
- window[this.urbanKey] = isUrbanFn(result)
107
+ window[this.urbanKey] = isUrbanFn(result, this.isChinaUrban)
104
108
  this.areaTree = window[this.urbanKey]
105
109
  } else if (this.isStreet) {
106
110
  window[this.streetKey] = treeFn(result)
@@ -133,12 +137,21 @@ const treeFn = (data) => {
133
137
  })
134
138
  }
135
139
 
136
- const isUrbanFn = (data) => {
140
+ const isUrbanFn = (data, isChinaUrban = false) => {
137
141
  return data?.map((res) => {
138
- if (res.regionLevel === '2' || !res.children?.length) {
142
+ const regionLevel = String(res.regionLevel)
143
+ // 直辖市只保留一级节点,直接返回接口原有的两位 regionNo,不伪造下级编码。
144
+ const isMunicipality =
145
+ isChinaUrban && regionLevel === '1' && ['11', '12', '31', '50'].includes(String(res.regionNo))
146
+ if (isChinaUrban && regionLevel === '1' && !isMunicipality) {
147
+ // 普通省份仅用于展开;checkStrictly 模式下禁用父节点不影响子节点选择。
148
+ res.disabled = true
149
+ }
150
+ if (isMunicipality || (!isChinaUrban && regionLevel === '2') || !res.children?.length) {
139
151
  res.children = null
140
152
  } else {
141
- res.children = isUrbanFn(res.children)
153
+ // 保留省代管县级市等三级节点,解除原先在二级统一截断的限制。
154
+ res.children = isUrbanFn(res.children, isChinaUrban)
142
155
  }
143
156
  return res
144
157
  })
@@ -1,8 +1,8 @@
1
1
  <template>
2
- <el-descriptions class="n20-descriptions" :column="column" size="default" border>
2
+ <el-descriptions class="n20-descriptions" :column="currentColumn" size="default" border>
3
3
  <slot></slot>
4
- <template v-if="this.$slots.default.length === 1">
5
- <el-descriptions-item v-for="(item, index) in column - 1" :key="index" />
4
+ <template v-if="this.$slots.default && this.$slots.default.length === 1">
5
+ <el-descriptions-item v-for="(item, index) in currentColumn - 1" :key="index" />
6
6
  </template>
7
7
  </el-descriptions>
8
8
  </template>
@@ -20,27 +20,48 @@ export default {
20
20
  default: true
21
21
  }
22
22
  },
23
+ data() {
24
+ return {
25
+ currentColumn: this.column
26
+ }
27
+ },
28
+ watch: {
29
+ column(val) {
30
+ this.currentColumn = val
31
+ },
32
+ autoResize(val) {
33
+ if (val) {
34
+ this.createResize()
35
+ } else {
36
+ this.currentColumn = this.column
37
+ this.destroyResize()
38
+ }
39
+ }
40
+ },
23
41
  created() {
24
42
  if (!this.autoResize) return
25
- this.resize()
26
- window.addEventListener('resize', this.resize)
43
+ this.createResize()
27
44
  },
28
45
  beforeDestroy() {
29
- window.removeEventListener('resize', this.resize)
46
+ this.destroyResize()
30
47
  },
31
48
  methods: {
32
49
  resize() {
33
50
  let wW = document.documentElement.clientWidth
34
51
  if (wW <= 1024) {
35
- this.column = 1
52
+ this.currentColumn = 1
36
53
  } else if (wW > 1024 && wW <= 1600) {
37
- this.column = 2
54
+ this.currentColumn = 2
38
55
  } else if (wW > 1600 && wW <= 1920) {
39
- this.column = 3
56
+ this.currentColumn = 3
40
57
  } else if (wW > 1920) {
41
- this.column = 4
58
+ this.currentColumn = 4
42
59
  }
43
60
  },
61
+ createResize() {
62
+ this.resize()
63
+ window.addEventListener('resize', this.resize)
64
+ },
44
65
  destroyResize() {
45
66
  window.removeEventListener('resize', this.resize)
46
67
  }
@@ -23,6 +23,7 @@
23
23
  | ------------ | ------------- | ----------------- | --------------------------------- |
24
24
  | value | Number/String | undefined | 绑定值 |
25
25
  | stringMode | Boolean | false | 高精度模式,非空绑定值和 input/change 事件值使用字符串 |
26
+ | isString | Boolean | false | stringMode 兼容别名;小数位超过15位时自动按 true 处理 |
26
27
  | type | String | 'money' | 输入框类型,可选值:'money'、'rate'、'number' |
27
28
  | maxlength | Number | 16 | 最大输入长度 |
28
29
  | min | Number/String | -9999999999999.99 | 最小值限制;高精度模式可传字符串 |
@@ -113,7 +114,7 @@
113
114
 
114
115
  ### 20 位小数汇率
115
116
 
116
- `stringMode` 默认关闭,原有金额/利率的精度、数值事件保持原样。开启后,输入、回显、步进、范围比较和变更事件使用高精度十进制处理。`input` / `change` 的非空值是字符串,清空为 `undefined`;`blur` / `clear` 事件签名保持原样。
117
+ `stringMode` `isString` 默认关闭,原有金额/利率的精度、数值事件保持原样。任一配置开启,或 `dNum` / `format` 超过 15 位安全小数位时,组件会自动进入高精度字符串模式。输入、回显、步进、范围比较和变更事件使用高精度十进制处理,失焦时按最大位数四舍五入并移除尾部 `0`,例如 `0.200000` 回传 `"0.2"`。
117
118
 
118
119
  下面 `cl-*` 是默认注册前缀;业务项目按自己的 `Vue.use(n20, { prefix })` 替换标签。
119
120
 
@@ -141,9 +142,9 @@ export default {
141
142
  </script>
142
143
  ```
143
144
 
144
- - `stringMode` 不改变 `dNum`、`format` 和 `maxlength` 默认值。`format` 仍优先于 `dNum`;有旧 `format` 配置时需同步调整。
145
+ - `stringMode` / `isString` 不改变 `dNum`、`format` 和 `maxlength` 默认值。`format` 仍优先于 `dNum`;有旧 `format` 配置时需同步调整。小数位超过 15 位时即使两个开关都为 `false`,也会自动使用字符串模式。
145
146
  - `maxlength` 统计全部字符,默认 16。20 位小数加上 `0.` 至少需要 22;按整数位、负号和小数点配置总长度。示例的 35 可容纳默认范围的 13 位整数、负号、小数点和 20 位小数。
146
- - 默认按十进制四舍五入到配置位数并补零;`rangeAuto` 开启后至少补到配置位数,并保留更多已有小数位。需要最多 20 位时使用默认 `rangeAuto=false`。
147
+ - 默认按十进制四舍五入到配置位数并移除尾部 `0`;`rangeAuto` 开启后至少按配置位数处理,并保留更多已有小数位。
147
148
  - `min`、`max`、`step` 的字符串形式用于高精度模式;普通模式继续传 Number。`step` 使用正值。`stepStrictly` 的中点方向与原有 `Math.round` 一致。
148
149
  - 可粘贴科学计数法,提交展开为普通十进制字符串。空值、NaN、Infinity、非十进制输入不作为有效数字。
149
150
  - 按上下箭头改变输入框内容,提交时机与旧模式相同,在 change/blur 时同步绑定值。
@@ -36,6 +36,7 @@ import { $lc } from '../../utils/i18n/index'
36
36
  import N from '../../utils/numberPor'
37
37
  import { Decimal, parseDecimal } from '../../utils/decimal'
38
38
 
39
+ const MAX_SAFE_DECIMAL_PLACES = 15
39
40
 
40
41
  export default {
41
42
  name: 'InputNumber',
@@ -50,6 +51,11 @@ export default {
50
51
  type: Boolean,
51
52
  default: false
52
53
  },
54
+ // isString 是 stringMode 的兼容别名;超过安全小数位时会自动生效。
55
+ isString: {
56
+ type: Boolean,
57
+ default: false
58
+ },
53
59
  /**
54
60
  * 输入框类型
55
61
  * - money: 金额类型,默认保留2位小数,启用千分位格式化
@@ -162,7 +168,7 @@ export default {
162
168
  watch: {
163
169
  value: {
164
170
  handler(val) {
165
- if (this.stringMode) {
171
+ if (this.isStringMode()) {
166
172
  this.setStringDisplay(val)
167
173
  return
168
174
  }
@@ -199,10 +205,13 @@ export default {
199
205
  immediate: true
200
206
  },
201
207
  fNum() {
202
- if (this.stringMode) this.setStringDisplay(this.value)
208
+ if (this.isStringMode()) this.setStringDisplay(this.value)
203
209
  }
204
210
  },
205
211
  methods: {
212
+ isStringMode() {
213
+ return this.stringMode || this.isString || this.fNum > MAX_SAFE_DECIMAL_PLACES
214
+ },
206
215
  // rangeAuto 允许已有小数位超过配置值,其余情况按配置位数四舍五入。
207
216
  formatStringValue(value, originalValue = value) {
208
217
  const decimal = parseDecimal(value)
@@ -212,8 +221,12 @@ export default {
212
221
  const places = this.rangeAuto
213
222
  ? Math.max(this.fNum, decimal.decimalPlaces(), fraction ? fraction[1].length : 0)
214
223
  : this.fNum
215
- // 先舍入再输出,让接近零的负数规范化为零,避免显示值与事件值的符号不同。
216
- return decimal.toDecimalPlaces(places).toFixed(places)
224
+ // 先舍入再输出,并移除尾部 0,避免保存值与接口回显值不一致。
225
+ const fixedValue = decimal.toDecimalPlaces(places).toFixed(places)
226
+ const trimmedValue = fixedValue
227
+ .replace(/(\.\d*?[1-9])0+$/, '$1')
228
+ .replace(/\.0+$/, '')
229
+ return trimmedValue === '-0' ? '0' : trimmedValue
217
230
  },
218
231
  setStringDisplay(value) {
219
232
  const text = this.formatStringValue(value)
@@ -266,7 +279,7 @@ export default {
266
279
  },
267
280
  stepFn(ev) {
268
281
  if ((ev.code === 'ArrowUp' || ev.code === 'ArrowDown') && !this.disabled) {
269
- if (this.stringMode) {
282
+ if (this.isStringMode()) {
270
283
  const value = parseDecimal(this.valueStr)
271
284
  const step = parseDecimal(this.step)
272
285
  if (value && step && step.gt(0)) {
@@ -296,7 +309,7 @@ export default {
296
309
  }
297
310
  },
298
311
  inputFn(valStr) {
299
- if (this.stringMode) {
312
+ if (this.isStringMode()) {
300
313
  // 编辑中的符号和小数点暂时保留,完整值在失焦时统一规范化。
301
314
  if (['', '-', '+', '.', '-.', '+.'].includes(valStr) || parseDecimal(valStr)) {
302
315
  this.preValue = valStr
@@ -318,7 +331,7 @@ export default {
318
331
  this.changeIng = false
319
332
  })
320
333
 
321
- if (this.stringMode) {
334
+ if (this.isStringMode()) {
322
335
  this.changeStringValue(valStr)
323
336
  return
324
337
  }