文件
jw-beauty/miniprogram/utils/mock.js
T
Guoguo b80e872600 fix: comprehensive security, quality and consistency fixes
Server:
- Block startup with default JWT secrets in production
- Make subscription verify admin-only (no payment integration yet)
- Add device ownership validation on command/result, event, treatment/sync
- Remove admin token from request body fallback
- Add pageParams boundary protection (pageSize capped at 100)
- Fix COS getObjectUrl to use callback-based Promise
- Add settings key whitelist matching frontend fields
- Add user existence check before subscription creation
- Fix firmware always returning has_update:true
- Replace hardcoded trial subscription with actual DB query
- Extract shared utilities (limitClause, toMysqlDate, formatDate)

Miniprogram:
- Replace fake PD random data with placeholder
- Mark client-timer treatment completions with source field
- Disable mock.js
- Fix BLE listener leaks (save refs, cleanup in onUnload)
- Fix ble.off clearing all listeners (pass specific callback)
- Add BLE disconnect detection via onBLEConnectionStateChange
- Fix subscription status type consistency (number not string)
- Fix scan callback accumulation in ble.js
- Fix history stats accumulation across pages
- Fix subscribe-success/treatment-done hardcoded values
- Fix profile subscription view logic
- Replace purchase flow with admin-contact modal
- Add error logging in command-sync report

Admin console:
- Fix AdminLayout logout (require->import, logout->clearToken)
- Remove all mock data from production request.js
- Replace dashboard fake data with real API calls
- Replace monthly_revenue with subscription_count
- Fix subscription stats fallback (|| -> ??)
- Add token expiry tracking (7 days)
- Unify device status map and subscription status text
- Fix user page record link navigation
- Fix subscription createForm.user_id type handling
- Add error feedback in all empty catch blocks
- Remove unused remember checkbox and uview-plus dependency
- Extract common CSS to shared stylesheet (-900 lines)
- Extract formatDate to shared utils/format.js
- Show real admin name in layout header
2026-04-28 08:46:59 -07:00

146 行
3.1 KiB
JavaScript

var MOCK_TOKEN = 'mock_token_dev_' + Date.now()
var MOCK_USER = {
user_id: 10001,
open_id: 'mock_open_id_12345',
nickname: '测试用户',
avatar_url: '',
phone: '',
gender: 0,
created_at: '2025-01-01T00:00:00.000Z'
}
var MOCK_DEVICE = {
device_id: 'DEV001',
name: '我的光子美容仪',
firmware_version: '1.0.0',
battery_level: 85,
status: 'online',
bind_time: '2025-01-01T00:00:00.000Z'
}
var MOCK_SUBSCRIPTION = {
plan_type: 'trial',
status: 'active',
start_time: '2025-01-01T00:00:00.000Z',
end_time: '2025-02-01T00:00:00.000Z',
remaining_days: 30
}
var MOCK_TREATMENTS = [
{
session_id: 'S20250101001',
device_id: 'DEV001',
regions: [1, 2],
wavelength: 630,
brightness: 5,
duration: 600000,
mode: 1,
avg_pd: 128,
created_at: '2025-01-15T10:30:00.000Z'
},
{
session_id: 'S20250102002',
device_id: 'DEV001',
regions: [1],
wavelength: 850,
brightness: 3,
duration: 300000,
mode: 2,
avg_pd: 96,
created_at: '2025-01-14T08:00:00.000Z'
}
]
var mockHandlers = {
'POST /api/v1/auth/login': function () {
return {
code: 0,
data: {
token: MOCK_TOKEN,
user_id: MOCK_USER.user_id,
user_info: MOCK_USER
}
}
},
'POST /api/v1/auth/refresh': function () {
return { code: 0, data: { token: MOCK_TOKEN } }
},
'GET /api/v1/user/profile': function () {
return { code: 0, data: MOCK_USER }
},
'PUT /api/v1/user/profile': function (data) {
Object.assign(MOCK_USER, data)
return { code: 0, data: MOCK_USER }
},
'POST /api/v1/device/bind': function (data) {
var d = Object.assign({}, MOCK_DEVICE, { device_id: data.device_id || 'DEV001' })
return {
code: 0,
data: {
device: d,
bind_token: 'mock_bind_token_' + Date.now(),
subscription: MOCK_SUBSCRIPTION
}
}
},
'POST /api/v1/device/unbind': function () {
return { code: 0, data: {} }
},
'GET /api/v1/device/list': function () {
return { code: 0, data: { devices: [MOCK_DEVICE], total: 1 } }
},
'GET /api/v1/device/detail': function () {
return { code: 0, data: MOCK_DEVICE }
},
'GET /api/v1/subscription/status': function () {
return { code: 0, data: MOCK_SUBSCRIPTION }
},
'POST /api/v1/subscription/purchase': function (data) {
return {
code: 0,
data: {
order_id: 'ORD' + Date.now(),
plan_type: data.plan_type,
status: 'paid'
}
}
},
'POST /api/v1/subscription/verify': function () {
return { code: 0, data: { valid: true } }
},
'POST /api/v1/treatment/sync': function (data) {
return { code: 0, data: { session_id: data.session_id || 'S' + Date.now() } }
},
'GET /api/v1/treatment/history': function () {
return { code: 0, data: { records: MOCK_TREATMENTS, total: MOCK_TREATMENTS.length } }
}
}
function handle(method, path, data) {
var key = method + ' ' + path
var handler = mockHandlers[key]
if (!handler) {
return { code: -1, message: 'mock: 未定义的接口 ' + key }
}
return handler(data)
}
module.exports = {
handle: handle,
MOCK_TOKEN: MOCK_TOKEN,
enabled: false
}