@@ -84,6 +95,41 @@ const CommonCard = ({
{authorName}
+
+
+
+ )
+}
+
+interface LoadMoreCardProps {
+ onClick: () => void
+}
+
+const LoadMoreCard = ({ onClick }: LoadMoreCardProps) => {
+ const cardRef = useRef
(null)
+
+ useEffect(() => {
+ cardRef.current &&
+ VanillaTilt.init(cardRef.current, {
+ reverse: true,
+ max: 8,
+ glare: true,
+ ['max-glare']: 0.3,
+ scale: 1.03
+ })
+ }, [])
+
+ return (
+
+
+
+ {' '}
+
+ 加载更多
)
@@ -91,24 +137,31 @@ const CommonCard = ({
const Store = () => {
const [isLoading, setIsLoading] = useState(false)
- const [currentPage, setCurrentPage] = useState(1)
+ const [currentPage, setCurrentPage] = useState(0)
const [hasNextPage, setHasNextPage] = useState(true)
- const [toolData, setToolData] = useState()
+ const [toolData, setToolData] = useState([])
- const getTool = () => {
+ const getTool = (page: number) => {
if (isLoading) {
return
}
setIsLoading(true)
void message.loading({ content: '加载工具列表中', key: 'LOADING', duration: 0 })
- void r_tool_store_get({ currentPage })
+ void r_tool_store_get({ currentPage: page })
.then((res) => {
const response = res.data
switch (response.code) {
case DATABASE_SELECT_SUCCESS:
- setToolData(response.data?.records)
+ setCurrentPage(page)
+ setToolData([...toolData, ...response.data!.records])
+ if (response.data?.current === response.data?.pages) {
+ setHasNextPage(false)
+ }
+ break
+ default:
+ void message.error('加载失败,请稍后重试')
}
})
.finally(() => {
@@ -117,13 +170,20 @@ const Store = () => {
})
}
+ const handleOnLoadMore = () => {
+ if (isLoading) {
+ return
+ }
+ getTool(currentPage + 1)
+ }
+
useEffect(() => {
- getTool()
+ getTool(1)
}, [])
return (
<>
-
+
{toolData?.map((value) => (
@@ -136,13 +196,15 @@ const Store = () => {
}
toolName={value.name}
toolId={value.toolId}
- url={''}
+ toolDesc={value.description}
+ url={`/view/${value.author.username}/${value.toolId}`}
authorName={value.author.userInfo.nickname}
authorAvatar={value.author.userInfo.avatar}
authorUsername={value.author.username}
ver={value.ver}
/>
))}
+ {hasNextPage && }
diff --git a/src/pages/Tools/View.tsx b/src/pages/Tools/View.tsx
index 7f15644..2e1c0f6 100644
--- a/src/pages/Tools/View.tsx
+++ b/src/pages/Tools/View.tsx
@@ -16,22 +16,32 @@ const View = () => {
const [compiledCode, setCompiledCode] = useState('')
const render = (toolVo: ToolVo) => {
- try {
- const baseDist = base64ToStr(toolVo.base.dist.data!)
- const files = base64ToFiles(toolVo.source.data!)
- const importMap = JSON.parse(files[IMPORT_MAP_FILE_NAME].value) as IImportMap
+ if (username === '!') {
+ try {
+ const baseDist = base64ToStr(toolVo.base.dist.data!)
+ const files = base64ToFiles(toolVo.source.data!)
+ const importMap = JSON.parse(files[IMPORT_MAP_FILE_NAME].value) as IImportMap
- void compiler
- .compile(files, importMap, toolVo.entryPoint)
- .then((result) => {
- const output = result.outputFiles[0].text
- setCompiledCode(`${output}\n${baseDist}`)
- })
- .catch((reason) => {
- void message.error(`编译失败:${reason}`)
- })
- } catch (e) {
- void message.error('载入工具失败')
+ void compiler
+ .compile(files, importMap, toolVo.entryPoint)
+ .then((result) => {
+ const output = result.outputFiles[0].text
+ setCompiledCode(`${output}\n${baseDist}`)
+ })
+ .catch((reason) => {
+ void message.error(`编译失败:${reason}`)
+ })
+ } catch (e) {
+ void message.error('载入工具失败')
+ }
+ } else {
+ try {
+ const baseDist = base64ToStr(toolVo.base.dist.data!)
+ const dist = base64ToStr(toolVo.dist.data!)
+ setCompiledCode(`${dist}\n${baseDist}`)
+ } catch (e) {
+ void message.error('载入工具失败')
+ }
}
}
diff --git a/src/pages/Tools/index.tsx b/src/pages/Tools/index.tsx
index b27f0dd..d7b3a39 100644
--- a/src/pages/Tools/index.tsx
+++ b/src/pages/Tools/index.tsx
@@ -36,6 +36,7 @@ interface CommonCardProps
url?: string
onOpen?: () => void
onEdit?: () => void
+ onSource?: () => void
onPublish?: () => void
onCancelReview?: () => void
onDelete?: () => void
@@ -58,6 +59,7 @@ const CommonCard = ({
url,
onOpen,
onEdit,
+ onSource,
onPublish,
onCancelReview,
onDelete,
@@ -102,6 +104,11 @@ const CommonCard = ({
)}
+ {onSource && (
+