feat: init
This commit is contained in:
@@ -12,12 +12,5 @@
|
||||
"scripts": {
|
||||
"lint": "eslint src --ext .ts,.tsx",
|
||||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"antd-mobile": "^5.34.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
49
packages/shared/src/error-page/errorBoundary/index.tsx
Normal file
49
packages/shared/src/error-page/errorBoundary/index.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
// components/ErrorBoundary/index.tsx
|
||||
import React, { Component, ReactNode } from "react";
|
||||
import { Result, Button } from "antd-mobile";
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
fallback?: ReactNode;
|
||||
}
|
||||
|
||||
interface State {
|
||||
hasError: boolean;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
class ErrorBoundary extends Component<Props, State> {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = { hasError: false };
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(error: Error): State {
|
||||
return { hasError: true, error };
|
||||
}
|
||||
|
||||
componentDidCatch(error: Error, errorInfo: any) {
|
||||
console.error("ErrorBoundary caught an error:", error, errorInfo);
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) {
|
||||
if (this.props.fallback) {
|
||||
return this.props.fallback;
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ padding: "20px", textAlign: "center" }}>
|
||||
<Result status="error" title="页面出错了" description="抱歉,页面出现了错误" />
|
||||
<Button color="primary" onClick={() => window.location.reload()}>
|
||||
刷新页面
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
export default ErrorBoundary;
|
||||
20
packages/shared/src/error-page/index.module.less
Normal file
20
packages/shared/src/error-page/index.module.less
Normal file
@@ -0,0 +1,20 @@
|
||||
// components/ErrorPages/ErrorPages.module.less
|
||||
.errorPage {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
margin-top: 24px;
|
||||
|
||||
.button {
|
||||
min-width: 100px;
|
||||
}
|
||||
}
|
||||
25
packages/shared/src/error-page/notFound/index.tsx
Normal file
25
packages/shared/src/error-page/notFound/index.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
// components/ErrorPages/NotFound.tsx
|
||||
import React from "react";
|
||||
import { Button, Result } from "antd-mobile";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import styles from "../index.module.less";
|
||||
|
||||
const NotFound: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<div className={styles.errorPage}>
|
||||
<Result status="error" title="页面不存在" description="抱歉,您访问的页面不存在" />
|
||||
<div className={styles.actions}>
|
||||
<Button color="primary" onClick={() => navigate(-1)} className={styles.button}>
|
||||
返回上页
|
||||
</Button>
|
||||
<Button onClick={() => navigate("/")} className={styles.button}>
|
||||
回到首页
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default NotFound;
|
||||
29
packages/shared/src/error-page/serverError/index.tsx
Normal file
29
packages/shared/src/error-page/serverError/index.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
// components/ErrorPages/ServerError.tsx
|
||||
import React from "react";
|
||||
import { Button, Result } from "antd-mobile";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import styles from "../index.module.less";
|
||||
|
||||
const ServerError: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleRefresh = () => {
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.errorPage}>
|
||||
<Result status="error" title="服务器错误" description="服务器开小差了,请稍后再试" />
|
||||
<div className={styles.actions}>
|
||||
<Button color="primary" onClick={handleRefresh} className={styles.button}>
|
||||
刷新页面
|
||||
</Button>
|
||||
<Button onClick={() => navigate("/")} className={styles.button}>
|
||||
回到首页
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ServerError;
|
||||
@@ -12,7 +12,7 @@ function XPopup(props: DefinedProps) {
|
||||
const { visible, title, children, onClose } = props;
|
||||
|
||||
return (
|
||||
<Popup visible={visible} closeOnMaskClick={true} className="xpopup">
|
||||
<Popup visible={visible} closeOnMaskClick={true} className="xpopup" onMaskClick={onClose}>
|
||||
<div className="header">
|
||||
<h3 className="title">{title}</h3>
|
||||
<span className="closeIcon" onClick={onClose}>
|
||||
|
||||
@@ -1,10 +1,26 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules"]
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
},
|
||||
"typeRoots": ["./types"]
|
||||
}
|
||||
}
|
||||
|
||||
19
packages/shared/types/global.d.ts
vendored
Normal file
19
packages/shared/types/global.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// src/types/global.d.ts
|
||||
declare module "*.module.less" {
|
||||
const classes: { readonly [key: string]: string };
|
||||
export default classes;
|
||||
}
|
||||
|
||||
declare module "*.module.css" {
|
||||
const classes: { readonly [key: string]: string };
|
||||
export default classes;
|
||||
}
|
||||
|
||||
// 其他资源文件
|
||||
declare module "*.png";
|
||||
declare module "*.jpg";
|
||||
declare module "*.jpeg";
|
||||
declare module "*.gif";
|
||||
declare module "*.svg";
|
||||
declare module "*.ico";
|
||||
declare module "*.webp";
|
||||
Reference in New Issue
Block a user