From 464801240879db2848a8bbd3254c13aca09095ee Mon Sep 17 00:00:00 2001 From: sgqy Date: Thu, 24 Nov 2022 19:30:56 +0900 Subject: [PATCH] add comma settings (#302) --- components/Format.js | 4 +++- config/cfg_default.js | 3 +++ config/system/cfg_system.js | 9 ++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/components/Format.js b/components/Format.js index c9066709..43824654 100644 --- a/components/Format.js +++ b/components/Format.js @@ -1,5 +1,6 @@ import lodash from 'lodash' import { Character } from '../models/index.js' +import { Cfg } from '../components/index.js' let CharId = Character.CharId @@ -10,7 +11,8 @@ let Format = { comma: function (num, fix = 0) { num = parseFloat((num * 1).toFixed(fix)) let [integer, decimal] = String.prototype.split.call(num, '.') - integer = integer.replace(/\d(?=(\d{3})+$)/g, '$&,') // 正则先行断言 + let re = new RegExp(`\\d(?=(\\d{${Cfg.get('commaGroup', 3)}})+$)`, 'g'); + integer = integer.replace(re, '$&,') // 正则先行断言 = /\d(?=(\d{3})+$)/g return `${integer}${fix > 0 ? '.' + (decimal || lodash.repeat('0', fix)) : ''}` }, pct: function (num, fix = 1) { diff --git a/config/cfg_default.js b/config/cfg_default.js index 16716bd1..c0b78c71 100644 --- a/config/cfg_default.js +++ b/config/cfg_default.js @@ -17,6 +17,9 @@ export const avatarWife = true // 戳一戳卡片 export const avatarPoke = true +// 数字分组 +export const commaGroup = 3 + /** ************ 【角色资料与信息查询】 ************* */ // #刻晴图鉴 的图鉴信息 export const charWiki = true diff --git a/config/system/cfg_system.js b/config/system/cfg_system.js index 096d3659..ec69aed3 100644 --- a/config/system/cfg_system.js +++ b/config/system/cfg_system.js @@ -47,7 +47,14 @@ export const cfgSchema = { key: '戳一戳', def: true, oldCfgKey: 'char.poke' - } + }, + commaGroup: { + title: '数字逗号分组', + key: '逗号', + def: 3, + type: 'num', + desc: '根据语言习惯设置数字分组,如千位组设为 3,万位组设为 4。(暂不支持欧洲样式)' + }, } }, wiki: {