Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Jan 16, 2024
1 parent 58f1004 commit bb806a7
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 107 deletions.
7 changes: 6 additions & 1 deletion packages/canyon-backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
6 changes: 6 additions & 0 deletions packages/canyon-backend/src/common/models/page-info.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Field, ID, ObjectType } from '@nestjs/graphql';

// total、pageSize、current
@ObjectType()
export class PageInfoModel {
}
11 changes: 11 additions & 0 deletions packages/canyon-backend/src/project/project-pages.model.ts
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 11 additions & 5 deletions packages/canyon-backend/src/project/project.resolver.ts
Original file line number Diff line number Diff line change
@@ -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<Project[]> {
return this.projectService.getProjects();
@Args('current', { type: () => Int }) current: number,
@Args('pageSize', { type: () => Int }) pageSize: number,
@Args('keyword', { type: () => String }) keyword: string,
): Promise<ProjectPagesModel> {
console.log(current, pageSize);
return this.projectService.getProjects(current, pageSize, keyword);
// console.log(da);
// return da
}
}
42 changes: 35 additions & 7 deletions packages/canyon-backend/src/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}),
};
});
});
}
}
2 changes: 1 addition & 1 deletion packages/canyon-platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
109 changes: 54 additions & 55 deletions packages/canyon-platform/src/ScrollBasedLayout.tsx
Original file line number Diff line number Diff line change
@@ -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 <div>
<div style={{display: 'flex',borderBottom:`1px solid ${token.colorBorder}`}}>
<div style={{
width: '260px', background: '', position: `${isScrolled ? 'unset' : 'fixed'}`,
display: `${!isScrolled ? 'unset' : 'flex'}`,
flexDirection: 'column',
}}>
return (
<div>
<div style={{ display: 'flex', borderBottom: `1px solid ${token.colorBorder}` }}>
<div
style={{
width: '260px',
background: '',
position: `${isScrolled ? 'unset' : 'fixed'}`,
display: `${!isScrolled ? 'unset' : 'flex'}`,
flexDirection: 'column',
}}
>
<div style={{ flex: '1' }}></div>

<div style={{flex: '1'}}>

</div>

<div style={{height: '100vh', background: ''}}>
{sideBar}
</div>
</div>

<div style={{
flex: '1', background: 'skyblue', marginLeft: `${
!isScrolled ? '260px' : '0'
}`,
minHeight:'100vh',
}}>
{mainContent}
</div>
<div style={{ height: '100vh', background: '' }}>{sideBar}</div>
</div>
<div id={'footer'} style={{height: '200px'}}>
{footer}

<div
style={{
flex: '1',
background: 'skyblue',
marginLeft: `${!isScrolled ? '260px' : '0'}`,
minHeight: '100vh',
}}
>
{mainContent}
</div>
</div>
<div id={'footer'} style={{ height: '200px' }}>
{footer}
</div>
</div>
}
);
};

export default ScrollBasedLayout
export default ScrollBasedLayout;
56 changes: 56 additions & 0 deletions packages/canyon-platform/src/components/app/app.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
42 changes: 17 additions & 25 deletions packages/canyon-platform/src/components/app/footer.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<footer className={'mx-auto w-[1250px] px-6 pb-20 pt-16'}>
<nav className={'flex gap-8 justify-between'}>
{lists2.map((item) => {
<nav className={'grid grid-cols-4 gap-8'}>
{lists.map((item) => {
return (
<div>
<div key={item.title}>
<div className={'text-[16px] px-3.5 py-2'}>{item.title}</div>
<div>
{item.children.map((child) => {
return (
<div className={'px-3.5 py-2'}>
<Text className={'text-[16px]'} type={'secondary'}>
{child.label}
</Text>
{/*<div>{child.value}</div>*/}
</div>
<Text
key={child.label}
className={
'text-[16px] cursor-pointer px-3.5 py-2 rounded block hover:bg-[#F0F0F0]'
}
type={'secondary'}
onClick={() => {
window.open(child.link);
}}
>
{child.label}
</Text>
);
})}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
query GetProjects {
getProjects {
id
name
pathWithNamespace
description
reportTimes
lastReportTime
query GetProjects($current: Int!, $pageSize: Int!, $keyword: String!) {
getProjects(current:$current, pageSize:$pageSize, keyword:$keyword) {
total
data {
id
name
pathWithNamespace
description
reportTimes
lastReportTime
}
}
}
2 changes: 1 addition & 1 deletion packages/canyon-platform/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function Index() {
>
<div className={'text-2xl font-bold flex items-center'}>
<img className={'w-[36px] mr-[8px]'} src={logoSvg} alt='' />
Canyon
Arex
</div>
</div>

Expand Down
Loading

0 comments on commit bb806a7

Please sign in to comment.