123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- /**
- * I18n Mock Handlers
- * 国际化相关的 mock 处理器
- */
- /**
- * 获取多语言列表 - 成功场景
- *
- * @description 获取系统支持的语言列表
- * @method GET
- * @url /dr/api/v1/pub/language
- * @access 公开接口
- *
- * @returns {Object[]} data - 语言列表
- * @returns {string} data[].language - 语言代码(en/zh)
- * @returns {string} data[].display - 语言显示名称
- *
- * @example
- * mockGetLanguageListSuccess();
- * cy.wait('@getLanguageListSuccess').its('response.body.data').should('have.length', 2);
- *
- * @see docs/DR.md - 章节4
- */
- export function mockGetLanguageListSuccess() {
- cy.intercept('GET', '/dr/api/v1/pub/language', {
- statusCode: 200,
- body: {
- code: "0x000000",
- data: [
- {
- language: "en",
- display: "English"
- },
- {
- language: "zh",
- display: "简体中文"
- }
- ],
- description: "Success",
- solution: ""
- }
- }).as('getLanguageListSuccess');
- }
- /**
- * 获取多语言列表 - 空列表场景
- *
- * @description 获取多语言列表,返回空列表
- * @method GET
- * @url /dr/api/v1/pub/language
- * @access 公开接口
- *
- * @returns {Object[]} data - 空语言列表
- *
- * @example
- * mockGetLanguageListEmpty();
- * cy.wait('@getLanguageListEmpty');
- *
- * @see docs/DR.md - 章节4
- */
- export function mockGetLanguageListEmpty() {
- cy.intercept('GET', '/dr/api/v1/pub/language', {
- statusCode: 200,
- body: {
- code: "0x000000",
- data: [],
- description: "Success",
- solution: ""
- }
- }).as('getLanguageListEmpty');
- }
- /**
- * 获取翻译文件 - 成功场景
- *
- * @description 获取指定语言的翻译文件
- * @method GET
- * @url /dr/api/v1/pub/trans/{locale}/{locale}.js
- * @access 公开接口
- *
- * @param {string} locale - 语言代码(zh_CN/en_US)
- *
- * @returns {Object} 翻译键值对
- *
- * @example
- * mockI18nSuccess('en_US');
- * cy.wait('@getI18nZHSuccess');
- *
- * @see docs/DR.md - 章节3
- */
- export function mockI18nSuccess(locale: 'zh_CN' | 'en_US') {
- const mockData = locale === 'zh_CN' ? {
- greeting: '你好,世界!',
- name: '张三',
- patient: '患者管理',
- register: '注册',
- tasklist: '任务清单',
- historylist: '历史清单',
- archivelist: '归档清单',
- bin: '回收站',
- outputlist: '传输清单',
- exam: '检查',
- examlist: '检查清单',
- process: '处理',
- print: '打印',
- printlist: '打印清单',
- worklist: '任务清单',
- 'worklist.operationPanel': '操作面板',
- 'register.basicInfoPanel': '基本信息表单区域',
- 'register.protocolListPanel': '待选择协议列表区域',
- 'register.selectedProtocolListPanel': '已选择协议列表区域',
- 'worklistTable.patientId': '患者编号',
- 'worklistTable.name': '患者姓名',
- 'register.patientId': '患者编号',
- 'register.patientName': '患者姓名',
- 'register.gender': '性别',
- 'register.gender.male': '男',
- 'register.gender.female': '女',
- // Login page
- 'login.username': '用户名',
- 'login.username.placeholder': '请输入用户名',
- 'login.username.required': '请输入用户名',
- 'login.password': '密码',
- 'login.password.placeholder': '请输入密码',
- 'login.password.required': '请输入密码',
- 'login.submit': '登录',
- 'login.emergency': '急诊',
- 'login.success': '登录成功',
- 'login.failed': '登录失败',
- 'login.failedDetail': ',详情:',
- 'login.networkError': ',网络错误:',
- 'login.unknownError': '未知错误',
- 'login.emergency.success': '急诊模式启动成功',
- 'login.emergency.failed': '急诊操作失败:'
- } : {
- greeting: 'Hello, world!',
- name: 'John Doe',
- patient: 'Patient Management',
- register: 'Register',
- tasklist: 'Task List',
- historylist: 'History List',
- archivelist: 'Archive List',
- bin: 'Recycle Bin',
- outputlist: 'Transfer List',
- exam: 'Examination',
- examlist: 'Examination List',
- process: 'Process',
- print: 'Print',
- printlist: 'Print List',
- worklist: 'Task List',
- 'worklist.operationPanel': 'Operation Panel',
- 'register.basicInfoPanel': 'Basic Information Form Area',
- 'register.protocolListPanel': 'Protocol Selection List Area',
- 'register.selectedProtocolListPanel': 'Selected Protocol List Area',
- 'worklistTable.patientId': 'Patient ID',
- 'worklistTable.name': 'Patient Name',
- 'register.patientId': 'Patient ID',
- 'register.patientName': 'Patient Name',
- 'register.gender': 'Gender',
- 'register.gender.male': 'Male',
- 'register.gender.female': 'Female',
- // Login page
- 'login.username': 'Username',
- 'login.username.placeholder': 'Enter username',
- 'login.username.required': 'Please enter username',
- 'login.password': 'Password',
- 'login.password.placeholder': 'Enter password',
- 'login.password.required': 'Please enter password',
- 'login.submit': 'Login',
- 'login.emergency': 'Emergency',
- 'login.success': 'Login successful',
- 'login.failed': 'Login failed',
- 'login.failedDetail': ', details: ',
- 'login.networkError': ', network error: ',
- 'login.unknownError': 'Unknown error',
- 'login.emergency.success': 'Emergency mode activated successfully',
- 'login.emergency.failed': 'Emergency operation failed: '
- };
- cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale.split('_')[0]}.js`, (req) => {
- req.reply({
- statusCode: 200,
- body: mockData
- });
- }).as(`getI18n${locale.toUpperCase()}Success`);
- }
- // 封装获取多语言资源失败的 mock (404错误)
- export function mockI18nError(locale: 'zh_CN' | 'en_US') {
- cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale.split('_')[0]}.js`, (req) => {
- req.reply({
- statusCode: 404,
- body: {
- message: 'Not Found',
- error: 'Translation file not found'
- }
- });
- }).as(`getI18n${locale.toUpperCase()}Error`);
- }
- // 封装获取多语言资源服务器错误的 mock (500错误)
- export function mockI18nServerError(locale: 'zh_CN' | 'en_US') {
- cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale.split('_')[0]}.js`, (req) => {
- req.reply({
- statusCode: 500,
- body: {
- message: 'Internal Server Error',
- error: 'Server error occurred'
- }
- });
- }).as(`getI18n${locale.toUpperCase()}ServerError`);
- }
- // 封装获取多语言资源超时的 mock
- export function mockI18nTimeout(locale: 'zh_CN' | 'en_US') {
- cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale.split('_')[0]}.js`, (req) => {
- req.reply({
- delay: 30000, // 30秒延迟,模拟超时
- statusCode: 200,
- body: {}
- });
- }).as(`getI18n${locale.toUpperCase()}Timeout`);
- }
- // 封装获取多语言资源格式错误的 mock
- export function mockI18nInvalidFormat(locale: 'zh_CN' | 'en_US') {
- cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale.split('_')[0]}.js`, (req) => {
- req.reply({
- statusCode: 200,
- body: "invalid json format" // 返回非JSON格式数据
- });
- }).as(`getI18n${locale.toUpperCase()}InvalidFormat`);
- }
- // 封装获取多语言资源空数据的 mock
- export function mockI18nEmptyData(locale: 'zh_CN' | 'en_US') {
- cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale.split('_')[0]}.js`, (req) => {
- req.reply({
- statusCode: 200,
- body: {} // 返回空对象
- });
- }).as(`getI18n${locale.toUpperCase()}EmptyData`);
- }
- // 封装获取多语言资源网络错误的 mock
- export function mockI18nNetworkError(locale: 'zh_CN' | 'en_US') {
- cy.intercept('GET', `/dr/api/v1/pub/trans/${locale}/${locale.split('_')[0]}.js`, (req) => {
- req.reply({
- forceNetworkError: true
- });
- }).as(`getI18n${locale.toUpperCase()}NetworkError`);
- }
- // 封装软件信息API的 mock,避免影响页面加载
- export function mockSoftwareInfo(locale: 'zh_CN' | 'en_US' = 'zh_CN') {
- cy.intercept('GET', '/dr/api/v1/pub/software_info', (req) => {
- req.reply({
- statusCode: 200,
- body: {
- code: "0x000000",
- data: {
- FPD: "Physics",
- GEN: "Physics",
- current_locale: locale,
- default_locale: "zh_CN",
- guest: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NjA0OTc2NDksImlkIjoyLCJuYW1lIjoiZ3Vlc3QifQ.hUV5_GOzlWKDeFioJCsHMG2IXa0oJPfNNlPsr69ypqc",
- language: ["en", "zh"],
- product: "VETDROS",
- server: {
- auth: {
- build: "2025-10-08 11:06:08",
- desc: "Authentication Server repo",
- submodule: ["0baa8db0[rpc_idl]"],
- version: "0.4.0-21-g4a37cc7"
- },
- dcmtk: {
- build: "2025-09-29 16:35:39",
- desc: "Dcmtk Server repo",
- submodule: ["c2039235[rpc_idl]"],
- version: "0.4.0-2-g36bc18f"
- },
- imgProc: {
- build: "2025-09-29 16:36:36",
- desc: "Img Proc Server repo",
- submodule: [
- "d00bfca5[auto_wwwl]",
- "89fd9218[collimator_circle]",
- "c9582bbe[collimator_rect]",
- "98c510bd[enhance]",
- "6f9bf7de[enhance_v3]",
- "5905e001[rpc_idl]"
- ],
- version: "0.4.0-7-gca1c8a4"
- },
- protocol: {
- build: "2025-10-08 11:06:13",
- desc: "Protocol Server repo",
- submodule: ["0baa8db0[rpc_idl]"],
- version: "0.4.0-8-g47990eb"
- },
- resource: {
- build: "2025-10-08 11:06:17",
- desc: "Resource Server repo",
- submodule: ["9725e654[rpc_idl]"],
- version: "0.4.0-9-g10766e8"
- },
- study: {
- build: "2025-10-08 11:06:15",
- desc: "Study Server repo",
- submodule: ["8595ea2d[rpc_idl]"],
- version: "0.5.0-1-g7620712"
- },
- task: {
- build: "2025-10-08 11:06:19",
- desc: "Task Server repo",
- submodule: ["8595ea2d[rpc_idl]"],
- version: "0.4.0-11-g494849d"
- }
- },
- sn: "19d5d2eb-8b720370-7d617b19-670dd1ae"
- },
- description: "Success",
- solution: ""
- }
- });
- }).as('getSoftwareInfo');
- }
- // 封装logger API的 mock,避免影响页面加载
- export function mockLogger() {
- cy.intercept('POST', '/log', (req) => {
- req.reply({
- statusCode: 204, // No Content - 更适合日志请求,不会被误认为页面导航
- body: null, // 明确返回 null,避免任何可能的页面影响
- headers: {
- 'content-type': 'application/json',
- 'cache-control': 'no-cache'
- }
- });
- }).as('postLog');
- }
- // 封装所有必要的API mock,避免影响页面加载
- export function mockAllRequiredAPIs(locale: 'zh_CN' | 'en_US' = 'zh_CN') {
- mockSoftwareInfo(locale);
- mockLogger();
- }
|