add comma settings (#302)

This commit is contained in:
sgqy 2022-11-24 19:30:56 +09:00 committed by GitHub
parent 5b23ea3349
commit 4648012408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -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) {

View File

@ -17,6 +17,9 @@ export const avatarWife = true
// 戳一戳卡片
export const avatarPoke = true
// 数字分组
export const commaGroup = 3
/** ************ 【角色资料与信息查询】 ************* */
// #刻晴图鉴 的图鉴信息
export const charWiki = true

View File

@ -47,7 +47,14 @@ export const cfgSchema = {
key: '戳一戳',
def: true,
oldCfgKey: 'char.poke'
}
},
commaGroup: {
title: '数字逗号分组',
key: '逗号',
def: 3,
type: 'num',
desc: '根据语言习惯设置数字分组,如千位组设为 3万位组设为 4。暂不支持欧洲样式'
},
}
},
wiki: {