From bb806a7d179e64f70f5c0ed1860131cd897b674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allen=20Zhang=20=28=E5=BC=A0=E6=B6=9B=29?= Date: Tue, 16 Jan 2024 12:56:03 +0800 Subject: [PATCH] upd --- packages/canyon-backend/schema.gql | 7 +- .../src/common/models/page-info.model.ts | 6 + .../src/project/project-pages.model.ts | 11 ++ .../src/project/project.resolver.ts | 16 ++- .../src/project/project.service.ts | 42 +++++-- packages/canyon-platform/package.json | 2 +- .../canyon-platform/src/ScrollBasedLayout.tsx | 109 +++++++++--------- .../src/components/app/app.json | 56 +++++++++ .../src/components/app/footer.tsx | 42 +++---- .../backend/gql/queries/GetProjects.graphql | 19 +-- packages/canyon-platform/src/pages/index.tsx | 2 +- .../src/pages/index/projects/index.tsx | 53 ++++++++- 12 files changed, 258 insertions(+), 107 deletions(-) create mode 100644 packages/canyon-backend/src/common/models/page-info.model.ts create mode 100644 packages/canyon-backend/src/project/project-pages.model.ts create mode 100644 packages/canyon-platform/src/components/app/app.json diff --git a/packages/canyon-backend/schema.gql b/packages/canyon-backend/schema.gql index f7e18fb4..41d21680 100644 --- a/packages/canyon-backend/schema.gql +++ b/packages/canyon-backend/schema.gql @@ -28,10 +28,15 @@ type Project { lastReportTime: DateTime! } +type ProjectPagesModel { + data: [Project!]! + total: Float! +} + type Query { """提供执行此查询的用户的详细信息(通过授权 Bearer 标头)""" me: User! """获取Project""" - getProjects: [Project!]! + getProjects(current: Int!, pageSize: Int!, keyword: String!): ProjectPagesModel! } \ No newline at end of file diff --git a/packages/canyon-backend/src/common/models/page-info.model.ts b/packages/canyon-backend/src/common/models/page-info.model.ts new file mode 100644 index 00000000..3ac65fdd --- /dev/null +++ b/packages/canyon-backend/src/common/models/page-info.model.ts @@ -0,0 +1,6 @@ +import { Field, ID, ObjectType } from '@nestjs/graphql'; + +// total、pageSize、current +@ObjectType() +export class PageInfoModel { +} diff --git a/packages/canyon-backend/src/project/project-pages.model.ts b/packages/canyon-backend/src/project/project-pages.model.ts new file mode 100644 index 00000000..1d0dd6a2 --- /dev/null +++ b/packages/canyon-backend/src/project/project-pages.model.ts @@ -0,0 +1,11 @@ +import {Field, ID, ObjectType, Resolver} from '@nestjs/graphql'; +import { Project } from './project.model'; + +@ObjectType() +export class ProjectPagesModel { + @Field(() => [Project]) + data: Project[]; + + @Field(() => Number) + total: number; +} diff --git a/packages/canyon-backend/src/project/project.resolver.ts b/packages/canyon-backend/src/project/project.resolver.ts index da64f34a..fe503672 100755 --- a/packages/canyon-backend/src/project/project.resolver.ts +++ b/packages/canyon-backend/src/project/project.resolver.ts @@ -1,21 +1,27 @@ -import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; +import { Args, Int, Mutation, Query, Resolver } from '@nestjs/graphql'; import { GqlAuthGuard } from '../guards/gql-auth.guard'; import { UseGuards } from '@nestjs/common'; import { GqlUser } from '../decorators/gql-user.decorator'; import { AuthUser } from '../types/AuthUser'; import { Project } from './project.model'; +import { ProjectPagesModel } from './project-pages.model'; import { ProjectService } from './project.service'; @Resolver(() => 'Project') export class ProjectResolver { constructor(private readonly projectService: ProjectService) {} - @Query(() => [Project], { + @Query(() => ProjectPagesModel, { description: '获取Project', }) @UseGuards(GqlAuthGuard) getProjects( @GqlUser() user: AuthUser, - // @Args('projectID', { type: () => String }) projectID: string, - ): Promise { - return this.projectService.getProjects(); + @Args('current', { type: () => Int }) current: number, + @Args('pageSize', { type: () => Int }) pageSize: number, + @Args('keyword', { type: () => String }) keyword: string, + ): Promise { + console.log(current, pageSize); + return this.projectService.getProjects(current, pageSize, keyword); + // console.log(da); + // return da } } diff --git a/packages/canyon-backend/src/project/project.service.ts b/packages/canyon-backend/src/project/project.service.ts index 485b236a..b827dedd 100755 --- a/packages/canyon-backend/src/project/project.service.ts +++ b/packages/canyon-backend/src/project/project.service.ts @@ -56,15 +56,43 @@ export class ProjectService { }, }); } - async getProjects() { - return this.prisma.project.findMany().then((res) => { - return res.map((item) => { + async getProjects(current, pageSize, keyword) { + const total = await this.prisma.project.count({ + where: { + OR: [ + { description: { contains: keyword } }, + { name: { contains: keyword } }, + { pathWithNamespace: { contains: keyword } }, + { id: { contains: keyword } }, + ], + }, + }); + return this.prisma.project + .findMany({ + where: { + OR: [ + { description: { contains: keyword } }, + { name: { contains: keyword } }, + { pathWithNamespace: { contains: keyword } }, + { id: { contains: keyword } }, + ], + }, + skip: (current - 1) * pageSize, + take: pageSize - 0, + }) + .then((res) => { return { - ...item, - lastReportTime: new Date(), - reportTimes: 1, + total: total, + // pageSize: 10, + // current: 1, + data: res.map((item) => { + return { + ...item, + lastReportTime: new Date(), + reportTimes: 1, + }; + }), }; }); - }); } } diff --git a/packages/canyon-platform/package.json b/packages/canyon-platform/package.json index 9f49d054..54a8568b 100644 --- a/packages/canyon-platform/package.json +++ b/packages/canyon-platform/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev-platform": "vite", "build": "vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", diff --git a/packages/canyon-platform/src/ScrollBasedLayout.tsx b/packages/canyon-platform/src/ScrollBasedLayout.tsx index 5c4ba435..484e0cf5 100644 --- a/packages/canyon-platform/src/ScrollBasedLayout.tsx +++ b/packages/canyon-platform/src/ScrollBasedLayout.tsx @@ -1,68 +1,67 @@ -import {FC, ReactNode, useEffect, useState} from "react"; -import {theme} from "antd"; +import { theme } from 'antd'; +import { FC, ReactNode, useEffect, useState } from 'react'; const { useToken } = theme; const ScrollBasedLayout: FC<{ - sideBar: ReactNode, - mainContent: ReactNode, - footer: ReactNode, -}> = ({ - sideBar, - mainContent, - footer, - }) => { - const {token} = useToken(); - const [isScrolled, setIsScrolled] = useState(false); + sideBar: ReactNode; + mainContent: ReactNode; + footer: ReactNode; +}> = ({ sideBar, mainContent, footer }) => { + const { token } = useToken(); + const [isScrolled, setIsScrolled] = useState(false); - useEffect(() => { - const handleScroll = () => { - const scrollY = window.scrollY || document.documentElement.scrollTop; - const footer = document.getElementById('footer'); + useEffect(() => { + const handleScroll = () => { + const scrollY = window.scrollY || document.documentElement.scrollTop; + const footer = document.getElementById('footer'); - console.log(scrollY, 'scrollY', window.innerHeight) - // 检查滚动是否超过100vh - setIsScrolled(scrollY + window.innerHeight > footer.offsetTop); - }; + // console.log(scrollY, 'scrollY', window.innerHeight) + // 检查滚动是否超过100vh + setIsScrolled(scrollY + window.innerHeight > footer.offsetTop); + }; - // 添加滚动事件监听器 - window.addEventListener('scroll', handleScroll); + // 添加滚动事件监听器 + window.addEventListener('scroll', handleScroll); - // 在组件卸载时移除监听器,以防止内存泄漏 - return () => { - window.removeEventListener('scroll', handleScroll); - }; - }, []); // 仅在组件挂载和卸载时运行 + // 在组件卸载时移除监听器,以防止内存泄漏 + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }, []); // 仅在组件挂载和卸载时运行 - return
-
-
+ return ( +
+
+
+
-
- -
- -
- {sideBar} -
-
- -
- {mainContent} -
+
{sideBar}
-
- {footer} + +
+ {mainContent}
+
+
+ {footer} +
-} + ); +}; -export default ScrollBasedLayout \ No newline at end of file +export default ScrollBasedLayout; diff --git a/packages/canyon-platform/src/components/app/app.json b/packages/canyon-platform/src/components/app/app.json new file mode 100644 index 00000000..3b11800a --- /dev/null +++ b/packages/canyon-platform/src/components/app/app.json @@ -0,0 +1,56 @@ +{ + "footer": [ + { + "title": "Product", + "children": [ + { + "label": "Arex on GitHub", + "link": "https://github.com/arextest" + }, + { + "label": "Star Us on GitHub", + "link": "https://github.com/arextest/arex" + } + ] + }, + { + "title": "Resources", + "children": [ + { + "label": "Docs", + "link": "https://docs.arextest.com" + }, + { + "label": "Changelog", + "link": "https://github.com/arextest/arex-agent-java" + } + ] + }, + { + "title": "Company", + "children": [ + { + "label": "Home", + "link": "https://arextest.com" + }, + { + "label": "Pricing", + "link": "https://arextest.com/pricing" + } + ] + }, + { + "title": "Legal", + "children": [ + { + "label": "Terms of service", + "link": "https://expo.dev/terms" + }, + { + "label": "Guidelines", + "link": "https://expo.dev/terms" + } + ] + } + ] +} diff --git a/packages/canyon-platform/src/components/app/footer.tsx b/packages/canyon-platform/src/components/app/footer.tsx index 93f390cc..1da183a9 100644 --- a/packages/canyon-platform/src/components/app/footer.tsx +++ b/packages/canyon-platform/src/components/app/footer.tsx @@ -1,38 +1,30 @@ import { Typography } from 'antd'; const { Text } = Typography; +import app from './app.json'; const AppFooter = () => { - const lists = [ - { - title: 'Product', - children: [ - { - label: 'Expo on GitHub', - value: 'Expo on GitHub', - }, - { - label: 'Expo CLI on GitHub', - value: 'Expo CLI on GitHub', - }, - ], - }, - ]; - const lists2 = [lists[0], lists[0], lists[0], lists[0]]; + const lists = app.footer; return (