174 lines
4.8 KiB
JavaScript
174 lines
4.8 KiB
JavaScript
const time = '2026-10-13T10:00:00+08:00'
|
|
const order = {
|
|
id: 1,
|
|
order_no: 'MOCK-ORDER-001',
|
|
order_type: 'single_card',
|
|
buyer_type: 'personal',
|
|
payment_status: 2,
|
|
payment_status_text: '已支付',
|
|
payment_method: 'wechat',
|
|
total_amount: 1000,
|
|
actual_paid_amount: 1000,
|
|
third_party_trade_no: 'MOCK-TRADE-001',
|
|
payment_channel: 'wechat',
|
|
payment_merchant_name: '模拟收款商户',
|
|
commission_status: 2,
|
|
commission_result: 2,
|
|
created_at: time,
|
|
updated_at: time,
|
|
paid_at: time,
|
|
items: [],
|
|
payments: [
|
|
{
|
|
payment_no: 'MOCK-PAY-002',
|
|
payment_method: 'wechat',
|
|
payment_channel: 'wechat',
|
|
payment_merchant_name: '模拟收款商户',
|
|
third_party_trade_no: 'MOCK-TRADE-001',
|
|
amount: 1000,
|
|
status: 1,
|
|
created_at: time,
|
|
paid_at: time,
|
|
expire_at: null
|
|
},
|
|
{
|
|
payment_no: 'MOCK-PAY-001',
|
|
payment_method: 'alipay',
|
|
payment_channel: 'fuiou',
|
|
payment_merchant_name: '模拟收款商户',
|
|
third_party_trade_no: '',
|
|
amount: 1000,
|
|
status: 2,
|
|
created_at: time,
|
|
paid_at: null,
|
|
expire_at: null
|
|
}
|
|
]
|
|
}
|
|
const application = {
|
|
id: 1,
|
|
status: 4,
|
|
status_name: '审批提交失败',
|
|
recoverable: true,
|
|
approval_submission_status: 3,
|
|
paid_amount: 1000,
|
|
created_at: time
|
|
}
|
|
const registration = {
|
|
id: 1,
|
|
status: 3,
|
|
recoverable: true,
|
|
phone: '13800000000',
|
|
username: 'mock-user',
|
|
shop_name: '模拟店铺',
|
|
created_at: time
|
|
}
|
|
const rule = {
|
|
id: 1,
|
|
package_id: 1,
|
|
package_name: '模拟套餐',
|
|
threshold_percent: 80,
|
|
enabled: true,
|
|
enabled_name: '启用',
|
|
remark: '',
|
|
updated_at: time
|
|
}
|
|
const traffic = {
|
|
id: 1,
|
|
package_name: '模拟套餐',
|
|
threshold_percent: 80,
|
|
threshold_mb: 819.2,
|
|
used_mb: 0,
|
|
limit_mb: 1024,
|
|
triggered_at: time,
|
|
notification_status: 1,
|
|
asset_type: 'iot_card',
|
|
asset_identifier: 'MOCK-ASSET'
|
|
}
|
|
const exchange = {
|
|
id: 1,
|
|
exchange_no: 'MOCK-EXCHANGE-001',
|
|
status: 3,
|
|
status_name: '已发货待确认',
|
|
status_text: '已发货待确认',
|
|
old_asset_type: 'iot_card',
|
|
old_asset_identifier: 'MOCK-OLD-ASSET',
|
|
new_asset_identifier: 'MOCK-NEW-ASSET',
|
|
flow_type: 'shipping',
|
|
flow_type_name: '物流换货',
|
|
migration_status: 'pending',
|
|
created_at: time,
|
|
updated_at: time
|
|
}
|
|
|
|
export const mockApiPlugin = {
|
|
name: 'october-local-mock-api',
|
|
configureServer(server) {
|
|
server.middlewares.use((req, res, next) => {
|
|
const path = new URL(req.url, 'http://127.0.0.1').pathname
|
|
if (!path.startsWith('/api/')) return next()
|
|
if (path === '/api/auth/login' || path === '/api/auth/me') {
|
|
const user = {
|
|
id: 1,
|
|
user_type: 1,
|
|
username: '模拟管理员',
|
|
phone: '13800000000',
|
|
roles: ['R_SUPER']
|
|
}
|
|
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
|
res.end(
|
|
JSON.stringify({
|
|
code: 0,
|
|
msg: 'mock',
|
|
data: {
|
|
access_token: 'local-mock-only',
|
|
refresh_token: '',
|
|
expires_in: 3600,
|
|
user,
|
|
permissions: ['*:*:*'],
|
|
buttons: [],
|
|
menus: [{ url: '/asset-management', name: '资产管理' }]
|
|
}
|
|
})
|
|
)
|
|
return
|
|
}
|
|
if (req.method !== 'GET') {
|
|
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
|
res.end(
|
|
JSON.stringify({
|
|
code: 1202,
|
|
msg: '模拟请求:未调用真实后台',
|
|
data: { phone: '13800000000' }
|
|
})
|
|
)
|
|
return
|
|
}
|
|
const page = (items) => ({
|
|
items,
|
|
list: items,
|
|
total: items.length,
|
|
page: 1,
|
|
size: 20,
|
|
page_size: 20
|
|
})
|
|
let data = page([])
|
|
if (path === '/api/admin/orders/1') data = order
|
|
if (path === '/api/admin/exchanges') data = page([exchange])
|
|
if (path === '/api/admin/exchanges/1') data = exchange
|
|
if (path === '/api/admin/orders') data = page([order])
|
|
if (path === '/api/admin/employee-collection-applications/1')
|
|
data = { application, allocations: [], attempts: [] }
|
|
if (path === '/api/admin/employee-collection-applications') data = page([application])
|
|
if (path === '/api/admin/agent-distribution-registrations/1') data = registration
|
|
if (path === '/api/admin/agent-distribution-registrations') data = page([registration])
|
|
if (path === '/api/admin/package-traffic-alert-rules') data = page([rule])
|
|
if (path === '/api/admin/package-traffic-alert-rules/1') data = rule
|
|
if (path === '/api/admin/package-traffic-alerts') data = page([traffic])
|
|
if (path === '/api/admin/package-traffic-alerts/1') data = traffic
|
|
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
|
res.end(JSON.stringify({ code: 0, msg: 'mock', data }))
|
|
})
|
|
}
|
|
}
|