This commit is contained in:
@@ -101,11 +101,55 @@ const exchange = {
|
||||
updated_at: time
|
||||
}
|
||||
|
||||
const associations = [
|
||||
{
|
||||
id: 101,
|
||||
asset_id: 1001,
|
||||
asset_type: 'iot_card',
|
||||
asset_identifier: exchange.new_asset_identifier,
|
||||
phone: '13800000000',
|
||||
status: 1,
|
||||
status_name: '有效',
|
||||
established_at: time
|
||||
},
|
||||
{
|
||||
id: 102,
|
||||
asset_id: 1001,
|
||||
asset_type: 'iot_card',
|
||||
asset_identifier: exchange.new_asset_identifier,
|
||||
phone: '13800000000',
|
||||
status: 0,
|
||||
status_name: '已失效',
|
||||
established_at: time
|
||||
},
|
||||
{
|
||||
id: 103,
|
||||
asset_id: 1002,
|
||||
asset_type: 'iot_card',
|
||||
asset_identifier: exchange.old_asset_identifier,
|
||||
phone: '13800000000',
|
||||
status: 1,
|
||||
status_name: '有效',
|
||||
established_at: time
|
||||
},
|
||||
{
|
||||
id: 104,
|
||||
asset_id: 1002,
|
||||
asset_type: 'iot_card',
|
||||
asset_identifier: exchange.old_asset_identifier,
|
||||
phone: '13900000000',
|
||||
status: 1,
|
||||
status_name: '有效',
|
||||
established_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
|
||||
const url = new URL(req.url, 'http://127.0.0.1')
|
||||
const path = url.pathname
|
||||
if (!path.startsWith('/api/')) return next()
|
||||
if (path === '/api/auth/login' || path === '/api/auth/me') {
|
||||
const user = {
|
||||
@@ -134,6 +178,37 @@ export const mockApiPlugin = {
|
||||
return
|
||||
}
|
||||
if (req.method !== 'GET') {
|
||||
if (path === '/api/admin/phone-asset-associations/batch-unbind') {
|
||||
let body = ''
|
||||
req.on('data', (chunk) => {
|
||||
body += chunk
|
||||
})
|
||||
req.on('end', () => {
|
||||
const request = JSON.parse(body)
|
||||
const items = request.assets.map((asset) => {
|
||||
const matches = associations.filter(
|
||||
(row) =>
|
||||
row.asset_id === asset.asset_id &&
|
||||
row.asset_type === asset.asset_type &&
|
||||
row.status === 1
|
||||
)
|
||||
matches.forEach((row) => {
|
||||
row.status = 0
|
||||
row.status_name = '已失效'
|
||||
})
|
||||
return { ...asset, success: true, unbound_count: matches.length, reason: '' }
|
||||
})
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
code: 0,
|
||||
msg: 'mock',
|
||||
data: { success_count: items.length, fail_count: 0, items }
|
||||
})
|
||||
)
|
||||
})
|
||||
return
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
@@ -153,6 +228,15 @@ export const mockApiPlugin = {
|
||||
page_size: 20
|
||||
})
|
||||
let data = page([])
|
||||
if (path === '/api/admin/phone-asset-associations')
|
||||
data = page(
|
||||
associations.filter(
|
||||
(row) =>
|
||||
(!url.searchParams.get('asset_identifier') ||
|
||||
row.asset_identifier === url.searchParams.get('asset_identifier')) &&
|
||||
(!url.searchParams.get('phone') || row.phone === url.searchParams.get('phone'))
|
||||
)
|
||||
)
|
||||
if (path === '/api/admin/orders/1') data = order
|
||||
if (path === '/api/admin/exchanges') data = page([exchange])
|
||||
if (path === '/api/admin/exchanges/1') data = exchange
|
||||
|
||||
Reference in New Issue
Block a user