import { checkActivation } from './activationService'; // 获取设备信息 export const getDeviceInfo = () => { try { const device = uni.getDeviceInfo(); return { id: device.deviceId || 'unknown', model: device.model || 'unknown', brand: device.brand || 'unknown', system: device.system || 'unknown', version: device.version || 'unknown' }; } catch (error) { console.error('获取设备信息失败:', error); return { id: 'error', model: 'error', brand: 'error', system: 'error', version: 'error' }; } }; // 检查试用期状态 export const checkTrialStatus = async () => { try { // 检查激活状态 const activation = await checkActivation(); if (activation.isValid) { return { isTrial: false, isValid: true }; } // 检查试用期 const trialEndDate = new Date('2023-12-31'); // 应从系统设置获取 const today = new Date(); const isTrial = today <= trialEndDate; return { isTrial, isValid: isTrial, daysLeft: isTrial ? Math.ceil((trialEndDate - today) / (1000 * 60 * 60 * 24)) : 0, trialEndDate: trialEndDate.toISOString().split('T')[0] }; } catch (error) { console.error('检查试用期状态失败:', error); return { isTrial: false, isValid: false }; } }; // 全局试用期检查拦截 export const setupTrialInterceptor = () => { // 应用启动时检查 uni.onAppShow(() => { checkTrialStatus().then(status => { if (!status.isValid) { uni.redirectTo({ url: '/pages/system/activation' }); } }); }); // 路由跳转前检查 uni.addInterceptor('navigateTo', { invoke(args) { return checkTrialStatus().then(status => { if (!status.isValid && !args.url.includes('/system/activation')) { uni.redirectTo({ url: '/pages/system/activation' }); return false; } return true; }); } }); };