@nstc-business/imes 1.0.32 → 1.0.33

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": "@nstc-business/imes",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "private": false,
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -154,16 +154,14 @@ export const SUB_MODEL_LABEL = '测算子模型'
154
154
  /** 子模型独立测算按钮文案 */
155
155
  export const SUB_MODEL_CALC_BTN = '子模型测算'
156
156
 
157
- /** 子模型测算结果展示(优先 resultText,否则格式化 result) */
157
+ /** 子模型测算结果展示(计算/统计读 digits,评价分数+等级固定2位) */
158
158
  export function subModelResultText(row, modelWrap) {
159
159
  if (!row) return ''
160
- if (row.resultText != null && row.resultText !== '') {
161
- return row.resultText
162
- }
163
- if (row.result !== '' && row.result != null) {
164
- return resultByShowStyle(row, modelWrap)
165
- }
166
- return ''
160
+ return formatDisplayModelResult(
161
+ { result: row.result, resultText: row.resultText },
162
+ modelWrap,
163
+ { modelType: row.itemType, thousands: row.showStyle === 2 }
164
+ )
167
165
  }
168
166
 
169
167
  export function isCalcModel(row) {
@@ -223,6 +221,31 @@ export function digitsCalc(row, modelWrap) {
223
221
  */
224
222
  export const SCORE_DIGITS = 2
225
223
 
224
+ /**
225
+ * 模型结果小数位:读模型返回的 digits,缺省回退 2
226
+ * (计算模型用;对应后台全局计算位数配置)
227
+ */
228
+ export function modelResultDigits(modelWrap) {
229
+ return modelWrap && modelWrap.digits != null ? modelWrap.digits : 2
230
+ }
231
+
232
+ /**
233
+ * 模型结果数值格式化:按模型 digits 四舍五入保留小数位(仅计算模型)
234
+ * @param {*} val
235
+ * @param {*} modelWrap
236
+ * @param {{ thousands?: boolean }} [options]
237
+ */
238
+ export function formatModelResultText(val, modelWrap, options = {}) {
239
+ if (val === '' || val == null) return ''
240
+ const num = Number(val)
241
+ if (Number.isNaN(num)) return String(val)
242
+ let text = num.toFixed(modelResultDigits(modelWrap))
243
+ if (options.thousands) {
244
+ text = addThousands(text)
245
+ }
246
+ return text
247
+ }
248
+
226
249
  /**
227
250
  * 得分数值格式化:四舍五入,固定保留 SCORE_DIGITS 位
228
251
  * @param {*} val
@@ -239,6 +262,61 @@ export function formatScoreText(val, options = {}) {
239
262
  return text
240
263
  }
241
264
 
265
+ /**
266
+ * 解析模型种类:顶层 type(1/2/3) 或节点 itemType(12/11/13)
267
+ * @returns {'eval'|'calc'|'stat'|'other'}
268
+ */
269
+ export function resolveModelKind(type) {
270
+ const t = Number(type)
271
+ if (t === 1 || t === ITEM_TYPE.EVAL_MODEL) return 'eval'
272
+ if (t === 2 || t === ITEM_TYPE.CALC_MODEL) return 'calc'
273
+ if (t === 3 || t === ITEM_TYPE.STAT_MODEL) return 'stat'
274
+ return 'other'
275
+ }
276
+
277
+ /**
278
+ * 测算结果展示:
279
+ * - 计算/统计模型:按模型 digits(后台全局计算位数)
280
+ * - 评价模型:分数固定 2 位;有等级则「分数(等级)」,等级为空只显示分数
281
+ * @param {{ result?: *, resultText?: * }} payload
282
+ * @param {*} modelWrap
283
+ * @param {{ modelType?: number|string, thousands?: boolean }} [options]
284
+ */
285
+ export function formatDisplayModelResult(payload, modelWrap, options = {}) {
286
+ const result = payload && payload.result
287
+ const resultText = payload && payload.resultText
288
+ const modelType = options.modelType != null ? options.modelType : modelWrap && modelWrap.type
289
+ const kind = resolveModelKind(modelType)
290
+ const hasScore = result !== '' && result != null
291
+ const grade =
292
+ resultText !== '' && resultText != null ? String(resultText).trim() : ''
293
+
294
+ if (kind === 'eval') {
295
+ if (!hasScore && !grade) return ''
296
+ const parts = []
297
+ if (hasScore) {
298
+ parts.push(formatScoreText(result, { thousands: options.thousands }))
299
+ }
300
+ // 等级为空不展示;「未知」等非空等级文案仍展示
301
+ if (grade) {
302
+ parts.push(`(${grade})`)
303
+ }
304
+ return parts.join('')
305
+ }
306
+
307
+ const raw = hasScore ? result : grade
308
+ if (raw === '' || raw == null) return ''
309
+ const text = String(raw).trim()
310
+ if (!/^-?\d+(\.\d+)?$/.test(text)) {
311
+ return String(raw)
312
+ }
313
+ // 计算/统计模型读 digits;其他固定 2 位
314
+ if (kind === 'calc' || kind === 'stat') {
315
+ return formatModelResultText(text, modelWrap, { thousands: options.thousands })
316
+ }
317
+ return formatScoreText(text, { thousands: options.thousands })
318
+ }
319
+
242
320
  /** 模型指标得分 / 模型指标系数数值(权重之后的 result);得分不读模型 digits */
243
321
  export function resultByShowStyle(row, modelWrap) {
244
322
  if (!row || (row.result !== 0 && (row.result === '' || row.result == null))) {
@@ -319,15 +397,13 @@ export function indicatorResultText(row, modelWrap) {
319
397
  /** 从子模型节点解析指标值展示文案 */
320
398
  export function resolveSubModelValueText(row, modelWrap) {
321
399
  if (!row) return ''
322
- if (row.resultText != null && row.resultText !== '') {
323
- return row.resultText
324
- }
325
- const text = indicatorResultText(row, modelWrap)
326
- if (text) return text
327
- if (row.result !== '' && row.result != null) {
328
- return resultByShowStyle(row, modelWrap)
329
- }
330
- return ''
400
+ const modelResult = formatDisplayModelResult(
401
+ { result: row.result, resultText: row.resultText },
402
+ modelWrap,
403
+ { modelType: row.itemType, thousands: row.showStyle === 2 }
404
+ )
405
+ if (modelResult) return modelResult
406
+ return indicatorResultText(row, modelWrap)
331
407
  }
332
408
 
333
409
  /** 子模型指标值:子模型测算后展示计算结果(固化,避免父模型测算覆盖 result 后丢失) */
@@ -252,6 +252,7 @@ import {
252
252
  subModelResultText as formatSubModelResult,
253
253
  saveSubModelValueText,
254
254
  formatScoreText,
255
+ formatDisplayModelResult,
255
256
  resolveCalcEchoValue,
256
257
  shouldApplyModifiedVal
257
258
  } from './helpers'
@@ -459,21 +460,14 @@ export default {
459
460
  if (this.model.version === '' || this.model.version == null) return '--'
460
461
  return `版本${this.model.version}`
461
462
  },
462
- /** 测算结果展示:优先 resultText,统计模型计算模式可回退到 result;得分固定 2 位四舍五入 */
463
+ /** 测算结果:计算/统计读 digits;评价固定2位且有等级则「分数(等级)」 */
463
464
  displayResultText() {
464
- const raw =
465
- this.resultText !== '' && this.resultText != null
466
- ? this.resultText
467
- : this.calcResult !== '' && this.calcResult != null
468
- ? this.calcResult
469
- : null
470
- if (raw === null || raw === '') return '--'
471
- const text = String(raw).trim()
472
- // 纯数字得分:固定 2 位;非数字文案原样展示
473
- if (/^-?\d+(\.\d+)?$/.test(text)) {
474
- return formatScoreText(text)
475
- }
476
- return String(raw)
465
+ const text = formatDisplayModelResult(
466
+ { result: this.calcResult, resultText: this.resultText },
467
+ this.model,
468
+ { modelType: this.model && this.model.type }
469
+ )
470
+ return text || '--'
477
471
  },
478
472
  /** 评价模型展示「模型得分」,计算模型展示「模型公式」 */
479
473
  formulaRowLabel() {
package/src/index.js CHANGED
@@ -19,7 +19,7 @@ if (typeof window !== 'undefined' && window.Vue) {
19
19
  }
20
20
 
21
21
  export default {
22
- version: '1.0.24',
22
+ version: '1.0.33',
23
23
  install,
24
24
  ModelCalculate,
25
25
  MeasureCalc,