mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-09-12 16:40:40 +08:00
067f3ed98a
1. 新增mp-html、qs等生产依赖,补全项目基础库 2. 新增平台判断、缓存、工具函数等通用工具集 3. 新增标签页、网站浏览页、关于页等业务页面 4. 新增分类卡片、通知弹窗等业务组件 5. 新增uts-progressNotification、liu-poster、uhalo-upgrade等uni模块 6. 补充audio/video组件样式补件,修复uni-components路径缺失问题 7. 新增环境变量Halo个人令牌配置项 8. 重构store导出结构,新增appConfig/halo/setting三个状态模块 9. 新增tsconfig编译目标配置,适配更高版本ES语法
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
/**
|
|
* 图片缓存工具(源自旧项目 utils/imageCache.js,按需命名导出)
|
|
* 下载图片到本地缓存(APP 端),返回本地路径
|
|
*/
|
|
import { checkIsUrl } from './url'
|
|
|
|
const CACHE_PREFIX = 'IMAGE_CACHE_'
|
|
|
|
/**
|
|
* 缓存图片(存在则直接返回缓存路径,否则下载)
|
|
* @param url 图片远程地址
|
|
* @returns 可用的本地/远程路径
|
|
*/
|
|
export function getCachedImage(url: string): Promise<string> {
|
|
return new Promise((resolve) => {
|
|
if (!checkIsUrl(url)) {
|
|
resolve(url)
|
|
return
|
|
}
|
|
const key = CACHE_PREFIX + url
|
|
// #ifdef APP-PLUS
|
|
const cached = uni.getStorageSync(key)
|
|
if (cached) {
|
|
resolve(cached)
|
|
return
|
|
}
|
|
uni.downloadFile({
|
|
url,
|
|
success: (res) => {
|
|
if (res.statusCode === 200) {
|
|
try {
|
|
uni.setStorageSync(key, res.tempFilePath)
|
|
resolve(res.tempFilePath)
|
|
}
|
|
catch (e) {
|
|
console.error('图片缓存写入失败', e)
|
|
resolve(url)
|
|
}
|
|
}
|
|
else {
|
|
resolve(url)
|
|
}
|
|
},
|
|
fail: () => {
|
|
resolve(url)
|
|
},
|
|
})
|
|
// #endif
|
|
// #ifndef APP-PLUS
|
|
resolve(url)
|
|
// #endif
|
|
})
|
|
}
|