dsh-postapi 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +139 -2
- package/cordis.patch.yml +3 -0
- package/dist/client.js +5651 -0
- package/docs/DETAIL.md +27 -0
- package/docs/apifox-design-spec.md +101 -0
- package/docs/apifox-research/analysis.md +254 -0
- package/docs/apifox-ui-delivery.md +150 -0
- package/docs/apifox-visual-parity-spec.md +353 -0
- package/docs/feature-matrix.md +112 -0
- package/docs/flow-reference/sequence-reference.html +163 -0
- package/docs/interface-contract-v2.md +175 -0
- package/docs/interface-contract.md +105 -0
- package/docs/nav-layout-v2-spec.md +107 -0
- package/docs/preview.svg +9 -0
- package/docs/probe-client.legacy.js +31 -0
- package/docs/rootcause-sidebar-vanish.md +95 -0
- package/docs/rootcause.md +86 -0
- package/docs/sidebar-notes.md +153 -0
- package/docs/ui-audit.md +197 -0
- package/docs/ui-notes.md +98 -0
- package/docs/v2-delivery.md +99 -0
- package/icon.svg +4 -0
- package/index.js +5 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +73 -4
- package/src/client/index.js +132 -0
- package/src/client/jsx-shim.js +9 -0
- package/src/client/pages/__tests__/heights.test.js +135 -0
- package/src/client/pages/components/AssertTable.jsx +122 -0
- package/src/client/pages/components/BodyEditor.jsx +91 -0
- package/src/client/pages/components/EmptyState.jsx +52 -0
- package/src/client/pages/components/FolderTree.jsx +109 -0
- package/src/client/pages/components/JsonEditor.jsx +45 -0
- package/src/client/pages/components/ParamTable.jsx +226 -0
- package/src/client/pages/components/ResponsePanel.jsx +278 -0
- package/src/client/pages/components/ScriptPanel.jsx +99 -0
- package/src/client/pages/components/StatusPill.jsx +35 -0
- package/src/client/pages/components/__tests__/apifox-ui.test.js +291 -0
- package/src/client/pages/components/__tests__/pages-a.test.js +392 -0
- package/src/client/pages/components/__tests__/tree.test.js +379 -0
- package/src/client/pages/components/headerPresets.js +63 -0
- package/src/client/pages/debug.jsx +576 -0
- package/src/client/pages/design-tokens.css +2604 -0
- package/src/client/pages/doc.jsx +552 -0
- package/src/client/pages/env.jsx +378 -0
- package/src/client/pages/flow.jsx +349 -0
- package/src/client/pages/history.jsx +238 -0
- package/src/client/pages/import.jsx +396 -0
- package/src/client/pages/mock.jsx +316 -0
- package/src/client/pages/overview.jsx +348 -0
- package/src/client/pages/schema.jsx +317 -0
- package/src/client/pages/search.jsx +216 -0
- package/src/client/pages/sequence.jsx +344 -0
- package/src/client/pages/settings.jsx +205 -0
- package/src/client/pages/test.jsx +470 -0
- package/src/client/pages/theme.js +27 -0
- package/src/client/pages-entry.js +20 -0
- package/src/client/shell/ApiTitle.js +19 -0
- package/src/client/shell/Body.js +492 -0
- package/src/client/shell/definition.js +57 -0
- package/src/client/shell/locales.js +185 -0
- package/src/client/shell/menu.js +174 -0
- package/src/client/shell/registry.js +530 -0
- package/src/host/bridge.js +407 -0
- package/src/host/codegen.js +356 -0
- package/src/host/import-export.js +1044 -0
- package/src/host/index.js +102 -0
- package/src/host/mock-server.js +303 -0
- package/src/host/request.js +336 -0
- package/src/host/script-sandbox.js +272 -0
- package/src/host/storage.js +803 -0
- package/src/host/test-runner.js +126 -0
- package/src/host/variables.js +108 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostAPI 客户端文案字典:zh 为 key-set 的事实来源(官方 sidebar-files 惯例),
|
|
3
|
+
* en 与 zh 键集逐项对齐;注册于 'postapi' 命名空间。
|
|
4
|
+
*/
|
|
5
|
+
export const POSTAPI_NS = 'postapi'
|
|
6
|
+
|
|
7
|
+
/** 简体中文字典(键集事实来源)。 */
|
|
8
|
+
export const zh = {
|
|
9
|
+
'type.label': 'PostAPI',
|
|
10
|
+
'guide.title': '打开 PostAPI',
|
|
11
|
+
'guide.description': '接口设计、调试、Mock、测试与文档',
|
|
12
|
+
'nav.overview': '总览',
|
|
13
|
+
'nav.doc': '文档',
|
|
14
|
+
'nav.debug': '调试',
|
|
15
|
+
'nav.mock': 'Mock',
|
|
16
|
+
'nav.schema': '数据模型',
|
|
17
|
+
'nav.env': '环境',
|
|
18
|
+
'nav.history': '历史',
|
|
19
|
+
'nav.test': '测试',
|
|
20
|
+
'nav.import': '导入导出',
|
|
21
|
+
'nav.flow': '流程图',
|
|
22
|
+
'nav.search': '搜索',
|
|
23
|
+
'nav.settings': '设置',
|
|
24
|
+
// —— 顶栏(Apifox 工作台骨架 §3)——
|
|
25
|
+
'topbar.search': '全局搜索',
|
|
26
|
+
'topbar.searchPlaceholder': '搜索接口 / 目录 / 模型',
|
|
27
|
+
'topbar.newEndpoint': '新建接口',
|
|
28
|
+
'topbar.env': '环境',
|
|
29
|
+
'topbar.envDefault': '默认环境',
|
|
30
|
+
'topbar.theme': '主题',
|
|
31
|
+
'topbar.themeDark': '深色',
|
|
32
|
+
'topbar.themeLight': '浅色',
|
|
33
|
+
'topbar.themeHint': '切换浅色 / 深色皮肤',
|
|
34
|
+
'topbar.settings': '设置',
|
|
35
|
+
// —— 新建三级菜单(与 Apifox 左侧「+」同构)——
|
|
36
|
+
'topbar.new': '新建',
|
|
37
|
+
'menu.new.api': '接口',
|
|
38
|
+
'menu.new.apiHttp': 'HTTP 接口',
|
|
39
|
+
'menu.new.apiHttpBlank': '新建空白接口',
|
|
40
|
+
'menu.new.apiHttpCopy': '从已有接口复制',
|
|
41
|
+
'menu.new.apiWs': 'WebSocket 接口',
|
|
42
|
+
'menu.new.apiWsBlank': '新建 WebSocket 接口',
|
|
43
|
+
'menu.new.apiWsCopy': '从已有接口复制',
|
|
44
|
+
'menu.new.apiRpc': 'RPC 接口',
|
|
45
|
+
'menu.new.apiGrpc': 'gRPC 接口',
|
|
46
|
+
'menu.new.apiGraphql': 'GraphQL 接口',
|
|
47
|
+
'menu.new.folder': '目录',
|
|
48
|
+
'menu.new.folderBlank': '新建目录',
|
|
49
|
+
'menu.new.folderSub': '新建子目录',
|
|
50
|
+
'menu.new.folderSubOne': '一级子目录',
|
|
51
|
+
'menu.new.folderSubTwo': '二级子目录',
|
|
52
|
+
'menu.new.schema': '数据模型',
|
|
53
|
+
'menu.new.schemaJson': '新建 JSON 模型',
|
|
54
|
+
'menu.new.schemaImport': '从 JSON 导入',
|
|
55
|
+
'menu.new.quick': '快捷请求',
|
|
56
|
+
'menu.new.import': '导入',
|
|
57
|
+
'menu.new.importDoc': '导入接口文档',
|
|
58
|
+
'menu.new.importOpenapi': 'OpenAPI / Swagger',
|
|
59
|
+
'menu.new.importPostman': 'Postman 集合',
|
|
60
|
+
'menu.new.importHar': 'HAR 抓包',
|
|
61
|
+
'menu.new.importCurl': 'cURL 命令',
|
|
62
|
+
'menu.new.importData': '导入数据',
|
|
63
|
+
'menu.new.importEnv': '环境变量',
|
|
64
|
+
'menu.new.importSchema': '数据模型',
|
|
65
|
+
'menu.new.test': '测试',
|
|
66
|
+
'menu.new.testCase': '新建测试用例',
|
|
67
|
+
'menu.new.testScenario': '新建测试场景',
|
|
68
|
+
'menu.new.env': '环境',
|
|
69
|
+
'menu.new.flow': '流程图',
|
|
70
|
+
// —— 左树 / 右栏 ——
|
|
71
|
+
'group.project': '项目',
|
|
72
|
+
'group.api': '接口',
|
|
73
|
+
'group.data': '数据',
|
|
74
|
+
'group.quality': '质量',
|
|
75
|
+
'group.tools': '工具',
|
|
76
|
+
'aside.nav': '导航',
|
|
77
|
+
'aside.about': '当前页面',
|
|
78
|
+
'aside.shortcuts': '快捷入口',
|
|
79
|
+
'aside.noContext': '暂无上下文信息',
|
|
80
|
+
'aside.page.overview': '项目总览:项目卡片、最近接口与快捷入口。',
|
|
81
|
+
'aside.page.doc': '接口文档:目录树、参数表与多响应示例。',
|
|
82
|
+
'aside.page.debug': '调试:编辑请求并查看响应与耗时。',
|
|
83
|
+
'aside.page.mock': 'Mock:启动本地 Mock 服务并维护期望响应。',
|
|
84
|
+
'aside.page.schema': '数据模型:JSON Schema 定义与示例生成。',
|
|
85
|
+
'aside.page.env': '环境:环境变量、全局变量与密钥。',
|
|
86
|
+
'aside.page.history': '历史:调试请求记录与回放。',
|
|
87
|
+
'aside.page.test': '测试:用例、场景与断言结果。',
|
|
88
|
+
'aside.page.import': '导入导出:OpenAPI / Postman / HAR / cURL。',
|
|
89
|
+
'aside.page.flow': '流程图:接口调用顺序与时序。',
|
|
90
|
+
'aside.page.search': '搜索:按关键字检索接口、目录与模型。',
|
|
91
|
+
'aside.page.settings': '设置:主题、语言与项目参数。',
|
|
92
|
+
'placeholder.title': '页面未注册',
|
|
93
|
+
'placeholder.body': '该页面尚未注册:页面由 src/client/pages/ 自注册(window.__postapiPages.register)。',
|
|
94
|
+
'placeholder.hint': '页面注册后此处渲染对应内容。',
|
|
95
|
+
'api.missing': 'postapi.storage / postapi.request 桥尚未连通,当前为内存桩。',
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 英文字典,键集与 zh 完全一致。 */
|
|
99
|
+
export const en = {
|
|
100
|
+
'type.label': 'PostAPI',
|
|
101
|
+
'guide.title': 'Open PostAPI',
|
|
102
|
+
'guide.description': 'API design, debug, mock, test and docs',
|
|
103
|
+
'nav.overview': 'Overview',
|
|
104
|
+
'nav.doc': 'Doc',
|
|
105
|
+
'nav.debug': 'Debug',
|
|
106
|
+
'nav.mock': 'Mock',
|
|
107
|
+
'nav.schema': 'Schemas',
|
|
108
|
+
'nav.env': 'Envs',
|
|
109
|
+
'nav.history': 'History',
|
|
110
|
+
'nav.test': 'Tests',
|
|
111
|
+
'nav.import': 'Import/Export',
|
|
112
|
+
'nav.flow': 'Flow',
|
|
113
|
+
'nav.search': 'Search',
|
|
114
|
+
'nav.settings': 'Settings',
|
|
115
|
+
'topbar.search': 'Global search',
|
|
116
|
+
'topbar.searchPlaceholder': 'Search endpoints / folders / schemas',
|
|
117
|
+
'topbar.newEndpoint': 'New endpoint',
|
|
118
|
+
'topbar.env': 'Environment',
|
|
119
|
+
'topbar.envDefault': 'Default env',
|
|
120
|
+
'topbar.theme': 'Theme',
|
|
121
|
+
'topbar.themeDark': 'Dark',
|
|
122
|
+
'topbar.themeLight': 'Light',
|
|
123
|
+
'topbar.themeHint': 'Toggle light / dark skin',
|
|
124
|
+
'topbar.settings': 'Settings',
|
|
125
|
+
// —— New menu (three levels, same shape as Apifox "+") ——
|
|
126
|
+
'topbar.new': 'New',
|
|
127
|
+
'menu.new.api': 'API',
|
|
128
|
+
'menu.new.apiHttp': 'HTTP API',
|
|
129
|
+
'menu.new.apiHttpBlank': 'Blank API',
|
|
130
|
+
'menu.new.apiHttpCopy': 'Copy from existing',
|
|
131
|
+
'menu.new.apiWs': 'WebSocket API',
|
|
132
|
+
'menu.new.apiWsBlank': 'New WebSocket API',
|
|
133
|
+
'menu.new.apiWsCopy': 'Copy from existing',
|
|
134
|
+
'menu.new.apiRpc': 'RPC API',
|
|
135
|
+
'menu.new.apiGrpc': 'gRPC API',
|
|
136
|
+
'menu.new.apiGraphql': 'GraphQL API',
|
|
137
|
+
'menu.new.folder': 'Folder',
|
|
138
|
+
'menu.new.folderBlank': 'New folder',
|
|
139
|
+
'menu.new.folderSub': 'New subfolder',
|
|
140
|
+
'menu.new.folderSubOne': 'First-level subfolder',
|
|
141
|
+
'menu.new.folderSubTwo': 'Second-level subfolder',
|
|
142
|
+
'menu.new.schema': 'Schema',
|
|
143
|
+
'menu.new.schemaJson': 'New JSON schema',
|
|
144
|
+
'menu.new.schemaImport': 'Import from JSON',
|
|
145
|
+
'menu.new.quick': 'Quick request',
|
|
146
|
+
'menu.new.import': 'Import',
|
|
147
|
+
'menu.new.importDoc': 'Import API document',
|
|
148
|
+
'menu.new.importOpenapi': 'OpenAPI / Swagger',
|
|
149
|
+
'menu.new.importPostman': 'Postman collection',
|
|
150
|
+
'menu.new.importHar': 'HAR capture',
|
|
151
|
+
'menu.new.importCurl': 'cURL command',
|
|
152
|
+
'menu.new.importData': 'Import data',
|
|
153
|
+
'menu.new.importEnv': 'Environments',
|
|
154
|
+
'menu.new.importSchema': 'Schemas',
|
|
155
|
+
'menu.new.test': 'Test',
|
|
156
|
+
'menu.new.testCase': 'New test case',
|
|
157
|
+
'menu.new.testScenario': 'New scenario',
|
|
158
|
+
'menu.new.env': 'Environment',
|
|
159
|
+
'menu.new.flow': 'Flow diagram',
|
|
160
|
+
'group.project': 'Project',
|
|
161
|
+
'group.api': 'API',
|
|
162
|
+
'group.data': 'Data',
|
|
163
|
+
'group.quality': 'Quality',
|
|
164
|
+
'group.tools': 'Tools',
|
|
165
|
+
'aside.nav': 'Navigation',
|
|
166
|
+
'aside.about': 'This page',
|
|
167
|
+
'aside.shortcuts': 'Shortcuts',
|
|
168
|
+
'aside.noContext': 'No context for this page',
|
|
169
|
+
'aside.page.overview': 'Project overview: cards, recent endpoints and shortcuts.',
|
|
170
|
+
'aside.page.doc': 'Endpoint doc: tree, parameter tables and response examples.',
|
|
171
|
+
'aside.page.debug': 'Debug: edit a request and inspect the response.',
|
|
172
|
+
'aside.page.mock': 'Mock: start the local mock server and maintain expectations.',
|
|
173
|
+
'aside.page.schema': 'Schemas: JSON Schema definitions and example generation.',
|
|
174
|
+
'aside.page.env': 'Environments: env vars, globals and secrets.',
|
|
175
|
+
'aside.page.history': 'History: debug request records and replay.',
|
|
176
|
+
'aside.page.test': 'Tests: cases, scenarios and assertion results.',
|
|
177
|
+
'aside.page.import': 'Import/Export: OpenAPI / Postman / HAR / cURL.',
|
|
178
|
+
'aside.page.flow': 'Flow: endpoint call order and timing.',
|
|
179
|
+
'aside.page.search': 'Search: keyword lookup across endpoints, folders and schemas.',
|
|
180
|
+
'aside.page.settings': 'Settings: theme, language and project options.',
|
|
181
|
+
'placeholder.title': 'Page not registered',
|
|
182
|
+
'placeholder.body': 'This page is not registered yet: pages self-register from src/client/pages/ (window.__postapiPages.register).',
|
|
183
|
+
'placeholder.hint': 'The page renders here once registered.',
|
|
184
|
+
'api.missing': 'postapi.storage / postapi.request bridge not reachable; using the in-memory stub.',
|
|
185
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 新建菜单数据(三级,与 Apifox 左侧「+」按钮同构)。
|
|
3
|
+
*
|
|
4
|
+
* Apifox 的「+」是三级结构:
|
|
5
|
+
* 一级:接口 / 目录 / 快捷请求 / 数据模型 / 导入 / 模块 …(按资源类型分组)
|
|
6
|
+
* 二级:一级项自身的具体类型(如「接口」下的 HTTP / WebSocket / gRPC / GraphQL)
|
|
7
|
+
* 三级:具体格式或子类型(如「导入」下的 OpenAPI / Postman / HAR / cURL)
|
|
8
|
+
*
|
|
9
|
+
* 这里只描述数据与动作,不渲染任何 DOM;渲染由 Body.js 的 MenuTree 负责,
|
|
10
|
+
* 便于单测直接断言层级与动作。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** 叶子动作的形态:navigate 跳路由,trigger 触发页内行为(由 body 注入回调)。 */
|
|
14
|
+
export function leaf(id, labelKey, action) {
|
|
15
|
+
return { id, labelKey, action }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 三级菜单树。
|
|
20
|
+
* action 形态:
|
|
21
|
+
* { kind: 'route', hash: '#/doc' } 跳转路由
|
|
22
|
+
* { kind: 'route', hash: '#/doc', query } 带查询串
|
|
23
|
+
* { kind: 'event', name: 'new-endpoint' } 交给页面/宿主处理
|
|
24
|
+
*/
|
|
25
|
+
export const NEW_MENU = [
|
|
26
|
+
{
|
|
27
|
+
id: 'api',
|
|
28
|
+
labelKey: 'menu.new.api',
|
|
29
|
+
children: [
|
|
30
|
+
{
|
|
31
|
+
id: 'api-http',
|
|
32
|
+
labelKey: 'menu.new.apiHttp',
|
|
33
|
+
children: [
|
|
34
|
+
{ id: 'api-http-blank', labelKey: 'menu.new.apiHttpBlank', action: { kind: 'route', hash: '#/doc', query: 'new=1' } },
|
|
35
|
+
{ id: 'api-http-copy', labelKey: 'menu.new.apiHttpCopy', action: { kind: 'route', hash: '#/doc', query: 'copy=1' } },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'api-ws',
|
|
40
|
+
labelKey: 'menu.new.apiWs',
|
|
41
|
+
children: [
|
|
42
|
+
{ id: 'api-ws-blank', labelKey: 'menu.new.apiWsBlank', action: { kind: 'route', hash: '#/doc', query: 'protocol=websocket' } },
|
|
43
|
+
{ id: 'api-ws-copy', labelKey: 'menu.new.apiWsCopy', action: { kind: 'route', hash: '#/doc', query: 'protocol=websocket©=1' } },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'api-rpc',
|
|
48
|
+
labelKey: 'menu.new.apiRpc',
|
|
49
|
+
children: [
|
|
50
|
+
{ id: 'api-rpc-grpc', labelKey: 'menu.new.apiGrpc', action: { kind: 'route', hash: '#/doc', query: 'protocol=grpc' } },
|
|
51
|
+
{ id: 'api-rpc-graphql', labelKey: 'menu.new.apiGraphql', action: { kind: 'route', hash: '#/doc', query: 'protocol=graphql' } },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 'folder',
|
|
58
|
+
labelKey: 'menu.new.folder',
|
|
59
|
+
children: [
|
|
60
|
+
{ id: 'folder-blank', labelKey: 'menu.new.folderBlank', action: { kind: 'route', hash: '#/doc', query: 'newFolder=1' } },
|
|
61
|
+
{
|
|
62
|
+
id: 'folder-sub',
|
|
63
|
+
labelKey: 'menu.new.folderSub',
|
|
64
|
+
children: [
|
|
65
|
+
{ id: 'folder-sub-one', labelKey: 'menu.new.folderSubOne', action: { kind: 'route', hash: '#/doc', query: 'newFolder=1&depth=2' } },
|
|
66
|
+
{ id: 'folder-sub-two', labelKey: 'menu.new.folderSubTwo', action: { kind: 'route', hash: '#/doc', query: 'newFolder=1&depth=3' } },
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 'schema',
|
|
73
|
+
labelKey: 'menu.new.schema',
|
|
74
|
+
children: [
|
|
75
|
+
{ id: 'schema-json', labelKey: 'menu.new.schemaJson', action: { kind: 'route', hash: '#/schema', query: 'new=1' } },
|
|
76
|
+
{ id: 'schema-import', labelKey: 'menu.new.schemaImport', action: { kind: 'route', hash: '#/schema', query: 'import=1' } },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'quick',
|
|
81
|
+
labelKey: 'menu.new.quick',
|
|
82
|
+
action: { kind: 'route', hash: '#/debug', query: 'quick=1' },
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: 'import',
|
|
86
|
+
labelKey: 'menu.new.import',
|
|
87
|
+
children: [
|
|
88
|
+
{
|
|
89
|
+
id: 'import-doc',
|
|
90
|
+
labelKey: 'menu.new.importDoc',
|
|
91
|
+
children: [
|
|
92
|
+
{ id: 'import-openapi', labelKey: 'menu.new.importOpenapi', action: { kind: 'route', hash: '#/import', query: 'kind=openapi' } },
|
|
93
|
+
{ id: 'import-postman', labelKey: 'menu.new.importPostman', action: { kind: 'route', hash: '#/import', query: 'kind=postman' } },
|
|
94
|
+
{ id: 'import-har', labelKey: 'menu.new.importHar', action: { kind: 'route', hash: '#/import', query: 'kind=har' } },
|
|
95
|
+
{ id: 'import-curl', labelKey: 'menu.new.importCurl', action: { kind: 'route', hash: '#/import', query: 'kind=curl' } },
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: 'import-data',
|
|
100
|
+
labelKey: 'menu.new.importData',
|
|
101
|
+
children: [
|
|
102
|
+
{ id: 'import-env', labelKey: 'menu.new.importEnv', action: { kind: 'route', hash: '#/import', query: 'kind=env' } },
|
|
103
|
+
{ id: 'import-schema', labelKey: 'menu.new.importSchema', action: { kind: 'route', hash: '#/import', query: 'kind=schema' } },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
{ id: 'sep-1', separator: true },
|
|
109
|
+
{
|
|
110
|
+
id: 'test',
|
|
111
|
+
labelKey: 'menu.new.test',
|
|
112
|
+
children: [
|
|
113
|
+
{ id: 'test-case', labelKey: 'menu.new.testCase', action: { kind: 'route', hash: '#/test', query: 'new=case' } },
|
|
114
|
+
{ id: 'test-scenario', labelKey: 'menu.new.testScenario', action: { kind: 'route', hash: '#/test', query: 'new=scenario' } },
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: 'env',
|
|
119
|
+
labelKey: 'menu.new.env',
|
|
120
|
+
action: { kind: 'route', hash: '#/env', query: 'new=1' },
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: 'flow',
|
|
124
|
+
labelKey: 'menu.new.flow',
|
|
125
|
+
action: { kind: 'route', hash: '#/flow', query: 'new=1' },
|
|
126
|
+
},
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
/** 树深度(1 = 只有一级;本表最大 3)。 */
|
|
130
|
+
export function menuDepth(items) {
|
|
131
|
+
let max = 0
|
|
132
|
+
for (const item of Array.isArray(items) ? items : []) {
|
|
133
|
+
const d = item && Array.isArray(item.children) && item.children.length
|
|
134
|
+
? 1 + menuDepth(item.children)
|
|
135
|
+
: 1
|
|
136
|
+
if (d > max) max = d
|
|
137
|
+
}
|
|
138
|
+
return max
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 按 id 查节点(递归)。 */
|
|
142
|
+
export function findMenuNode(items, id) {
|
|
143
|
+
for (const item of Array.isArray(items) ? items : []) {
|
|
144
|
+
if (!item) continue
|
|
145
|
+
if (item.id === id) return item
|
|
146
|
+
if (Array.isArray(item.children)) {
|
|
147
|
+
const hit = findMenuNode(item.children, id)
|
|
148
|
+
if (hit) return hit
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return null
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** 从根到目标 id 的路径(用于键盘导航与面包屑式展开)。 */
|
|
155
|
+
export function menuPath(items, id, trail) {
|
|
156
|
+
const base = Array.isArray(trail) ? trail : []
|
|
157
|
+
for (const item of Array.isArray(items) ? items : []) {
|
|
158
|
+
if (!item) continue
|
|
159
|
+
const next = base.concat([item])
|
|
160
|
+
if (item.id === id) return next
|
|
161
|
+
if (Array.isArray(item.children)) {
|
|
162
|
+
const hit = menuPath(item.children, id, next)
|
|
163
|
+
if (hit) return hit
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return null
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** 把 action 折成 hash(route 类)。 */
|
|
170
|
+
export function actionHash(action) {
|
|
171
|
+
if (!action || action.kind !== 'route') return ''
|
|
172
|
+
const q = action.query ? (action.hash.indexOf('?') >= 0 ? '&' : '?') + action.query : ''
|
|
173
|
+
return action.hash + q
|
|
174
|
+
}
|