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语法
46 lines
971 B
TypeScript
46 lines
971 B
TypeScript
/**
|
|
* 点赞状态工具(源自旧项目 utils/upvote.js,按需命名导出)
|
|
* 文章/瞬间点赞状态本地缓存
|
|
*/
|
|
import { getCache, setCache } from './storage'
|
|
|
|
const upvote = {
|
|
key: 'upvote_records',
|
|
maxLength: 300,
|
|
}
|
|
|
|
/** 获取已点赞记录列表 */
|
|
function getRecords(): string[] {
|
|
return getCache<string[]>(upvote.key) || []
|
|
}
|
|
|
|
/** 保存点赞记录列表 */
|
|
function setRecords(list: string[]) {
|
|
setCache(upvote.key, list)
|
|
}
|
|
|
|
/**
|
|
* 是否已点赞
|
|
* @param key 点赞目标标识(如 post name)
|
|
*/
|
|
export function hasUpvoted(key: string): boolean {
|
|
return getRecords().includes(key)
|
|
}
|
|
|
|
/**
|
|
* 记录点赞(超过最大长度时清空旧记录)
|
|
* @param key 点赞目标标识
|
|
*/
|
|
export function addUpvoteRecord(key: string) {
|
|
const list = getRecords()
|
|
if (list.length >= upvote.maxLength) {
|
|
// 记录过多时重置
|
|
setRecords([key])
|
|
return
|
|
}
|
|
if (!list.includes(key)) {
|
|
list.push(key)
|
|
setRecords(list)
|
|
}
|
|
}
|