feat(modules/web): 支持网络字体

close #4210
This commit is contained in:
Xwite
2024-09-29 20:03:37 +08:00
parent bf91a6f206
commit 82bf7e709e
4 changed files with 62 additions and 7 deletions
+1 -1
View File
@@ -173,7 +173,7 @@ const getProxyCoverUrl = (coverUrl) => {
/** /**
* 从阅读获取需要特定处理的图片 * 从阅读获取需要特定处理的图片
* @param {string} src * @param {string} src
* @param {`{number}`} width * @param {number|`${number}`} width
*/ */
const getProxyImageUrl = (src, width) => { const getProxyImageUrl = (src, width) => {
if (src.startsWith(legado_http_origin)) return src if (src.startsWith(legado_http_origin)) return src
+3 -1
View File
@@ -3,9 +3,11 @@
// @ts-nocheck // @ts-nocheck
// Generated by unplugin-vue-components // Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399 // Read more: https://github.com/vuejs/core/pull/3399
import '@vue/runtime-core'
export {} export {}
declare module 'vue' { declare module '@vue/runtime-core' {
export interface GlobalComponents { export interface GlobalComponents {
BookItems: typeof import('./components/BookItems.vue')['default'] BookItems: typeof import('./components/BookItems.vue')['default']
CatalogItem: typeof import('./components/CatalogItem.vue')['default'] CatalogItem: typeof import('./components/CatalogItem.vue')['default']
+56 -3
View File
@@ -45,14 +45,13 @@
<el-popover <el-popover
placement="top" placement="top"
width="180" width="270"
trigger="click" trigger="click"
v-model:visible="customFontSavePopVisible" v-model:visible="customFontSavePopVisible"
> >
<p> <p>
请确认输入的字体名称完整无误并且该字体已经安装在您的设备上 已经安装在您的设备上的字体请确认输入的字体名称完整无误或者从网络下载字体
</p> </p>
<p>确定保存吗</p>
<div style="text-align: right; margin: 0"> <div style="text-align: right; margin: 0">
<el-button <el-button
size="small" size="small"
@@ -69,6 +68,12 @@
" "
>确定</el-button >确定</el-button
> >
<el-button
type="primary"
size="small"
@click="loadFontFromURL"
>网络下载</el-button
>
</div> </div>
<template #reference> <template #reference>
<span type="text" class="font-item">保存</span> <span type="text" class="font-item">保存</span>
@@ -180,6 +185,7 @@ import "../assets/fonts/popfont.css";
import "../assets/fonts/iconfont.css"; import "../assets/fonts/iconfont.css";
import settings from "../config/themeConfig"; import settings from "../config/themeConfig";
import API from "@api"; import API from "@api";
const store = useBookStore(); const store = useBookStore();
const theme = ref(0); const theme = ref(0);
@@ -265,6 +271,53 @@ const setCustomFont = () => {
config.value.customFontName = customFontName.value; config.value.customFontName = customFontName.value;
saveConfig(config.value); saveConfig(config.value);
}; };
// 加载网络字体
const loadFontFromURL = () => {
ElMessageBox.prompt(
"请输入 字体网络链接",
"提示",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
inputPattern: /^https?:.+$/,
inputErrorMessage: "url 形式不正确",
beforeClose: (action, instance, done) => {
if (action === "confirm") {
instance.confirmButtonLoading = true;
instance.confirmButtonText = "下载中……";
// instance.inputValue
const url = instance.inputValue
if (typeof FontFace !== "function") {
ElMessage.error("浏览器不支持FontFace");
return done();
}
const fontface = new FontFace(
customFontName.value,
`url("${url}")`
)
//@ts-ignore
document.fonts.add(fontface);
fontface.load()
//API.getBookShelf()
.then(function () {
instance.confirmButtonLoading = false;
ElMessage.info("字体加载成功!");
setCustomFont();
done();
})
.catch(function (error) {
instance.confirmButtonLoading = false;
instance.confirmButtonText = "确定";
ElMessage.error("下载失败,请检查您输入的 url");
throw error;
});
} else {
done();
}
},
}
);
}
const fontSize = computed(() => { const fontSize = computed(() => {
return store.config.fontSize; return store.config.fontSize;
+2 -2
View File
@@ -166,7 +166,8 @@ const setIP = () => {
instance.confirmButtonLoading = true; instance.confirmButtonLoading = true;
instance.confirmButtonText = "校验中……"; instance.confirmButtonText = "校验中……";
// instance.inputValue // instance.inputValue
API.testLeagdoHttpUrlConnection("http://" + instance.inputValue) const ip = instance.inputValue;
API.testLeagdoHttpUrlConnection("http://" + ip)
//API.getBookShelf() //API.getBookShelf()
.then(function (response) { .then(function (response) {
instance.confirmButtonLoading = false; instance.confirmButtonLoading = false;
@@ -175,7 +176,6 @@ const setIP = () => {
// response.data.data.length // response.data.data.length
// ); // );
//store.addBooks(response.data.data); //store.addBooks(response.data.data);
const ip = instance.inputValue;
store.setConnectType("success"); store.setConnectType("success");
store.setConnectStatus("已连接 " + ip); store.setConnectStatus("已连接 " + ip);
store.clearSearchBooks(); store.clearSearchBooks();