21 lines
664 B
TypeScript
21 lines
664 B
TypeScript
/** 支付状态 localStorage key */
|
||
export const PAY_STORAGE_KEY = "pay";
|
||
|
||
/** 是否已支付(含测试标记 pay=ok) */
|
||
export function isPaid(): boolean {
|
||
if (typeof window === "undefined") return false;
|
||
return localStorage.getItem(PAY_STORAGE_KEY) === "ok";
|
||
}
|
||
|
||
/** 前 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 {
|
||
if (isFreeTrial(moduleIndex, lessonIndex)) return true;
|
||
return isPaid();
|
||
}
|