import { http } from 'msw'; export const handlers = [ // Handler 1: 获取患者类型 http.get('/dr/api/v1/auth/protocol/patient_type', async () => { // 忽略eslint // eslint-disable-next-line return new Response( JSON.stringify({ code: '0x000000', description: 'Success', solution: '', data: { patient_type_list: [ { id: '1', patient_type_id: 'Human', patient_type_name: 'Human', patient_type_local: 'Human', patient_type_description: 'Human', sort: 1, is_enabled: true, product: 'DROC', is_pre_install: true, }, { id: '2', patient_type_id: 'SpecialType', patient_type_name: 'SpecialType', patient_type_local: 'SpecialType', patient_type_description: 'SpecialType', sort: 2, is_enabled: false, product: 'DROC', is_pre_install: true, }, ], }, }), { status: 200, headers: { 'Content-Type': 'application/json' }, // Simulate 500ms delay delay: 500, } ); }), // Handler 2: 获取body part http.get('/dr/api/v1/auth/protocol/body_part', async () => { // eslint-disable-next-line return new Response( JSON.stringify({ code: '0x000000', description: 'Success', solution: '', data: { body_part_list: [ { id: '1', body_part_id: 'Human_SKULL', body_part_name: '颅骨', body_part_local: '颅骨', body_part_description: 'Skull', patient_type: 'Human', category: 'DX', sort: 1, is_enabled: true, product: 'DROC', is_pre_install: true, }, { id: '2', body_part_id: 'Human_NECK', body_part_name: '颈部', body_part_local: '颈部', body_part_description: 'Neck', patient_type: 'Human', category: 'DX', sort: 2, is_enabled: true, product: 'DROC', is_pre_install: true, }, ], }, }), { status: 200, headers: { 'Content-Type': 'application/json' }, } ); }), // Handler 6: 登陆 http.post('/dr/api/v1/pub/login', async ({ request }) => { const { username, password } = await request.json(); if (username === 'admin' && password === '123456') { // eslint-disable-next-line return new Response( JSON.stringify({ code: '0x000000', description: 'Success', solution: '', data: { token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTEyNzc1ODgsImlkIjoxLCJuYW1lIjoiYWRtaW4ifQ.0qIzacOIf0-YluwAlrkaNJ9lf9w8IKneWEXh_mjUoN4', expire: 1751277588, uid: 1, name: 'admin', avatar: '', }, }), { status: 200, headers: { 'Content-Type': 'application/json' }, delay: 500, } ); } else { // eslint-disable-next-line return new Response( JSON.stringify({ code: '0x000001', description: 'Invalid username or password', solution: '', data: {}, }), { status: 401, headers: { 'Content-Type': 'application/json' }, } ); } }), ];