dsh-half-page 0.3.24 → 0.3.25
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/client.js +30 -2
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -60,7 +60,35 @@ window.__ModuleLoader__.load({
|
|
|
60
60
|
return out
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
const CN_DIGIT = { 零: 0, 〇: 0, 一: 1, 二: 2, 两: 2, 三: 3, 四: 4, 五: 5, 六: 6, 七: 7, 八: 8, 九: 9 }
|
|
64
|
+
const cnNum = (s) => {
|
|
65
|
+
const t = String(s || '').replace(/[0-9]/g, (d) => String.fromCharCode(d.charCodeAt(0) - 65248))
|
|
66
|
+
if (/^[0-9]+$/.test(t)) return Number(t)
|
|
67
|
+
let n = 0
|
|
68
|
+
let cur = 0
|
|
69
|
+
for (const ch of t) {
|
|
70
|
+
if (ch === '十') { n += (cur || 1) * 10; cur = 0 }
|
|
71
|
+
else if (ch === '百') { n += (cur || 1) * 100; cur = 0 }
|
|
72
|
+
else if (ch === '千') { n += (cur || 1) * 1000; cur = 0 }
|
|
73
|
+
else if (CN_DIGIT[ch] !== undefined) cur = CN_DIGIT[ch]
|
|
74
|
+
else return NaN
|
|
75
|
+
}
|
|
76
|
+
return n + cur
|
|
77
|
+
}
|
|
78
|
+
const chapterNo = (title) => {
|
|
79
|
+
const m = String(title || '').match(/第([0-90-9零〇一二三四五六七八九十百千两]+)章/)
|
|
80
|
+
return m ? cnNum(m[1]) : NaN
|
|
81
|
+
}
|
|
82
|
+
// 有几章、从第几章到第几章(章名认不出数字就不显示范围)
|
|
83
|
+
const chapterRange = (chapters) => {
|
|
84
|
+
const nos = (chapters || []).map((c) => chapterNo(c && c.title)).filter((n) => Number.isFinite(n))
|
|
85
|
+
if (!nos.length) return ''
|
|
86
|
+
const a = Math.min.apply(null, nos)
|
|
87
|
+
const b = Math.max.apply(null, nos)
|
|
88
|
+
return a === b ? ('第 ' + a + ' 章') : ('第 ' + a + '–' + b + ' 章')
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function Panel() {
|
|
64
92
|
const [state, setState] = useState(null)
|
|
65
93
|
const [confirmId, setConfirmId] = useState('')
|
|
66
94
|
const [tab, setTab] = useState('read')
|
|
@@ -297,7 +325,7 @@ window.__ModuleLoader__.load({
|
|
|
297
325
|
return h('div', { key: bi, style: { marginBottom: 10 } },
|
|
298
326
|
h('div', { style: { ...S.row, marginBottom: 4 } },
|
|
299
327
|
h('div', { style: { fontWeight: 600 } }, bk.book),
|
|
300
|
-
h('div', { style: S.dim }, total + ' 章'),
|
|
328
|
+
h('div', { style: S.dim }, total + ' 章' + (chapterRange(bk.chapters) ? ' · ' + chapterRange(bk.chapters) : '')),
|
|
301
329
|
h('div', { style: { flex: 1 } }),
|
|
302
330
|
paged ? h('button', { style: S.btn, disabled: page <= 0, onClick: () => setView({ page: page - 1 }) }, '‹') : null,
|
|
303
331
|
paged ? h('div', { style: { ...S.dim, minWidth: 46, textAlign: 'center' } }, all ? '全部' : ((page + 1) + ' / ' + pages)) : null,
|