refactor(admin-js): unify money and percent formatting for mini charts
This commit is contained in:
@@ -12,6 +12,31 @@
|
|||||||
return (root || document).querySelector(sel);
|
return (root || document).querySelector(sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatMoney(v) {
|
||||||
|
var n = Number(v || 0);
|
||||||
|
if (!isFinite(n)) {
|
||||||
|
n = 0;
|
||||||
|
}
|
||||||
|
// 统一口径:两位小数 + 千分位
|
||||||
|
try {
|
||||||
|
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||||
|
} catch (e) {
|
||||||
|
return n.toFixed(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatPct(ratio, digits) {
|
||||||
|
var d = (digits == null) ? 1 : Number(digits);
|
||||||
|
if (!isFinite(d) || d < 0) {
|
||||||
|
d = 1;
|
||||||
|
}
|
||||||
|
var r = Number(ratio || 0);
|
||||||
|
if (!isFinite(r)) {
|
||||||
|
r = 0;
|
||||||
|
}
|
||||||
|
return (r * 100).toFixed(d);
|
||||||
|
}
|
||||||
|
|
||||||
// 续费缺订阅治理:绑定成功后自动滚动到顶部提示区(让运营立刻看到 success/warning/error)
|
// 续费缺订阅治理:绑定成功后自动滚动到顶部提示区(让运营立刻看到 success/warning/error)
|
||||||
// 说明:由后端 redirect url 追加 attached_subscription=1 触发。
|
// 说明:由后端 redirect url 追加 attached_subscription=1 触发。
|
||||||
if (window.location && window.location.search && window.location.search.indexOf('attached_subscription=1') >= 0) {
|
if (window.location && window.location.search && window.location.search.indexOf('attached_subscription=1') >= 0) {
|
||||||
@@ -120,7 +145,7 @@
|
|||||||
|
|
||||||
var date = (p && p.date) ? String(p.date) : '';
|
var date = (p && p.date) ? String(p.date) : '';
|
||||||
var count = (p && p.count != null) ? String(p.count) : '0';
|
var count = (p && p.count != null) ? String(p.count) : '0';
|
||||||
bar.title = date + ':' + count + ' 单,已付 ¥' + paid.toFixed(2);
|
bar.title = date + ':' + count + ' 单,已付 ¥' + formatMoney(paid);
|
||||||
|
|
||||||
el.appendChild(bar);
|
el.appendChild(bar);
|
||||||
});
|
});
|
||||||
@@ -183,9 +208,9 @@
|
|||||||
|
|
||||||
var val = document.createElement('div');
|
var val = document.createElement('div');
|
||||||
val.className = 'adm-mini-rank-value';
|
val.className = 'adm-mini-rank-value';
|
||||||
val.textContent = '¥' + paid.toFixed(2);
|
val.textContent = '¥' + formatMoney(paid);
|
||||||
|
|
||||||
row.title = 'Top' + (idx + 1) + ':已付 ¥' + paid.toFixed(2) + ',订单数 ' + String(p && p.count != null ? p.count : 0);
|
row.title = 'Top' + (idx + 1) + ':已付 ¥' + formatMoney(paid) + ',订单数 ' + String(p && p.count != null ? p.count : 0);
|
||||||
|
|
||||||
row.appendChild(name);
|
row.appendChild(name);
|
||||||
row.appendChild(wrap);
|
row.appendChild(wrap);
|
||||||
@@ -246,9 +271,9 @@
|
|||||||
|
|
||||||
var val = document.createElement('div');
|
var val = document.createElement('div');
|
||||||
val.className = 'adm-mini-share-value';
|
val.className = 'adm-mini-share-value';
|
||||||
val.textContent = (ratio * 100).toFixed(1) + '%';
|
val.textContent = formatPct(ratio, 1) + '%';
|
||||||
|
|
||||||
row.title = 'Top' + (idx + 1) + ':' + cnt + ' 单,占比 ' + (ratio * 100).toFixed(1) + '%';
|
row.title = 'Top' + (idx + 1) + ':' + cnt + ' 单,占比 ' + formatPct(ratio, 1) + '%';
|
||||||
|
|
||||||
row.appendChild(name);
|
row.appendChild(name);
|
||||||
row.appendChild(wrap);
|
row.appendChild(wrap);
|
||||||
|
|||||||
Reference in New Issue
Block a user