diff --git a/app/admin/controller/docs/Doc36ZiHuaMobileApi.php b/app/admin/controller/docs/Doc36ZiHuaMobileApi.php new file mode 100644 index 0000000..a18a90f --- /dev/null +++ b/app/admin/controller/docs/Doc36ZiHuaMobileApi.php @@ -0,0 +1,77 @@ +initializeBackend($request); + if ($response !== null) { + return $response; + } + + $path = $this->docAbsolutePath(); + if (!is_file($path)) { + return $this->error(__('Document file not found')); + } + + $raw = file_get_contents($path); + if ($raw === false) { + return $this->error(__('Failed to read document')); + } + + return $this->success('', [ + 'markdown' => $raw, + 'filename' => '36字花-移动端接口设计草案.md', + ]); + } + + public function download(Request $request): Response + { + $response = $this->initializeBackend($request); + if ($response !== null) { + return $response; + } + + $path = $this->docAbsolutePath(); + if (!is_file($path)) { + return $this->error(__('Document file not found')); + } + + $body = file_get_contents($path); + if ($body === false) { + return $this->error(__('Failed to read document')); + } + + $utf8Name = '36字花-移动端接口设计草案.md'; + $asciiFallback = '36zihua-mobile-api-design-draft.md'; + $disposition = sprintf( + 'attachment; filename="%s"; filename*=UTF-8\'\'%s', + $asciiFallback, + rawurlencode($utf8Name) + ); + + return new Response(200, [ + 'Content-Type' => 'text/markdown; charset=UTF-8', + 'Content-Disposition' => $disposition, + 'Cache-Control' => 'private, max-age=0, must-revalidate', + ], $body); + } + + private function docAbsolutePath(): string + { + return rtrim(base_path(), DIRECTORY_SEPARATOR . '/') . DIRECTORY_SEPARATOR . self::DOC_RELATIVE; + } +} diff --git a/app/admin/lang/en.php b/app/admin/lang/en.php index c60ea01..1518b42 100644 --- a/app/admin/lang/en.php +++ b/app/admin/lang/en.php @@ -96,4 +96,6 @@ return [ 'Please input correct username' => 'Please enter the correct username', 'Please enter a valid commission rate for non-top role group' => 'Non-top role groups require a commission rate between 0 and 100 (%)', 'Group Name Arr' => 'Group Name Arr', + 'Document file not found' => 'Document file not found', + 'Failed to read document' => 'Failed to read document', ]; \ No newline at end of file diff --git a/app/admin/lang/zh-cn.php b/app/admin/lang/zh-cn.php index ca6d866..4ed359f 100644 --- a/app/admin/lang/zh-cn.php +++ b/app/admin/lang/zh-cn.php @@ -115,4 +115,6 @@ return [ 'Please input correct username' => '请输入正确的用户名', 'Please enter a valid commission rate for non-top role group' => '非顶级角色组须填写 0~100 的分红比例(%)', 'Group Name Arr' => '分组名称数组', + 'Document file not found' => '文档文件不存在', + 'Failed to read document' => '读取文档失败', ]; \ No newline at end of file diff --git a/app/common/lang/en/admin_rule_title.php b/app/common/lang/en/admin_rule_title.php index 68f76c5..e4e07bc 100644 --- a/app/common/lang/en/admin_rule_title.php +++ b/app/common/lang/en/admin_rule_title.php @@ -124,4 +124,12 @@ return [ // 其它中文按钮文案 '期号开关' => 'Period toggle', '手动创建下一期' => 'Create next period manually', + + // Markdown 文档目录 + 'Markdown文档' => 'Markdown documents', + + // 文档:36字花移动端接口草案 + '36字花移动端接口文档' => '36 Zihua mobile API design draft', + '拉取正文' => 'Load document body', + '下载 Markdown' => 'Download Markdown', ]; diff --git a/web/package.json b/web/package.json index 1885725..b958c78 100644 --- a/web/package.json +++ b/web/package.json @@ -19,6 +19,7 @@ "element-plus": "2.9.1", "font-awesome": "4.7.0", "lodash-es": "4.17.21", + "marked": "9.1.6", "mitt": "3.0.1", "nprogress": "0.2.0", "pinia": "2.3.0", diff --git a/web/src/lang/backend/en.ts b/web/src/lang/backend/en.ts index 293704a..d70ea5c 100644 --- a/web/src/lang/backend/en.ts +++ b/web/src/lang/backend/en.ts @@ -85,6 +85,12 @@ export default { 'Newly added tasks will never start because they are blocked by failed tasks!(Web terminal)', 'Failed to modify the source command, Please try again manually': 'Failed to modify the source command. Please try again manually.', }, + docs36ziMobileApi: { + download: 'Download Markdown', + load_fail: 'Failed to load document', + doc_title: '36 Zihua Mobile API Design Draft', + nav_outline: 'Outline', + }, vite: { Later: '稍后', 'Restart hot update': '重启热更新', diff --git a/web/src/lang/backend/zh-cn.ts b/web/src/lang/backend/zh-cn.ts index 031c5f3..c04c136 100644 --- a/web/src/lang/backend/zh-cn.ts +++ b/web/src/lang/backend/zh-cn.ts @@ -85,6 +85,12 @@ export default { 'Newly added tasks will never start because they are blocked by failed tasks': '新添加的任务永远不会开始,因为被失败的任务阻塞!(WEB终端)', 'Failed to modify the source command, Please try again manually': '修改源的命令执行失败,请手动重试。', }, + docs36ziMobileApi: { + download: '下载 Markdown', + load_fail: '文档加载失败', + doc_title: '36字花移动端接口设计草案', + nav_outline: '目录', + }, vite: { Later: '稍后', 'Restart hot update': '重启热更新', diff --git a/web/src/views/backend/docs/doc36ZiHuaMobileApi/index.vue b/web/src/views/backend/docs/doc36ZiHuaMobileApi/index.vue new file mode 100644 index 0000000..5de2edb --- /dev/null +++ b/web/src/views/backend/docs/doc36ZiHuaMobileApi/index.vue @@ -0,0 +1,279 @@ + + + + + + {{ pageTitle }} + {{ t('docs36ziMobileApi.download') }} + + + {{ loadError }} + + + + + {{ t('docs36ziMobileApi.nav_outline') }} + + + + {{ + item.text + }} + + + + + + + + + + + + + + + + +