40 lines
2.1 KiB
JavaScript
40 lines
2.1 KiB
JavaScript
// Local-only visual QA: no request reaches the real backend.
|
|
import { preview } from 'vite';
|
|
|
|
let notificationRead = false;
|
|
|
|
const server = await preview({
|
|
configFile: false,
|
|
build: { outDir: 'dist/build/h5' },
|
|
preview: { host: '127.0.0.1', port: 48138, strictPort: true },
|
|
plugins: [{
|
|
name: 'mock-h5-api',
|
|
configurePreviewServer(server) {
|
|
server.middlewares.use((req, res, next) => {
|
|
if (!req.url.startsWith('/__mock/')) return next();
|
|
let data = {};
|
|
if (req.url.startsWith('/__mock/asset/info')) data = {
|
|
identifier: 'A', asset_type: 'card', bound_phone: '13800000001',
|
|
current_package: '测试套餐', current_package_id: 1, current_package_usage_id: 1,
|
|
real_total_mb: 1024, real_used_mb: 256,
|
|
estimated_final_expires_at: '2026-10-13T16:00:00Z', days_until_final_expiry: 0, is_expiring: true,
|
|
expiry_reminder: { remaining_days: 0, expires_at: '2026-10-13T16:00:00Z', level: 'red', level_name: '即将到期' }
|
|
};
|
|
if (req.url.startsWith('/__mock/notifications')) data = { count: 0, items: [], total: 0 };
|
|
if (process.env.H5_MOCK_NOTIFICATIONS === '1') {
|
|
if (req.url.startsWith('/__mock/notifications/unread-count')) data = { count: notificationRead ? 0 : 1 };
|
|
else if (/^\/__mock\/notifications\/42\/read/.test(req.url)) { notificationRead = true; data = { success: true }; }
|
|
else if (req.url.startsWith('/__mock/notifications/read-all')) { notificationRead = true; data = { updated_count: 1 }; }
|
|
else if (req.url.startsWith('/__mock/notifications')) data = {
|
|
items: [{ id: 42, title: '套餐临期提醒', body: '您的套餐即将到期,请及时续费。', category: 'expiry', severity: 'warning', is_read: notificationRead, created_at: '2026-10-13T08:00:00+08:00' }], total: 1
|
|
};
|
|
}
|
|
const conflict = req.url.startsWith('/__mock/auth/bind-phone');
|
|
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
res.end(JSON.stringify({ code: conflict ? 1192 : 0, msg: conflict ? '该资产已绑定手机号,如需更换请联系管理员' : 'success', data }));
|
|
});
|
|
}
|
|
}]
|
|
});
|
|
server.printUrls();
|