chore(模块): 对脚手架做了些更改

This commit is contained in:
cclu 2025-02-27 19:50:31 +08:00
parent beb008c078
commit 6ed190d92e
11 changed files with 233 additions and 18 deletions

View File

@ -1,5 +1,5 @@
// import { defineConfig } from "umi";
// import proxy from './proxy';
import proxy from './proxy';
//不使用defineConfig则能在其他地方获取这些配置
export default {
@ -11,5 +11,105 @@ export default {
title: 'UMI4 Admin',
favicons: [
'/favicon.svg'
],
routes: [
{
id: 1,
key: '1',
path: '/',
redirect: '',
name: '首页'
},
{
id: 2,
key: '2',
name: '关于',
path: '/about',
redirect: '/about/m',
routes: [
{
id: 21,
key: '2-1',
name: '关于你',
path: '/about/u',
redirect: '/about/u/1',
pid: 2,
routes: [
{
id: 211,
key: '2-1-1',
name: '关于你1',
path: '/about/u/index',
redirect: '',
pid: 21
},
{
id: 212,
key: '2-1-2',
name: '关于你2',
path: '/about/u/2',
redirect: '',
pid: 21
}
]
},
{
id: 22,
key: '2-2',
path: '/about/m',
redirect: '',
name: '(页面元素权限)关于我',
pid: 2
},
{
id: 23,
key: '2-3',
path: '/about/um',
redirect: '',
name: '关于你和我',
pid: 2
}
]
},
{
id: 3,
key: '3',
name: '教师',
path: '/teacher',
redirect: '/teacher/u',
routes: [
{
id: 31,
key: '3-1',
path: '/teacher/u',
redirect: '',
name: '(403)关于你教师',
pid: 3
},
{
id: 32,
key: '3-2',
path: '/teacher/m',
redirect: '',
name: '关于我教师',
pid: 3
},
{
id: 33,
key: '3-3',
path: '/teacher/um',
redirect: '',
name: '关于你和我教师',
pid: 3
}
]
},
{
id: 4,
key: '4',
name: '(404)学生',
path: '/student',
redirect: '',
}
]
};

View File

@ -1,7 +1,8 @@
const proxy = {
'/api': {
target: 'https://preview.pro.ant.design',
changeOrigin: true
target: 'http://10.104.1.38:3000',
changeOrigin: true,
pathRewrite: { '^/api': '' },
}
}

View File

@ -20,12 +20,12 @@ const handleCommonRes = (data: Record<string, unknown> | Record<string, unknown>
const userApi = {
//登录
'POST /api/user/login': async (req: Request, res: Response) => {
const { UserPassWord, UserPassport, mobile, captcha } = req.body;
const { password, username, mobile, captcha } = req.body;
await waitTime(2000);
switch (true) {
case UserPassport === 'admin' && UserPassWord === 'ant.design':
case UserPassport === 'user' && UserPassWord === 'ant.design':
case username === 'admin' && password === 'ant.design':
case username === 'user' && password === 'ant.design':
case /^1\d{10}$/.test(mobile) && Boolean(captcha):
res.send(
handleCommonRes({
@ -159,7 +159,7 @@ const userApi = {
id: 211,
key: '2-1-1',
name: '关于你1',
path: '/about/u/1',
path: '/about/u/index',
redirect: '',
pid: 21
},

View File

@ -13,6 +13,7 @@
"@ant-design/pro-components": "^2.8.6",
"antd": "^5.21.2",
"axios": "^1.7.7",
"crypto-js": "^4.2.0",
"dva": "^3.0.0-alpha.1",
"umi": "^4.3.24"
},

View File

@ -49,6 +49,8 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
const [collapsed, setCollapsed] = useState(false);
const [openKeys, setOpenKeys] = useState(['']);
const { pathname } = useLocation();
const {
dispatch,
user: {
@ -139,6 +141,8 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
// ];
console.log('consumableMenu', consumableMenu);
const location = useLocation();
console.log('location', location);
// 改变panes
const handleTabsPanes = (payload: any): void => {
@ -183,7 +187,7 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
guid: "2",
hideInMenu: false,
name: "关于你1",
path: "/about/u/1",
path: "/about/u/index",
},
{
SYSTEMMODULE_DESC: "",

View File

@ -108,6 +108,7 @@ const UserModel: UserModelType = {
effects: {
//登录
*login({ payload }, { call, put }) {
console.log('payload', payload);
yield put({
type: 'save',
@ -117,6 +118,7 @@ const UserModel: UserModelType = {
});
const res: API.LoginResponse = yield call(userLogin, payload);
console.log('res', res);
//登录成功之后设置token并获取用户信息等数据
if (!res.code) {

View File

@ -1,9 +1,10 @@
const authority: PageAuthority = {
'/': [
'/',
],
'/about/u/1': [
'/about/u/1',
'/about/u/index': [
'/about/u/index',
],
'/about/u/2': [
'/about/u/2',

View File

@ -88,8 +88,7 @@ const Index: FC<UserConnectedProps> = (props) => {
}}
>
<ProFormText
name="UserPassport"
name="username"
fieldProps={{
size: 'large',
prefix: <UserOutlined className={styles.prefixIcon} />,
@ -103,7 +102,7 @@ const Index: FC<UserConnectedProps> = (props) => {
]}
/>
<ProFormText.Password
name="UserPassWord"
name="password"
fieldProps={{
size: 'large',
prefix: <LockFilled className={styles.prefixIcon} />,

View File

@ -1,9 +1,21 @@
import request from '@/utils/request';
//登录
export const userLogin = (params: Record<string, unknown>): Promise<API.LoginResponse> => (
request.post('/api/user/login', params)
);
// export const userLogin = (params: Record<string, unknown>): Promise<API.LoginResponse> => (
// request.post('/api/user/login', params)
// );
// 登录
export async function userLogin(params: any) {
console.log('paramsuserLogin', params);
const data = await request.post('/api/user/login', params)
// const data = await request.post('/auth/login', params)
console.log('data', data);
return data
}
//获取用户信息
export const retrieveUserInfo = (): Promise<API.UserInfoResponse> => (

View File

@ -2,15 +2,23 @@ import axios from 'axios';
import { getDvaApp } from 'umi';
import { notification } from 'antd';
import type { AxiosRequestHeaders } from 'axios/index';
import CryptoJS from "crypto-js";
const { UMI_APP_BASEURL } = process.env;
const instance = axios.create({ baseURL: UMI_APP_BASEURL });
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
// const instance = axios.create({ baseURL: '/api' });
instance.interceptors.request.use(
(config) => {
// 对data数据进行加密
// if (config.data) {
// config.data = preprocessData(JSON.stringify(config.data)); // 调用预处理函数
// }
config.headers = {
...config.headers,
Authorization: localStorage.getItem('Authorization') || '',
@ -27,13 +35,19 @@ instance.interceptors.response.use(
const { data } = response;
const { code } = data;
if (code) {
if (code !== 200) {
notification.error({
message: data.message,
});
}
return data;
const timestamp = getFormattedDate()
// let res = JSON.parse(decryptAESECB(data.data, timestamp))
// return res;
// console.log('resdsa', data);
return data
},
//状态码不为2xx的时候执行
(error) => {
@ -72,4 +86,80 @@ instance.interceptors.response.use(
},
);
// 加密
const encryptAESECB = (data: string, key: string) => {
// const cipher = CryptoJS.createCipheriv('aes-128-ecb', key, null); // ECB 模式不需要 IV
const newKey = CryptoJS.enc.Utf8.parse(key); // 密钥必须是 16 字节
const cipher = CryptoJS.AES.encrypt(data, newKey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
let encrypted = cipher.ciphertext.toString(CryptoJS.enc.Hex);
// let encrypted = cipher.update(data, 'utf8', 'hex');
// encrypted += cipher.final('hex');
return encrypted;
}
// 解密
const decryptAESECB = (data: string, key: string) => {
// const decipher = CryptoJS.createDecipheriv('aes-128-ecb', key, null);
// let decrypted = decipher.update(data, 'hex', 'utf8');
// decrypted += decipher.final('utf8');
const newKey = CryptoJS.enc.Utf8.parse(key);
const encryptedData = CryptoJS.enc.Hex.parse(data);
// 解密操作
const decrypted = CryptoJS.AES.decrypt({ ciphertext: encryptedData }, newKey, {
mode: CryptoJS.mode.ECB, // ECB 模式
padding: CryptoJS.pad.Pkcs7 // PKCS7 填充方式
});
// 将解密后的结果转为 UTF-8 字符串
const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
return decryptedText;
}
// md5 签名
const md5 = (key: string, data: string, timestamp: string) => {
const text = "s" + key + data + timestamp;
return CryptoJS.MD5(text).toString(CryptoJS.enc.Hex);
}
// 生成签名戳
const getFormattedDate = () => {
const date = new Date();
const year = date.getFullYear(); // 获取年份 (yyyy)
const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份 (MM)
const day = String(date.getDate()).padStart(2, '0'); // 获取日期 (dd)
const hours = String(date.getHours()).padStart(2, '0'); // 获取小时 (HH)
return `es0${year}${month}${day}${hours}0es`; // 拼接成 yyyyMMddHH 格式
}
// 加密方法
const preprocessData = (data: string) => {
console.log('data', data);
// YYYYMMDD
let timestamp = getFormattedDate()
console.log('timestamp', timestamp);
// 秒为单位的时间戳
let timeSecond = parseInt((new Date().getTime() / 1000).toString())
console.log('timeSecond', timeSecond);
// 数据的加密
let encryptionData = encryptAESECB(data, timestamp)
console.log('encryptionData', encryptionData);
// md5签名方法
let md5Data = md5(timestamp, encryptionData, timestamp)
console.log('md5Data', md5Data);
let res = {
data: encryptionData,
timestamp: timeSecond,
sign: md5Data
}
console.log('res', res);
return res
}
export default instance;

View File

@ -4630,6 +4630,11 @@ crypto-browserify@^3.11.0:
randombytes "^2.1.0"
randomfill "^1.0.4"
crypto-js@^4.2.0:
version "4.2.0"
resolved "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631"
integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==
css-blank-pseudo@^3.0.3:
version "3.0.3"
resolved "https://registry.npmmirror.com/css-blank-pseudo/-/css-blank-pseudo-3.0.3.tgz#36523b01c12a25d812df343a32c322d2a2324561"