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,396 @@
|
|
|
1
|
+
// import.jsx — 导入导出 + 代码生成页(Apifox 工作台:导入卡片 + 导出按钮组 + 结果 pre)
|
|
2
|
+
// 自注册:模块求值期入队 __postapiQueue
|
|
3
|
+
// 数据:api.import.{openapi,postman,har,curl} / api.export.{openapi,postman,har,markdown} / api.codegen.run
|
|
4
|
+
// 失败页面内显示错误文案(不弹窗);结果统一渲染到可复制的 pre 块
|
|
5
|
+
// 视觉基线:docs/apifox-design-spec.md —— .pp-card / .pp-btn 按钮组 / .pp-pre / .pp-select
|
|
6
|
+
import React, { useEffect, useRef, useState } from 'react'
|
|
7
|
+
import { applyTheme } from './theme.js'
|
|
8
|
+
|
|
9
|
+
;(window.__postapiQueue = window.__postapiQueue || []).push(['import', ImportPage]) // 注册表就绪前入队
|
|
10
|
+
|
|
11
|
+
/** 顶部页签(Apifox「导入导出数据」把导入 / 导出分成两页,代码生成单列一块) */
|
|
12
|
+
const IO_TABS = [
|
|
13
|
+
{ id: 'import', label: '导入' },
|
|
14
|
+
{ id: 'export', label: '导出' },
|
|
15
|
+
{ id: 'codegen', label: '代码生成' },
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
/** 占位提示:用数组 join 构造多行文本,避免在源码里出现裸换行 */
|
|
19
|
+
const PH_OPENAPI = ['{', ' "openapi": "3.0.0",', ' "info": { "title": "示例", "version": "1.0.0" },', ' "paths": {}', '}'].join('\n')
|
|
20
|
+
const PH_POSTMAN = ['{', ' "info": { "name": "示例" },', ' "item": []', '}'].join('\n')
|
|
21
|
+
const PH_HAR = ['{', ' "log": { "version": "1.2", "entries": [] }', '}'].join('\n')
|
|
22
|
+
const PH_CURL = "curl -X GET 'https://api.example.com/pets' -H 'Accept: application/json'"
|
|
23
|
+
|
|
24
|
+
const IMPORT_KINDS = [
|
|
25
|
+
{ id: 'openapi', label: 'OpenAPI / Swagger', hint: '粘贴 OpenAPI 3 或 Swagger 2 JSON/YAML 文本', placeholder: PH_OPENAPI },
|
|
26
|
+
{ id: 'postman', label: 'Postman', hint: '粘贴 Postman Collection v2.1 JSON 文本', placeholder: PH_POSTMAN },
|
|
27
|
+
{ id: 'har', label: 'HAR', hint: '粘贴浏览器导出的 HAR JSON 文本', placeholder: PH_HAR },
|
|
28
|
+
{ id: 'curl', label: 'cURL', hint: '粘贴 cURL 命令(可多条,逐行)', placeholder: PH_CURL },
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
const EXPORT_KINDS = [
|
|
32
|
+
{ id: 'openapi', label: 'OpenAPI 3', hint: '标准 OpenAPI 3.0 文档' },
|
|
33
|
+
{ id: 'postman', label: 'Postman', hint: 'Postman Collection v2.1' },
|
|
34
|
+
{ id: 'har', label: 'HAR', hint: 'HTTP Archive 1.2' },
|
|
35
|
+
{ id: 'markdown', label: 'Markdown', hint: '可读文档' },
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
const LANGS = [
|
|
39
|
+
{ id: 'curl', label: 'cURL' },
|
|
40
|
+
{ id: 'fetch', label: 'JavaScript fetch' },
|
|
41
|
+
{ id: 'axios', label: 'JavaScript axios' },
|
|
42
|
+
{ id: 'python', label: 'Python requests' },
|
|
43
|
+
{ id: 'go', label: 'Go net/http' },
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const MOCK_CURL = "curl -X GET 'https://api.example.test/api/v1/orders?page=1' -H 'Accept: application/json'"
|
|
47
|
+
|
|
48
|
+
const MOCK_ENDPOINT = {
|
|
49
|
+
id: 'ep_1001', name: '查询订单列表', method: 'GET', url: 'https://api.example.test/api/v1/orders',
|
|
50
|
+
params: [{ key: 'page', value: '1', enabled: true }],
|
|
51
|
+
headers: [{ key: 'Accept', value: 'application/json', enabled: true }],
|
|
52
|
+
body: { type: 'none', content: '' },
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 结果文本化:字符串原样、对象 JSON 美化(页面 pre 与复制共用)。 */
|
|
56
|
+
export function resultText(value) {
|
|
57
|
+
if (value === undefined || value === null) return ''
|
|
58
|
+
if (typeof value === 'string') return value
|
|
59
|
+
try {
|
|
60
|
+
return JSON.stringify(value, null, 2)
|
|
61
|
+
} catch {
|
|
62
|
+
return String(value)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 导入结果摘要:把各 importer 返回结构折算成统一计数。 */
|
|
67
|
+
export function importSummary(res) {
|
|
68
|
+
const data = res && res.data !== undefined ? res.data : res
|
|
69
|
+
if (!data || typeof data !== 'object') return { endpoints: 0, folders: 0, schemas: 0 }
|
|
70
|
+
const count = (v) => (Array.isArray(v) ? v.length : 0)
|
|
71
|
+
return {
|
|
72
|
+
endpoints: count(data.endpoints),
|
|
73
|
+
folders: count(data.folders),
|
|
74
|
+
schemas: count(data.schemas),
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function errText(err) {
|
|
79
|
+
return err && err.message ? err.message : String(err)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function ImportPage(props) {
|
|
83
|
+
const rootRef = useRef(null)
|
|
84
|
+
const api = (props && props.api) || (typeof window !== 'undefined' ? window.__postapiApi : undefined)
|
|
85
|
+
const storage = api && api.storage
|
|
86
|
+
const [projects, setProjects] = useState([{ id: 'proj_demo01', name: '订单中心' }])
|
|
87
|
+
const [projectId, setProjectId] = useState('proj_demo01')
|
|
88
|
+
const [isMock, setIsMock] = useState(true)
|
|
89
|
+
const [error, setError] = useState('')
|
|
90
|
+
const [notice, setNotice] = useState('')
|
|
91
|
+
const [ioTab, setIoTab] = useState('import')
|
|
92
|
+
const [importKind, setImportKind] = useState('openapi')
|
|
93
|
+
const [importText, setImportText] = useState(MOCK_CURL)
|
|
94
|
+
const [importOut, setImportOut] = useState('')
|
|
95
|
+
// 最近一次导入的 bundle(folders/endpoints/schemas 骨架),供「保存到项目」真正落盘
|
|
96
|
+
const [bundle, setBundle] = useState(null)
|
|
97
|
+
const [exportKind, setExportKind] = useState('openapi')
|
|
98
|
+
const [exportOut, setExportOut] = useState('')
|
|
99
|
+
const [lang, setLang] = useState('curl')
|
|
100
|
+
const [codeOut, setCodeOut] = useState('')
|
|
101
|
+
const [busy, setBusy] = useState(false)
|
|
102
|
+
|
|
103
|
+
useEffect(() => applyTheme(rootRef.current), [])
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const boot = async () => {
|
|
107
|
+
if (!storage || typeof storage.listProjects !== 'function') return
|
|
108
|
+
try {
|
|
109
|
+
const list = await storage.listProjects()
|
|
110
|
+
if (Array.isArray(list) && list.length > 0) {
|
|
111
|
+
setProjects(list)
|
|
112
|
+
setProjectId(list[0].id)
|
|
113
|
+
setIsMock(false)
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
setError('加载项目列表失败:' + errText(err))
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
boot()
|
|
120
|
+
}, [])
|
|
121
|
+
|
|
122
|
+
const pickImportKind = (id) => {
|
|
123
|
+
setImportKind(id)
|
|
124
|
+
setImportOut('')
|
|
125
|
+
setBundle(null)
|
|
126
|
+
setError('')
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const runImport = async () => {
|
|
130
|
+
const fn = api && api.import && api.import[importKind]
|
|
131
|
+
if (typeof fn !== 'function') {
|
|
132
|
+
setError('当前桥未提供 api.import.' + importKind + '(契约 §5 POST /import/' + importKind + ')')
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
const raw = String(importText || '')
|
|
136
|
+
if (!raw.trim()) {
|
|
137
|
+
setError('导入内容为空')
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
// 桥签名:curl 接字符串(api.import.curl(text)),其余三种接已解析的 JSON 对象。
|
|
141
|
+
let payload = raw
|
|
142
|
+
if (importKind !== 'curl') {
|
|
143
|
+
try {
|
|
144
|
+
payload = JSON.parse(raw)
|
|
145
|
+
} catch (err) {
|
|
146
|
+
setError('导入内容不是合法 JSON:' + errText(err))
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
setBusy(true)
|
|
151
|
+
setError('')
|
|
152
|
+
setImportOut('')
|
|
153
|
+
setBundle(null)
|
|
154
|
+
try {
|
|
155
|
+
const res = await fn(payload)
|
|
156
|
+
const summary = importSummary(res)
|
|
157
|
+
setImportOut(resultText(res))
|
|
158
|
+
// 解析结果留在页面里;点「保存到项目」才真正写盘(纯本地,不涉及云端)
|
|
159
|
+
setBundle(res && res.data !== undefined ? res.data : res)
|
|
160
|
+
setNotice('解析完成:接口 ' + summary.endpoints + ' 条 / 目录 ' + summary.folders + ' 个 / 模型 ' + summary.schemas + ' 个,点「保存到项目」写入当前项目')
|
|
161
|
+
} catch (err) {
|
|
162
|
+
setError('导入失败:' + errText(err))
|
|
163
|
+
} finally {
|
|
164
|
+
setBusy(false)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** 把上一次导入的骨架真正落盘:storage.importBundle 单次原子写入。 */
|
|
169
|
+
const saveImport = async () => {
|
|
170
|
+
if (!bundle || typeof bundle !== 'object') {
|
|
171
|
+
setError('还没有可保存的导入结果,先点「开始导入」')
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
if (!storage || typeof storage.importBundle !== 'function') {
|
|
175
|
+
setError('当前桥未提供 api.storage.importBundle(契约 §5 POST /storage/importBundle)')
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
setBusy(true)
|
|
179
|
+
setError('')
|
|
180
|
+
try {
|
|
181
|
+
const res = await storage.importBundle(projectId, bundle)
|
|
182
|
+
const written = res && typeof res === 'object' ? res : {}
|
|
183
|
+
const num = (v) => (typeof v === 'number' ? v : 0)
|
|
184
|
+
setNotice('已保存到项目:目录 ' + num(written.folders) + ' 个 / 接口 ' + num(written.endpoints) + ' 个 / 模型 ' + num(written.schemas) + ' 个')
|
|
185
|
+
} catch (err) {
|
|
186
|
+
setError('保存失败:' + errText(err))
|
|
187
|
+
} finally {
|
|
188
|
+
setBusy(false)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const runExport = async (kind) => {
|
|
193
|
+
const id = kind || exportKind
|
|
194
|
+
const fn = api && api.export && api.export[id]
|
|
195
|
+
if (typeof fn !== 'function') {
|
|
196
|
+
setError('当前桥未提供 api.export.' + id + '(契约 §5 POST /export/' + id + ')')
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
if (!storage || typeof storage.getProject !== 'function') {
|
|
200
|
+
setError('导出需要先读取项目:当前桥未提供 api.storage.getProject')
|
|
201
|
+
return
|
|
202
|
+
}
|
|
203
|
+
setBusy(true)
|
|
204
|
+
setError('')
|
|
205
|
+
setExportOut('')
|
|
206
|
+
try {
|
|
207
|
+
// 桥签名:export.<kind>(project) 接项目对象(不是 projectId),故先读盘再导出。
|
|
208
|
+
const project = await storage.getProject(projectId)
|
|
209
|
+
const res = await fn(project)
|
|
210
|
+
setExportKind(id)
|
|
211
|
+
setExportOut(resultText(res))
|
|
212
|
+
setNotice('导出完成:' + id)
|
|
213
|
+
} catch (err) {
|
|
214
|
+
setError('导出失败:' + errText(err))
|
|
215
|
+
} finally {
|
|
216
|
+
setBusy(false)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const runCodegen = async () => {
|
|
221
|
+
if (!api || !api.codegen || typeof api.codegen.run !== 'function') {
|
|
222
|
+
setError('当前桥未提供 api.codegen.run(契约 §5 POST /codegen/run)')
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
setBusy(true)
|
|
226
|
+
setError('')
|
|
227
|
+
setCodeOut('')
|
|
228
|
+
try {
|
|
229
|
+
// 桥签名:codegen.run({ endpoint, env, lang }),返回生成后的代码字符串。
|
|
230
|
+
const res = await api.codegen.run({ endpoint: MOCK_ENDPOINT, lang })
|
|
231
|
+
setCodeOut(resultText(res))
|
|
232
|
+
setNotice('代码生成完成:' + lang)
|
|
233
|
+
} catch (err) {
|
|
234
|
+
setError('代码生成失败:' + errText(err))
|
|
235
|
+
} finally {
|
|
236
|
+
setBusy(false)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const copy = async (text, label) => {
|
|
241
|
+
if (!text) {
|
|
242
|
+
setError('没有可复制的内容(先执行一次)')
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
|
|
247
|
+
await navigator.clipboard.writeText(text)
|
|
248
|
+
setNotice(label + '已复制到剪贴板')
|
|
249
|
+
} else {
|
|
250
|
+
setError('当前环境无剪贴板权限,请手动选中下方文本复制')
|
|
251
|
+
}
|
|
252
|
+
} catch (err) {
|
|
253
|
+
setError('复制失败:' + errText(err))
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const currentImport = IMPORT_KINDS.find((k) => k.id === importKind) || IMPORT_KINDS[0]
|
|
258
|
+
const currentExport = EXPORT_KINDS.find((k) => k.id === exportKind) || EXPORT_KINDS[0]
|
|
259
|
+
const currentLang = LANGS.find((l) => l.id === lang) || LANGS[0]
|
|
260
|
+
|
|
261
|
+
return (
|
|
262
|
+
<div className="pp-scope pp-page" data-page="import" ref={rootRef}>
|
|
263
|
+
<div className="pp-overview-head">
|
|
264
|
+
<span className="pp-overview-title">导入导出与代码生成</span>
|
|
265
|
+
<div className="pp-overview-actions">
|
|
266
|
+
<label className="pp-meta">项目</label>
|
|
267
|
+
<select className="pp-select" value={projectId} onChange={(e) => setProjectId(e.target.value)}>
|
|
268
|
+
{projects.map((p) => <option key={p.id} value={p.id}>{p.name || p.id}</option>)}
|
|
269
|
+
</select>
|
|
270
|
+
</div>
|
|
271
|
+
</div>
|
|
272
|
+
<div className="pp-overview-content">
|
|
273
|
+
<div className="pp-toolbar">
|
|
274
|
+
<span className="pp-meta">
|
|
275
|
+
{isMock ? '示例数据 — api 桥不可用,操作按钮会提示缺失的方法' : '数据来源:api.import / api.export / api.codegen'}
|
|
276
|
+
</span>
|
|
277
|
+
</div>
|
|
278
|
+
{error ? <p className="pp-error-text">{error}</p> : null}
|
|
279
|
+
{notice ? <p className="pp-muted">{notice}</p> : null}
|
|
280
|
+
|
|
281
|
+
{/* Apifox 导入导出同构:顶部页签分区(导入 / 导出 / 代码生成),
|
|
282
|
+
每区「左格式列表 + 右内容」。原来「导入 + 导出」两列并排各占 240px,
|
|
283
|
+
textarea 与按钮组都被压到换行;代码生成又单独占一整张卡,三块高度参差。 */}
|
|
284
|
+
<div className="pp-io-layout">
|
|
285
|
+
<div className="pp-tabs">
|
|
286
|
+
{IO_TABS.map((t) => (
|
|
287
|
+
<button key={t.id} className="pp-tab" data-active={ioTab === t.id ? 'true' : 'false'}
|
|
288
|
+
onClick={() => setIoTab(t.id)}>{t.label}</button>
|
|
289
|
+
))}
|
|
290
|
+
</div>
|
|
291
|
+
|
|
292
|
+
<div className="pp-io-body">
|
|
293
|
+
<nav className="pp-io-side" aria-label={ioTab === 'export' ? '导出格式' : ioTab === 'codegen' ? '目标语言' : '导入格式'}>
|
|
294
|
+
{ioTab === 'import' ? (
|
|
295
|
+
<>
|
|
296
|
+
<div className="pp-io-side-title">导入来源</div>
|
|
297
|
+
{IMPORT_KINDS.map((k) => (
|
|
298
|
+
<button key={k.id} className="pp-io-item" data-active={importKind === k.id ? 'true' : 'false'}
|
|
299
|
+
onClick={() => pickImportKind(k.id)}>{k.label}</button>
|
|
300
|
+
))}
|
|
301
|
+
</>
|
|
302
|
+
) : null}
|
|
303
|
+
{ioTab === 'export' ? (
|
|
304
|
+
<>
|
|
305
|
+
<div className="pp-io-side-title">导出格式</div>
|
|
306
|
+
{EXPORT_KINDS.map((k) => (
|
|
307
|
+
<button key={k.id} className="pp-io-item" data-active={exportKind === k.id ? 'true' : 'false'}
|
|
308
|
+
onClick={() => setExportKind(k.id)}>{k.label}</button>
|
|
309
|
+
))}
|
|
310
|
+
</>
|
|
311
|
+
) : null}
|
|
312
|
+
{ioTab === 'codegen' ? (
|
|
313
|
+
<>
|
|
314
|
+
<div className="pp-io-side-title">目标语言</div>
|
|
315
|
+
{LANGS.map((l) => (
|
|
316
|
+
<button key={l.id} className="pp-io-item" data-active={lang === l.id ? 'true' : 'false'}
|
|
317
|
+
onClick={() => setLang(l.id)}>{l.label}</button>
|
|
318
|
+
))}
|
|
319
|
+
</>
|
|
320
|
+
) : null}
|
|
321
|
+
</nav>
|
|
322
|
+
|
|
323
|
+
<div className="pp-io-main">
|
|
324
|
+
{ioTab === 'import' ? (
|
|
325
|
+
<>
|
|
326
|
+
<div className="pp-io-head">
|
|
327
|
+
<span className="pp-io-title">{currentImport.label}</span>
|
|
328
|
+
<button className="pp-btn pp-btn-sm" onClick={() => setImportText('')} disabled={busy || !importText}>
|
|
329
|
+
清空
|
|
330
|
+
</button>
|
|
331
|
+
</div>
|
|
332
|
+
<div className="pp-note">{currentImport.hint}</div>
|
|
333
|
+
<textarea className="pp-textarea pp-io-input" rows={10} value={importText}
|
|
334
|
+
placeholder={currentImport.placeholder}
|
|
335
|
+
onChange={(e) => setImportText(e.target.value)} />
|
|
336
|
+
<div className="pp-toolbar-inline" style={{ marginTop: 'var(--sp-3)' }}>
|
|
337
|
+
<button className="pp-btn pp-btn-primary" onClick={runImport} disabled={busy}>开始导入</button>
|
|
338
|
+
<button className="pp-btn" onClick={saveImport} disabled={busy || !bundle}>保存到项目</button>
|
|
339
|
+
<button className="pp-btn" onClick={() => copy(importOut, '导入结果')} disabled={!importOut}>复制结果</button>
|
|
340
|
+
</div>
|
|
341
|
+
{bundle ? (
|
|
342
|
+
<div className="pp-io-stats">
|
|
343
|
+
<span className="pp-pill pp-pill-ok">已解析</span>
|
|
344
|
+
<span className="pp-meta">接口 {importSummary(bundle).endpoints} 条</span>
|
|
345
|
+
<span className="pp-meta">目录 {importSummary(bundle).folders} 个</span>
|
|
346
|
+
<span className="pp-meta">模型 {importSummary(bundle).schemas} 个</span>
|
|
347
|
+
</div>
|
|
348
|
+
) : null}
|
|
349
|
+
{importOut ? <pre className="pp-pre pp-pre-scroll pp-io-pre">{importOut}</pre> : null}
|
|
350
|
+
</>
|
|
351
|
+
) : null}
|
|
352
|
+
|
|
353
|
+
{ioTab === 'export' ? (
|
|
354
|
+
<>
|
|
355
|
+
<div className="pp-io-head">
|
|
356
|
+
<span className="pp-io-title">{currentExport.label}</span>
|
|
357
|
+
<span className="pp-meta">{currentExport.hint}</span>
|
|
358
|
+
</div>
|
|
359
|
+
<div className="pp-note">导出读取当前项目对象后交给 api.export,结果可直接复制或另存。</div>
|
|
360
|
+
<div className="pp-toolbar-inline" style={{ marginTop: 'var(--sp-3)' }}>
|
|
361
|
+
<button className="pp-btn pp-btn-primary" onClick={() => runExport(exportKind)} disabled={busy}>
|
|
362
|
+
导出 {currentExport.label}
|
|
363
|
+
</button>
|
|
364
|
+
<button className="pp-btn" onClick={() => copy(exportOut, '导出结果')} disabled={!exportOut}>复制结果</button>
|
|
365
|
+
</div>
|
|
366
|
+
<div className="pp-meta" style={{ marginTop: 'var(--sp-2)' }}>
|
|
367
|
+
当前项目:{projectId} · 格式:{exportKind}
|
|
368
|
+
</div>
|
|
369
|
+
{exportOut ? <pre className="pp-pre pp-pre-scroll pp-io-pre">{exportOut}</pre> : null}
|
|
370
|
+
</>
|
|
371
|
+
) : null}
|
|
372
|
+
|
|
373
|
+
{ioTab === 'codegen' ? (
|
|
374
|
+
<>
|
|
375
|
+
<div className="pp-io-head">
|
|
376
|
+
<span className="pp-io-title">{currentLang.label}</span>
|
|
377
|
+
</div>
|
|
378
|
+
<div className="pp-io-sample">
|
|
379
|
+
<span className="pp-meta">示例接口</span>
|
|
380
|
+
<span className="pp-method" data-method={MOCK_ENDPOINT.method}>{MOCK_ENDPOINT.method}</span>
|
|
381
|
+
<span className="pp-mono pp-ellipsis">{MOCK_ENDPOINT.url}</span>
|
|
382
|
+
</div>
|
|
383
|
+
<div className="pp-toolbar-inline" style={{ marginTop: 'var(--sp-3)' }}>
|
|
384
|
+
<button className="pp-btn pp-btn-primary" onClick={runCodegen} disabled={busy}>生成代码</button>
|
|
385
|
+
<button className="pp-btn" onClick={() => copy(codeOut, '生成代码')} disabled={!codeOut}>复制代码</button>
|
|
386
|
+
</div>
|
|
387
|
+
{codeOut ? <pre className="pp-pre pp-pre-scroll pp-io-pre">{codeOut}</pre> : null}
|
|
388
|
+
</>
|
|
389
|
+
) : null}
|
|
390
|
+
</div>
|
|
391
|
+
</div>
|
|
392
|
+
</div>
|
|
393
|
+
</div>
|
|
394
|
+
</div>
|
|
395
|
+
)
|
|
396
|
+
}
|