chore: update sentence loading error
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package constant
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
@@ -26,13 +25,25 @@ var (
|
||||
// initSentences 初始化:统计行数和记录每行偏移
|
||||
func initSentences() {
|
||||
sentenceOnce.Do(func() {
|
||||
scanner := bufio.NewScanner(bytes.NewReader(sentenceData))
|
||||
data := sentenceData
|
||||
var offset int64 = 0
|
||||
for scanner.Scan() {
|
||||
for {
|
||||
// 记录当前行的起始位置
|
||||
lineOffsets = append(lineOffsets, offset)
|
||||
// scanner.Bytes() returns the line without newline
|
||||
offset += int64(len(scanner.Bytes())) + 1 // +1 for newline
|
||||
lineCount++
|
||||
|
||||
// 寻找下一个换行符
|
||||
idx := bytes.IndexByte(data[offset:], '\n')
|
||||
if idx == -1 {
|
||||
// 最后一行没有换行符
|
||||
break
|
||||
}
|
||||
|
||||
// 移动到下一行的起始位置
|
||||
offset += int64(idx) + 1
|
||||
if offset >= int64(len(data)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -40,24 +51,26 @@ func initSentences() {
|
||||
// GetRandomSentence 随机获取一条古诗词
|
||||
func GetRandomSentence() string {
|
||||
initSentences()
|
||||
if lineCount == 0 {
|
||||
if lineCount <= 0 {
|
||||
return "欢迎使用白虎面板"
|
||||
}
|
||||
|
||||
targetIndex := rand.Intn(lineCount)
|
||||
start := lineOffsets[targetIndex]
|
||||
|
||||
// 找到行结束位置(通过下一个偏移量或文件末尾)
|
||||
// 确定当前行的结束位置
|
||||
var end int64
|
||||
if targetIndex < lineCount-1 {
|
||||
end = lineOffsets[targetIndex+1] - 1 // -1 移除换行符
|
||||
end = lineOffsets[targetIndex+1]
|
||||
} else {
|
||||
end = int64(len(sentenceData))
|
||||
}
|
||||
|
||||
// 确保不越界并移除末尾可能的回车符 (Windows \r\n)
|
||||
line := sentenceData[start:end]
|
||||
line = bytes.TrimRight(line, "\r\n")
|
||||
// 提取行并清理两端的空白字符(包括 \r, \n)
|
||||
line := bytes.TrimSpace(sentenceData[start:end])
|
||||
if len(line) == 0 {
|
||||
return "欢迎使用白虎面板"
|
||||
}
|
||||
|
||||
var sData []string
|
||||
if err := json.Unmarshal(line, &sData); err == nil && len(sData) >= 1 {
|
||||
|
||||
@@ -95,12 +95,12 @@
|
||||
--sidebar-border: #e5e7eb;
|
||||
--sidebar-ring: #9ca3af;
|
||||
|
||||
/* 字体栈定义 */
|
||||
--font-main: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans CN", sans-serif;
|
||||
/* 字体栈定义 - 优先使用 Inter Variable 以获得最佳的可变字体支持 */
|
||||
--font-main: 'Inter Variable', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans CN", sans-serif;
|
||||
}
|
||||
|
||||
.is-windows {
|
||||
--font-main: 'Inter', 'Noto Sans SC', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans CN", sans-serif;
|
||||
--font-main: 'Inter Variable', 'Inter', 'Noto Sans SC', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans CN", sans-serif;
|
||||
}
|
||||
|
||||
/* OKLCH support targeting modern browsers */
|
||||
@@ -216,12 +216,23 @@
|
||||
}
|
||||
|
||||
body {
|
||||
@apply bg-background text-foreground antialiased;
|
||||
/* 增强字体栈:根据平台差异化 Noto Sans SC 与 system-ui 的优先级 */
|
||||
@apply bg-background text-foreground;
|
||||
/* 增强字体栈与高级特性优化 */
|
||||
font-family: var(--font-main);
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
letter-spacing: -0.01em;
|
||||
letter-spacing: -0.011em;
|
||||
|
||||
/* Inter 字体高级特性优化:
|
||||
cv05: l 增加尾钩 (提升识别)
|
||||
cv08: G 增加尖角
|
||||
cv11: 单层小写 a
|
||||
ss01: 开口数字 (更现代)
|
||||
ss03: 圆形 0
|
||||
*/
|
||||
font-feature-settings: "cv05", "cv08", "cv11", "ss01", "ss03";
|
||||
font-optical-sizing: auto;
|
||||
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
text-rendering: optimizeLegibility;
|
||||
@@ -247,8 +258,11 @@
|
||||
body {
|
||||
font-size: 15.5px;
|
||||
line-height: 1.55;
|
||||
letter-spacing: -0.01em;
|
||||
/* 移动端使用 antialiased 以匹配高 DPI 渲染 */
|
||||
letter-spacing: -0.011em;
|
||||
/* 移动端增强字体渲染 */
|
||||
font-family: var(--font-main);
|
||||
font-feature-settings: "cv05", "cv08", "cv11", "ss01", "ss03";
|
||||
font-optical-sizing: auto;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ function handleClick() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span v-bind="$attrs" class="truncate block cursor-pointer hover:text-primary transition-colors font-mono" :title="text || '-'"
|
||||
<span v-bind="$attrs" class="truncate block cursor-pointer hover:text-primary transition-colors" :title="text || '-'"
|
||||
@click.stop="handleClick">
|
||||
{{ text || '-' }}
|
||||
</span>
|
||||
@@ -30,7 +30,7 @@ function handleClick() {
|
||||
<BaihuDialog v-model:open="showDialog" :title="title">
|
||||
<div class="max-h-[60vh] overflow-y-auto custom-scrollbar">
|
||||
<div class="p-4 bg-muted/30 rounded-xl border border-border/50">
|
||||
<p class="text-[13.5px] leading-relaxed text-foreground/90 break-all whitespace-pre-wrap font-mono">
|
||||
<p class="text-[13.5px] leading-relaxed text-foreground/90 break-all whitespace-pre-wrap">
|
||||
{{ text }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user