jiangchengfeiyi-xiaochengxu/common/globalFont.js
2025-04-02 23:45:33 +08:00

67 lines
1.5 KiB
JavaScript

import { bkgPubilcPath,loginUrl } from "./globalImagesUrl";
import { ref } from 'vue';
const bkgUrl = ref(loginUrl + '/bkg.png')
//缓存背景图片
const bkgCache = 'bkgCache'; //缓存的键
export const getFonts =()=>{ //改为查询背景图片
wx.getStorage({
key: bkgCache,
success: (res) => {
// console.log('缓存图片的路径--->',res.data);
bkgPubilcPath.value = res.data
},
fail: ()=> {
wx.downloadFile({
url: bkgUrl.value,
success: (res) => {
console.log('成功res--->',res);
if(res.statusCode === 200) {
const filePath = res.tempFilePath;
wx.setStorage({
key: bkgCache,
data: filePath
});
// console.log('图片下载并缓存成功,本地路径--->',filePath);
bkgPubilcPath.value= filePath
} else {
console.log('图片下载失败');
}
},
fail: (err) => {
console.log('下载失败',err);
}
})
}
})
}
export const getZSFont = () => {
uni.loadFontFace({
family: 'ZhongShanFonts',
source: `url("https://www.carboner.cn:8888/api/file/download/ZhongShanFonts.ttf")`,
success:(res) =>{
console.log('success',res);
},
fail:(err) => {
console.log('err',err);
}
})
}
//欢迎页
export const getFZXZFont = () => {
uni.loadFontFace({
family: 'FangZhengXiaoZhuan',
source: `url("https://www.carboner.cn:8888/api/file/download/FangZhengXiaoZhuan.ttf")`,
success:(res) =>{
console.log('success',res);
},
fail:(err) => {
console.log('err',err);
}
})
}