fix: card content font
This commit is contained in:
@@ -290,30 +290,35 @@ const fontList = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
const selectedFont = ref(fontList[0]);
|
const selectedFont = ref(fontList[0]);
|
||||||
|
const loadedFonts = ref(new Set()); // 记录已加载的字体
|
||||||
|
|
||||||
const changeFont = (font) => {
|
const changeFont = (font) => {
|
||||||
if (font.url) {
|
// 1. 如果是默认字体或已加载过的字体,直接应用
|
||||||
uni.showLoading({ title: "加载字体中" });
|
if (!font.url || loadedFonts.value.has(font.family)) {
|
||||||
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 {
|
|
||||||
selectedFont.value = font;
|
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([]);
|
const greetingLib = ref([]);
|
||||||
|
|||||||
Reference in New Issue
Block a user