feat: 一些bug修复

This commit is contained in:
R524809
2026-05-25 16:26:20 +08:00
parent 4d6b65e223
commit e998da37cb
8 changed files with 90 additions and 42 deletions
@@ -52,6 +52,24 @@ function getDailyGroupIndex(letters?: string[]): number {
return idx >= 0 ? idx : 0;
}
function pickRandomIndexExcept(total: number, current: number): number {
if (total <= 1) return 0;
let next = Math.floor(Math.random() * total);
while (next === current) {
next = Math.floor(Math.random() * total);
}
return next;
}
function pickRandomLetterExcept(current: string): string {
if (LETTERS_UPPER.length <= 1) return LETTERS_UPPER[0] ?? 'A';
let next = LETTERS_UPPER[Math.floor(Math.random() * LETTERS_UPPER.length)];
while (next === current) {
next = LETTERS_UPPER[Math.floor(Math.random() * LETTERS_UPPER.length)];
}
return next;
}
const pageInfoLookup = getModeInfo;
type PageData = CanvasDataState & {
@@ -279,6 +297,51 @@ createPage(
this.drawCanvas();
},
/** 预览区刷新:按当前模式随机换字母 / 分组后重绘 */
onPreviewRefresh() {
const mode = this.data.traceMode;
const updates: Partial<PageData> = {};
switch (mode) {
case 'letter-tracing-single': {
const next = pickRandomLetterExcept(
this.data.selectedLetter,
);
updates.selectedLetter = next;
updates.selectedLetterPair = `${next}${next.toLowerCase()}`;
break;
}
case 'letter-tracing-case-pairing':
case 'letter-tracing-half':
updates.letterCaseLower = !this.data.letterCaseLower;
break;
case 'letter-tracing-three':
updates.selectedTripleGroupIdx = pickRandomIndexExcept(
TRIPLE_GROUPS.length,
this.data.selectedTripleGroupIdx,
);
break;
case 'letter-tracing-daily-checkin':
updates.selectedDailyGroupIdx = pickRandomIndexExcept(
DAILY_GROUPS.length,
this.data.selectedDailyGroupIdx,
);
break;
default:
break;
}
if (Object.keys(updates).length > 0) {
this.setData(
updates as Partial<PageData> & WechatMiniprogram.IAnyObject,
() => this.drawCanvas(),
);
return;
}
this.drawCanvas();
},
async onPreviewFavorite() {
const next = !this.data.isPreviewFavorite;
this.setData({ isPreviewFavorite: next });
@@ -4,10 +4,11 @@
<view class="lt-main">
<preview-card
id="previewCard"
showRefresh="{{false}}"
showRefresh="{{true}}"
showFavorite="{{true}}"
favorited="{{isPreviewFavorite}}"
bind:canvas-ready="onCanvasReady"
bind:refresh="onPreviewRefresh"
bind:favorite="onPreviewFavorite" />
<!-- 选择字母(默认字帖模式) -->