's'
This commit is contained in:
@@ -1,31 +1,20 @@
|
||||
/**
|
||||
* 课程支付状态 - localStorage(来自 nomadlms)
|
||||
* 与 join 报名支付分离,课程解锁用此模块
|
||||
* 课程解锁 - 校验登录态 + VIP(/api/vip/check)
|
||||
* 与 join 报名支付分离,课程解锁用 VIP 状态
|
||||
*/
|
||||
|
||||
const PAY_STORAGE_KEY = "lms-pay";
|
||||
|
||||
/** 是否已支付(课程已解锁) */
|
||||
export function isPaid(): boolean {
|
||||
if (typeof window === "undefined") return false;
|
||||
return localStorage.getItem(PAY_STORAGE_KEY) === "ok";
|
||||
}
|
||||
|
||||
/** 设置已支付(支付成功后调用) */
|
||||
export function setPaid(): void {
|
||||
if (typeof window === "undefined") return;
|
||||
localStorage.setItem(PAY_STORAGE_KEY, "ok");
|
||||
window.dispatchEvent(new CustomEvent("pay:updated"));
|
||||
}
|
||||
|
||||
/** 前 2 章为试看,无需支付 */
|
||||
export function isFreeTrial(moduleIndex: number, lessonIndex: number): boolean {
|
||||
if (moduleIndex === 0 && lessonIndex < 2) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 章节是否可观看 */
|
||||
export function canWatchLesson(moduleIndex: number, lessonIndex: number): boolean {
|
||||
/** 章节是否可观看(需传入 vip 状态,来自 useAuthAndVip 或 /api/vip/check) */
|
||||
export function canWatchLesson(
|
||||
moduleIndex: number,
|
||||
lessonIndex: number,
|
||||
vip: boolean
|
||||
): boolean {
|
||||
if (isFreeTrial(moduleIndex, lessonIndex)) return true;
|
||||
return isPaid();
|
||||
return vip;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user