diff --git a/apps/admin/.gitignore b/apps/admin/.gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/apps/admin/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/apps/admin/index.html b/apps/admin/index.html new file mode 100644 index 0000000..e0d1c84 --- /dev/null +++ b/apps/admin/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + React + TS + + +
+ + + diff --git a/apps/admin/package.json b/apps/admin/package.json new file mode 100644 index 0000000..ad3d9aa --- /dev/null +++ b/apps/admin/package.json @@ -0,0 +1,26 @@ +{ + "name": "@backset/admin", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "preview": "vite preview" + }, + "dependencies": { + "antd": "^5.2.0", + "less": "^4.1.3", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-router-dom": "6.8.0" + }, + "devDependencies": { + "@types/react": "^18.0.27", + "@types/react-dom": "^18.0.10", + "@types/react-router-dom": "5.3.3", + "@vitejs/plugin-react": "^3.1.0", + "typescript": "^4.9.3", + "vite": "^4.1.0" + } +} \ No newline at end of file diff --git a/apps/admin/public/vite.svg b/apps/admin/public/vite.svg new file mode 100644 index 0000000..e7b8dfb --- /dev/null +++ b/apps/admin/public/vite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/apps/admin/src/App.tsx b/apps/admin/src/App.tsx new file mode 100644 index 0000000..b57ebf5 --- /dev/null +++ b/apps/admin/src/App.tsx @@ -0,0 +1,53 @@ +import "./assets/less/common.less"; +import { Route, Routes, useNavigate } from "react-router-dom"; +import User from "./view/User"; +import Home from "./view/Home"; +import { Guard } from "./router/Guard"; + +function App() { + const navigate = useNavigate(); + + const routerList = [ + { + path: "/", + element: , + name: "首页", + }, + { + path: "user", + element: , + name: "用户", + }, + ]; + + return ( + <> +
header
+
+ +
+ + {routerList.map((router) => ( + {router.element}} + /> + ))} + 404} /> + +
+
+ + ); +} + +export default App; diff --git a/apps/admin/src/assets/less/common.less b/apps/admin/src/assets/less/common.less new file mode 100644 index 0000000..77806dd --- /dev/null +++ b/apps/admin/src/assets/less/common.less @@ -0,0 +1,16 @@ +body, +html { + margin: 0; + padding: 0; + font-size: 14px; +} + +* { + box-sizing: border-box; +} + +ul { + list-style: none; + margin: 0; + padding: 0; +} diff --git a/apps/admin/src/assets/react.svg b/apps/admin/src/assets/react.svg new file mode 100644 index 0000000..6c87de9 --- /dev/null +++ b/apps/admin/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/apps/admin/src/hooks/index.tsx b/apps/admin/src/hooks/index.tsx new file mode 100644 index 0000000..6aef2f3 --- /dev/null +++ b/apps/admin/src/hooks/index.tsx @@ -0,0 +1,31 @@ +/* eslint-disable react-hooks/exhaustive-deps */ +import { useCallback, useEffect, useState } from "react"; + +/** + * 挂载 + */ +export const useMount = (func: () => void) => { + useEffect(() => { + func(); + }, []); +}; + +/** + * 卸载 + */ +export const useUnmount = (func: () => void) => { + useEffect( + () => () => { + func(); + }, + [] + ); +}; + +/** + * forceUpdate + */ +export const useUpdate = () => { + const [, setState] = useState({}); + return useCallback(() => setState({}), []); +}; diff --git a/apps/admin/src/main.tsx b/apps/admin/src/main.tsx new file mode 100644 index 0000000..54001c9 --- /dev/null +++ b/apps/admin/src/main.tsx @@ -0,0 +1,9 @@ +import ReactDOM from "react-dom/client"; +import App from "./App"; +import { BrowserRouter as Router } from "react-router-dom"; + +ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( + + + +); diff --git a/apps/admin/src/router/Guard.tsx b/apps/admin/src/router/Guard.tsx new file mode 100644 index 0000000..8792003 --- /dev/null +++ b/apps/admin/src/router/Guard.tsx @@ -0,0 +1,16 @@ +import React, { useEffect } from "react"; +import { useLocation } from "react-router-dom"; + +interface IGuardProps { + children: JSX.Element; +} + +export const Guard = (props: IGuardProps) => { + const location = useLocation(); + + useEffect(() => { + console.log("location.pathname changed 拦截", location.pathname); + }, [location.pathname]); + + return props.children; +}; diff --git a/apps/admin/src/test.less b/apps/admin/src/test.less new file mode 100644 index 0000000..96c4622 --- /dev/null +++ b/apps/admin/src/test.less @@ -0,0 +1,3 @@ +body { + background: grey; +} diff --git a/apps/admin/src/view/Home/index.tsx b/apps/admin/src/view/Home/index.tsx new file mode 100644 index 0000000..698a383 --- /dev/null +++ b/apps/admin/src/view/Home/index.tsx @@ -0,0 +1,12 @@ +import { Button, message } from "antd"; + +export default function Index() { + const onClick = () => { + message.info("hi"); + }; + return ( +
+ +
+ ); +} diff --git a/apps/admin/src/view/User/index.tsx b/apps/admin/src/view/User/index.tsx new file mode 100644 index 0000000..d4c560b --- /dev/null +++ b/apps/admin/src/view/User/index.tsx @@ -0,0 +1,5 @@ +import React from "react"; + +export default function Index() { + return
UserIndex
; +} diff --git a/apps/admin/src/vite-env.d.ts b/apps/admin/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/apps/admin/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/apps/admin/tsconfig.json b/apps/admin/tsconfig.json new file mode 100644 index 0000000..3d0a51a --- /dev/null +++ b/apps/admin/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "target": "ESNext", + "useDefineForClassFields": true, + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "allowJs": false, + "skipLibCheck": true, + "esModuleInterop": false, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "module": "ESNext", + "moduleResolution": "Node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx" + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/apps/admin/tsconfig.node.json b/apps/admin/tsconfig.node.json new file mode 100644 index 0000000..9d31e2a --- /dev/null +++ b/apps/admin/tsconfig.node.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "composite": true, + "module": "ESNext", + "moduleResolution": "Node", + "allowSyntheticDefaultImports": true + }, + "include": ["vite.config.ts"] +} diff --git a/apps/admin/vite.config.ts b/apps/admin/vite.config.ts new file mode 100644 index 0000000..5a33944 --- /dev/null +++ b/apps/admin/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import react from '@vitejs/plugin-react' + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [react()], +}) diff --git a/packages/ui/package.json b/packages/ui/package.json index 2facf13..fb35ce9 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -2,7 +2,7 @@ "name": "@backset/ui", "version": "1.0.0", "main": "dist/index", - "types": "dist/index", + "types": "dist/index.d.ts", "scripts": { "build": "rimraf ./dist && tsc -p ./tsconfig.build.json" } diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts index 6b9c963..d898c02 100644 --- a/packages/ui/src/index.ts +++ b/packages/ui/src/index.ts @@ -1,5 +1 @@ -import { cipher, foo } from "@demo/util"; - -console.log(foo); - -console.log(cipher); +export const useArticle = () => "article";