feat: 前端逐字复制(仅代理端口改 30010)+ run.sh + check-module.sh + 文档
前端:从 ssw-jnpf-lite-react/src/frontend 逐字复制(package-lock.json 一并复制), 唯一改动 = vite.config.ts 的代理目标 30000 → 30010(含紧邻注释行的端口); src/api/request.ts 的注释与 axios timeout: 30000 逐字节保留。 脚本:run.sh(install/build/dev/backend/frontend/stop/logs,退出码 0/1/2, kill_ports 只清 30010 与 5173);scripts/check-module.sh(9 接触点静态自检, 纯静态零 node 依赖)。 文档:README.md、docs/runbook.md、.env.example;CLAUDE.md 逐条核对并与代码同步, HANDOFF.md §0 状态表与 §9 交接话术改为交付态。 Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
1 parent
8366a3745f
commit
8edcd3507d
31 files changed
+4536
-33
No files matched your search
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>SSW JNPF Lite · React MVP</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+2115
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "ssw-jnpf-lite-react-frontend",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.7.0",
|
||||
"crypto-js": "^4.2.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-router-dom": "^6.26.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/react": "^18.3.0",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@vitejs/plugin-react": "^4.3.0",
|
||||
"typescript": "^5.4.0",
|
||||
"vite": "^5.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
|
||||
import { JSX } from 'react';
|
||||
import Login from './views/Login';
|
||||
import Dashboard from './views/Dashboard';
|
||||
import DemoItem from './views/DemoItem';
|
||||
import Product from './views/Product';
|
||||
import Book from './views/Book';
|
||||
import UserManage from './views/UserManage';
|
||||
import RoleManage from './views/RoleManage';
|
||||
import OrganizeManage from './views/OrganizeManage';
|
||||
import MenuManage from './views/MenuManage';
|
||||
import { getToken } from './api/request';
|
||||
|
||||
function RequireAuth({ children }: { children: JSX.Element }) {
|
||||
const token = getToken();
|
||||
const location = useLocation();
|
||||
if (!token) return <Navigate to="/login" state={{ from: location }} replace />;
|
||||
return children;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<Dashboard />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/demo-item"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<DemoItem />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/shop/Product"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<Product />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/books/Book"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<Book />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/system/User"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<UserManage />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/system/Role"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<RoleManage />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/system/Organize"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<OrganizeManage />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/system/Module"
|
||||
element={
|
||||
<RequireAuth>
|
||||
<MenuManage />
|
||||
</RequireAuth>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import request from './request';
|
||||
|
||||
export async function login(account: string, passwordHex: string) {
|
||||
const params = new URLSearchParams();
|
||||
params.set('account', account);
|
||||
params.set('password', passwordHex);
|
||||
params.set('grant_type', 'password');
|
||||
// Content-Type: application/x-www-form-urlencoded,与 JNPF 登录一致
|
||||
return (await request.post('/oauth/Login', params.toString(), {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
})) as { token: string; expiresIn: number; tokenTypeName: string };
|
||||
}
|
||||
|
||||
export async function currentUser() {
|
||||
return (await request.get('/oauth/CurrentUser')) as {
|
||||
userInfo: any;
|
||||
menuList: any[];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import request from './request';
|
||||
|
||||
export const listBooks = () => request.get('/ssw/books/Book/List');
|
||||
export const saveBook = (dto: any) => request.post('/ssw/books/Book/Save', dto);
|
||||
export const deleteBook = (id: string) => request.delete(`/ssw/books/Book/Delete?id=${id}`);
|
||||
@@ -0,0 +1,7 @@
|
||||
import request from './request';
|
||||
|
||||
// Product 业务 API —— 端点与后端 @Controller('api/ssw/shop/Product') 对应
|
||||
export const listProducts = () => request.get('/ssw/shop/Product/List');
|
||||
export const saveProduct = (dto: any) => request.post('/ssw/shop/Product/Save', dto);
|
||||
export const deleteProduct = (id: string) =>
|
||||
request.delete(`/ssw/shop/Product/Delete?id=${id}`);
|
||||
@@ -0,0 +1,72 @@
|
||||
import axios, { AxiosError, AxiosInstance } from 'axios';
|
||||
|
||||
/**
|
||||
* 请求层 —— 复刻 JNPF/jweb 的 ActionResult 适配语义:
|
||||
* - 统一 baseURL '/api'(dev 由 vite proxy 转发到 30000)
|
||||
* - 拦截器处理 code:600/601/602 -> 清 token 跳 /login(对齐 jweb enum.ts: TOKEN_TIMEOUT/TOKEN_LOGGED/TOKEN_ERROR)
|
||||
* - code !== 200 -> reject
|
||||
* - 成功时把 ActionResult 的 data 解包抛给调用方
|
||||
* 迁 jweb(Vue) 时这些逻辑 1:1 对应 vben 的 defHttp 拦截器,前端零改。
|
||||
*/
|
||||
const TOKEN_KEY = 'ssw_token';
|
||||
|
||||
export function getToken(): string | null {
|
||||
return localStorage.getItem(TOKEN_KEY);
|
||||
}
|
||||
export function setToken(raw: string) {
|
||||
const t = raw.startsWith('bearer ') ? raw : `bearer ${raw}`;
|
||||
localStorage.setItem(TOKEN_KEY, t);
|
||||
}
|
||||
export function clearToken() {
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
}
|
||||
|
||||
interface SswRequest extends AxiosInstance {
|
||||
get<T = any>(url: string, config?: any): Promise<T>;
|
||||
post<T = any>(url: string, data?: any, config?: any): Promise<T>;
|
||||
put<T = any>(url: string, data?: any, config?: any): Promise<T>;
|
||||
delete<T = any>(url: string, config?: any): Promise<T>;
|
||||
}
|
||||
|
||||
const request = axios.create({ baseURL: '/api', timeout: 30000 }) as SswRequest;
|
||||
|
||||
request.interceptors.request.use((config) => {
|
||||
const token = getToken();
|
||||
config.headers.set('App-Code', 'sswflow');
|
||||
config.headers.set('Jnpf-Origin', 'pc');
|
||||
if (token) config.headers.set('Authorization', token);
|
||||
return config;
|
||||
});
|
||||
|
||||
function redirectLogin() {
|
||||
if (location.pathname !== '/login') {
|
||||
location.replace(`/login?next=${encodeURIComponent(location.pathname + location.search)}`);
|
||||
}
|
||||
}
|
||||
|
||||
request.interceptors.response.use(
|
||||
(resp) => {
|
||||
const body = resp.data || {};
|
||||
if (body.code === 600 || body.code === 601 || body.code === 602) {
|
||||
clearToken();
|
||||
redirectLogin();
|
||||
return Promise.reject(new Error('NOT_LOGIN'));
|
||||
}
|
||||
if (body.code !== undefined && body.code !== 200) {
|
||||
return Promise.reject(new Error(body.msg || '操作失败'));
|
||||
}
|
||||
return body.data !== undefined ? body.data : body;
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
const status = error.response?.status;
|
||||
const body: any = error.response?.data || {};
|
||||
if (status === 401 || body.code === 600 || body.code === 601 || body.code === 602) {
|
||||
clearToken();
|
||||
redirectLogin();
|
||||
return Promise.reject(new Error('NOT_LOGIN'));
|
||||
}
|
||||
return Promise.reject(new Error(body.msg || error.message || '请求失败'));
|
||||
},
|
||||
);
|
||||
|
||||
export default request;
|
||||
@@ -0,0 +1,36 @@
|
||||
import request from './request';
|
||||
|
||||
// 用户
|
||||
export const listUsers = () => request.get('/ssw/sys/User/List');
|
||||
export const saveUser = (dto: any) => request.post('/ssw/sys/User/Save', dto);
|
||||
export const deleteUser = (id: string) =>
|
||||
request.delete(`/ssw/sys/User/Delete?id=${id}`);
|
||||
|
||||
// 角色
|
||||
export const listRoles = () => request.get('/ssw/sys/Role/List');
|
||||
export const saveRole = (dto: any) => request.post('/ssw/sys/Role/Save', dto);
|
||||
export const deleteRole = (id: string) =>
|
||||
request.delete(`/ssw/sys/Role/Delete?id=${id}`);
|
||||
export const roleModules = (roleId: string) =>
|
||||
request.get(`/ssw/sys/Role/Modules?roleId=${roleId}`);
|
||||
|
||||
// 机构
|
||||
export const listOrganize = () => request.get('/ssw/sys/Organize/List');
|
||||
export const saveOrganize = (dto: any) => request.post('/ssw/sys/Organize/Save', dto);
|
||||
export const deleteOrganize = (id: string) =>
|
||||
request.delete(`/ssw/sys/Organize/Delete?id=${id}`);
|
||||
|
||||
// 菜单
|
||||
export const listModules = () => request.get('/ssw/sys/Module/List');
|
||||
export const saveModule = (dto: any) => request.post('/ssw/sys/Module/Save', dto);
|
||||
export const deleteModule = (id: string) =>
|
||||
request.delete(`/ssw/sys/Module/Delete?id=${id}`);
|
||||
|
||||
// 统一授权(角色→菜单,对齐 JNPF PUT /api/permission/Authority/Data/{objectId})
|
||||
// module 是一维 String[](官方 AuthorizeDataUpForm.module = String[]);
|
||||
// 半选节点由调用方合并进同一数组(对齐 MenuAuth.vue: [...checkedKeys, ...halfCheckedKeys])
|
||||
export const saveRoleModules = (roleId: string, moduleIds: string[]) =>
|
||||
request.put(`/permission/Authority/Data/${roleId}`, {
|
||||
objectType: 'role',
|
||||
module: moduleIds,
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import App from './App';
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
@@ -0,0 +1,26 @@
|
||||
import CryptoJS from 'crypto-js';
|
||||
|
||||
/**
|
||||
* 登录密码加密 —— 与 JNPF 后端 LiteLoginController / dacli / ssw-jnpf-lite(Vue) 完全一致。
|
||||
* 检验向量:encryptPassword('123456') ===
|
||||
* 'd4958348e22108119b3ef57b022c83f4bf857dd0b247eaab15b9a43d47ee3c503900f7135bf0de255bc33620c3cdc02b'
|
||||
*/
|
||||
const CIPHER_KEY = 'EY8WePvjM5GGwQzn';
|
||||
|
||||
function md5(str: string): string {
|
||||
return CryptoJS.MD5(str).toString();
|
||||
}
|
||||
|
||||
export function encryptPassword(plain: string): string {
|
||||
const key = CryptoJS.enc.Utf8.parse(md5(CIPHER_KEY));
|
||||
const src = CryptoJS.enc.Utf8.parse(md5(plain));
|
||||
return CryptoJS.AES.encrypt(src, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
})
|
||||
.ciphertext.toString(CryptoJS.enc.Hex);
|
||||
}
|
||||
|
||||
export function md5Hex(str: string): string {
|
||||
return md5(str);
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { listBooks, saveBook, deleteBook } from '../api/book';
|
||||
import { wrap, card, btn, btnDanger, input as inputStyle, tableStyle, th, td } from './ui';
|
||||
|
||||
// 字段用去前缀名:id / title / author / isbn / category / price / stock
|
||||
// (JNPF 后端 Jackson 会剥掉 f_ 前缀)
|
||||
interface Book {
|
||||
id: string;
|
||||
title?: string;
|
||||
author?: string;
|
||||
isbn?: string;
|
||||
category?: string;
|
||||
price?: string;
|
||||
stock?: number;
|
||||
}
|
||||
|
||||
export default function Books() {
|
||||
const [items, setItems] = useState<Book[]>([]);
|
||||
const [form, setForm] = useState({
|
||||
title: '',
|
||||
author: '',
|
||||
isbn: '',
|
||||
category: '',
|
||||
price: '',
|
||||
stock: '',
|
||||
});
|
||||
|
||||
async function load() {
|
||||
const data = await listBooks();
|
||||
setItems(data || []);
|
||||
}
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
function update(k: keyof Book, v: string) {
|
||||
setForm((f) => ({ ...f, [k]: v }));
|
||||
}
|
||||
|
||||
async function add() {
|
||||
if (!form.title) return;
|
||||
await saveBook({
|
||||
title: form.title,
|
||||
author: form.author || undefined,
|
||||
isbn: form.isbn || undefined,
|
||||
category: form.category || undefined,
|
||||
price: form.price || '0.00',
|
||||
stock: form.stock ? Number(form.stock) : 0,
|
||||
});
|
||||
setForm({ title: '', author: '', isbn: '', category: '', price: '', stock: '' });
|
||||
load();
|
||||
}
|
||||
async function del(id: string) {
|
||||
await deleteBook(id);
|
||||
load();
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={wrap}>
|
||||
<div style={card}>
|
||||
<h2 style={{ margin: 0 }}>图书超市</h2>
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(3, minmax(140px, 1fr))',
|
||||
gap: 8,
|
||||
margin: '12px 0',
|
||||
}}
|
||||
>
|
||||
<input
|
||||
value={form.title}
|
||||
onChange={(e) => update('title', e.target.value)}
|
||||
placeholder="书名"
|
||||
style={inputStyle}
|
||||
/>
|
||||
<input
|
||||
value={form.author}
|
||||
onChange={(e) => update('author', e.target.value)}
|
||||
placeholder="作者"
|
||||
style={inputStyle}
|
||||
/>
|
||||
<input
|
||||
value={form.isbn}
|
||||
onChange={(e) => update('isbn', e.target.value)}
|
||||
placeholder="ISBN"
|
||||
style={inputStyle}
|
||||
/>
|
||||
<input
|
||||
value={form.category}
|
||||
onChange={(e) => update('category', e.target.value)}
|
||||
placeholder="分类"
|
||||
style={inputStyle}
|
||||
/>
|
||||
<input
|
||||
value={form.price}
|
||||
onChange={(e) => update('price', e.target.value)}
|
||||
placeholder="价格"
|
||||
style={inputStyle}
|
||||
/>
|
||||
<input
|
||||
value={form.stock}
|
||||
onChange={(e) => update('stock', e.target.value)}
|
||||
placeholder="库存"
|
||||
style={inputStyle}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<button style={btn} onClick={add}>
|
||||
新增
|
||||
</button>
|
||||
<button style={{ ...btn, background: '#2a3340' }} onClick={() => history.back()}>
|
||||
返回
|
||||
</button>
|
||||
</div>
|
||||
<table style={tableStyle}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style={th}>书名</th>
|
||||
<th style={th}>作者</th>
|
||||
<th style={th}>ISBN</th>
|
||||
<th style={th}>分类</th>
|
||||
<th style={th}>价格</th>
|
||||
<th style={th}>库存</th>
|
||||
<th style={th}>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{items.map((it) => (
|
||||
<tr key={it.id}>
|
||||
<td style={td}>{it.title}</td>
|
||||
<td style={td}>{it.author}</td>
|
||||
<td style={td}>{it.isbn}</td>
|
||||
<td style={td}>{it.category}</td>
|
||||
<td style={td}>¥{it.price}</td>
|
||||
<td style={td}>{it.stock}</td>
|
||||
<td style={td}>
|
||||
<button style={btnDanger} onClick={() => del(it.id)}>
|
||||
删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{items.length === 0 && (
|
||||
<tr>
|
||||
<td style={td} colSpan={7}>
|
||||
暂无数据
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { currentUser } from '../api/auth';
|
||||
import { clearToken } from '../api/request';
|
||||
import { wrap, card, btnGhost, btn } from './ui';
|
||||
|
||||
interface MenuNode {
|
||||
id: string;
|
||||
fullName: string;
|
||||
urlAddress?: string;
|
||||
icon?: string;
|
||||
parentId: string;
|
||||
children: MenuNode[];
|
||||
}
|
||||
|
||||
export default function Dashboard() {
|
||||
const nav = useNavigate();
|
||||
const [menu, setMenu] = useState<MenuNode[]>([]);
|
||||
const [user, setUser] = useState<any>(null);
|
||||
|
||||
useEffect(() => {
|
||||
currentUser()
|
||||
.then((d) => {
|
||||
setMenu(d.menuList || []);
|
||||
setUser(d.userInfo);
|
||||
})
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
function goto(addr?: string) {
|
||||
if (addr) nav('/' + addr);
|
||||
}
|
||||
function logout() {
|
||||
clearToken();
|
||||
location.reload();
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={wrap}>
|
||||
<div style={card}>
|
||||
<h2>SSW JNPF Lite · React</h2>
|
||||
<div style={{ color: '#9aa7b5' }}>
|
||||
{user?.userAccount} {user?.isAdministrator ? '(管理员)' : ''}
|
||||
</div>
|
||||
<h3 style={{ marginTop: 16 }}>功能菜单</h3>
|
||||
{menu.map((node) => (
|
||||
<div key={node.id} style={{ marginBottom: 10 }}>
|
||||
<div style={{ color: '#9aa7b5', fontSize: 12 }}>{node.fullName}</div>
|
||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', marginTop: 4 }}>
|
||||
{node.children.map((c) => (
|
||||
<button key={c.id} style={btnGhost} onClick={() => goto(c.urlAddress)}>
|
||||
{c.fullName}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<button style={{ ...btn, background: '#712b13', marginTop: 12 }} onClick={logout}>
|
||||
退出
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import request from '../api/request';
|
||||
|
||||
// 注意:字段用去前缀名(title/status/id),与 JNPF 后端 Jackson 的 f-前缀剥离一致
|
||||
interface DemoItem {
|
||||
id: string;
|
||||
title?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export default function DemoItem() {
|
||||
const [items, setItems] = useState<DemoItem[]>([]);
|
||||
const [title, setTitle] = useState('');
|
||||
|
||||
async function load() {
|
||||
const data = await request.get('/ssw/demo/DemoItem/List');
|
||||
setItems(data || []);
|
||||
}
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
async function add() {
|
||||
if (!title) return;
|
||||
await request.post('/ssw/demo/DemoItem/Save', { title, status: '草稿' });
|
||||
setTitle('');
|
||||
load();
|
||||
}
|
||||
async function del(id: string) {
|
||||
await request.delete(`/ssw/demo/DemoItem/Delete?id=${id}`);
|
||||
load();
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={wrap}>
|
||||
<div style={card}>
|
||||
<h2>DemoItem</h2>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<input
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="标题"
|
||||
style={input}
|
||||
/>
|
||||
<button style={btn} onClick={add}>
|
||||
新增
|
||||
</button>
|
||||
</div>
|
||||
<ul>
|
||||
{items.map((it) => (
|
||||
<li key={it.id} style={{ display: 'flex', gap: 12, alignItems: 'center' }}>
|
||||
<span>
|
||||
{it.title}({it.status})
|
||||
</span>
|
||||
<button style={{ ...btn, background: '#712b13' }} onClick={() => del(it.id)}>
|
||||
删除
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<button style={link} onClick={() => history.back()}>
|
||||
返回
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const wrap: React.CSSProperties = { minHeight: '100vh', padding: 40, background: '#0f1419', color: '#eee' };
|
||||
const card: React.CSSProperties = {
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 12,
|
||||
padding: 24,
|
||||
background: '#1a1f26',
|
||||
borderRadius: 12,
|
||||
minWidth: 360,
|
||||
};
|
||||
const input: React.CSSProperties = {
|
||||
padding: 8,
|
||||
borderRadius: 6,
|
||||
border: '1px solid #333',
|
||||
background: '#0f1419',
|
||||
color: '#eee',
|
||||
};
|
||||
const btn: React.CSSProperties = {
|
||||
padding: 8,
|
||||
borderRadius: 6,
|
||||
border: 0,
|
||||
background: '#185fa5',
|
||||
color: '#fff',
|
||||
cursor: 'pointer',
|
||||
};
|
||||
const link: React.CSSProperties = {
|
||||
padding: 8,
|
||||
background: 'transparent',
|
||||
border: 0,
|
||||
color: '#85b7eb',
|
||||
cursor: 'pointer',
|
||||
textAlign: 'left',
|
||||
};
|
||||
@@ -0,0 +1,81 @@
|
||||
import { useState } from 'react';
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
import { login } from '../api/auth';
|
||||
import { setToken } from '../api/request';
|
||||
import { encryptPassword } from '../utils/cipher';
|
||||
|
||||
export default function Login() {
|
||||
const [account, setAccount] = useState('admin');
|
||||
const [password, setPassword] = useState('123456');
|
||||
const [err, setErr] = useState('');
|
||||
const nav = useNavigate();
|
||||
const loc = useLocation();
|
||||
|
||||
async function onSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setErr('');
|
||||
try {
|
||||
const hex = encryptPassword(password);
|
||||
const res = await login(account, hex);
|
||||
setToken(res.token);
|
||||
const next = (loc.state as any)?.from?.pathname || '/';
|
||||
nav(next);
|
||||
} catch (e: any) {
|
||||
setErr(e.message || '登录失败');
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={wrap}>
|
||||
<form onSubmit={onSubmit} style={card}>
|
||||
<h2>SSW JNPF Lite · React</h2>
|
||||
<input value={account} onChange={(e) => setAccount(e.target.value)} placeholder="账号" style={input} />
|
||||
<input
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
type="password"
|
||||
placeholder="密码"
|
||||
style={input}
|
||||
/>
|
||||
{err && <div style={{ color: '#e24b4a' }}>{err}</div>}
|
||||
<button type="submit" style={btn}>
|
||||
登录
|
||||
</button>
|
||||
<div style={{ fontSize: 12, color: '#888' }}>默认 admin / 123456</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const wrap: React.CSSProperties = {
|
||||
minHeight: '100vh',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
background: '#0f1419',
|
||||
color: '#eee',
|
||||
};
|
||||
const card: React.CSSProperties = {
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 12,
|
||||
padding: 24,
|
||||
background: '#1a1f26',
|
||||
borderRadius: 12,
|
||||
width: 300,
|
||||
};
|
||||
const input: React.CSSProperties = {
|
||||
padding: 8,
|
||||
borderRadius: 6,
|
||||
border: '1px solid #333',
|
||||
background: '#0f1419',
|
||||
color: '#eee',
|
||||
};
|
||||
const btn: React.CSSProperties = {
|
||||
padding: 10,
|
||||
borderRadius: 6,
|
||||
border: 0,
|
||||
background: '#185fa5',
|
||||
color: '#fff',
|
||||
cursor: 'pointer',
|
||||
};
|
||||
@@ -0,0 +1,155 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import * as api from '../api/sys';
|
||||
import { wrap, card, btn, btnDanger, btnGhost, input, tableStyle, th, td } from './ui';
|
||||
|
||||
export default function MenuManage() {
|
||||
const [rows, setRows] = useState<any[]>([]);
|
||||
const [editing, setEditing] = useState<any>(null);
|
||||
const [form, setForm] = useState({
|
||||
fullName: '',
|
||||
urlAddress: '',
|
||||
parentId: '0',
|
||||
type: 2,
|
||||
icon: '',
|
||||
sortCode: 0,
|
||||
});
|
||||
|
||||
async function load() {
|
||||
setRows(await api.listModules());
|
||||
}
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
const nameOf = (id: string) =>
|
||||
id === '0' ? '(根)' : (rows.find((r) => r.id === id)?.fullName ?? id);
|
||||
|
||||
function openEdit(r?: any) {
|
||||
if (r)
|
||||
setForm({
|
||||
fullName: r.fullName,
|
||||
urlAddress: r.urlAddress || '',
|
||||
parentId: r.parentId || '0',
|
||||
type: r.type ?? 2,
|
||||
icon: r.icon || '',
|
||||
sortCode: r.sortCode ?? 0,
|
||||
});
|
||||
else setForm({ fullName: '', urlAddress: '', parentId: '0', type: 2, icon: '', sortCode: 0 });
|
||||
setEditing(r || {});
|
||||
}
|
||||
async function submit() {
|
||||
if (!form.fullName) return alert('菜单名必填');
|
||||
await api.saveModule({ ...form, id: editing?.id });
|
||||
setEditing(null);
|
||||
await load();
|
||||
}
|
||||
async function del(id: string) {
|
||||
if (!confirm('确认删除该菜单?')) return;
|
||||
await api.deleteModule(id);
|
||||
await load();
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={wrap}>
|
||||
<div style={card}>
|
||||
<h2>菜单管理</h2>
|
||||
<button style={btn} onClick={() => openEdit()}>
|
||||
新增菜单
|
||||
</button>
|
||||
<table style={tableStyle}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style={th}>名称</th>
|
||||
<th style={th}>地址(key)</th>
|
||||
<th style={th}>上级</th>
|
||||
<th style={th}>排序</th>
|
||||
<th style={th}>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((r) => (
|
||||
<tr key={r.id}>
|
||||
<td style={td}>{r.fullName}</td>
|
||||
<td style={td}>{r.urlAddress}</td>
|
||||
<td style={td}>{nameOf(r.parentId)}</td>
|
||||
<td style={td}>{r.sortCode}</td>
|
||||
<td style={td}>
|
||||
<button style={btnGhost} onClick={() => openEdit(r)}>
|
||||
编辑
|
||||
</button>{' '}
|
||||
<button style={btnDanger} onClick={() => del(r.id)}>
|
||||
删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{editing && (
|
||||
<div style={{ ...card, marginTop: 16 }}>
|
||||
<h3>{editing.id ? '编辑' : '新增'}菜单</h3>
|
||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="菜单名"
|
||||
value={form.fullName}
|
||||
onChange={(e) => setForm({ ...form, fullName: e.target.value })}
|
||||
/>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="地址(key) 如 system/User"
|
||||
value={form.urlAddress}
|
||||
onChange={(e) => setForm({ ...form, urlAddress: e.target.value })}
|
||||
/>
|
||||
<select
|
||||
style={input}
|
||||
value={form.parentId}
|
||||
onChange={(e) => setForm({ ...form, parentId: e.target.value })}
|
||||
>
|
||||
<option value="0">(根)</option>
|
||||
{rows
|
||||
.filter((r) => r.id !== editing?.id)
|
||||
.map((r) => (
|
||||
<option key={r.id} value={r.id}>
|
||||
{r.fullName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
style={input}
|
||||
value={form.type}
|
||||
onChange={(e) => setForm({ ...form, type: +e.target.value })}
|
||||
>
|
||||
<option value={1}>目录</option>
|
||||
<option value={2}>页面</option>
|
||||
<option value={3}>按钮</option>
|
||||
</select>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="图标"
|
||||
value={form.icon}
|
||||
onChange={(e) => setForm({ ...form, icon: e.target.value })}
|
||||
/>
|
||||
<input
|
||||
style={input}
|
||||
type="number"
|
||||
placeholder="排序"
|
||||
value={form.sortCode}
|
||||
onChange={(e) => setForm({ ...form, sortCode: +e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||
<button style={btn} onClick={submit}>
|
||||
保存
|
||||
</button>
|
||||
<button style={btnGhost} onClick={() => setEditing(null)}>
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import * as api from '../api/sys';
|
||||
import { wrap, card, btn, btnDanger, btnGhost, input, tableStyle, th, td } from './ui';
|
||||
|
||||
export default function OrganizeManage() {
|
||||
const [rows, setRows] = useState<any[]>([]);
|
||||
const [editing, setEditing] = useState<any>(null);
|
||||
const [form, setForm] = useState({ fullName: '', parentId: '0' });
|
||||
|
||||
async function load() {
|
||||
setRows(await api.listOrganize());
|
||||
}
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
const nameOf = (id: string) =>
|
||||
id === '0' ? '(根)' : (rows.find((r) => r.id === id)?.fullName ?? id);
|
||||
|
||||
function openEdit(r?: any) {
|
||||
if (r) setForm({ fullName: r.fullName, parentId: r.parentId || '0' });
|
||||
else setForm({ fullName: '', parentId: '0' });
|
||||
setEditing(r || {});
|
||||
}
|
||||
async function submit() {
|
||||
if (!form.fullName) return alert('机构名必填');
|
||||
await api.saveOrganize({ ...form, id: editing?.id });
|
||||
setEditing(null);
|
||||
await load();
|
||||
}
|
||||
async function del(id: string) {
|
||||
if (!confirm('确认删除该机构?')) return;
|
||||
try {
|
||||
await api.deleteOrganize(id);
|
||||
} catch (e: any) {
|
||||
return alert(e.message || '删除失败');
|
||||
}
|
||||
await load();
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={wrap}>
|
||||
<div style={card}>
|
||||
<h2>机构管理</h2>
|
||||
<button style={btn} onClick={() => openEdit()}>
|
||||
新增机构
|
||||
</button>
|
||||
<table style={tableStyle}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style={th}>名称</th>
|
||||
<th style={th}>上级</th>
|
||||
<th style={th}>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((r) => (
|
||||
<tr key={r.id}>
|
||||
<td style={td}>{r.fullName}</td>
|
||||
<td style={td}>{nameOf(r.parentId)}</td>
|
||||
<td style={td}>
|
||||
<button style={btnGhost} onClick={() => openEdit(r)}>
|
||||
编辑
|
||||
</button>{' '}
|
||||
<button style={btnDanger} onClick={() => del(r.id)}>
|
||||
删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{editing && (
|
||||
<div style={{ ...card, marginTop: 16 }}>
|
||||
<h3>{editing.id ? '编辑' : '新增'}机构</h3>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="机构名"
|
||||
value={form.fullName}
|
||||
onChange={(e) => setForm({ ...form, fullName: e.target.value })}
|
||||
/>
|
||||
<select
|
||||
style={input}
|
||||
value={form.parentId}
|
||||
onChange={(e) => setForm({ ...form, parentId: e.target.value })}
|
||||
>
|
||||
<option value="0">(根)</option>
|
||||
{rows
|
||||
.filter((r) => r.id !== editing?.id)
|
||||
.map((r) => (
|
||||
<option key={r.id} value={r.id}>
|
||||
{r.fullName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||
<button style={btn} onClick={submit}>
|
||||
保存
|
||||
</button>
|
||||
<button style={btnGhost} onClick={() => setEditing(null)}>
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { listProducts, saveProduct, deleteProduct } from '../api/product';
|
||||
import { wrap, card, btn, btnDanger, input as inputStyle, tableStyle, th, td } from './ui';
|
||||
|
||||
// 字段用去前缀名:id / title / price(后端 Jackson 会剥掉 f_ 前缀)
|
||||
interface Product {
|
||||
id: string;
|
||||
title?: string;
|
||||
price?: string;
|
||||
}
|
||||
|
||||
export default function Product() {
|
||||
const [items, setItems] = useState<Product[]>([]);
|
||||
const [title, setTitle] = useState('');
|
||||
const [price, setPrice] = useState('');
|
||||
|
||||
async function load() {
|
||||
const data = await listProducts();
|
||||
setItems(data || []);
|
||||
}
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
async function add() {
|
||||
if (!title) return;
|
||||
await saveProduct({ title, price: price || '0.00' });
|
||||
setTitle('');
|
||||
setPrice('');
|
||||
load();
|
||||
}
|
||||
async function del(id: string) {
|
||||
await deleteProduct(id);
|
||||
load();
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={wrap}>
|
||||
<div style={card}>
|
||||
<h2 style={{ margin: 0 }}>产品管理</h2>
|
||||
<div style={{ display: 'flex', gap: 8, margin: '12px 0' }}>
|
||||
<input
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="产品名称"
|
||||
style={inputStyle}
|
||||
/>
|
||||
<input
|
||||
value={price}
|
||||
onChange={(e) => setPrice(e.target.value)}
|
||||
placeholder="价格"
|
||||
style={{ ...inputStyle, width: 100 }}
|
||||
/>
|
||||
<button style={btn} onClick={add}>
|
||||
新增
|
||||
</button>
|
||||
<button style={{ ...btn, background: '#2a3340' }} onClick={() => history.back()}>
|
||||
返回
|
||||
</button>
|
||||
</div>
|
||||
<table style={tableStyle}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style={th}>名称</th>
|
||||
<th style={th}>价格</th>
|
||||
<th style={th}>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{items.map((it) => (
|
||||
<tr key={it.id}>
|
||||
<td style={td}>{it.title}</td>
|
||||
<td style={td}>¥{it.price}</td>
|
||||
<td style={td}>
|
||||
<button style={btnDanger} onClick={() => del(it.id)}>
|
||||
删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{items.length === 0 && (
|
||||
<tr>
|
||||
<td style={td} colSpan={3}>
|
||||
暂无数据
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import * as api from '../api/sys';
|
||||
import { wrap, card, btn, btnDanger, btnGhost, input, tableStyle, th, td } from './ui';
|
||||
|
||||
export default function RoleManage() {
|
||||
const [rows, setRows] = useState<any[]>([]);
|
||||
const [modules, setModules] = useState<any[]>([]);
|
||||
const [editing, setEditing] = useState<any>(null);
|
||||
const [form, setForm] = useState({ fullName: '', enCode: '', description: '' });
|
||||
// 授权面板
|
||||
const [authRoleId, setAuthRoleId] = useState('');
|
||||
const [checked, setChecked] = useState<string[]>([]);
|
||||
|
||||
async function load() {
|
||||
setRows(await api.listRoles());
|
||||
setModules(await api.listModules());
|
||||
}
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
function openEdit(r?: any) {
|
||||
if (r) setForm({ fullName: r.fullName, enCode: r.enCode || '', description: r.description || '' });
|
||||
else setForm({ fullName: '', enCode: '', description: '' });
|
||||
setEditing(r || {});
|
||||
}
|
||||
async function submit() {
|
||||
if (!form.fullName) return alert('角色名必填');
|
||||
await api.saveRole({ ...form, id: editing?.id });
|
||||
setEditing(null);
|
||||
await load();
|
||||
}
|
||||
async function del(id: string) {
|
||||
if (!confirm('确认删除该角色?')) return;
|
||||
await api.deleteRole(id);
|
||||
await load();
|
||||
}
|
||||
async function openAuth(roleId: string) {
|
||||
setAuthRoleId(roleId);
|
||||
const ids = (await api.roleModules(roleId)) || [];
|
||||
setChecked(ids);
|
||||
}
|
||||
async function saveAuth() {
|
||||
await api.saveRoleModules(authRoleId, checked);
|
||||
alert('授权已保存');
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={wrap}>
|
||||
<div style={card}>
|
||||
<h2>角色管理</h2>
|
||||
<button style={btn} onClick={() => openEdit()}>
|
||||
新增角色
|
||||
</button>
|
||||
<table style={tableStyle}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style={th}>角色名</th>
|
||||
<th style={th}>编码</th>
|
||||
<th style={th}>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((r) => (
|
||||
<tr key={r.id}>
|
||||
<td style={td}>{r.fullName}</td>
|
||||
<td style={td}>{r.enCode}</td>
|
||||
<td style={td}>
|
||||
<button style={btnGhost} onClick={() => openEdit(r)}>
|
||||
编辑
|
||||
</button>{' '}
|
||||
<button style={btnGhost} onClick={() => openAuth(r.id)}>
|
||||
授权菜单
|
||||
</button>{' '}
|
||||
<button style={btnDanger} onClick={() => del(r.id)}>
|
||||
删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{editing && (
|
||||
<div style={{ ...card, marginTop: 16 }}>
|
||||
<h3>{editing.id ? '编辑' : '新增'}角色</h3>
|
||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="角色名"
|
||||
value={form.fullName}
|
||||
onChange={(e) => setForm({ ...form, fullName: e.target.value })}
|
||||
/>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="编码"
|
||||
value={form.enCode}
|
||||
onChange={(e) => setForm({ ...form, enCode: e.target.value })}
|
||||
/>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="描述"
|
||||
value={form.description}
|
||||
onChange={(e) => setForm({ ...form, description: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||
<button style={btn} onClick={submit}>
|
||||
保存
|
||||
</button>
|
||||
<button style={btnGhost} onClick={() => setEditing(null)}>
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{authRoleId && (
|
||||
<div style={{ ...card, marginTop: 16 }}>
|
||||
<h3>角色菜单授权({authRoleId})</h3>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
{modules.map((m) => (
|
||||
<label key={m.id}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked.includes(m.id)}
|
||||
onChange={(e) =>
|
||||
setChecked((prev) =>
|
||||
e.target.checked
|
||||
? [...prev, m.id]
|
||||
: prev.filter((x) => x !== m.id),
|
||||
)
|
||||
}
|
||||
/>{' '}
|
||||
{m.fullName}
|
||||
<span style={{ color: '#7a8794' }}> ({m.urlAddress})</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||
<button style={btn} onClick={saveAuth}>
|
||||
保存授权
|
||||
</button>
|
||||
<button style={btnGhost} onClick={() => setAuthRoleId('')}>
|
||||
关闭
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import * as api from '../api/sys';
|
||||
import { wrap, card, btn, btnDanger, btnGhost, input, tableStyle, th, td } from './ui';
|
||||
|
||||
export default function UserManage() {
|
||||
const [rows, setRows] = useState<any[]>([]);
|
||||
const [roleOptions, setRoleOptions] = useState<any[]>([]);
|
||||
const [editing, setEditing] = useState<any>(null);
|
||||
const [form, setForm] = useState({
|
||||
account: '',
|
||||
realName: '',
|
||||
password: '',
|
||||
isAdministrator: false,
|
||||
roleIds: [] as string[],
|
||||
});
|
||||
|
||||
async function load() {
|
||||
setRows(await api.listUsers());
|
||||
setRoleOptions(await api.listRoles());
|
||||
}
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
function openEdit(r?: any) {
|
||||
if (r)
|
||||
setForm({
|
||||
account: r.account,
|
||||
realName: r.realName || '',
|
||||
password: '',
|
||||
isAdministrator: r.isAdministrator === 1,
|
||||
roleIds: r.roleIds || [],
|
||||
});
|
||||
else setForm({ account: '', realName: '', password: '', isAdministrator: false, roleIds: [] });
|
||||
setEditing(r || {});
|
||||
}
|
||||
async function submit() {
|
||||
if (!form.account) return alert('账号必填');
|
||||
await api.saveUser({ ...form, id: editing?.id });
|
||||
setEditing(null);
|
||||
await load();
|
||||
}
|
||||
async function del(id: string) {
|
||||
if (!confirm('确认删除该用户?')) return;
|
||||
await api.deleteUser(id);
|
||||
await load();
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={wrap}>
|
||||
<div style={card}>
|
||||
<h2>用户管理</h2>
|
||||
<button style={btn} onClick={() => openEdit()}>
|
||||
新增用户
|
||||
</button>
|
||||
<table style={tableStyle}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style={th}>账号</th>
|
||||
<th style={th}>姓名</th>
|
||||
<th style={th}>角色</th>
|
||||
<th style={th}>管理员</th>
|
||||
<th style={th}>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((r) => (
|
||||
<tr key={r.id}>
|
||||
<td style={td}>{r.account}</td>
|
||||
<td style={td}>{r.realName}</td>
|
||||
<td style={td}>{(r.roleNames || []).join(',')}</td>
|
||||
<td style={td}>{r.isAdministrator === 1 ? '是' : '否'}</td>
|
||||
<td style={td}>
|
||||
<button style={btnGhost} onClick={() => openEdit(r)}>
|
||||
编辑
|
||||
</button>{' '}
|
||||
<button style={btnDanger} onClick={() => del(r.id)}>
|
||||
删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{editing && (
|
||||
<div style={{ ...card, marginTop: 16 }}>
|
||||
<h3>{editing.id ? '编辑' : '新增'}用户</h3>
|
||||
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center' }}>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="账号"
|
||||
value={form.account}
|
||||
onChange={(e) => setForm({ ...form, account: e.target.value })}
|
||||
/>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="姓名"
|
||||
value={form.realName}
|
||||
onChange={(e) => setForm({ ...form, realName: e.target.value })}
|
||||
/>
|
||||
<input
|
||||
style={input}
|
||||
placeholder="密码(留空不改)"
|
||||
type="password"
|
||||
value={form.password}
|
||||
onChange={(e) => setForm({ ...form, password: e.target.value })}
|
||||
/>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.isAdministrator}
|
||||
onChange={(e) => setForm({ ...form, isAdministrator: e.target.checked })}
|
||||
/>{' '}
|
||||
管理员
|
||||
</label>
|
||||
<select
|
||||
multiple
|
||||
style={input}
|
||||
value={form.roleIds}
|
||||
onChange={(e) =>
|
||||
setForm({
|
||||
...form,
|
||||
roleIds: Array.from(e.target.selectedOptions).map((o) => o.value),
|
||||
})
|
||||
}
|
||||
>
|
||||
{roleOptions.map((r) => (
|
||||
<option key={r.id} value={r.id}>
|
||||
{r.fullName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div style={{ marginTop: 12, display: 'flex', gap: 8 }}>
|
||||
<button style={btn} onClick={submit}>
|
||||
保存
|
||||
</button>
|
||||
<button style={btnGhost} onClick={() => setEditing(null)}>
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { CSSProperties } from 'react';
|
||||
|
||||
export const wrap: CSSProperties = {
|
||||
minHeight: '100vh',
|
||||
padding: 24,
|
||||
background: '#0f1419',
|
||||
color: '#eee',
|
||||
fontFamily: 'system-ui, sans-serif',
|
||||
};
|
||||
export const card: CSSProperties = {
|
||||
background: '#1a1f26',
|
||||
borderRadius: 12,
|
||||
padding: 20,
|
||||
};
|
||||
export const btn: CSSProperties = {
|
||||
padding: '8px 14px',
|
||||
borderRadius: 6,
|
||||
border: 0,
|
||||
background: '#185fa5',
|
||||
color: '#fff',
|
||||
cursor: 'pointer',
|
||||
};
|
||||
export const btnDanger: CSSProperties = { ...btn, background: '#a1322b' };
|
||||
export const btnGhost: CSSProperties = { ...btn, background: '#2a3340' };
|
||||
export const input: CSSProperties = {
|
||||
padding: 8,
|
||||
borderRadius: 6,
|
||||
border: '1px solid #333',
|
||||
background: '#0f1419',
|
||||
color: '#eee',
|
||||
};
|
||||
export const tableStyle: CSSProperties = {
|
||||
width: '100%',
|
||||
borderCollapse: 'collapse',
|
||||
marginTop: 12,
|
||||
};
|
||||
export const th: CSSProperties = {
|
||||
textAlign: 'left',
|
||||
padding: '8px',
|
||||
borderBottom: '1px solid #2a3340',
|
||||
color: '#9aa7b5',
|
||||
};
|
||||
export const td: CSSProperties = {
|
||||
padding: '8px',
|
||||
borderBottom: '1px solid #1f2630',
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"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",
|
||||
"strict": false,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
host: '127.0.0.1', // macOS 上 vite 默认只 bind ::1 (IPv6),强制 IPv4 避免 127.0.0.1 被 reset
|
||||
port: 5173,
|
||||
strictPort: true, // 端口被占直接报错而不是自动换端口(让 perm-smoke 端口断言稳定)
|
||||
proxy: {
|
||||
// 所有 /api 请求转发到 NestJS 后端(30010),与 JNPF 网关代理一致
|
||||
'/api': 'http://127.0.0.1:30010',
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user