From 9f5c5d2d1fa89bd4e2de0e1b4f397bae09438f6f Mon Sep 17 00:00:00 2001 From: zzc <1761997216@qq.com> Date: Thu, 22 Jan 2026 14:56:32 +0800 Subject: [PATCH] fix: card content font --- pages/make/index.vue | 45 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/pages/make/index.vue b/pages/make/index.vue index 968668e..49856d3 100644 --- a/pages/make/index.vue +++ b/pages/make/index.vue @@ -290,30 +290,35 @@ const fontList = [ }, ]; const selectedFont = ref(fontList[0]); +const loadedFonts = ref(new Set()); // 记录已加载的字体 const changeFont = (font) => { - if (font.url) { - uni.showLoading({ title: "加载字体中" }); - uni.loadFontFace({ - global: true, - family: font.family, - source: `url("${font.url}")`, - scopes: ["webview", "native"], - success: () => { - selectedFont.value = font; - uni.hideLoading(); - }, - fail: (err) => { - console.error(err); - uni.hideLoading(); - // 如果加载失败,可以尝试直接设置(有些情况可能已经缓存或本地支持) - // 或者提示用户 - uni.showToast({ title: "字体加载失败", icon: "none" }); - }, - }); - } else { + // 1. 如果是默认字体或已加载过的字体,直接应用 + if (!font.url || loadedFonts.value.has(font.family)) { selectedFont.value = font; + return; } + + // 2. 否则加载字体 + uni.showLoading({ title: "加载字体中", mask: true }); + uni.loadFontFace({ + global: true, + family: font.family, + source: `url("${font.url}")`, + scopes: ["webview", "native"], + success: () => { + selectedFont.value = font; + loadedFonts.value.add(font.family); // 标记为已加载 + uni.hideLoading(); + }, + fail: (err) => { + console.error(err); + uni.hideLoading(); + // 如果加载失败,可以尝试直接设置(有些情况可能已经缓存或本地支持) + // 或者提示用户 + uni.showToast({ title: "字体加载失败", icon: "none" }); + }, + }); }; const greetingLib = ref([]);