From d3f0d23a5b2a31b42e3edbec3239c6d589536167 Mon Sep 17 00:00:00 2001 From: wb-fc932227 Date: Fri, 20 Oct 2023 17:18:19 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=94=AF=E6=8C=81v3=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/app-card-ui/package.json | 10 +- .../src/components/readme/index.tsx | 120 ++++++++++++++---- 2 files changed, 105 insertions(+), 25 deletions(-) diff --git a/packages/app-card-ui/package.json b/packages/app-card-ui/package.json index 184914a..73f7805 100644 --- a/packages/app-card-ui/package.json +++ b/packages/app-card-ui/package.json @@ -1,6 +1,6 @@ { "name": "@serverless-cd/app-card-ui", - "version": "0.0.8", + "version": "0.0.9", "scripts": { "start": "dumi dev", "docs:build": "dumi build", @@ -38,9 +38,13 @@ "access": "public" }, "devDependencies": { + "@alicloud/console-components": ">=1.0.0", + "@types/jest": "^29.5.6", "@types/qs": "^6.9.7", "dumi": "^1.1.0", - "father": "^4.0.0-rc.2" + "father": "^4.0.0-rc.2", + "moment": "^2.29.4", + "styled-components": "^6.1.0" }, "repository": "git@github.com:g-fengchen/ui.git" -} \ No newline at end of file +} diff --git a/packages/app-card-ui/src/components/readme/index.tsx b/packages/app-card-ui/src/components/readme/index.tsx index 504977e..71a2113 100644 --- a/packages/app-card-ui/src/components/readme/index.tsx +++ b/packages/app-card-ui/src/components/readme/index.tsx @@ -1,16 +1,22 @@ -import React, { FC, useState, PropsWithChildren } from 'react'; +import { + Balloon, + Button, + Icon, + Loading, + Message, +} from '@alicloud/console-components'; import { SlidePanel } from '@alicloud/console-components-slide-panel'; -import { Loading, Balloon, Message, Button, Icon } from '@alicloud/console-components'; -import Nav, { NavKey } from './Nav'; -import ExternalLink from './ExternalLink'; -import ReactMarkdown from './ReactMarkdown'; -import GithubIcon from './GithubIcon'; import { parseReadme } from '@serverless-cd/ui-help'; -import { i18n, copyText, lang } from '../../utils'; import axios from 'axios'; +import { find, get, isEmpty, isFunction, map } from 'lodash'; import qs from 'qs'; -import { get, isEmpty, map, find, isFunction } from 'lodash'; -import { IApiTypeVal, IApiType } from '../../types'; +import React, { FC, PropsWithChildren, useState } from 'react'; +import { IApiType, IApiTypeVal } from '../../types'; +import { copyText, i18n, lang } from '../../utils'; +import ExternalLink from './ExternalLink'; +import GithubIcon from './GithubIcon'; +import Nav, { NavKey } from './Nav'; +import ReactMarkdown from './ReactMarkdown'; function copy(val) { copyText(val); @@ -32,6 +38,7 @@ export type Props = PropsWithChildren & { visible?: boolean; env?: 'vscode' | 'web'; fetchReadme?: () => Promise; + isV3?: boolean; }; const AliReadme: FC = (props) => { @@ -46,11 +53,13 @@ const AliReadme: FC = (props) => { activeTab, fetchReadme, visible: readmeVisible = false, + isV3 = false, } = props; const [visible, setVisible] = useState(readmeVisible); const [loading, setLoading] = useState(false); const [readmeInfo, setReadmeInfo] = useState({}); + const fetchApps = async () => { try { const result = await axios({ @@ -85,8 +94,7 @@ const AliReadme: FC = (props) => { const fetchData = async () => { setLoading(true); - const [app, content] = await Promise.all([fetchApps(), fetchContent()]); - const appInfo = find(app, (item) => item.package === name); + const [content, appInfo] = isV3 ? await fetchV3(name) : await fetchV2(name); if (content.match(/(?=)/)) { const data = parseReadme(content); setReadmeInfo({ @@ -102,6 +110,42 @@ const AliReadme: FC = (props) => { setLoading(false); }; + const fetchV3 = async (name) => { + const { version = {}, package: app = {} } = await getAppV3(name); + if (!isEmpty(version)) return [version.readme, app]; + else [] + }; + + const fetchV2 = async (name) => { + const [app, content] = await Promise.all([fetchApps(), fetchContent()]); + const appInfo = find(app, (item) => item.package === name); + return [content, appInfo] + }; + + const getAppV3 = async (projectName) => { + try { + const result = await axios({ + method: 'get', + url: `https://api.devsapp.cn/v3/console/project/${projectName}?lang=${lang()}`, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }); + const Response = get(result, 'data.body', {}); + + return { + ...Response, + package: { + ...get(Response, 'package', {}), + package: get(Response, 'package.name'), + title: Response.name, + }, + }; + } catch (e) { + return {}; + } + }; + const doFetchReadme = async () => { setLoading(true); try { @@ -199,7 +243,9 @@ const AliReadme: FC = (props) => { }; const renderBody = () => { if (loading) { - return ; + return ( + + ); } // 兼容旧模版 if (typeof readmeInfo === 'string') { @@ -208,8 +254,14 @@ const AliReadme: FC = (props) => { return (